// File: /workspace/github_c_makefile_star2_O3/markdryan[P]subtilis/arch/arm32/arm_reg_alloc.c
// Function: prv_alloc_stran_instr
static void prv_alloc_stran_instr(void *user_data, subtilis_arm_op_t *op,
				  subtilis_arm_instr_type_t type,
				  subtilis_arm_stran_instr_t *instr,
				  subtilis_error_t *err)
{
	int dist_dest;
	int dist_op2;
	size_t vreg_dest;
	size_t vreg_base;
	bool fixed_reg_base;
	bool fixed_reg_dest = false;
	int dist_base = -1;
	subtilis_arm_reg_t *reg = NULL;
	subtilis_arm_reg_ud_t *ud = user_data;

	if (type == SUBTILIS_ARM_INSTR_STR) {
		vreg_dest = instr->dest;
		fixed_reg_dest = subtilis_arm_reg_alloc_ensure(
		    ud, op, ud->int_regs, ud->int_regs, &instr->dest, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
	}

	vreg_base = instr->base;
	fixed_reg_base = subtilis_arm_reg_alloc_ensure(
	    ud, op, ud->int_regs, ud->int_regs, &instr->base, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	reg = prv_ensure_op2(ud, op, &instr->offset, &dist_op2, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return;

	if (!fixed_reg_base) {
		dist_base = subtilis_arm_reg_alloc_calculate_dist(
		    ud, vreg_base, op, &ud->int_regs->dist_walker,
		    ud->int_regs);
		if (dist_base == -1)
			ud->int_regs->phys_to_virt[instr->base] = INT_MAX;
	}

	if (type == SUBTILIS_ARM_INSTR_STR) {
		if (!fixed_reg_dest) {
			dist_dest = subtilis_arm_reg_alloc_calculate_dist(
			    ud, vreg_dest, op, &ud->int_regs->dist_walker,
			    ud->int_regs);
			if (dist_dest == -1)
				ud->int_regs->phys_to_virt[instr->dest] =
				    INT_MAX;
			ud->int_regs->next[instr->dest] = dist_dest;
		}
	} else {
		subtilis_arm_reg_alloc_alloc_dest(ud, op, &instr->dest, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return;
	}

	if (!fixed_reg_base)
		ud->int_regs->next[instr->base] = dist_base;
	if (reg)
		ud->int_regs->next[*reg] = dist_op2;

	ud->instr_count++;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %r13
movq %rcx, %r14
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %rbx
cmpl $0x13, %edx
jne 0x54040
leaq 0x8(%r14), %r8
movq 0x8(%r14), %rax
movq %rax, 0x20(%rsp)
movq 0x8(%rbx), %rcx
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %r9
callq 0x52fd8
movl %eax, 0x4(%rsp)
cmpl $0x0, (%r13)
jne 0x54073
jmp 0x54048
movl $0x0, 0x4(%rsp)
leaq 0x10(%r14), %r8
movq 0x10(%r14), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rbx), %rcx
movq %rbx, %rdi
movq %r12, %rsi
movq %r8, 0x18(%rsp)
movq %r13, %r9
callq 0x52fd8
cmpl $0x0, (%r13)
je 0x54082
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl $0xfffffffd, 0x18(%r14) # imm = 0xFFFFFFFD
jne 0x540b8
leaq 0x20(%r14), %rcx
leaq 0x14(%rsp), %rdx
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %r8
movl %eax, %r15d
callq 0x55f53
cmpl $0x0, (%r13)
jne 0x54073
movq %rax, %rcx
movl %r15d, %eax
movq %rcx, %r15
jmp 0x540bb
xorl %r15d, %r15d
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testb %al, %al
movb %al, 0x3(%rsp)
jne 0x54107
movq 0x8(%rbx), %r8
leaq 0x90(%r8), %rcx
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rdx
callq 0x52d7c
movl %eax, %ecx
cmpl $-0x1, %eax
jne 0x54107
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x18(%rsp), %rcx
movq (%rcx), %rcx
movq $0x7fffffff, (%rax,%rcx,8) # imm = 0x7FFFFFFF
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl $0x13, %ebp
movl %ecx, 0x8(%rsp)
jne 0x5415d
cmpb $0x0, 0x4(%rsp)
movb 0x3(%rsp), %bpl
jne 0x54189
movq 0x8(%rbx), %r8
leaq 0x90(%r8), %rcx
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
movq %r12, %rdx
callq 0x52d7c
movq 0x8(%rbx), %rcx
cmpl $-0x1, %eax
jne 0x54150
movq 0x8(%rcx), %rdx
movq 0x8(%r14), %rsi
movq $0x7fffffff, (%rdx,%rsi,8) # imm = 0x7FFFFFFF
movq 0x10(%rcx), %rcx
movq 0x8(%r14), %rdx
movl %eax, (%rcx,%rdx,4)
jmp 0x54189
addq $0x8, %r14
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq $-0x1, %rcx
movq %r13, %r8
callq 0x531ec
cmpl $0x0, (%r13)
movb 0x3(%rsp), %bpl
jne 0x54073
testb %bpl, %bpl
jne 0x541a5
movq 0x8(%rbx), %rax
movq 0x10(%rax), %rax
movq 0x18(%rsp), %rcx
movq (%rcx), %rcx
movl 0x8(%rsp), %edx
movl %edx, (%rax,%rcx,4)
testq %r15, %r15
je 0x541bc
movl 0x14(%rsp), %eax
movq 0x8(%rbx), %rcx
movq 0x10(%rcx), %rcx
movq (%r15), %rdx
movl %eax, (%rcx,%rdx,4)
incq 0x20(%rbx)
jmp 0x54073