// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/arch/arm32/arm_reg_alloc.c
// Function: prv_new_regs
static subtilis_arm_reg_class_t *prv_new_regs(
	size_t reg_count, size_t max_regs, size_t reg_start, size_t reg_size,
	size_t args, int32_t max_offset, subtilis_arm_reg_spill_imm_t spill_imm,
	subtilis_arm_reg_stran_imm_t stran_imm,
	subtilis_arm_instr_type_t store_type,
	subtilis_arm_instr_type_t load_type,
	subtilis_arm_fp_is_fixed_t is_fixed, subtilis_error_t *err)

/* clang-format on */
{
	size_t i;
	size_t index;
	subtilis_arm_reg_class_t *regs;
	size_t reg_args = 4;

	regs = calloc(sizeof(*regs), 1);
	if (!regs) {
		subtilis_error_set_oom(err);
		goto on_error;
	}

	regs->phys_to_virt = malloc(sizeof(*regs->phys_to_virt) * max_regs);
	if (!regs->phys_to_virt) {
		subtilis_error_set_oom(err);
		goto on_error;
	}

	regs->next = malloc(sizeof(*regs->next) * max_regs);
	if (!regs->next) {
		subtilis_error_set_oom(err);
		goto on_error;
	}

	if (args <= reg_args) {
		reg_args = args;
		regs->spill_top = 0;
	} else {
		regs->spill_top = args - reg_args;
	}

	regs->spilt_regs = malloc(reg_count * sizeof(int32_t));
	if (!regs->spilt_regs) {
		subtilis_error_set_oom(err);
		goto on_error;
	}
	regs->spill_stack = malloc(reg_count * sizeof(size_t));
	if (!regs->spill_stack) {
		subtilis_error_set_oom(err);
		goto on_error;
	}
	regs->max_regs = max_regs;
	regs->spill_max = regs->spill_top;
	regs->reg_size = reg_size;
	regs->spill_imm = spill_imm;
	regs->stran_imm = stran_imm;
	regs->store_type = store_type;
	regs->load_type = load_type;
	regs->max_offset = max_offset;
	regs->is_fixed = is_fixed;

	for (i = 0; i < reg_count; i++) {
		regs->spilt_regs[i] = -1;
		regs->spill_stack[i] = i * reg_size;
	}
	regs->vr_reg_count = reg_count;

	for (i = 0; i < reg_args; i++) {
		regs->next[i] = -1;
		regs->phys_to_virt[i] = i + reg_start;
	}

	for (; i < max_regs; i++) {
		regs->next[i] = -1;
		regs->phys_to_virt[i] = INT_MAX;
	}

	for (i = reg_args; i < args; i++) {
		index = i - reg_args;
		regs->spilt_regs[i + reg_start] = index * reg_size;
	}

	if (i > reg_args) {
		regs->spilt_args = i - reg_args;
		regs->spill_top = regs->spilt_args;
		regs->spill_max = regs->spill_top;
		for (i = 0; i < regs->spilt_args; i++)
			regs->spill_stack[i] = INT_MAX;
	} else {
		regs->spilt_args = 0;
	}

	regs->spill_points = NULL;
	regs->spill_points_count = 0;
	regs->spill_points_max = 0;

	return regs;

on_error:

	free(regs->spilt_regs);
	free(regs->next);
	free(regs->phys_to_virt);
	free(regs);

	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r9d, %ebp
movq %r8, %r14
movq %rcx, %r15
movq %rdx, 0x28(%rsp)
movq %rsi, %r13
movq %rdi, %r12
movl $0x2e0, %edi            # imm = 0x2E0
movl $0x1, %esi
callq 0x12150
movq %rax, %rbx
testq %rax, %rax
je 0x55601
movq %r14, 0x8(%rsp)
leaq (,%r13,8), %rdi
callq 0x121d0
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x55608
movq %rax, %r14
movl %ebp, 0x14(%rsp)
leaq (,%r13,4), %rdi
callq 0x121d0
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x5560f
movq %rax, %rbp
xorl %eax, %eax
movq 0x8(%rsp), %rdx
movq %rdx, %rcx
subq $0x4, %rcx
cmovaeq %rcx, %rax
movl $0x4, %ecx
cmovbq %rdx, %rcx
movq %rcx, (%rsp)
movq %rax, 0x30(%rbx)
leaq (,%r12,4), %rdi
movq %rdi, 0x30(%rsp)
callq 0x121d0
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x55616
movq %rbp, 0x18(%rsp)
movq %rax, 0x20(%rsp)
leaq (,%r12,8), %rdi
callq 0x121d0
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x5561d
movq %rax, %rbp
movq 0x90(%rsp), %rax
movl 0x88(%rsp), %ecx
movl 0x80(%rsp), %edx
movq 0x78(%rsp), %rsi
movq 0x70(%rsp), %rdi
movq %r13, (%rbx)
movq 0x30(%rbx), %r8
movq %r8, 0x38(%rbx)
movq %r15, 0x40(%rbx)
movq %rdi, 0x58(%rbx)
movq %rsi, 0x60(%rbx)
movl %edx, 0x68(%rbx)
movl %ecx, 0x6c(%rbx)
movl 0x14(%rsp), %ecx
movl %ecx, 0x48(%rbx)
movq %rax, 0x70(%rbx)
testq %r12, %r12
je 0x555bd
movq 0x20(%rsp), %rdi
movl $0xff, %esi
movq 0x30(%rsp), %rdx
callq 0x12140
xorl %eax, %eax
xorl %ecx, %ecx
movq %rax, (%rbp,%rcx,8)
incq %rcx
addq %r15, %rax
cmpq %rcx, %r12
jne 0x555ad
movq %r12, 0x18(%rbx)
cmpq $0x0, 0x8(%rsp)
je 0x55672
movq (%rsp), %r12
leaq (,%r12,4), %rdx
movq 0x18(%rsp), %rdi
movl $0xff, %esi
callq 0x12140
xorl %eax, %eax
movq 0x28(%rsp), %rdx
leaq (%rdx,%rax), %rcx
movq %rcx, (%r14,%rax,8)
incq %rax
cmpq %rax, %r12
jne 0x555ef
jmp 0x55675
movl $0x153, %ecx            # imm = 0x153
jmp 0x55622
movl $0x159, %ecx            # imm = 0x159
jmp 0x55622
movl $0x15f, %ecx            # imm = 0x15F
jmp 0x55622
movl $0x16c, %ecx            # imm = 0x16C
jmp 0x55622
movl $0x171, %ecx            # imm = 0x171
movq 0x98(%rsp), %rdi
leaq 0x205aa(%rip), %rdx     # 0x75bdb
movl $0x1, %esi
callq 0x145f4
movq 0x20(%rbx), %rdi
callq 0x122c0
movq 0x10(%rbx), %rdi
callq 0x122c0
movq 0x8(%rbx), %rdi
callq 0x122c0
movq %rbx, %rdi
callq 0x122c0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r12d, %r12d
cmpq %r13, %r12
jae 0x556ab
movq (%rsp), %rax
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax,4), %rdi
movq %r13, %rdx
subq %rax, %rdx
shlq $0x2, %rdx
movl $0xff, %esi
callq 0x12140
movq $0x7fffffff, (%r14,%r12,8) # imm = 0x7FFFFFFF
incq %r12
cmpq %r12, %r13
jne 0x5569b
movq (%rsp), %rdi
movq %rdi, %rax
movq 0x8(%rsp), %rsi
cmpq $0x5, %rsi
jb 0x556e1
movq 0x28(%rsp), %rax
movq 0x20(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
xorl %ecx, %ecx
movq %rdi, %rdx
movl %ecx, (%rax,%rdx,4)
incq %rdx
addl %r15d, %ecx
cmpq %rdx, %rsi
jne 0x556d0
movq %rsi, %rax
cmpq $0x5, %rax
jb 0x5570b
subq %rdi, %rax
movq %rax, 0x50(%rbx)
movq %rax, 0x30(%rbx)
movq %rax, 0x38(%rbx)
xorl %ecx, %ecx
movq $0x7fffffff, (%rbp,%rcx,8) # imm = 0x7FFFFFFF
incq %rcx
cmpq %rcx, %rax
jne 0x556f8
jmp 0x55713
movq $0x0, 0x50(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x78(%rbx)
movq $0x0, 0x88(%rbx)
jmp 0x55660