// File: /workspace/github_c_makefile_star2_O2/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
subq $0x10, %rsp
movq %r8, 0x8(%rsp)
andl $0x0, (%rsp)
pushq $0xd
popq %rsi
pushq $0xf
popq %rdx
pushq $0xe
popq %rcx
xorl %r8d, %r8d
movq %rbx, %r9
callq 0x4d213
popq %rax
popq %rcx
cmpl $0x0, (%r14)
jne 0x5dfec
subq $0x8, %rsp
pushq $0x2
popq %rsi
pushq $0x4
popq %rdx
pushq $0xe
popq %rcx
movq %r15, %rdi
xorl %r8d, %r8d
movq %r12, %r9
pushq %r14
pushq $0x1
pushq %r12
callq 0x4ced7
addq $0x20, %rsp
cmpl $0x0, (%r14)
jne 0x5dfec
pushq $0xd
popq %rsi
pushq $0xf
popq %rdx
pushq $0xe
popq %rcx
movq %r15, %rdi
xorl %r8d, %r8d
movq %r13, %r9
pushq %r14
pushq $-0x1000000             # imm = 0xFF000000
callq 0x4d213
popq %rax
popq %rcx
cmpl $0x0, (%r14)
jne 0x5dfec
pushq $0xc
popq %rsi
pushq $0xe
popq %rdx
movq %r15, %rdi
xorl %ecx, %ecx
movq %r13, %r8
movq %r13, %r9
pushq %r14
pushq $0xff0000               # imm = 0xFF0000
callq 0x4d357
popq %rax
popq %rcx
cmpl $0x0, (%r14)
jne 0x5dfec
pushq $0x8
popq %rsi
pushq $0xe
popq %rdx
movq %r15, %rdi
movq %r12, %rcx
movq %r13, %r8
movq %r14, %r9
callq 0x4d921
cmpl $0x0, (%r14)
je 0x5dffb
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x4
popq %rbp
movq %r15, %rdi
pushq $0xd
popq %rsi
movq %r14, %rdx
callq 0x4c92b
cmpl $0x0, (%r14)
jne 0x5dfec
pushq $0x1
popq %rdx
movl %edx, 0x8(%rax)
xorl %esi, %esi
movb %sil, 0xc(%rax)
movq %r12, 0x10(%rax)
pushq $0x2
popq %rcx
movl %ecx, 0x20(%rax)
movb %sil, 0x40(%rax)
movq %r12, 0x28(%rax)
movl %ecx, 0x30(%rax)
movl %edx, %r10d
movl %ebp, %ecx
shll %cl, %r10d
movl %r10d, 0x38(%rax)
movq %r15, %rdi
pushq $0xc
popq %rsi
xorl %ecx, %ecx
movq %rbx, %r8
movq %rbx, %r9
pushq %r14
pushq %r10
callq 0x4d357
popq %rax
popq %rcx
cmpl $0x0, (%r14)
jne 0x5dfec
movq %rbp, %r13
subq $0x1, %r13
jb 0x5e098
leaq 0x12972(%rip), %rax     # 0x709e0
movl (%rax,%rbp,4), %r8d
movq %r15, %rdi
pushq $0x8
popq %rsi
pushq $0xe
popq %rdx
movq %r12, %rcx
movq %r14, %r9
callq 0x4d87e
cmpl $0x0, (%r14)
movq %r13, %rbp
je 0x5dffe
jmp 0x5dfec
subq $0x8, %rsp
pushq $0x2
popq %rsi
pushq $0x4
popq %rdx
pushq $0xe
popq %rcx
movq %r15, %rdi
xorl %r8d, %r8d
movq %rbx, %r9
pushq %r14
pushq $0x4
pushq %rbx
callq 0x4ced7
addq $0x28, %rsp
jmp 0x5dff0