// File: /workspace/github_c_makefile_star2_O2/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 0x2da95
movq %rax, %rbx
movq $0x1, 0x150(%rax)
movl $0x9, (%rax)
pushq $0x1
popq %rdi
movl $0x148, %esi            # imm = 0x148
callq 0x12150
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x2daae
movq %r15, (%rsp)
movl $0x8, (%rax)
movq %rax, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x2db73
cmpl $0x0, (%r14)
jne 0x2dac5
movq %r13, 0x10(%rbx)
xorl %r15d, %r15d
pushq $0x1
popq %rbp
cmpq %r15, %r13
je 0x2dae1
movl $0x148, %esi            # imm = 0x148
movq %rbp, %rdi
callq 0x12150
movq %rax, 0x18(%rbx,%r15,8)
testq %rax, %rax
je 0x2db45
movl $0x8, (%rax)
movq %rax, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x2db73
incq %r15
addq $0x148, %r12            # imm = 0x148
cmpl $0x0, (%r14)
je 0x2da4b
jmp 0x2dac5
leaq 0x415dc(%rip), %rdx     # 0x6f078
pushq $0x1
popq %rsi
movq %r14, %rdi
movl $0xca, %ecx
callq 0x1429e
jmp 0x2dacd
leaq 0x415c3(%rip), %rdx     # 0x6f078
pushq $0x1
popq %rsi
movq %r14, %rdi
movl $0xd4, %ecx
callq 0x1429e
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
movq (%rsp), %rax
movq %rax, 0x148(%rbx)
movq %rbx, %rax
addq $0x158, %rax            # imm = 0x158
xorps %xmm0, %xmm0
movups %xmm0, 0x158(%rbx)
movq 0x10(%rbx), %rcx
xorl %edx, %edx
movl $0x7ffee0, %esi         # imm = 0x7FFEE0
xorl %edi, %edi
xorl %r8d, %r8d
cmpq %rcx, %r8
jae 0x2dacf
movq 0x18(%rbx,%r8,8), %r9
movl (%r9), %r9d
cmpl $0x16, %r9d
ja 0x2db5c
btl %r9d, %esi
jae 0x2db33
incq %rdx
movq %rdx, (%rax)
incq %r8
jmp 0x2db0f
cmpl $0x4, %r9d
jne 0x2db5c
incq %rdi
movq %rdi, 0x160(%rbx)
jmp 0x2db2e
leaq 0x4152c(%rip), %rdx     # 0x6f078
pushq $0x1
popq %rsi
movq %r14, %rdi
movl $0xe0, %ecx
jmp 0x2dac0
leaq 0x41515(%rip), %rdx     # 0x6f078
pushq $0xf
popq %rsi
movq %r14, %rdi
movl $0x107, %ecx            # imm = 0x107
jmp 0x2dac0