// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movl $0x1, %edi
movl $0x148, %esi            # imm = 0x148
callq 0x12130
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x2019c
movq -0x28(%rbp), %rdi
movl $0x1, %esi
leaq 0x8a4ab(%rip), %rdx     # 0xaa630
movl $0x619, %ecx            # imm = 0x619
callq 0x158e0
movq $0x0, -0x8(%rbp)
jmp 0x20597
movq -0x40(%rbp), %rax
movl $0x8, (%rax)
movq -0x20(%rbp), %rax
movl $0x9, (%rax)
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x28(%rbp), %r8
movl $0x1, %ecx
callq 0x1f410
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x201f4
jmp 0x2056d
movq -0x40(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x5c(%rbp)
addl $-0x5, %eax
subl $0x3, %eax
jb 0x20228
jmp 0x20207
movl -0x5c(%rbp), %eax
subl $0x9, %eax
je 0x2024a
jmp 0x20211
movl -0x5c(%rbp), %eax
addl $-0x11, %eax
subl $0x3, %eax
jb 0x20228
jmp 0x2021e
movl -0x5c(%rbp), %eax
subl $0x16, %eax
je 0x2024a
jmp 0x2028b
movq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x58(%rbp), %rdi
callq 0x120d0
movq %rax, %rcx
movq -0x68(%rbp), %rax
subq $0x1, %rcx
movb $0x0, (%rax,%rcx)
jmp 0x2028d
movq -0x58(%rbp), %rdi
movl $0x40, %esi
callq 0x120e0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x20282
movq -0x28(%rbp), %rdi
movl $0xf, %esi
leaq 0x8a3bd(%rip), %rdx     # 0xaa630
movl $0x638, %ecx            # imm = 0x638
callq 0x158e0
jmp 0x2056d
movq -0x38(%rbp), %rax
movb $0x0, (%rax)
jmp 0x2028d
jmp 0x2028d
movq -0x18(%rbp), %rdi
callq 0x12d70
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x20563
movq -0x30(%rbp), %rdi
leaq 0x8afea(%rip), %rsi     # 0xab29c
callq 0x12140
cmpl $0x0, %eax
jne 0x20563
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x205b0
andb $0x1, %al
movb %al, -0x41(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x202e8
jmp 0x2056d
testb $0x1, -0x41(%rbp)
jne 0x202fb
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x20597
movq -0x18(%rbp), %rdi
callq 0x12d70
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x6, (%rax)
je 0x20358
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x38(%rax), %r9d
movl $0x12, %esi
leaq 0x8af3b(%rip), %rcx     # 0xab276
leaq 0x8a2ee(%rip), %rax     # 0xaa630
movq %rax, (%rsp)
movl $0x64d, 0x8(%rsp)       # imm = 0x64D
callq 0x156d0
jmp 0x2056d
movq -0x20(%rbp), %rax
cmpq $0x20, 0x10(%rax)
jb 0x203b2
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
addq $0x1, %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x38(%rax), %r9d
movl $0x29, %esi
movl $0x20, %ecx
leaq 0x8a294(%rip), %rax     # 0xaa630
movq %rax, (%rsp)
movl $0x655, 0x8(%rsp)       # imm = 0x655
callq 0x157b0
jmp 0x2056d
movl $0x1, %edi
movl $0x148, %esi            # imm = 0x148
callq 0x12130
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x203eb
movq -0x28(%rbp), %rdi
movl $0x1, %esi
leaq 0x8a254(%rip), %rdx     # 0xaa630
movl $0x65b, %ecx            # imm = 0x65B
callq 0x158e0
jmp 0x2056d
movq -0x50(%rbp), %rax
movl $0x8, (%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x20870
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x20418
jmp 0x2056d
movq -0x50(%rbp), %rdx
movq -0x20(%rbp), %rax
movq -0x20(%rbp), %rsi
movq 0x10(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x10(%rsi)
movq %rdx, 0x18(%rax,%rcx,8)
movq $0x0, -0x50(%rbp)
movq -0x18(%rbp), %rdi
callq 0x12d70
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x2, (%rax)
je 0x2049d
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x38(%rax), %r9d
movl $0x16, %esi
leaq 0x8adf6(%rip), %rcx     # 0xab276
leaq 0x8a1a9(%rip), %rax     # 0xaa630
movq %rax, (%rsp)
movl $0x66b, 0x8(%rsp)       # imm = 0x66B
callq 0x156d0
jmp 0x2056d
movq -0x30(%rbp), %rdi
leaq 0x8a6a9(%rip), %rsi     # 0xaab51
callq 0x12140
cmpl $0x0, %eax
jne 0x204d9
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x133f0
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x204d4
jmp 0x2056d
jmp 0x20561
movq -0x30(%rbp), %rdi
leaq 0x8a0c5(%rip), %rsi     # 0xaa5a9
callq 0x12140
cmpl $0x0, %eax
je 0x20530
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x38(%rax), %r9d
movl $0x16, %esi
leaq 0x8ad5e(%rip), %rcx     # 0xab276
leaq 0x8a111(%rip), %rax     # 0xaa630
movq %rax, (%rsp)
movl $0x678, 0x8(%rsp)       # imm = 0x678
callq 0x156d0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x133f0
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x2054f
jmp 0x2056d
movq -0x18(%rbp), %rdi
callq 0x12d70
movq %rax, -0x30(%rbp)
jmp 0x20308
jmp 0x20563
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x20597
cmpq $0x0, -0x50(%rbp)
je 0x20586
movq -0x50(%rbp), %rdi
callq 0x3e100
movq -0x50(%rbp), %rdi
callq 0x12290
movq -0x58(%rbp), %rdi
callq 0x12290
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)