// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/frontend/parser_call.c
// Function: subtilis_parser_parse_call_type
char *subtilis_parser_parse_call_type(subtilis_parser_t *p, subtilis_token_t *t,
				      subtilis_type_t *type,
				      subtilis_error_t *err)
{
	const char *tbuf;
	char *at;
	subtilis_type_t *ret_type;
	bool have_params;
	subtilis_type_t *p_type = NULL;
	char *name = NULL;

	ret_type = calloc(1, sizeof(*ret_type));
	if (!ret_type) {
		subtilis_error_set_oom(err);
		return NULL;
	}

	ret_type->type = SUBTILIS_TYPE_VOID;
	type->type = SUBTILIS_TYPE_FN;
	type->params.fn.ret_val = ret_type;
	type->params.fn.num_params = 0;

	name = prv_initial_proc_fn_type(p, t, ret_type, true, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto on_error;

	/* We don't store any type information in the name of the type,
	 * apart from the fact it's a procedure or a function.  So strip
	 * the return type if it's there.
	 */

	switch (ret_type->type) {
	case SUBTILIS_TYPE_INTEGER:
	case SUBTILIS_TYPE_BYTE:
	case SUBTILIS_TYPE_STRING:
	case SUBTILIS_TYPE_VECTOR_INTEGER:
	case SUBTILIS_TYPE_VECTOR_BYTE:
	case SUBTILIS_TYPE_VECTOR_STRING:
		name[strlen(name) - 1] = 0;
		break;
	case SUBTILIS_TYPE_FN:
	case SUBTILIS_TYPE_REC:
		at = strchr(name, '@');
		if (!at) {
			subtilis_error_set_assertion_failed(err);
			goto on_error;
		}
		*at = 0;
		break;
	default:
		break;
	}

	tbuf = subtilis_token_get_text(t);
	if ((t->type == SUBTILIS_TOKEN_OPERATOR) && !strcmp(tbuf, "(")) {
		have_params = prv_complete_array_type(p, t, ret_type, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto on_error;
		if (!have_params)
			return name;

		tbuf = subtilis_token_get_text(t);
		for (;;) {
			if (t->type != SUBTILIS_TOKEN_IDENTIFIER) {
				subtilis_error_set_id_expected(
				    err, tbuf, p->l->stream->name, p->l->line);
				goto on_error;
			}

			if (type->params.fn.num_params >= SUBTILIS_MAX_ARGS) {
				subtilis_error_set_too_many_args(
				    err, type->params.fn.num_params + 1,
				    SUBTILIS_MAX_ARGS, p->l->stream->name,
				    p->l->line);
				goto on_error;
			}

			p_type = calloc(1, sizeof(*p_type));
			if (!ret_type) {
				subtilis_error_set_oom(err);
				goto on_error;
			}
			p_type->type = SUBTILIS_TYPE_VOID;

			prv_parse_param_type(p, t, p_type, err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto on_error;

			type->params.fn.params[type->params.fn.num_params++] =
			    p_type;
			p_type = NULL;

			tbuf = subtilis_token_get_text(t);
			if (t->type != SUBTILIS_TOKEN_OPERATOR) {
				subtilis_error_set_right_bkt_expected(
				    err, tbuf, p->l->stream->name, p->l->line);
				goto on_error;
			}

			if (!strcmp(tbuf, ")")) {
				subtilis_lexer_get(p->l, t, err);
				if (err->type != SUBTILIS_ERROR_OK)
					goto on_error;
				break;
			}

			if (strcmp(tbuf, ",")) {
				subtilis_error_set_right_bkt_expected(
				    err, tbuf, p->l->stream->name, p->l->line);
			}

			subtilis_lexer_get(p->l, t, err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto on_error;
			tbuf = subtilis_token_get_text(t);
		}
	}

	return name;

on_error:

	if (p_type) {
		subtilis_type_free(p_type);
		free(p_type);
	}
	free(name);

	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %rcx, %r14
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %r15
movl $0x1, %edi
movl $0x148, %esi            # imm = 0x148
callq 0x12150
testq %rax, %rax
je 0x1c3b7
movq %rax, %rbp
movl $0x8, (%rax)
movl $0x9, (%r13)
movq %rax, 0x8(%r13)
movq $0x0, 0x10(%r13)
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
movl $0x1, %ecx
movq %r14, %r8
callq 0x1b01f
movq %rax, %rbx
cmpl $0x0, (%r14)
je 0x1c3e7
xorl %ebp, %ebp
testq %rbp, %rbp
je 0x1c3ad
movq %rbp, %rdi
callq 0x2f843
movq %rbp, %rdi
callq 0x122c0
movq %rbx, %rdi
callq 0x122c0
jmp 0x1c3d0
leaq 0x57262(%rip), %rdx     # 0x73620
movq %r14, %rdi
movl $0x1, %esi
movl $0x619, %ecx            # imm = 0x619
callq 0x145f4
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl (%rbp), %eax
cmpl $0x16, %eax
ja 0x1c40e
movl $0xe00e0, %ecx          # imm = 0xE00E0
btl %eax, %ecx
jae 0x1c670
movq %rbx, %rdi
callq 0x120f0
addq %rbx, %rax
decq %rax
movb $0x0, (%rax)
movq %r12, %rdi
callq 0x12ad0
cmpl $0x2, (%r12)
jne 0x1c3d2
leaq 0x57dee(%rip), %rsi     # 0x74212
movq %rax, %rdi
callq 0x12160
testl %eax, %eax
jne 0x1c3d2
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r14, %rcx
callq 0x1c72c
cmpl $0x0, (%r14)
jne 0x1c396
testb %al, %al
je 0x1c3d2
movq %r12, %rdi
callq 0x12ad0
cmpl $0x6, (%r12)
jne 0x1c637
leaq 0x8(%r12), %rax
movq %rax, 0x8(%rsp)
movq 0x10(%r13), %rdx
cmpq $0x20, %rdx
jae 0x1c6b2
movl $0x1, %edi
movl $0x148, %esi            # imm = 0x148
callq 0x12150
movq %rax, %rbp
movl $0x8, (%rax)
movq %r12, %rdi
callq 0x12ad0
movq %rax, (%rsp)
leaq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r14, %rdx
callq 0x2f72e
cmpl $0x0, (%r14)
jne 0x1c57e
movq (%rsp), %rsi
movl 0x10(%rsp), %eax
cmpl $0x16, %eax
je 0x1c4cc
cmpl $0x9, %eax
jne 0x1c4e6
movq %r15, %rdi
leaq 0x10(%rsp), %rdx
movq %r14, %rcx
callq 0x1f7e6
cmpl $0x0, (%r14)
jne 0x1c574
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12eda
cmpl $0x0, (%r14)
jne 0x1c574
movq %r12, %rdi
callq 0x12ad0
cmpl $0x2, (%r12)
jne 0x1c534
movq %rax, (%rsp)
movq %rax, %rdi
leaq 0x57cfb(%rip), %rsi     # 0x74212
callq 0x12160
testl %eax, %eax
je 0x1c546
movq (%rsp), %rdi
leaq 0x5a126(%rip), %rsi     # 0x76651
callq 0x12160
testl %eax, %eax
je 0x1c55e
movq %rbp, %rdi
leaq 0x10(%rsp), %rsi
movq %r14, %rdx
callq 0x2fa5f
jmp 0x1c574
movq %r15, %rdi
movq %r12, %rsi
leaq 0x10(%rsp), %rdx
movq %rbp, %rcx
movq %r14, %r8
callq 0x1d849
jmp 0x1c574
movq %r15, %rdi
movq %r12, %rsi
leaq 0x10(%rsp), %rdx
movq %rbp, %rcx
movq %r14, %r8
callq 0x1d916
leaq 0x10(%rsp), %rdi
callq 0x2f843
cmpl $0x0, (%r14)
jne 0x1c398
movq 0x10(%r13), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x10(%r13)
movq %rbp, 0x18(%r13,%rax,8)
movq %r12, %rdi
callq 0x12ad0
movq %rax, %rbp
cmpl $0x2, (%r12)
jne 0x1c6e0
movq %rbp, %rdi
leaq 0x57534(%rip), %rsi     # 0x73aed
callq 0x12160
testl %eax, %eax
je 0x1c70f
movq %rbp, %rdi
leaq 0x56fc8(%rip), %rsi     # 0x73598
callq 0x12160
testl %eax, %eax
je 0x1c60c
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
movq %r14, %rdi
movl $0x16, %esi
movq %rbp, %rdx
leaq 0x577ff(%rip), %rcx     # 0x73df5
pushq $0x678                  # imm = 0x678
leaq 0x5701e(%rip), %rax     # 0x73620
pushq %rax
callq 0x1442a
addq $0x10, %rsp
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12eda
cmpl $0x0, (%r14)
jne 0x1c396
movq %r12, %rdi
callq 0x12ad0
cmpl $0x6, (%r12)
je 0x1c46c
movq (%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x56fd7(%rip), %r10     # 0x73620
leaq 0x577a5(%rip), %rcx     # 0x73df5
movq %r14, %rdi
movl $0x12, %esi
movq %rax, %rdx
pushq $0x64d                  # imm = 0x64D
pushq %r10
callq 0x1442a
addq $0x10, %rsp
jmp 0x1c396
movl $0x400200, %ecx         # imm = 0x400200
btl %eax, %ecx
jae 0x1c40e
movq %rbx, %rdi
movl $0x40, %esi
callq 0x12100
testq %rax, %rax
jne 0x1c40b
leaq 0x56f85(%rip), %rdx     # 0x73620
movq %r14, %rdi
movl $0xf, %esi
movl $0x638, %ecx            # imm = 0x638
callq 0x145f4
jmp 0x1c396
incl %edx
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
movq %r14, %rdi
movl $0x29, %esi
movl $0x20, %ecx
pushq $0x655                  # imm = 0x655
leaq 0x56f48(%rip), %rax     # 0x73620
pushq %rax
callq 0x144d6
jmp 0x1c667
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x57703(%rip), %rcx     # 0x73df5
movq %r14, %rdi
movl $0x16, %esi
movq %rbp, %rdx
pushq $0x66b                  # imm = 0x66B
leaq 0x56f17(%rip), %rax     # 0x73620
pushq %rax
jmp 0x1c662
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12eda
cmpl $0x0, (%r14)
jne 0x1c396
jmp 0x1c3d2