// File: /workspace/github_c_makefile_star2_O3/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 $0x58, %rsp
movl %r9d, 0x34(%rsp)
movq %r8, %r15
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %rbp
movl $0x2e0, %edi            # imm = 0x2E0
movl $0x1, %esi
callq 0x12150
movq %rax, %rbx
testq %rax, %rax
je 0x5583a
movq %rbp, 0x28(%rsp)
leaq (,%r13,8), %rdi
callq 0x121d0
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x55841
movq %rax, %rbp
movq %r13, 0x40(%rsp)
leaq (,%r13,4), %rdi
movq %rdi, 0x50(%rsp)
callq 0x121d0
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x5589b
movq %rax, 0x20(%rsp)
movq %r12, 0x38(%rsp)
xorl %r12d, %r12d
movq %r15, %rax
subq $0x4, %r15
cmovbq %r12, %r15
movl $0x4, %ecx
movq %rax, 0x18(%rsp)
cmovbq %rax, %rcx
movq %rcx, 0x8(%rsp)
movq %r15, 0x30(%rbx)
movq 0x28(%rsp), %r13
leaq (,%r13,4), %rdi
movq %rdi, 0x48(%rsp)
callq 0x121d0
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x558a2
movq %rax, 0x10(%rsp)
leaq (,%r13,8), %rdi
callq 0x121d0
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x558a9
movq %rax, %r12
movq 0xb0(%rsp), %rax
movl 0xa8(%rsp), %ecx
movl 0xa0(%rsp), %edx
movq 0x98(%rsp), %rsi
movq 0x90(%rsp), %rdi
movq 0x40(%rsp), %r8
movq %r8, (%rbx)
movq %r15, 0x38(%rbx)
movq %r14, %r15
movq %r14, 0x40(%rbx)
movq %rdi, 0x58(%rbx)
movq %rsi, 0x60(%rbx)
movl %edx, 0x68(%rbx)
movl %ecx, 0x6c(%rbx)
movl 0x34(%rsp), %ecx
movl %ecx, 0x48(%rbx)
movq %rax, 0x70(%rbx)
testq %r13, %r13
movq 0x20(%rsp), %r13
je 0x55546
movq 0x10(%rsp), %rdi
movl $0xff, %esi
movq 0x48(%rsp), %rdx
callq 0x12140
movq 0x28(%rsp), %rcx
leaq 0x1(%rcx), %rax
andq $-0x2, %rax
decq %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
leaq (%r15,%r15), %rcx
movdqa 0x1e154(%rip), %xmm1    # 0x73620
xorl %edx, %edx
movdqa 0x1e15a(%rip), %xmm2    # 0x73630
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movdqa 0x2073a(%rip), %xmm4    # 0x75c20
xorl %esi, %esi
movdqa %xmm1, %xmm5
pxor %xmm2, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
movd %xmm5, %edi
notl %edi
testb $0x1, %dil
je 0x5551e
movq %rdx, (%r12,%rsi,8)
pxor %xmm3, %xmm5
pextrw $0x4, %xmm5, %edi
testb $0x1, %dil
je 0x55536
leaq (%r15,%rdx), %rdi
movq %rdi, 0x8(%r12,%rsi,8)
addq $0x2, %rsi
paddq %xmm4, %xmm1
addq %rcx, %rdx
cmpq %rsi, %rax
jne 0x554e8
movq 0x28(%rsp), %rax
movq %rax, 0x18(%rbx)
cmpq $0x0, 0x18(%rsp)
je 0x55616
movq 0x8(%rsp), %r14
leaq (,%r14,4), %rdx
movq %r13, %rdi
movl $0xff, %esi
callq 0x12140
leaq -0x1(%r14), %rax
movq %rax, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
leaq 0x8(,%r14,8), %rax
andq $-0x10, %rax
movdqa 0x1e089(%rip), %xmm1    # 0x73620
xorl %ecx, %ecx
movdqa 0x1e08f(%rip), %xmm2    # 0x73630
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movdqa 0x2066f(%rip), %xmm4    # 0x75c20
movq 0x38(%rsp), %rdx
movdqa %xmm1, %xmm5
pxor %xmm2, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
movd %xmm5, %esi
notl %esi
testb $0x1, %sil
je 0x555ed
movq %rdx, (%rbp,%rcx)
pxor %xmm3, %xmm5
pextrw $0x4, %xmm5, %esi
testb $0x1, %sil
je 0x55605
leaq 0x1(%rdx), %rsi
movq %rsi, 0x8(%rbp,%rcx)
paddq %xmm4, %xmm1
addq $0x10, %rcx
addq $0x2, %rdx
cmpq %rcx, %rax
jne 0x555b6
movq 0x40(%rsp), %r14
subq 0x8(%rsp), %r14
jbe 0x556f2
movq 0x8(%rsp), %rcx
leaq (,%rcx,4), %rax
leaq (,%rcx,4), %rdi
addq %r13, %rdi
movq %rcx, %r13
movq 0x50(%rsp), %rdx
subq %rax, %rdx
movl $0xff, %esi
callq 0x12140
leaq 0x1(%r14), %rax
andq $-0x2, %rax
decq %r14
movq %r14, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
leaq 0x8(,%r13,8), %rcx
addq %rbp, %rcx
xorl %edx, %edx
movdqa 0x1dfa3(%rip), %xmm1    # 0x73620
movdqa 0x1dfab(%rip), %xmm2    # 0x73630
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movq %rdx, %xmm4
pshufd $0x44, %xmm4, %xmm4     # xmm4 = xmm4[0,1,0,1]
por %xmm1, %xmm4
pxor %xmm2, %xmm4
movdqa %xmm4, %xmm5
pcmpgtd %xmm0, %xmm5
pcmpeqd %xmm0, %xmm4
pshufd $0xf5, %xmm4, %xmm6     # xmm6 = xmm4[1,1,3,3]
pand %xmm5, %xmm6
pshufd $0xf5, %xmm5, %xmm4     # xmm4 = xmm5[1,1,3,3]
por %xmm6, %xmm4
movd %xmm4, %esi
notl %esi
testb $0x1, %sil
je 0x556d2
movq $0x7fffffff, -0x8(%rcx,%rdx,8) # imm = 0x7FFFFFFF
pxor %xmm3, %xmm4
pextrw $0x4, %xmm4, %esi
testb $0x1, %sil
je 0x556e9
movq $0x7fffffff, (%rcx,%rdx,8) # imm = 0x7FFFFFFF
addq $0x2, %rdx
cmpq %rdx, %rax
jne 0x5568d
cmpq $0x5, 0x18(%rsp)
jb 0x55889
movq 0x8(%rsp), %rsi
movq 0x18(%rsp), %rcx
subq %rsi, %rcx
leaq 0x1(%rcx), %rax
andq $-0x2, %rax
movq %rcx, %r9
decq %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
leal (%r15,%r15), %ecx
shlq $0x2, %rsi
movq 0x38(%rsp), %rdx
leaq (%rsi,%rdx,4), %rdx
movq 0x10(%rsp), %rsi
addq %rsi, %rdx
addq $0x4, %rdx
xorl %esi, %esi
movdqa 0x1ded6(%rip), %xmm1    # 0x73620
movdqa 0x1dede(%rip), %xmm2    # 0x73630
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
xorl %edi, %edi
movq %rdi, %xmm4
pshufd $0x44, %xmm4, %xmm4     # xmm4 = xmm4[0,1,0,1]
por %xmm1, %xmm4
pxor %xmm2, %xmm4
movdqa %xmm4, %xmm5
pcmpgtd %xmm0, %xmm5
pcmpeqd %xmm0, %xmm4
pshufd $0xf5, %xmm4, %xmm6     # xmm6 = xmm4[1,1,3,3]
pand %xmm5, %xmm6
pshufd $0xf5, %xmm5, %xmm4     # xmm4 = xmm5[1,1,3,3]
por %xmm6, %xmm4
movd %xmm4, %r8d
notl %r8d
testb $0x1, %r8b
je 0x5579e
movl %esi, -0x4(%rdx,%rdi,4)
pxor %xmm3, %xmm4
pextrw $0x4, %xmm4, %r8d
testb $0x1, %r8b
je 0x557b6
leal (%r15,%rsi), %r8d
movl %r8d, (%rdx,%rdi,4)
addq $0x2, %rdi
addl %ecx, %esi
cmpq %rdi, %rax
jne 0x5575c
movq %r9, 0x50(%rbx)
movq %r9, 0x30(%rbx)
movq %r9, 0x38(%rbx)
xorl %ecx, %ecx
pcmpeqd %xmm3, %xmm3
movdqa 0x20445(%rip), %xmm4    # 0x75c20
movdqa %xmm1, %xmm5
pxor %xmm2, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
movd %xmm5, %edx
notl %edx
testb $0x1, %dl
je 0x55814
movq $0x7fffffff, (%r12,%rcx,8) # imm = 0x7FFFFFFF
pxor %xmm3, %xmm5
pextrw $0x4, %xmm5, %edx
testb $0x1, %dl
je 0x5582b
movq $0x7fffffff, 0x8(%r12,%rcx,8) # imm = 0x7FFFFFFF
addq $0x2, %rcx
paddq %xmm4, %xmm1
cmpq %rcx, %rax
jne 0x557db
jmp 0x55889
movl $0x153, %ecx            # imm = 0x153
jmp 0x55846
movl $0x159, %ecx            # imm = 0x159
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %r12d, %r12d
movq 0xb8(%rsp), %rdi
leaq 0x203d3(%rip), %rdx     # 0x75c30
movl $0x1, %esi
callq 0x145a4
movq %r12, %rdi
callq 0x122c0
movq %r14, %rdi
callq 0x122c0
movq %rbp, %rdi
callq 0x122c0
movq %rbx, %rdi
callq 0x122c0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x15f, %ecx            # imm = 0x15F
jmp 0x55848
movl $0x16c, %ecx            # imm = 0x16C
jmp 0x558b3
movl $0x171, %ecx            # imm = 0x171
movq 0x10(%rsp), %r12
movq 0x20(%rsp), %r14
jmp 0x5584e