// File: /workspace/github_c_makefile_star2_O3/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 0x1c4fa
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 0x1b109
movq %rax, %rbx
cmpl $0x0, (%r14)
je 0x1c52a
movq %rbx, %rdi
callq 0x122c0
jmp 0x1c513
leaq 0x57152(%rip), %rdx     # 0x73653
movq %r14, %rdi
movl $0x1, %esi
movl $0x619, %ecx            # imm = 0x619
callq 0x145a4
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 0x1c551
movl $0xe00e0, %ecx          # imm = 0xE00E0
btl %eax, %ecx
jae 0x1c75c
movq %rbx, %rdi
callq 0x120f0
addq %rbx, %rax
decq %rax
movb $0x0, (%rax)
movq %r12, %rdi
callq 0x12ad0
cmpl $0x2, (%r12)
jne 0x1c515
cmpb $0x28, (%rax)
jne 0x1c515
cmpb $0x0, 0x1(%rax)
jne 0x1c515
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r14, %rcx
callq 0x1c86a
cmpl $0x0, (%r14)
jne 0x1c4f0
testb %al, %al
je 0x1c515
movq %r12, %rdi
callq 0x12ad0
cmpl $0x6, (%r12)
jne 0x1c79e
leaq 0x8(%r12), %rax
movq %rax, 0x8(%rsp)
movq 0x10(%r13), %rdx
cmpq $0x20, %rdx
jae 0x1c7f0
movl $0x1, %edi
movl $0x148, %esi            # imm = 0x148
callq 0x12150
movq %rax, (%rsp)
movl $0x8, (%rax)
movq %r12, %rdi
callq 0x12ad0
movq %rax, %rbp
leaq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r14, %rdx
callq 0x2f457
cmpl $0x0, (%r14)
jne 0x1c7d7
movl 0x10(%rsp), %eax
cmpl $0x16, %eax
je 0x1c603
cmpl $0x9, %eax
jne 0x1c61c
movq %r15, %rdi
movq %rbp, %rsi
leaq 0x10(%rsp), %rdx
movq %r14, %rcx
callq 0x1f81b
cmpl $0x0, (%r14)
jne 0x1c686
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12edc
cmpl $0x0, (%r14)
jne 0x1c686
movq %r12, %rdi
callq 0x12ad0
cmpl $0x2, (%r12)
jne 0x1c675
movzbl (%rax), %ecx
cmpl $0x7b, %ecx
je 0x1c66b
cmpl $0x28, %ecx
jne 0x1c675
cmpb $0x0, 0x1(%rax)
jne 0x1c675
movq %r15, %rdi
movq %r12, %rsi
leaq 0x10(%rsp), %rdx
movq (%rsp), %rcx
movq %r14, %r8
callq 0x1d94d
jmp 0x1c686
cmpb $0x0, 0x1(%rax)
je 0x1c740
movq (%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq %r14, %rdx
callq 0x2f78a
leaq 0x10(%rsp), %rdi
callq 0x2f56e
cmpl $0x0, (%r14)
jne 0x1c7d7
movq 0x10(%r13), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x10(%r13)
movq (%rsp), %rcx
movq %rcx, 0x18(%r13,%rax,8)
movq %r12, %rdi
callq 0x12ad0
cmpl $0x2, (%r12)
jne 0x1c81e
movzbl (%rax), %ecx
cmpl $0x2c, %ecx
je 0x1c6da
cmpl $0x29, %ecx
jne 0x1c6e0
cmpb $0x0, 0x1(%rax)
jne 0x1c6e0
jmp 0x1c84d
cmpb $0x0, 0x1(%rax)
je 0x1c713
movq (%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
movq %r14, %rdi
movl $0x16, %esi
movq %rax, %rdx
leaq 0x57718(%rip), %rcx     # 0x73e15
pushq $0x678                  # imm = 0x678
leaq 0x56f4a(%rip), %rax     # 0x73653
pushq %rax
callq 0x143da
addq $0x10, %rsp
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12edc
cmpl $0x0, (%r14)
jne 0x1c4f0
movq %r12, %rdi
callq 0x12ad0
cmpl $0x6, (%r12)
je 0x1c5a7
jmp 0x1c79e
movq %r15, %rdi
movq %r12, %rsi
leaq 0x10(%rsp), %rdx
movq (%rsp), %rcx
movq %r14, %r8
callq 0x1da1a
jmp 0x1c686
movl $0x400200, %ecx         # imm = 0x400200
btl %eax, %ecx
jae 0x1c551
movq %rbx, %rdi
movl $0x40, %esi
callq 0x12100
testq %rax, %rax
jne 0x1c54e
leaq 0x56ecc(%rip), %rdx     # 0x73653
movq %r14, %rdi
movl $0xf, %esi
movl $0x638, %ecx            # imm = 0x638
callq 0x145a4
jmp 0x1c4f0
movq (%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x56ea3(%rip), %r10     # 0x73653
leaq 0x5765e(%rip), %rcx     # 0x73e15
movq %r14, %rdi
movl $0x12, %esi
movq %rax, %rdx
pushq $0x64d                  # imm = 0x64D
pushq %r10
callq 0x143da
addq $0x10, %rsp
jmp 0x1c4f0
movq (%rsp), %r14
movq %r14, %rdi
callq 0x2f56e
movq %r14, %rdi
callq 0x122c0
jmp 0x1c4f0
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 0x56e3d(%rip), %rax     # 0x73653
pushq %rax
callq 0x14486
jmp 0x1c7ce
movq (%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x575e5(%rip), %rcx     # 0x73e15
movq %r14, %rdi
movl $0x16, %esi
movq %rax, %rdx
pushq $0x66b                  # imm = 0x66B
leaq 0x56e0c(%rip), %rax     # 0x73653
pushq %rax
jmp 0x1c7c9
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12edc
cmpl $0x0, (%r14)
jne 0x1c4f0
jmp 0x1c515