memcmp32:
        stmfd sp!, {fp, lr}
        add   fp, sp, $4
        mov   r1, r10
        sub   r10, r3, $16
        add   r3, r10, $36
        add   r0, r10, $32
        str   r1, [r0]

        ldr   r2, [r10, $12] @ r2 = size

        ldr   r0, [r10, $4] @ r0 = offset1
        ldr   r1, [r10] @ r1 = mem
        add   r0, r0, r1
        add   r0, r0, r2
        add   r4, r8, r0, lsl $2 @ r4 = &(mem + offset1 + size) 

        ldr   r5, [r10, $8] @ r5 = offset2
        add   r5, r5, r1
        add   r5, r5, r2
        add   r5, r8, r5, lsl $2 @ r5 = &(mem + offset2 + size) 

memcmp32_loop:
        ldr   r0, [r4], $-4
        ldr   r1, [r5], $-4
        cmp   r0, r1
        bgt   memcmp32_negone
        blt   memcmp32_one
        subs  r2, r2, $1
        bpl   memcmp32_loop @ goto loop if r2 >= 0

        @ the memory is equal

        mov   r0, $0
        b     memcmp32_return

memcmp32_negone:
        mov   r0, $1
        mov   r1, $0
        sub   r0, r1, r0
        b     memcmp32_return

memcmp32_one:
        mov   r0, $1

memcmp32_return:
        str   r0, [r10]

@ (function-end 8)
        add   r3, r10, $4
        add   r0, r10, $32
        ldr   r10, [r0]
@ (return)
        ldmfd sp!, {fp, pc}
.ltorg
