// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movl 0x28(%rbp), %eax
movl 0x20(%rbp), %eax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movq 0x38(%rbp), %rdi
callq 0x3aa30
movq %rax, -0x40(%rbp)
movq 0x38(%rbp), %rax
cmpl $0x0, (%rax)
je 0x38cd0
jmp 0x38fd7
movl -0x1c(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, (%rax)
movl 0x20(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x8c(%rax)
movl 0x28(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x90(%rax)
movq -0x30(%rbp), %rax
movq 0x158(%rax), %rcx
movq -0x40(%rbp), %rax
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, 0x18(%rax)
movq -0x40(%rbp), %rax
movq %rcx, 0xc8(%rax)
movq -0x30(%rbp), %rax
movq 0x160(%rax), %rcx
movq -0x40(%rbp), %rax
addq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
movl -0x34(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x40(%rax)
movq -0x30(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x8(%rax)
movq $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
movq 0x38(%rbp), %rdx
callq 0x3d630
movq %rax, -0x48(%rbp)
movq 0x38(%rbp), %rax
cmpl $0x0, (%rax)
je 0x38d84
jmp 0x38fd7
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x38df7
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x48(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x38df2
cmpq $0x0, 0x30(%rbp)
je 0x38db6
movq -0x48(%rbp), %rcx
movq 0x30(%rbp), %rax
movq %rcx, (%rax)
movq 0x38(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq 0x10(%rbp), %r8
movq 0x18(%rbp), %rax
movl %eax, %r9d
movl $0x20, %esi
leaq 0x724a1(%rip), %rcx     # 0xab276
leaq 0x7203c(%rip), %rax     # 0xaae18
movq %rax, (%rsp)
movl $0x2eb, 0x8(%rsp)       # imm = 0x2EB
callq 0x156d0
jmp 0x38fd7
jmp 0x38ec5
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jb 0x38eb5
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
addq $0x40, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jae 0x38e36
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x50(%rbp), %rsi
shlq $0x3, %rsi
callq 0x121e0
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x38e74
movq 0x38(%rbp), %rdi
movl $0x1, %esi
leaq 0x71fb3(%rip), %rdx     # 0xaae18
movl $0x2f6, %ecx            # imm = 0x2F6
callq 0x158e0
jmp 0x38fd7
movq -0x58(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq -0x50(%rbp), %rdx
movq -0x10(%rbp), %rax
subq 0x8(%rax), %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x12110
movq -0x58(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x50(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x48(%rbp), %rcx
addq $0x1, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rdi
callq 0x39940
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x98(%rax)
movq -0x40(%rbp), %rdi
callq 0x39940
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0xa0(%rax)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movl (%rax), %eax
movl %eax, -0x5c(%rbp)
subl $0x4, %eax
je 0x38f4c
jmp 0x38f17
movl -0x5c(%rbp), %eax
addl $-0x5, %eax
subl $0x3, %eax
jb 0x38f6c
jmp 0x38f24
movl -0x5c(%rbp), %eax
subl $0x8, %eax
je 0x38f3b
jmp 0x38f2e
movl -0x5c(%rbp), %eax
addl $-0x9, %eax
subl $0xe, %eax
jb 0x38f6c
jmp 0x38f8c
movq -0x40(%rbp), %rax
movq $-0x1, 0xa8(%rax)
jmp 0x38fa8
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, 0x20(%rax)
movq -0x40(%rbp), %rax
movq %rcx, 0xa8(%rax)
jmp 0x38fa8
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, 0x18(%rax)
movq -0x40(%rbp), %rax
movq %rcx, 0xa8(%rax)
jmp 0x38fa8
movq 0x38(%rbp), %rdi
movl $0xf, %esi
leaq 0x71e7c(%rip), %rdx     # 0xaae18
movl $0x31f, %ecx            # imm = 0x31F
callq 0x158e0
jmp 0x38fd7
movq -0x40(%rbp), %rdx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x48(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
cmpq $0x0, 0x30(%rbp)
je 0x38fcd
movq -0x48(%rbp), %rcx
movq 0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x38ff1
movq -0x30(%rbp), %rdi
callq 0x3e040
movq -0x40(%rbp), %rdi
callq 0x392a0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)