// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/common/ir.c
// Function: prv_ir_prog_section_new
static subtilis_ir_section_t *prv_ir_prog_section_new(
	subtilis_ir_prog_t *p, const char *name,
	subtilis_ir_section_type_t section_type, size_t locals,
	subtilis_type_section_t *tp, subtilis_builtin_type_t ftype,
	const char *file, size_t line, int32_t eflag_offset,
	int32_t error_offset, size_t *index, subtilis_error_t *err)

/* clang-format on */
{
	subtilis_ir_section_t *s;
	size_t name_index;
	size_t new_max;
	subtilis_ir_section_t **new_pool;

	s = prv_ir_section_new(err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	s->section_type = section_type;
	s->eflag_offset = eflag_offset;
	s->error_offset = error_offset;
	s->reg_counter += tp->int_regs;
	s->cleanup_stack_reg = s->reg_counter++;
	s->freg_counter += tp->fp_regs;
	s->ftype = ftype;
	s->type = tp;
	tp = NULL;

	name_index = subtilis_string_pool_register(p->string_pool, name, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	if (name_index < p->num_sections) {
		if (p->sections[name_index]) {
			if (index)
				*index = name_index;

			subtilis_error_set_already_defined(err, name, file,
							   line);
			goto cleanup;
		}
	} else {
		if (name_index >= p->max_sections) {
			new_max = p->max_sections + SUBTILIS_CONFIG_PROC_GRAN;
			if (new_max < name_index + 1)
				new_max = name_index + 1;
			new_pool = realloc(p->sections,
					   sizeof(*p->sections) * new_max);
			if (!new_pool) {
				subtilis_error_set_oom(err);
				goto cleanup;
			}
			memset(&new_pool[p->num_sections], 0,
			       sizeof(*p->sections) *
				   (new_max - p->num_sections));
			p->sections = new_pool;
			p->max_sections = new_max;
		}
		p->num_sections = name_index + 1;
	}
	s->locals = locals;
	s->end_label = subtilis_ir_section_new_label(s);
	s->nofree_label = subtilis_ir_section_new_label(s);
	switch (s->type->type.params.fn.ret_val->type) {
	case SUBTILIS_TYPE_VOID:
		s->ret_reg = SIZE_MAX;
		break;
	case SUBTILIS_TYPE_REAL:
		s->ret_reg = s->freg_counter++;
		break;
	case SUBTILIS_TYPE_INTEGER:
	case SUBTILIS_TYPE_BYTE:
	case SUBTILIS_TYPE_ARRAY_REAL:
	case SUBTILIS_TYPE_ARRAY_INTEGER:
	case SUBTILIS_TYPE_ARRAY_BYTE:
	case SUBTILIS_TYPE_ARRAY_STRING:
	case SUBTILIS_TYPE_ARRAY_FN:
	case SUBTILIS_TYPE_ARRAY_REC:
	case SUBTILIS_TYPE_VECTOR_REAL:
	case SUBTILIS_TYPE_VECTOR_INTEGER:
	case SUBTILIS_TYPE_VECTOR_BYTE:
	case SUBTILIS_TYPE_VECTOR_STRING:
	case SUBTILIS_TYPE_VECTOR_FN:
	case SUBTILIS_TYPE_VECTOR_REC:
	case SUBTILIS_TYPE_STRING:
	case SUBTILIS_TYPE_FN:
	case SUBTILIS_TYPE_REC:
		s->ret_reg = s->reg_counter++;
		break;
	default:
		subtilis_error_set_assertion_failed(err);
		goto cleanup;
	}

	p->sections[name_index] = s;
	if (index)
		*index = name_index;

	return s;

cleanup:

	subtilis_type_section_delete(tp);
	prv_ir_section_delete(s);

	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r9d, %r12d
movq %r8, %r13
movq %rcx, 0x8(%rsp)
movl %edx, %r14d
movq %rsi, 0x10(%rsp)
movq %rdi, %rbp
movq 0x78(%rsp), %r15
movl $0x1, %edi
movl $0xe8, %esi
callq 0x12150
testq %rax, %rax
je 0x2c5d5
movq %rax, %rbx
movq $0x4, 0x18(%rax)
movl $0x9, 0x40(%rax)
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0xb0(%rax)
movdqu %xmm0, 0xc0(%rax)
jmp 0x2c5f0
leaq 0x477f4(%rip), %rdx     # 0x73dd0
movq %r15, %rdi
movl $0x1, %esi
movl $0x141, %ecx            # imm = 0x141
callq 0x145f4
xorl %ebx, %ebx
cmpl $0x0, (%r15)
jne 0x2c662
movl 0x68(%rsp), %eax
movl 0x60(%rsp), %ecx
movl %r14d, (%rbx)
movl %ecx, 0x8c(%rbx)
movl %eax, 0x90(%rbx)
movq 0x158(%r13), %rax
movq 0x18(%rbx), %rcx
leaq (%rcx,%rax), %rdx
leaq 0x1(%rcx,%rax), %rax
movq %rax, 0x18(%rbx)
movq %rdx, 0xc8(%rbx)
movq 0x160(%r13), %rax
addq %rax, 0x20(%rbx)
movl %r12d, 0x40(%rbx)
movq %r13, 0x8(%rbx)
movq %rbp, %r14
movq 0x18(%rbp), %rdi
movq 0x10(%rsp), %rbp
movq %rbp, %rsi
movq %r15, %rdx
movq %r15, %r12
callq 0x2f26d
cmpl $0x0, (%r15)
je 0x2c686
xorl %r13d, %r13d
movq %r13, %rdi
callq 0x2f7d2
movq %rbx, %rdi
callq 0x2c993
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
movq %rax, %r13
movq 0x70(%rsp), %r10
cmpq 0x8(%r14), %rax
jae 0x2c6de
movq (%r14), %rax
cmpq $0x0, (%rax,%r13,8)
je 0x2c744
movq 0x58(%rsp), %r9
movq 0x50(%rsp), %r8
testq %r10, %r10
je 0x2c6b7
movq %r13, (%r10)
leaq 0x47712(%rip), %rax     # 0x73dd0
leaq 0x47730(%rip), %rcx     # 0x73df5
movl $0x20, %esi
movq %rbp, %rdx
pushq $0x2eb                  # imm = 0x2EB
pushq %rax
callq 0x1442a
addq $0x10, %rsp
jmp 0x2c65f
movq 0x10(%r14), %rbp
cmpq %rbp, %r13
jb 0x2c73a
addq $0x40, %rbp
leaq 0x1(%r13), %rax
cmpq %rax, %rbp
cmovbeq %rax, %rbp
movq (%r14), %rdi
leaq (,%rbp,8), %rsi
callq 0x12210
testq %rax, %rax
je 0x2c7d6
movq %rax, %r15
movq 0x8(%r14), %rax
leaq (%r15,%rax,8), %rdi
movq %rbp, %rdx
subq %rax, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x12140
movq %r15, (%r14)
movq %rbp, 0x10(%r14)
movq %r12, %rdi
movq 0x70(%rsp), %r10
movq %r13, %rax
incq %rax
movq %rax, 0x8(%r14)
leaq 0x18(%rbx), %rax
movq 0x8(%rsp), %rcx
movq %rcx, 0x10(%rbx)
movq 0x8(%rbx), %rcx
movq 0x28(%rbx), %rdx
leaq 0x1(%rdx), %rsi
movq %rdx, 0x98(%rbx)
addq $0x2, %rdx
movq %rdx, 0x28(%rbx)
movq %rsi, 0xa0(%rbx)
movq 0x8(%rcx), %rcx
movl (%rcx), %ecx
leal -0x9(%rcx), %edx
cmpl $0xe, %edx
jae 0x2c7aa
movq (%rax), %rdx
leaq 0x1(%rdx), %rcx
movq %rcx, (%rax)
movq %rdx, 0xa8(%rbx)
movq (%r14), %rax
movq %rbx, (%rax,%r13,8)
testq %r10, %r10
je 0x2c674
movq %r13, (%r10)
jmp 0x2c674
leal -0x5(%rcx), %edx
cmpl $0x3, %edx
jb 0x2c781
cmpl $0x4, %ecx
je 0x2c7f4
movq $-0x1, %rdx
cmpl $0x8, %ecx
je 0x2c78b
leaq 0x47606(%rip), %rdx     # 0x73dd0
movl $0xf, %esi
movl $0x31f, %ecx            # imm = 0x31F
jmp 0x2c7ea
leaq 0x475f3(%rip), %rdx     # 0x73dd0
movq %r12, %rdi
movl $0x1, %esi
movl $0x2f6, %ecx            # imm = 0x2F6
callq 0x145f4
jmp 0x2c65f
leaq 0x20(%rbx), %rax
jmp 0x2c781