// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/arch/arm32/arm_heap.c
// Function: prv_split_small_block
static void prv_split_small_block(subtilis_arm_section_t *arm_s,
				  size_t good_label, subtilis_error_t *err)
{
	subtilis_arm_br_instr_t *br;
	subtilis_arm_instr_t *instr;
	subtilis_arm_data_instr_t *datai;
	subtilis_arm_stran_instr_t *stran;
	const subtilis_arm_reg_t heap_start = 0;
	const subtilis_arm_reg_t ret_val = 0;
	const subtilis_arm_reg_t slot_number = 2;
	const subtilis_arm_reg_t slot_ptr = 3;
	const subtilis_arm_reg_t next_slot = 4;
	const subtilis_arm_reg_t block_size = 5;
	const subtilis_arm_reg_t min_slot_size = 8;
	const subtilis_arm_reg_t zero = 9;

	size_t split_up_block_label = arm_s->label_counter++;

	subtilis_arm_add_mov_imm(arm_s, SUBTILIS_ARM_CCODE_AL, false,
				 min_slot_size, subtilis_arm_heap_min_slot_size,
				 err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_add_mov_imm(arm_s, SUBTILIS_ARM_CCODE_AL, false, zero, 0,
				 err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_section_add_label(arm_s, split_up_block_label, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

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

	instr =
	    subtilis_arm_section_add_instr(arm_s, SUBTILIS_ARM_INSTR_MOV, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;
	datai = &instr->operands.data;
	datai->ccode = SUBTILIS_ARM_CCODE_AL;
	datai->status = false;
	datai->dest = block_size;
	datai->op2.type = SUBTILIS_ARM_OP2_SHIFTED;
	datai->op2.op.shift.shift_reg = true;
	datai->op2.op.shift.reg = min_slot_size;
	datai->op2.op.shift.type = SUBTILIS_ARM_SHIFT_LSL;
	datai->op2.op.shift.shift.reg = next_slot;

	subtilis_arm_add_stran_imm(arm_s, SUBTILIS_ARM_INSTR_STR,
				   SUBTILIS_ARM_CCODE_AL, block_size, slot_ptr,
				   0, 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 = slot_ptr;
	stran->base = heap_start;
	stran->offset.type = SUBTILIS_ARM_OP2_SHIFTED;
	stran->offset.op.shift.reg = next_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, zero, slot_ptr, 4,
				   false, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	instr =
	    subtilis_arm_section_add_instr(arm_s, SUBTILIS_ARM_INSTR_ADD, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;
	datai = &instr->operands.data;
	datai->ccode = SUBTILIS_ARM_CCODE_AL;
	datai->status = false;
	datai->dest = slot_ptr;
	datai->op1 = slot_ptr;
	datai->op2.type = SUBTILIS_ARM_OP2_REG;
	datai->op2.op.reg = block_size;

	subtilis_arm_add_cmp(arm_s, SUBTILIS_ARM_INSTR_CMP,
			     SUBTILIS_ARM_CCODE_AL, next_slot, slot_number,
			     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_GT;
	br->link = false;
	br->target.label = split_up_block_label;

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

	subtilis_arm_add_add_imm(arm_s, SUBTILIS_ARM_CCODE_AL, false, ret_val,
				 slot_ptr, 8, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	/* We fallthrough to good label here. */
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movq 0x10(%rdi), %r15
leaq 0x1(%r15), %rax
movq %rax, 0x10(%rdi)
movl $0x8, %r9d
movl $0xd, %esi
movl $0xf, %edx
movl $0xe, %ecx
xorl %r8d, %r8d
pushq %rbx
pushq $0x20
callq 0x50249
addq $0x10, %rsp
cmpl $0x0, (%rbx)
jne 0x62852
movl $0x9, %r9d
movq %r14, %rdi
movl $0xd, %esi
movl $0xf, %edx
movl $0xe, %ecx
xorl %r8d, %r8d
pushq %rbx
pushq $0x0
callq 0x50249
addq $0x10, %rsp
cmpl $0x0, (%rbx)
jne 0x62852
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x4f587
cmpl $0x0, (%rbx)
jne 0x62852
subq $0x8, %rsp
movl $0x4, %r9d
movq %r14, %rdi
movl $0x2, %esi
movl $0x4, %edx
movl $0xe, %ecx
xorl %r8d, %r8d
pushq %rbx
pushq $0x1
pushq $0x4
callq 0x4fe13
addq $0x20, %rsp
cmpl $0x0, (%rbx)
jne 0x62852
movq %r14, %rdi
movl $0xd, %esi
movq %rbx, %rdx
callq 0x4f73a
cmpl $0x0, (%rbx)
jne 0x62852
movl $0xe, 0x8(%rax)
movb $0x0, 0xc(%rax)
movq $0x5, 0x10(%rax)
movl $0x2, 0x20(%rax)
movb $0x1, 0x40(%rax)
movq $0x8, 0x28(%rax)
xorl %r12d, %r12d
movl %r12d, 0x30(%rax)
movq $0x4, 0x38(%rax)
movl $0x5, %ecx
movl $0x3, %r8d
movq %r14, %rdi
movl $0x13, %esi
movl $0xe, %edx
xorl %r9d, %r9d
pushq %rbx
pushq %r12
callq 0x5067b
addq $0x10, %rsp
cmpl %r12d, (%rbx)
jne 0x62852
movq %r14, %rdi
movl $0x13, %esi
movq %rbx, %rdx
callq 0x4f73a
cmpl $0x0, (%rbx)
jne 0x62852
movl $0xe, 0x8(%rax)
movq $0x3, 0x10(%rax)
movq $0x0, 0x18(%rax)
movl $0x2, %ecx
movl %ecx, 0x20(%rax)
movq $0x4, 0x28(%rax)
xorl %r12d, %r12d
movl %r12d, 0x30(%rax)
movl %ecx, 0x38(%rax)
movb $0x0, 0x40(%rax)
movl $0x1, 0x48(%rax)
movl $0x9, %ecx
movl $0x3, %r8d
movq %r14, %rdi
movl $0x13, %esi
movl $0xe, %edx
movl $0x4, %r9d
pushq %rbx
pushq %r12
callq 0x5067b
addq $0x10, %rsp
cmpl %r12d, (%rbx)
jne 0x62852
movq %r14, %rdi
movl $0x4, %esi
movq %rbx, %rdx
callq 0x4f73a
cmpl $0x0, (%rbx)
jne 0x62852
movl $0xe, 0x8(%rax)
movb $0x0, 0xc(%rax)
movl $0x3, %ecx
movq %rcx, 0x10(%rax)
movq %rcx, 0x18(%rax)
movl $0x0, 0x20(%rax)
movq $0x5, 0x28(%rax)
movl $0x4, %ecx
movl $0x2, %r8d
movq %r14, %rdi
movl $0xa, %esi
movl $0xe, %edx
movq %rbx, %r9
callq 0x50b58
cmpl $0x0, (%rbx)
jne 0x62852
movq %r14, %rdi
movl $0x16, %esi
movq %rbx, %rdx
callq 0x4f73a
cmpl $0x0, (%rbx)
jne 0x62852
movl $0xc, 0x8(%rax)
movb $0x0, 0xc(%rax)
movq %r15, 0x18(%rax)
movl $0x5, %ecx
movl $0x3, %r8d
movq %r14, %rdi
movl $0x13, %esi
movl $0xe, %edx
xorl %r9d, %r9d
pushq %rbx
pushq $0x0
callq 0x5067b
addq $0x10, %rsp
cmpl $0x0, (%rbx)
je 0x6285e
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
subq $0x8, %rsp
movq %r14, %rdi
movl $0x4, %esi
movl $0x2, %edx
movl $0xe, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %rbx
pushq $0x8
pushq $0x3
callq 0x4fe13
addq $0x28, %rsp
jmp 0x62856