// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/arch/arm32/arm_heap.c
// Function: subtilis_arm_heap_free
void subtilis_arm_heap_free(subtilis_arm_section_t *arm_s,
			    subtilis_arm_reg_t heap_start,
			    subtilis_arm_reg_t block, subtilis_error_t *err)
{
	subtilis_arm_stran_instr_t *stran;
	subtilis_arm_instr_t *instr;
	const subtilis_arm_reg_t block_size = 3;
	const subtilis_arm_reg_t ptr = 4;
	const subtilis_arm_reg_t slot_number = 8;
	const subtilis_arm_reg_t scratch = 9;

	subtilis_arm_add_sub_imm(arm_s, SUBTILIS_ARM_CCODE_AL, false, block,
				 block, 8, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_add_stran_imm(arm_s, SUBTILIS_ARM_INSTR_LDR,
				   SUBTILIS_ARM_CCODE_AL, block_size, block, 0,
				   false, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	prv_get_slot(arm_s, block_size, slot_number, scratch, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_add_cmp_imm(arm_s, SUBTILIS_ARM_INSTR_CMP,
				 SUBTILIS_ARM_CCODE_AL, slot_number,
				 subtilis_arm_heap_max_slot, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_add_mov_imm(arm_s, SUBTILIS_ARM_CCODE_GT, false,
				 slot_number, subtilis_arm_heap_max_slot, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	instr =
	    subtilis_arm_section_add_instr(arm_s, SUBTILIS_ARM_INSTR_LDR, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;
	stran = &instr->operands.stran;

	stran->ccode = SUBTILIS_ARM_CCODE_AL;
	stran->dest = ptr;
	stran->base = heap_start;
	stran->offset.type = SUBTILIS_ARM_OP2_SHIFTED;
	stran->offset.op.shift.reg = slot_number;
	stran->offset.op.shift.type = SUBTILIS_ARM_SHIFT_LSL;
	stran->offset.op.shift.shift.integer = 2;
	stran->offset.op.shift.shift_reg = false;
	stran->pre_indexed = true;
	stran->write_back = false;
	stran->subtract = false;
	stran->byte = false;

	instr =
	    subtilis_arm_section_add_instr(arm_s, SUBTILIS_ARM_INSTR_STR, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;
	stran = &instr->operands.stran;

	stran->ccode = SUBTILIS_ARM_CCODE_AL;
	stran->dest = block;
	stran->base = heap_start;
	stran->offset.type = SUBTILIS_ARM_OP2_SHIFTED;
	stran->offset.op.shift.reg = slot_number;
	stran->offset.op.shift.type = SUBTILIS_ARM_SHIFT_LSL;
	stran->offset.op.shift.shift.integer = 2;
	stran->offset.op.shift.shift_reg = false;
	stran->pre_indexed = true;
	stran->write_back = false;
	stran->subtract = false;
	stran->byte = false;

	subtilis_arm_add_stran_imm(arm_s, SUBTILIS_ARM_INSTR_STR,
				   SUBTILIS_ARM_CCODE_AL, ptr, block, 4, false,
				   err);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x3, -0x38(%rbp)
movq $0x4, -0x40(%rbp)
movq $0x8, -0x48(%rbp)
movq $0x9, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %r9
movq -0x18(%rbp), %r10
movq -0x20(%rbp), %rax
movl $0x2, %esi
movl $0x4, %edx
movl $0xe, %ecx
xorl %r8d, %r8d
movq %r10, (%rsp)
movl $0x8, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x71640
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x9094e
jmp 0x90ba7
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %r8
movq -0x20(%rbp), %rax
movl $0x12, %esi
movl $0xe, %edx
movl $0x3, %ecx
xorl %r9d, %r9d
movl $0x0, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x72030
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x9098b
jmp 0x90ba7
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %r8
movl $0x3, %esi
movl $0x8, %edx
movl $0x9, %ecx
callq 0x8e780
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x909b5
jmp 0x90ba7
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %r9
movl $0xa, %esi
movl $0xe, %edx
movl $0x8, %ecx
movl $0xc, %r8d
callq 0x72620
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x909e5
jmp 0x90ba7
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl $0xd, %esi
movl $0xf, %edx
movl $0xc, %ecx
xorl %r8d, %r8d
movl $0x8, %r9d
movl $0xc, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x71b10
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x90a24
jmp 0x90ba7
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
movl $0x12, %esi
callq 0x70b50
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x90a48
jmp 0x90ba7
movq -0x30(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl $0xe, (%rax)
movq -0x28(%rbp), %rax
movq $0x4, 0x8(%rax)
movq -0x10(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rax
movl $0x2, 0x18(%rax)
movq -0x28(%rbp), %rax
movq $0x8, 0x20(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x28(%rax)
movq -0x28(%rbp), %rax
movl $0x2, 0x30(%rax)
movq -0x28(%rbp), %rax
movb $0x0, 0x38(%rax)
movq -0x28(%rbp), %rax
movb $0x1, 0x40(%rax)
movq -0x28(%rbp), %rax
movb $0x0, 0x41(%rax)
movq -0x28(%rbp), %rax
movb $0x0, 0x42(%rax)
movq -0x28(%rbp), %rax
movb $0x0, 0x43(%rax)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
movl $0x13, %esi
callq 0x70b50
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x90aef
jmp 0x90ba7
movq -0x30(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl $0xe, (%rax)
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rax
movl $0x2, 0x18(%rax)
movq -0x28(%rbp), %rax
movq $0x8, 0x20(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x28(%rax)
movq -0x28(%rbp), %rax
movl $0x2, 0x30(%rax)
movq -0x28(%rbp), %rax
movb $0x0, 0x38(%rax)
movq -0x28(%rbp), %rax
movb $0x1, 0x40(%rax)
movq -0x28(%rbp), %rax
movb $0x0, 0x41(%rax)
movq -0x28(%rbp), %rax
movb $0x0, 0x42(%rax)
movq -0x28(%rbp), %rax
movb $0x0, 0x43(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %r8
movq -0x20(%rbp), %rax
movl $0x13, %esi
movl $0xe, %edx
movl $0x4, %ecx
movl $0x4, %r9d
xorl %r10d, %r10d
movl $0x0, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x72030
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)