// File: /workspace/github_c_makefile_star2_O2/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, %r15d
movq %rsi, 0x8(%rsp)
movq %rdi, %rbp
movq 0x78(%rsp), %r14
pushq $0x1
popq %rdi
movl $0xe8, %esi
callq 0x12150
movq %rax, %rbx
testq %rax, %rax
je 0x2ada3
movq $0x4, 0x18(%rbx)
movl $0x9, 0x40(%rbx)
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0xb0(%rbx)
movdqu %xmm0, 0xc0(%rbx)
pushq $0x4
popq %rax
jmp 0x2adbc
leaq 0x42ff6(%rip), %rdx     # 0x6dda0
pushq $0x1
popq %rsi
movq %r14, %rdi
movl $0x141, %ecx            # imm = 0x141
callq 0x1429e
xorl %eax, %eax
cmpl $0x0, (%r14)
jne 0x2ae2a
movl 0x68(%rsp), %ecx
movl 0x60(%rsp), %edx
movl %r15d, (%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 %r14, %rdx
movq %r14, %r15
callq 0x2d6dc
cmpl $0x0, (%r14)
je 0x2ae4e
xorl %r13d, %r13d
movq %r13, %rdi
callq 0x2dc17
movq %rbx, %rdi
callq 0x2b14d
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movq %rax, %r13
movq 0x70(%rsp), %rsi
cmpq 0x8(%r12), %rax
jae 0x2aea4
movq (%r12), %rax
cmpq $0x0, (%rax,%r13,8)
je 0x2af20
movq 0x58(%rsp), %r9
movq 0x50(%rsp), %r8
testq %rsi, %rsi
je 0x2ae81
movq %r13, (%rsi)
leaq 0x42f18(%rip), %rax     # 0x6dda0
leaq 0x42f36(%rip), %rcx     # 0x6ddc5
pushq $0x20
popq %rsi
movq %rbp, %rdx
pushq $0x2eb                  # imm = 0x2EB
pushq %rax
callq 0x140cd
popq %rax
popq %rcx
jmp 0x2ae27
movq %r12, %r14
movq 0x10(%r12), %r12
cmpq %r12, %r13
jae 0x2aebc
movq %r13, %rbp
incq %rbp
movq %r14, %r12
jmp 0x2af1b
addq $0x40, %r12
movq %r13, %rbp
incq %rbp
cmpq %rbp, %r12
cmovbeq %rbp, %r12
movq (%r14), %rdi
leaq (,%r12,8), %rsi
callq 0x12210
testq %rax, %rax
je 0x2af91
movq 0x8(%r14), %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, (%r14)
movq %r12, 0x10(%r14)
movq %r15, %rdi
movq %r14, %r12
movq 0x70(%rsp), %rsi
movq %rbp, 0x8(%r12)
movq 0x10(%rsp), %rax
movq %rax, 0x10(%rbx)
movq 0x8(%rbx), %rax
movq 0x28(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rcx, 0x98(%rbx)
addq $0x2, %rcx
movq %rcx, 0x28(%rbx)
movq %rdx, 0xa0(%rbx)
movq 0x8(%rax), %rax
movl (%rax), %eax
cmpl $0x16, %eax
ja 0x2afbd
movl $0x7ffee0, %ecx         # imm = 0x7FFEE0
btl %eax, %ecx
jae 0x2afa5
movq %rbx, %rax
addq $0x18, %rax
movq (%rax), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rax)
movq %rcx, 0xa8(%rbx)
movq (%r12), %rax
movq %rbx, (%rax,%r13,8)
testq %rsi, %rsi
je 0x2ae3c
movq %r13, (%rsi)
jmp 0x2ae3c
leaq 0x42e08(%rip), %rdx     # 0x6dda0
pushq $0x1
popq %rsi
movq %r15, %rdi
movl $0x2f6, %ecx            # imm = 0x2F6
jmp 0x2afcc
cmpl $0x4, %eax
je 0x2afb4
cmpl $0x8, %eax
jne 0x2afbd
pushq $-0x1
popq %rcx
jmp 0x2af71
movq %rbx, %rax
addq $0x20, %rax
jmp 0x2af67
leaq 0x42ddc(%rip), %rdx     # 0x6dda0
pushq $0xf
popq %rsi
movl $0x31f, %ecx            # imm = 0x31F
callq 0x1429e
jmp 0x2ae27