	.section	.text
	.global	memmove
	.global	__aeabi_memmove
	.type	memmove, %function
memmove:
__aeabi_memmove:
	sub	sp, sp, #16
	str	r0, [sp, #12]	@ Save dst
	str	r1, [sp, #8]	@ Save src
	str	r2, [sp, #4]	@ Save length
	cmp	r1, r0		@ src < dst
	bcs	loop_two
	add	r1, r1, r2
	str	r1, [sp, #8]	@ src += length
	add	r0, r0, r2
	str	r0, [sp, #12]	@ dst += length
	b	loop_one
copy_and_decrement:
	ldr	r0, [sp, #8]
	sub	r0, r0, #1
	str	r0, [sp, #8]	@ src--
	ldr	r1, [sp, #12]
	sub	r1, r1, #1
	str	r1, [sp, #12]	@ dst--
	ldrb	r0, [r0]	@ r0 = *r0
	strb	r0, [r1]	@ *dst = *src, after subtraction
loop_one:
	ldr	r0, [sp, #4]
	subs	r1, r0, #1
	str	r1, [sp, #4]	@ length -= one
	cmp	r0, #0		@ length == zero
	bne	copy_and_decrement
	b	end
copy_and_increment:
	ldr	r0, [sp, #8]
	add	r1, r0, #1
	str	r1, [sp, #8]	@ src++
	ldr	r1, [sp, #12]
	add	r2, r1, #1
	str	r2, [sp, #12]	@ dst++
	ldrb	r0, [r0]	@ r0 = *r0
	strb	r0, [r1]	@ *dst = *src, before subtraction
loop_two:
	ldr	r0, [sp, #4]
	subs	r1, r0, #1
	str	r1, [sp, #4]	@ length -= one
	cmp	r0, #0		@ length == 0
	bne	copy_and_increment
end:
	add	sp, sp, #16
	mov	pc, lr		@ Return
