	.section	.text
	.global	rand
	.type	rand, %function
rand:
	sub	sp, sp, #8
	str	r0, [sp, #4]	@ Save address of seed
	ldr	r0, [sp, #4]
	ldr	r1, [r0]	@ seed, dereferenced
	ldr	r0, constant
	mul	r3, r1, r0	@ r3 = seed * r0
	add	r3, r3, #12288
	adds	r3, r3, #57	@ r3 = r3 + 12345
	ldr	r1, [sp, #4]
	str	r3, [r1]	@ Save new value of seed
	ldr	r3, [sp, #4]
	ldr	r0, [r3]	@ seed, dereferenced
	str	r0, [sp, #4]	@ Copy seed value to ret
	movs	r0, r0, lsr #11	@ R0 = R0 >> 11
	ldr	r1, [sp, #4]	@ r1 = ret
	eors	r0, r0, r1	@ r0 = r1 ^ r0
	str	r0, [sp, #4]	@ ret ^= ret >> 11
	ldr	r2, [sp, #4]	@ r2 = ret
	movs	r1, r2, lsl #7	@ R1 = R1 << 7
	ldr	r2, (constant + 4)
	ands	r2, r2, r1	@ r2 = r1 & r2
	ldr	r1, [sp, #4]	@ r1 = ret
	eors	r2, r2, r1	@ r2 = r2 ^ r1
	str	r2, [sp, #4]	@ ret ^= ret << 7 & 2636928640
	ldr	r2, [sp, #4]	@ r2 = ret
	movs	r1, r2, lsl #15	@ R1 = R1 << 15
	ldr	r2, (constant + 8)
	ands	r2, r2, r1	@ r1 & r2
	ldr	r1, [sp, #4]
	eors	r2, r2, r1	@ r2 = r1 ^ r2
	str	r2, [sp, #4]	@ ret ^= ret << 15 4022730752
	ldr	r2, [sp, #4]
	movs	r2, r2, lsr #18	@ R2 = R2 >> 18
	ldr	r1, [sp, #4]
	eors	r0, r2, r1	@ ret ^= ret >> 18
	movs	r0, r0, lsr #1	@ ret = ret / 2
	add	sp, sp, #8
	mov	pc, lr		@ Return
constant:
	.word	1103515245
	.word	2636928640
	.word	4022730752
