// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/arch/arm32/arm_heap.c
// Function: prv_move_block_to_start
static void prv_move_block_to_start(subtilis_arm_section_t *arm_s,
				    size_t good_label, size_t bad_label,
				    size_t slot12_alloc_label,
				    subtilis_error_t *err)
{
	subtilis_arm_br_instr_t *br;
	subtilis_arm_instr_t *instr;
	subtilis_arm_stran_instr_t *stran;
	const subtilis_arm_reg_t requested_size = 1;
	const subtilis_arm_reg_t heap_start = 0;
	const subtilis_arm_reg_t last_slot = 2;
	const subtilis_arm_reg_t previous_block = 3;
	const subtilis_arm_reg_t block_to_move = 5;
	const subtilis_arm_reg_t next_ptr = 6;
	const subtilis_arm_reg_t first_block = 7;

	subtilis_arm_add_stran_imm(arm_s, SUBTILIS_ARM_INSTR_LDR,
				   SUBTILIS_ARM_CCODE_AL, next_ptr,
				   block_to_move, 4, false, 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 = first_block;
	stran->base = heap_start;
	stran->offset.type = SUBTILIS_ARM_OP2_SHIFTED;
	stran->offset.op.shift.reg = last_slot;
	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, next_ptr,
				   previous_block, 4, false, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_add_stran_imm(arm_s, SUBTILIS_ARM_INSTR_STR,
				   SUBTILIS_ARM_CCODE_AL, first_block,
				   block_to_move, 4, false, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	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_to_move;
	stran->base = heap_start;
	stran->offset.type = SUBTILIS_ARM_OP2_SHIFTED;
	stran->offset.op.shift.reg = last_slot;
	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_mov_reg(arm_s, SUBTILIS_ARM_CCODE_AL, false,
				 previous_block, block_to_move, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_add_mov_reg(arm_s, SUBTILIS_ARM_CCODE_AL, false,
				 block_to_move, requested_size, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	instr =
	    subtilis_arm_section_add_instr(arm_s, SUBTILIS_ARM_INSTR_B, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	br = &instr->operands.br;
	br->ccode = SUBTILIS_ARM_CCODE_AL;
	br->link = false;
	br->target.label = slot12_alloc_label;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
movl $0x6, %ecx
movl $0x5, %r8d
movl $0x12, %esi
movl $0xe, %edx
movl $0x4, %r9d
pushq %r14
pushq $0x0
callq 0x5067b
addq $0x10, %rsp
cmpl $0x0, (%r14)
jne 0x623ae
movq %r15, %rdi
movl $0x12, %esi
movq %r14, %rdx
callq 0x4f73a
cmpl $0x0, (%r14)
jne 0x623ae
movl $0xe, 0x8(%rax)
movq $0x7, 0x10(%rax)
movq $0x0, 0x18(%rax)
movl $0x2, %ecx
movl %ecx, 0x20(%rax)
movq $0x2, 0x28(%rax)
xorl %r12d, %r12d
movl %r12d, 0x30(%rax)
movl %ecx, 0x38(%rax)
movb $0x0, 0x40(%rax)
movl $0x1, 0x48(%rax)
movl $0x6, %ecx
movl $0x3, %r8d
movq %r15, %rdi
movl $0x13, %esi
movl $0xe, %edx
movl $0x4, %r9d
pushq %r14
pushq %r12
callq 0x5067b
addq $0x10, %rsp
cmpl %r12d, (%r14)
jne 0x623ae
movl $0x7, %ecx
movl $0x5, %r8d
movq %r15, %rdi
movl $0x13, %esi
movl $0xe, %edx
movl $0x4, %r9d
pushq %r14
pushq $0x0
callq 0x5067b
addq $0x10, %rsp
cmpl $0x0, (%r14)
jne 0x623ae
movq %r15, %rdi
movl $0x13, %esi
movq %r14, %rdx
callq 0x4f73a
cmpl $0x0, (%r14)
jne 0x623ae
movl $0xe, 0x8(%rax)
movq $0x5, 0x10(%rax)
movq $0x0, 0x18(%rax)
movl $0x2, %ecx
movl %ecx, 0x20(%rax)
movq $0x2, 0x28(%rax)
movl $0x0, 0x30(%rax)
movl %ecx, 0x38(%rax)
movb $0x0, 0x40(%rax)
movl $0x1, 0x48(%rax)
subq $0x8, %rsp
movl $0x3, %r8d
movl $0x5, %r9d
movq %r15, %rdi
movl $0xd, %esi
movl $0xe, %edx
xorl %ecx, %ecx
pushq %r14
callq 0x5060d
addq $0x10, %rsp
cmpl $0x0, (%r14)
jne 0x623ae
subq $0x8, %rsp
movl $0x5, %r8d
movl $0x1, %r9d
movq %r15, %rdi
movl $0xd, %esi
movl $0xe, %edx
xorl %ecx, %ecx
pushq %r14
callq 0x5060d
addq $0x10, %rsp
cmpl $0x0, (%r14)
jne 0x623ae
movq %r15, %rdi
movl $0x16, %esi
movq %r14, %rdx
callq 0x4f73a
cmpl $0x0, (%r14)
jne 0x623ae
movl $0xe, 0x8(%rax)
movb $0x0, 0xc(%rax)
movq %rbx, 0x18(%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq