// File: /workspace/github_c_makefile_star2_O3/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, 0x10(%rsp)
movl %edx, %r14d
movq %rsi, 0x8(%rsp)
movq %rdi, %rbp
movq 0x78(%rsp), %r15
movl $0x1, %edi
movl $0xe8, %esi
callq 0x12150
movq %rax, %rbx
testq %rax, %rax
je 0x2c25a
movq $0x4, 0x18(%rbx)
movl $0x9, 0x40(%rbx)
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0xb0(%rbx)
movdqu %xmm0, 0xc0(%rbx)
movl $0x4, %eax
jmp 0x2c275
leaq 0x47b8f(%rip), %rdx     # 0x73df0
movq %r15, %rdi
movl $0x1, %esi
movl $0x141, %ecx            # imm = 0x141
callq 0x145a4
xorl %eax, %eax
cmpl $0x0, (%r15)
jne 0x2c2e3
movl 0x68(%rsp), %ecx
movl 0x60(%rsp), %edx
movl %r14d, (%rbx)
movl %edx, 0x8c(%rbx)
movl %ecx, 0x90(%rbx)
movq 0x158(%r13), %rcx
leaq (%rax,%rcx), %rdx
leaq 0x1(%rax,%rcx), %rax
movq %rax, 0x18(%rbx)
movq %rdx, 0xc8(%rbx)
movq 0x160(%r13), %rax
movq %rax, 0x20(%rbx)
movl %r12d, 0x40(%rbx)
movq %r13, 0x8(%rbx)
movq %rbp, %r12
movq 0x18(%rbp), %rdi
movq 0x8(%rsp), %rbp
movq %rbp, %rsi
movq %r15, %rdx
movq %r15, %r14
callq 0x2ef6e
cmpl $0x0, (%r15)
je 0x2c307
xorl %r13d, %r13d
movq %r13, %rdi
callq 0x2f4fb
movq %rbx, %rdi
callq 0x2c638
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(%r12), %rax
jae 0x2c364
movq (%r12), %rax
cmpq $0x0, (%rax,%r13,8)
je 0x2c3e0
movq 0x58(%rsp), %r9
movq 0x50(%rsp), %r8
testq %r10, %r10
je 0x2c33a
movq %r13, (%r10)
leaq 0x47aaf(%rip), %rax     # 0x73df0
leaq 0x47acd(%rip), %rcx     # 0x73e15
movl $0x20, %esi
movq %rbp, %rdx
pushq $0x2eb                  # imm = 0x2EB
pushq %rax
callq 0x143da
addq $0x10, %rsp
jmp 0x2c2e0
movq %r12, %r15
movq 0x10(%r12), %r12
cmpq %r12, %r13
jae 0x2c37c
movq %r13, %rbp
incq %rbp
movq %r15, %r12
jmp 0x2c3db
addq $0x40, %r12
movq %r13, %rbp
incq %rbp
cmpq %rbp, %r12
cmovbeq %rbp, %r12
movq (%r15), %rdi
leaq (,%r12,8), %rsi
callq 0x12210
testq %rax, %rax
je 0x2c473
movq 0x8(%r15), %rcx
leaq (%rax,%rcx,8), %rdi
movq %r12, %rdx
subq %rcx, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
movq %rax, 0x8(%rsp)
callq 0x12140
movq 0x8(%rsp), %rax
movq %rax, (%r15)
movq %r12, 0x10(%r15)
movq %r14, %rdi
movq %r15, %r12
movq 0x70(%rsp), %r10
movq %rbp, 0x8(%r12)
leaq 0x18(%rbx), %rax
movq 0x10(%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 0x2c447
movq (%rax), %rdx
leaq 0x1(%rdx), %rcx
movq %rcx, (%rax)
movq %rdx, 0xa8(%rbx)
movq (%r12), %rax
movq %rbx, (%rax,%r13,8)
testq %r10, %r10
je 0x2c2f5
movq %r13, (%r10)
jmp 0x2c2f5
leal -0x5(%rcx), %edx
cmpl $0x3, %edx
jb 0x2c41d
cmpl $0x4, %ecx
je 0x2c491
movq $-0x1, %rdx
cmpl $0x8, %ecx
je 0x2c427
leaq 0x47989(%rip), %rdx     # 0x73df0
movl $0xf, %esi
movl $0x31f, %ecx            # imm = 0x31F
jmp 0x2c487
leaq 0x47976(%rip), %rdx     # 0x73df0
movq %r14, %rdi
movl $0x1, %esi
movl $0x2f6, %ecx            # imm = 0x2F6
callq 0x145a4
jmp 0x2c2e0
movq %rbx, %rax
addq $0x20, %rax
jmp 0x2c41d