// File: /workspace/github_c_makefile_star2_O3/markdryan[P]subtilis/arch/arm32/arm_heap.c
// Function: prv_get_slot
static void prv_get_slot(subtilis_arm_section_t *arm_s,
			 subtilis_arm_reg_t value, subtilis_arm_reg_t ret,
			 subtilis_arm_reg_t scratch, subtilis_error_t *err)
{
	subtilis_arm_data_instr_t *datai;
	subtilis_arm_instr_t *instr;
	int32_t i;
	int32_t masks[5] = {0, 0x2, 0xc, 0xf0, 0xff00};

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

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

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

	subtilis_arm_add_data_imm(arm_s, SUBTILIS_ARM_INSTR_ORR,
				  SUBTILIS_ARM_CCODE_AL, false, scratch,
				  scratch, 0xff0000, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	subtilis_arm_add_cmp(arm_s, SUBTILIS_ARM_INSTR_TST,
			     SUBTILIS_ARM_CCODE_AL, value, scratch, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	for (i = 4; i >= 0; --i) {
		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_NE;
		datai->status = false;
		datai->dest = value;
		datai->op2.type = SUBTILIS_ARM_OP2_SHIFTED;
		datai->op2.op.shift.shift_reg = false;
		datai->op2.op.shift.reg = value;
		datai->op2.op.shift.type = SUBTILIS_ARM_SHIFT_LSR;
		datai->op2.op.shift.shift.integer = 1 << i;

		subtilis_arm_add_data_imm(arm_s, SUBTILIS_ARM_INSTR_ORR,
					  SUBTILIS_ARM_CCODE_NE, false, ret,
					  ret, 1 << i, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;

		if (i == 0)
			break;

		subtilis_arm_add_cmp_imm(arm_s, SUBTILIS_ARM_INSTR_TST,
					 SUBTILIS_ARM_CCODE_AL, value, masks[i],
					 err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
	}

	subtilis_arm_add_sub_imm(arm_s, SUBTILIS_ARM_CCODE_AL, false, ret, ret,
				 subtilis_arm_heap_min_slot_shift - 1, err);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r8, %r14
movq %rcx, %r13
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r15
movl $0xd, %esi
movl $0xf, %edx
movl $0xe, %ecx
xorl %r8d, %r8d
movq %rbx, %r9
pushq %r14
pushq $0x0
callq 0x50130
addq $0x10, %rsp
cmpl $0x0, (%r14)
jne 0x61555
subq $0x8, %rsp
movq %r15, %rdi
movl $0x2, %esi
movl $0x4, %edx
movl $0xe, %ecx
xorl %r8d, %r8d
movq %r12, %r9
pushq %r14
pushq $0x1
pushq %r12
callq 0x4fd3f
addq $0x20, %rsp
cmpl $0x0, (%r14)
jne 0x61555
movq %r15, %rdi
movl $0xd, %esi
movl $0xf, %edx
movl $0xe, %ecx
xorl %r8d, %r8d
movq %r13, %r9
pushq %r14
pushq $-0x1000000             # imm = 0xFF000000
callq 0x50130
addq $0x10, %rsp
cmpl $0x0, (%r14)
jne 0x61555
movq %r15, %rdi
movl $0xc, %esi
movl $0xe, %edx
xorl %ecx, %ecx
movq %r13, %r8
movq %r13, %r9
pushq %r14
pushq $0xff0000               # imm = 0xFF0000
callq 0x50297
addq $0x10, %rsp
cmpl $0x0, (%r14)
jne 0x61555
movq %r15, %rdi
movl $0x8, %esi
movl $0xe, %edx
movq %r12, %rcx
movq %r13, %r8
movq %r14, %r9
callq 0x5099c
cmpl $0x0, (%r14)
jne 0x61555
movq %r15, %rdi
movl $0xd, %esi
movq %r14, %rdx
callq 0x4f6e2
cmpl $0x0, (%r14)
je 0x61564
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x4, %ebp
movl $0x1, %ecx
movl %ecx, 0x8(%rax)
xorl %ecx, %ecx
movb %cl, 0xc(%rax)
movq %r12, 0x10(%rax)
movl $0x2, %edx
movl %edx, 0x20(%rax)
movb %cl, 0x40(%rax)
movq %r12, 0x28(%rax)
movl %edx, 0x30(%rax)
movl $0x1, %r10d
movl %ebp, %ecx
shll %cl, %r10d
movl %r10d, 0x38(%rax)
movq %r15, %rdi
movl $0xc, %esi
movl $0x1, %edx
xorl %ecx, %ecx
movq %rbx, %r8
movq %rbx, %r9
pushq %r14
pushq %r10
callq 0x50297
addq $0x10, %rsp
cmpl $0x0, (%r14)
jne 0x61555
movq %rbp, %r13
subq $0x1, %r13
jb 0x6161b
leaq 0x1549d(%rip), %rax     # 0x76a70
movl (%rax,%rbp,4), %r8d
movq %r15, %rdi
movl $0x8, %esi
movl $0xe, %edx
movq %r12, %rcx
movq %r14, %r9
callq 0x508d6
cmpl $0x0, (%r14)
jne 0x61555
movq %r15, %rdi
movl $0xd, %esi
movq %r14, %rdx
callq 0x4f6e2
cmpl $0x0, (%r14)
movq %r13, %rbp
je 0x61569
jmp 0x61555
subq $0x8, %rsp
movq %r15, %rdi
movl $0x2, %esi
movl $0x4, %edx
movl $0xe, %ecx
xorl %r8d, %r8d
movq %rbx, %r9
pushq %r14
pushq $0x4
pushq %rbx
callq 0x4fd3f
addq $0x28, %rsp
jmp 0x61559