// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %rdi
movl $0x148, %esi            # imm = 0x148
callq 0x12150
testq %rax, %rax
je 0x1be37
movq %rax, %rbp
movl $0x8, (%rax)
movl $0x9, (%r13)
movq %rax, 0x8(%r13)
andq $0x0, 0x10(%r13)
pushq $0x1
popq %rcx
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
movq %r14, %r8
callq 0x1a7b1
movq %rax, %rbx
cmpl $0x0, (%r14)
je 0x1be65
movq %rbx, %rdi
callq 0x122c0
jmp 0x1be4e
leaq 0x517d2(%rip), %rdx     # 0x6d610
pushq $0x1
popq %rsi
movq %r14, %rdi
movl $0x619, %ecx            # imm = 0x619
callq 0x1429e
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 0x1be8c
movl $0xe00e0, %ecx          # imm = 0xE00E0
btl %eax, %ecx
jae 0x1c089
movq %rbx, %rdi
callq 0x120f0
addq %rbx, %rax
decq %rax
movb $0x0, (%rax)
movq %r12, %rdi
callq 0x12a25
cmpl $0x2, (%r12)
jne 0x1be50
cmpb $0x28, (%rax)
jne 0x1be50
cmpb $0x0, 0x1(%rax)
jne 0x1be50
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r14, %rcx
callq 0x1c17d
cmpl $0x0, (%r14)
jne 0x1be2d
testb %al, %al
je 0x1be50
movq %r12, %rdi
callq 0x12a25
leaq 0x8(%r12), %rcx
movq %rcx, 0x8(%rsp)
cmpl $0x6, (%r12)
jne 0x1c0e0
movq 0x10(%r13), %rdx
cmpq $0x20, %rdx
jae 0x1c102
movl $0x148, %esi            # imm = 0x148
pushq $0x1
popq %rdi
callq 0x12150
movq %rax, (%rsp)
movl $0x8, (%rax)
movq %r12, %rdi
callq 0x12a25
movq %rax, %rbp
leaq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r14, %rdx
callq 0x2db73
cmpl $0x0, (%r14)
jne 0x1c0c7
movl 0x10(%rsp), %eax
cmpl $0x16, %eax
je 0x1bf3c
cmpl $0x9, %eax
jne 0x1bf55
movq %r15, %rdi
movq %rbp, %rsi
leaq 0x10(%rsp), %rdx
movq %r14, %rcx
callq 0x1eb36
cmpl $0x0, (%r14)
jne 0x1bfbf
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12e0e
cmpl $0x0, (%r14)
jne 0x1bfbf
movq %r12, %rdi
callq 0x12a25
cmpl $0x2, (%r12)
jne 0x1bfae
movzbl (%rax), %ecx
cmpl $0x7b, %ecx
je 0x1bfa4
cmpl $0x28, %ecx
jne 0x1bfae
cmpb $0x0, 0x1(%rax)
jne 0x1bfae
movq %r15, %rdi
movq %r12, %rsi
leaq 0x10(%rsp), %rdx
movq (%rsp), %rcx
movq %r14, %r8
callq 0x1cdeb
jmp 0x1bfbf
cmpb $0x0, 0x1(%rax)
je 0x1c06d
movq (%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq %r14, %rdx
callq 0x2de8a
leaq 0x10(%rsp), %rdi
callq 0x2dc7c
cmpl $0x0, (%r14)
jne 0x1c0c7
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 0x12a25
cmpl $0x2, (%r12)
jne 0x1c12c
movzbl (%rax), %ecx
cmpl $0x2c, %ecx
je 0x1c013
cmpl $0x29, %ecx
jne 0x1c019
cmpb $0x0, 0x1(%rax)
jne 0x1c019
jmp 0x1c160
cmpb $0x0, 0x1(%rax)
je 0x1c048
movq (%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
movq %r14, %rdi
pushq $0x16
popq %rsi
movq %rax, %rdx
leaq 0x51d91(%rip), %rcx     # 0x6ddc5
pushq $0x678                  # imm = 0x678
leaq 0x515d0(%rip), %rax     # 0x6d610
pushq %rax
callq 0x140cd
popq %rax
popq %rcx
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12e0e
cmpl $0x0, (%r14)
jne 0x1be2d
movq %r12, %rdi
callq 0x12a25
jmp 0x1bed7
movq %r15, %rdi
movq %r12, %rsi
leaq 0x10(%rsp), %rdx
movq (%rsp), %rcx
movq %r14, %r8
callq 0x1ceb1
jmp 0x1bfbf
movl $0x400200, %ecx         # imm = 0x400200
btl %eax, %ecx
jae 0x1be8c
pushq $0x40
popq %rsi
movq %rbx, %rdi
callq 0x12100
testq %rax, %rax
jne 0x1be89
leaq 0x5155e(%rip), %rdx     # 0x6d610
pushq $0xf
popq %rsi
movq %r14, %rdi
movl $0x638, %ecx            # imm = 0x638
callq 0x1429e
jmp 0x1be2d
movq (%rsp), %r14
movq %r14, %rdi
callq 0x2dc7c
movq %r14, %rdi
callq 0x122c0
jmp 0x1be2d
movq (%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x51cd3(%rip), %rcx     # 0x6ddc5
pushq $0x12
popq %rsi
movq %r14, %rdi
movq %rax, %rdx
pushq $0x64d                  # imm = 0x64D
jmp 0x1c14c
incl %edx
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
pushq $0x29
popq %rsi
pushq $0x20
popq %rcx
movq %r14, %rdi
pushq $0x655                  # imm = 0x655
leaq 0x514ec(%rip), %rax     # 0x6d610
pushq %rax
callq 0x14179
jmp 0x1c159
movq (%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x51c87(%rip), %rcx     # 0x6ddc5
pushq $0x16
popq %rsi
movq %r14, %rdi
movq %rax, %rdx
pushq $0x66b                  # imm = 0x66B
leaq 0x514bd(%rip), %rax     # 0x6d610
pushq %rax
callq 0x140cd
popq %rax
popq %rcx
jmp 0x1be2d
movq (%r15), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x12e0e
cmpl $0x0, (%r14)
jne 0x1be2d
jmp 0x1be50