Reverse Engineering challenge #81.

Tags: ARM MIPS ARM64 X64 ASM L1 .

What does this code do?

Optimizing GCC 4.8.4:


f:
	lea	eax, [rdi-1]
	or	edi, -2147483648
	test	eax, edi
	sete	al
	movzx	eax, al
	ret

Optimizing GCC 4.9.3 for ARM64:


f:
        sub     w1, w0, #1
        orr     w0, w0, -2147483648
        tst     w1, w0
        cset    w0, eq
        ret

(ARM) Optimizing Keil 5.05 (ARM mode):


f PROC
        ORR      r1,r0,#0x80000000
        SUB      r0,r0,#1
        TST      r1,r0
        MOVEQ    r0,#1
        MOVNE    r0,#0
        BX       lr
        ENDP

(ARM) Optimizing Keil 5.05 (Thumb mode):


f PROC
        MOVS     r1,#1
        LSLS     r1,r1,#31
        ORRS     r1,r1,r0
        SUBS     r0,r0,#1
        TST      r1,r0
        BNE      |L0.16|
        MOVS     r0,#1
        BX       lr
|L0.16|
        MOVS     r0,#0
        BX       lr
        ENDP

Optimizing GCC 4.4.5 for MIPS:


f:
        li      $2,-2147483648                  # 0xffffffff80000000
        or      $2,$4,$2
        addiu   $4,$4,-1
        and     $2,$4,$2
        j       $31
        sltu    $2,$2,1

More challenges: challenges.re; about solutions: challenges.re/#Solutions.