// File: /workspace/github_c_makefile_star2_O3/markdryan[P]subtilis/arch/arm32/arm_heap.c
// Function: prv_slot12_alloc
static void prv_slot12_alloc(subtilis_arm_section_t *arm_s, size_t good_label,
			     size_t bad_label, size_t exact_slot_size_label,
			     subtilis_error_t *err)
{
	subtilis_arm_br_instr_t *br;
	subtilis_arm_instr_t *instr;
	const subtilis_arm_reg_t ret_val = 0;
	subtilis_arm_data_instr_t *datai;
	const subtilis_arm_reg_t heap_start = 0;
	const subtilis_arm_reg_t segment = 1;
	const subtilis_arm_reg_t first_entry = 3;
	const subtilis_arm_reg_t next_ptr = 4;
	const subtilis_arm_reg_t block_size = 5;
	const subtilis_arm_reg_t scratch2 = 6;
	const subtilis_arm_reg_t split_block_size = 7;
	const subtilis_arm_reg_t split_slot = 8;
	const subtilis_arm_reg_t scratch3 = 9;
	const subtilis_arm_reg_t scratch = 10;
	const subtilis_arm_reg_t max_size_of_block = 10;

	subtilis_arm_add_stran_imm(arm_s, SUBTILIS_ARM_INSTR_LDR,
				   SUBTILIS_ARM_CCODE_AL, next_ptr, first_entry,
				   4, false, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

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

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

	subtilis_arm_add_stran_imm(arm_s, SUBTILIS_ARM_INSTR_STR,
				   SUBTILIS_ARM_CCODE_AL, next_ptr, heap_start,
				   subtilis_arm_heap_max_slot * sizeof(int32_t),
				   false, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

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

	subtilis_arm_add_add_imm(arm_s, SUBTILIS_ARM_CCODE_EQ, false, ret_val,
				 first_entry, 8, 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_EQ;
	br->link = false;
	br->target.label = good_label;

	subtilis_arm_add_mov_reg(arm_s, SUBTILIS_ARM_CCODE_AL, false, scratch,
				 split_block_size, 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 = segment;
	datai->op1 = first_entry;
	datai->op2.type = SUBTILIS_ARM_OP2_REG;
	datai->op2.op.reg = block_size;

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

	subtilis_arm_add_cmp_imm(arm_s, SUBTILIS_ARM_INSTR_CMP,
				 SUBTILIS_ARM_CCODE_AL, split_slot,
				 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,
				 split_slot, subtilis_arm_heap_max_slot, 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_GE;
	br->link = false;
	br->target.label = exact_slot_size_label;

	subtilis_arm_add_mov_imm(arm_s, SUBTILIS_ARM_CCODE_AL, false, scratch3,
				 subtilis_arm_heap_min_slot_size, 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 = scratch;
	datai->op2.type = SUBTILIS_ARM_OP2_SHIFTED;
	datai->op2.op.shift.shift_reg = true;
	datai->op2.op.shift.reg = scratch3;
	datai->op2.op.shift.type = SUBTILIS_ARM_SHIFT_LSL;
	datai->op2.op.shift.shift.reg = split_slot;

	subtilis_arm_add_cmp(arm_s, SUBTILIS_ARM_INSTR_CMP,
			     SUBTILIS_ARM_CCODE_AL, scratch, split_block_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_EQ;
	br->link = false;
	br->target.label = exact_slot_size_label;

	subtilis_arm_add_sub_imm(arm_s, SUBTILIS_ARM_CCODE_AL, false,
				 split_slot, split_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 = max_size_of_block;
	datai->op2.type = SUBTILIS_ARM_OP2_SHIFTED;
	datai->op2.op.shift.shift_reg = false;
	datai->op2.op.shift.reg = max_size_of_block;
	datai->op2.op.shift.type = SUBTILIS_ARM_SHIFT_LSR;
	datai->op2.op.shift.shift.integer = 1;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rcx, %rbx
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
movl $0x4, %ecx
movl $0x3, %r8d
movl $0x12, %esi
movl $0xe, %edx
movl $0x4, %r9d
pushq %rbx
pushq $0x0
callq 0x50516
addq $0x10, %rsp
cmpl $0x0, (%rbx)
jne 0x61a0d
movl $0x6, %ecx
movl $0x3, %r8d
movq %r14, %rdi
movl $0x12, %esi
movl $0xe, %edx
xorl %r9d, %r9d
pushq %rbx
pushq $0x0
callq 0x50516
addq $0x10, %rsp
cmpl $0x0, (%rbx)
jne 0x61a0d
movq %r14, %rdi
movl $0x2, %esi
movq %rbx, %rdx
callq 0x4f6e2
cmpl $0x0, (%rbx)
jne 0x61a0d
movl $0xe, 0x8(%rax)
movb $0x0, 0xc(%rax)
movq $0x7, 0x10(%rax)
movq $0x6, 0x18(%rax)
xorl %r13d, %r13d
movl %r13d, 0x20(%rax)
movq $0x5, 0x28(%rax)
movl $0x4, %ecx
movq %r14, %rdi
movl $0x13, %esi
movl $0xe, %edx
xorl %r8d, %r8d
movl $0x30, %r9d
pushq %rbx
pushq %r13
callq 0x50516
addq $0x10, %rsp
cmpl %r13d, (%rbx)
jne 0x61a0d
movl $0x7, %ecx
movq %r14, %rdi
movl $0xa, %esi
movl $0xe, %edx
xorl %r8d, %r8d
movq %rbx, %r9
callq 0x508d6
cmpl $0x0, (%rbx)
jne 0x61a0d
subq $0x8, %rsp
movq %r14, %rdi
movl $0x4, %esi
movl $0x2, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %rbx
pushq $0x8
pushq $0x3
callq 0x4fd3f
addq $0x20, %rsp
cmpl $0x0, (%rbx)
jne 0x61a0d
movq %r14, %rdi
movl $0x16, %esi
movq %rbx, %rdx
callq 0x4f6e2
cmpl $0x0, (%rbx)
jne 0x61a0d
movl $0x0, 0x8(%rax)
movb $0x0, 0xc(%rax)
movq %r12, 0x18(%rax)
subq $0x8, %rsp
movl $0xa, %r8d
movl $0x7, %r9d
movq %r14, %rdi
movl $0xd, %esi
movl $0xe, %edx
xorl %ecx, %ecx
pushq %rbx
callq 0x504b3
addq $0x10, %rsp
cmpl $0x0, (%rbx)
jne 0x61a0d
movq %r14, %rdi
movl $0x4, %esi
movq %rbx, %rdx
callq 0x4f6e2
cmpl $0x0, (%rbx)
jne 0x61a0d
movl $0xe, 0x8(%rax)
movb $0x0, 0xc(%rax)
movq $0x1, 0x10(%rax)
movq $0x3, 0x18(%rax)
movl $0x0, 0x20(%rax)
movq $0x5, 0x28(%rax)
movl $0xa, %esi
movl $0x8, %edx
movl $0x9, %ecx
movq %r14, %rdi
movq %rbx, %r8
callq 0x6144a
cmpl $0x0, (%rbx)
jne 0x61a0d
movl $0x8, %ecx
movq %r14, %rdi
movl $0xa, %esi
movl $0xe, %edx
movl $0xc, %r8d
movq %rbx, %r9
callq 0x508d6
cmpl $0x0, (%rbx)
jne 0x61a0d
movl $0x8, %r9d
movq %r14, %rdi
movl $0xd, %esi
movl $0xf, %edx
movl $0xc, %ecx
xorl %r8d, %r8d
pushq %rbx
pushq $0xc
callq 0x50130
addq $0x10, %rsp
cmpl $0x0, (%rbx)
jne 0x61a0d
movq %r14, %rdi
movl $0x16, %esi
movq %rbx, %rdx
callq 0x4f6e2
cmpl $0x0, (%rbx)
jne 0x61a0d
movl $0xa, 0x8(%rax)
movb $0x0, 0xc(%rax)
movq %r15, 0x18(%rax)
movl $0x9, %r9d
movq %r14, %rdi
movl $0xd, %esi
movl $0xf, %edx
movl $0xe, %ecx
xorl %r8d, %r8d
pushq %rbx
pushq $0x20
callq 0x50130
addq $0x10, %rsp
cmpl $0x0, (%rbx)
jne 0x61a0d
movq %r14, %rdi
movl $0xd, %esi
movq %rbx, %rdx
callq 0x4f6e2
cmpl $0x0, (%rbx)
jne 0x61a0d
movl $0xe, 0x8(%rax)
movb $0x0, 0xc(%rax)
movq $0xa, 0x10(%rax)
movl $0x2, 0x20(%rax)
movb $0x1, 0x40(%rax)
movq $0x9, 0x28(%rax)
movl $0x0, 0x30(%rax)
movq $0x8, 0x38(%rax)
movl $0xa, %ecx
movl $0x7, %r8d
movq %r14, %rdi
movl $0xa, %esi
movl $0xe, %edx
movq %rbx, %r9
callq 0x5099c
cmpl $0x0, (%rbx)
jne 0x61a0d
movq %r14, %rdi
movl $0x16, %esi
movq %rbx, %rdx
callq 0x4f6e2
cmpl $0x0, (%rbx)
jne 0x61a0d
movl $0x0, 0x8(%rax)
movb $0x0, 0xc(%rax)
movq %r15, 0x18(%rax)
subq $0x8, %rsp
movl $0x8, %r9d
movq %r14, %rdi
movl $0x2, %esi
movl $0x4, %edx
movl $0xe, %ecx
xorl %r8d, %r8d
pushq %rbx
pushq $0x1
pushq $0x8
callq 0x4fd3f
addq $0x20, %rsp
cmpl $0x0, (%rbx)
jne 0x61a0d
movq %r14, %rdi
movl $0xd, %esi
movq %rbx, %rdx
callq 0x4f6e2
cmpl $0x0, (%rbx)
jne 0x61a0d
movl $0xe, 0x8(%rax)
xorl %ecx, %ecx
movb %cl, 0xc(%rax)
movl $0xa, %edx
movq %rdx, 0x10(%rax)
movl $0x2, %esi
movl %esi, 0x20(%rax)
movb %cl, 0x40(%rax)
movq %rdx, 0x28(%rax)
movl %esi, 0x30(%rax)
movl $0x1, 0x38(%rax)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq