// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/common/type.c
// Function: subtilis_type_section_new
subtilis_type_section_t *
subtilis_type_section_new(const subtilis_type_t *rtype, size_t num_parameters,
			  const subtilis_type_t *parameters,
			  subtilis_check_args_t *check_args,
			  subtilis_error_t *err)

{
	size_t i;
	subtilis_type_t *ftype;
	subtilis_type_section_t *stype = malloc(sizeof(*stype));

	if (!stype) {
		subtilis_error_set_oom(err);
		return NULL;
	}

	stype->ref_count = 1;

	ftype = &stype->type;
	ftype->type = SUBTILIS_TYPE_FN;
	ftype->params.fn.ret_val = calloc(1, sizeof(*ftype->params.fn.ret_val));
	if (!ftype->params.fn.ret_val) {
		subtilis_error_set_oom(err);
		goto on_error;
	}
	ftype->params.fn.ret_val->type = SUBTILIS_TYPE_VOID;
	subtilis_type_init_copy(ftype->params.fn.ret_val, rtype, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto on_error;
	ftype->params.fn.num_params = num_parameters;
	for (i = 0; i < num_parameters; i++) {
		ftype->params.fn.params[i] =
		    calloc(1, sizeof(*ftype->params.fn.params[i]));
		if (!ftype->params.fn.params[i]) {
			subtilis_error_set_oom(err);
			goto on_error;
		}
		ftype->params.fn.params[i]->type = SUBTILIS_TYPE_VOID;

		subtilis_type_init_copy(ftype->params.fn.params[i],
					&parameters[i], err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto on_error;
	}
	stype->check_args = check_args;
	stype->int_regs = 0;
	stype->fp_regs = 0;

	for (i = 0; i < ftype->params.fn.num_params; i++) {
		switch (ftype->params.fn.params[i]->type) {
		case SUBTILIS_TYPE_INTEGER:
		case SUBTILIS_TYPE_BYTE:
		case SUBTILIS_TYPE_STRING:
		case SUBTILIS_TYPE_ARRAY_REAL:
		case SUBTILIS_TYPE_ARRAY_INTEGER:
		case SUBTILIS_TYPE_ARRAY_STRING:
		case SUBTILIS_TYPE_ARRAY_BYTE:
		case SUBTILIS_TYPE_ARRAY_FN:
		case SUBTILIS_TYPE_ARRAY_REC:
		case SUBTILIS_TYPE_VECTOR_REAL:
		case SUBTILIS_TYPE_VECTOR_INTEGER:
		case SUBTILIS_TYPE_VECTOR_STRING:
		case SUBTILIS_TYPE_VECTOR_BYTE:
		case SUBTILIS_TYPE_VECTOR_FN:
		case SUBTILIS_TYPE_VECTOR_REC:
		case SUBTILIS_TYPE_FN:
		case SUBTILIS_TYPE_REC:
			stype->int_regs++;
			break;
		case SUBTILIS_TYPE_REAL:
			stype->fp_regs++;
			break;
		default:
			subtilis_error_set_assertion_failed(err);
			goto on_error;
		}
	}

	return stype;

on_error:

	free(stype);
	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r8, %r14
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %rbp
movl $0x168, %edi            # imm = 0x168
callq 0x121d0
testq %rax, %rax
je 0x2f6c8
movq %rax, %rbx
movq $0x1, 0x150(%rax)
movl $0x9, (%rax)
movl $0x1, %edi
movl $0x148, %esi            # imm = 0x148
callq 0x12150
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x2f6e3
movl $0x8, (%rax)
movq %rax, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x2f72e
cmpl $0x0, (%r14)
jne 0x2f6fc
movq %r13, 0x10(%rbx)
testq %r13, %r13
je 0x2f64c
xorl %ebp, %ebp
movl $0x1, %edi
movl $0x148, %esi            # imm = 0x148
callq 0x12150
movq %rax, 0x18(%rbx,%rbp,8)
testq %rax, %rax
je 0x2f718
movl $0x8, (%rax)
movq %rax, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x2f72e
cmpl $0x0, (%r14)
jne 0x2f6fc
incq %rbp
addq $0x148, %r12            # imm = 0x148
cmpq %rbp, %r13
jne 0x2f602
movq %r15, 0x148(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x158(%rbx)
cmpq $0x0, 0x10(%rbx)
je 0x2f706
leaq 0x158(%rbx), %rax
movq %rbx, %rcx
addq $0x160, %rcx            # imm = 0x160
xorl %edx, %edx
movq 0x18(%rbx,%rdx,8), %rsi
movl (%rsi), %esi
leal -0x9(%rsi), %r8d
movq %rax, %rdi
cmpl $0xe, %r8d
jae 0x2f69d
incq (%rdi)
incq %rdx
cmpq 0x10(%rbx), %rdx
jb 0x2f67b
jmp 0x2f706
leal -0x5(%rsi), %r8d
movq %rax, %rdi
cmpl $0x3, %r8d
jb 0x2f68f
movq %rcx, %rdi
cmpl $0x4, %esi
je 0x2f68f
leaq 0x459ef(%rip), %rdx     # 0x750a8
movq %r14, %rdi
movl $0xf, %esi
movl $0x107, %ecx            # imm = 0x107
jmp 0x2f6f7
leaq 0x459d9(%rip), %rdx     # 0x750a8
movq %r14, %rdi
movl $0x1, %esi
movl $0xca, %ecx
callq 0x145f4
jmp 0x2f704
leaq 0x459be(%rip), %rdx     # 0x750a8
movq %r14, %rdi
movl $0x1, %esi
movl $0xd4, %ecx
callq 0x145f4
movq %rbx, %rdi
callq 0x122c0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x45989(%rip), %rdx     # 0x750a8
movq %r14, %rdi
movl $0x1, %esi
movl $0xe0, %ecx
jmp 0x2f6f7