Challenge RE #27

The challenge #27 is also a short one, but also kind of hacky because the resulting code is not intuitive at all. Here is the assembly code


_a$ = 8
_f	PROC
	mov	ecx, DWORD PTR _a$[esp-4]
	mov	eax, -968154503	; c64b2279H
	imul	ecx ;; edx = eax * ecx
	add	edx, ecx ;; edx += ecx
	sar	edx, 9  ;; edx >>= 9
	mov	eax, edx 
	shr	eax, 31		; 0000001fH => eax = eax >> 31
	add	eax, edx  ;; eax += edx 
	ret	0
_f	ENDP

Analysis

Getting this code into C code is not a hard task, comparing of course with previous cases. Here is the corresponding C code

int f(int a)
{
	int b = (0xc64b2279 * a + a) >> 9;

	return (b >> 31) + b;
}

I’m clueless with this one…no idea, I hate these hacky stuffs.

Conclusion

I’ll leave it unsolved.