// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/frontend/parser_call.c
// Function: subtilis_parser_call
subtilis_exp_t *subtilis_parser_call(subtilis_parser_t *p, subtilis_token_t *t,
				     subtilis_error_t *err)
{
	subtilis_exp_t *ret_val;
	const char *tbuf;
	subtilis_type_t fn_type;
	subtilis_exp_t *poss_args[SUBTILIS_MAX_ARGS];
	size_t i;
	subtilis_check_args_t *check_args = NULL;
	size_t num_poss_args = 0;
	bool vector = false;
	subtilis_type_section_t *stype = NULL;
	subtilis_type_t *ptypes = NULL;
	char *name = NULL;
	subtilis_parser_param_t *params = NULL;
	subtilis_ir_arg_t *args = NULL;

	fn_type.type = SUBTILIS_TYPE_VOID;

	name = prv_proc_name_and_type(p, t, &fn_type, false, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto on_error;

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

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

		tbuf = subtilis_token_get_text(t);
		if ((t->type != SUBTILIS_TOKEN_OPERATOR) || strcmp(tbuf, "}")) {
			subtilis_error_set_expected(
			    err, "} ", tbuf, p->l->stream->name, p->l->line);
			goto on_error;
		}
		subtilis_lexer_get(p->l, t, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto on_error;
		tbuf = subtilis_token_get_text(t);

		prv_process_vector_fn_type(p, name, &fn_type, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto on_error;
		vector = true;
	}
	if ((t->type == SUBTILIS_TOKEN_OPERATOR) && !strcmp(tbuf, "(")) {
		num_poss_args = subtilis_var_bracketed_args_have_b(
		    p, t, poss_args, SUBTILIS_MAX_ARGS, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto on_error;

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

		tbuf = subtilis_token_get_text(t);
		if (!vector && (t->type == SUBTILIS_TOKEN_OPERATOR) &&
		    !strcmp(tbuf, "(")) {
			/*
			 * The expressions in poss_args are type information
			 * for the return type of this function which is an
			 * array.
			 */

			prv_process_array_fn_type(p, poss_args, num_poss_args,
						  name, &fn_type, err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto on_error;

			for (i = 0; i < num_poss_args; i++)
				subtilis_exp_delete(poss_args[i]);

			num_poss_args = subtilis_var_bracketed_args_have_b(
			    p, t, poss_args, SUBTILIS_MAX_ARGS, err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto on_error;
			subtilis_lexer_get(p->l, t, err);
			if (err->type != SUBTILIS_ERROR_OK)
				goto on_error;
		}

		params = prv_call_parameters(p, poss_args, num_poss_args,
					     &check_args, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto on_error;
		args = prv_parser_to_ir_args(params, num_poss_args, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto on_error;
		ptypes = prv_parser_to_ptypes(params, num_poss_args, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto on_error;
	}

	prv_delete_params(params, num_poss_args);
	params = NULL;

	name = prv_complete_fn_name(name, &fn_type, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto on_error;

	stype = subtilis_type_section_new(&fn_type, num_poss_args, ptypes,
					  check_args, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto on_error;
	prv_delete_ptypes(ptypes, num_poss_args);
	ptypes = NULL;

	/* Ownership of stypes, args and name passed to this function. */

	ret_val =
	    subtilis_exp_add_call(p, name, SUBTILIS_BUILTINS_MAX, stype, args,
				  &fn_type, num_poss_args, true, err);

	subtilis_type_free(&fn_type);

	p->current->proc_called = true;

	return ret_val;

on_error:

	for (i = 0; i < num_poss_args; i++)
		subtilis_exp_delete(poss_args[i]);

	prv_delete_ptypes(ptypes, num_poss_args);
	if (check_args) {
		for (i = 0; i < num_poss_args; i++)
			free(check_args[i].arg_name);
		free(check_args);
	}
	prv_delete_params(params, num_poss_args);
	free(args);
	free(name);

	subtilis_type_free(&fn_type);

	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x268, %rsp            # imm = 0x268
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %r15
movq $0x0, 0x18(%rsp)
leaq 0x120(%rsp), %rdx
movl $0x8, (%rdx)
xorl %r14d, %r14d
xorl %ecx, %ecx
movq %r12, %r8
callq 0x1a77f
movq %rax, 0x8(%rsp)
cmpl $0x0, (%r12)
jne 0x1a34e
movq (%r15), %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x12eda
xorl %r14d, %r14d
cmpl $0x0, (%r12)
je 0x1a3ea
xorl %ebx, %ebx
xorl %r15d, %r15d
xorl %ebp, %ebp
testq %r14, %r14
je 0x1a36f
xorl %r12d, %r12d
movq 0x20(%rsp,%r12,8), %rdi
callq 0x2b4c3
incq %r12
cmpq %r12, %r14
jne 0x1a35d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1aecf
movq 0x18(%rsp), %rbx
testq %rbx, %rbx
je 0x1a3a9
testq %r14, %r14
je 0x1a3a1
movq %rbx, %r12
movq %r14, %r13
movq (%r12), %rdi
callq 0x122c0
addq $0x10, %r12
decq %r13
jne 0x1a38f
movq %rbx, %rdi
callq 0x122c0
movq %r15, %rdi
movq %r14, %rsi
callq 0x1adb8
movq %rbp, %rdi
callq 0x122c0
movq 0x8(%rsp), %rdi
callq 0x122c0
leaq 0x120(%rsp), %rdi
callq 0x2f843
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
callq 0x12ad0
cmpl $0x2, (%r13)
jne 0x1a425
leaq 0x5c251(%rip), %rsi     # 0x76651
movq %rax, %rbx
movq %rax, %rdi
callq 0x12160
testl %eax, %eax
je 0x1a4d0
movq %r15, 0x10(%rsp)
movl $0x0, 0x4(%rsp)
movq %rbx, %rax
jmp 0x1a432
movq %r15, 0x10(%rsp)
movl $0x0, 0x4(%rsp)
xorl %r14d, %r14d
cmpl $0x2, (%r13)
movl $0x0, %ebx
movl $0x0, %r15d
movl $0x0, %ebp
jne 0x1a476
leaq 0x59dbf(%rip), %rsi     # 0x74212
movq %rax, %rdi
callq 0x12160
xorl %r14d, %r14d
movl $0x0, %ebx
movl $0x0, %r15d
movl $0x0, %ebp
testl %eax, %eax
je 0x1a550
movq %r15, %rdi
movq %r14, %rsi
callq 0x1adb8
leaq 0x120(%rsp), %rsi
movq 0x8(%rsp), %rdi
movq %r12, %rdx
callq 0x1adf2
movq %rax, 0x8(%rsp)
cmpl $0x0, (%r12)
jne 0x1a4c8
movq 0x18(%rsp), %rcx
leaq 0x120(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
movq %r12, %r8
callq 0x2f57c
cmpl $0x0, (%r12)
je 0x1a5ef
xorl %r15d, %r15d
jmp 0x1a355
movq (%r15), %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x12eda
xorl %r14d, %r14d
cmpl $0x0, (%r12)
jne 0x1a34e
movq %r13, %rdi
callq 0x12ad0
movq %rax, %rbx
cmpl $0x2, (%r13)
jne 0x1a515
leaq 0x59116(%rip), %rsi     # 0x7361b
movq %rbx, %rdi
callq 0x12160
testl %eax, %eax
je 0x1a64e
movq (%r15), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x590f9(%rip), %rax     # 0x73620
leaq 0x590ef(%rip), %rdx     # 0x7361d
movq %r12, %rdi
movl $0x1d, %esi
movq %rbx, %rcx
pushq $0x1a2                  # imm = 0x1A2
pushq %rax
callq 0x1442a
addq $0x10, %rsp
xorl %r14d, %r14d
jmp 0x1a34e
leaq 0x20(%rsp), %rdx
movl $0x20, %ecx
movq 0x10(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %r8
callq 0x1f290
movq %rax, %r14
cmpl $0x0, (%r12)
jne 0x1a34e
movq (%rbp), %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x12eda
cmpl $0x0, (%r12)
jne 0x1a34e
movq %r13, %rdi
callq 0x12ad0
cmpb $0x0, 0x4(%rsp)
jne 0x1a5c2
cmpl $0x2, (%r13)
jne 0x1a5c2
leaq 0x59c60(%rip), %rsi     # 0x74212
movq %rax, %rdi
callq 0x12160
testl %eax, %eax
je 0x1a6f0
leaq 0x20(%rsp), %rsi
leaq 0x18(%rsp), %rcx
movq %rbp, %rdi
movq %r14, %rdx
movq %r12, %r8
callq 0x1aa48
movq %rax, %r15
cmpl $0x0, (%r12)
je 0x1a6ab
xorl %ebx, %ebx
jmp 0x1a353
movq %rax, %r15
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1aecf
subq $0x8, %rsp
leaq 0x128(%rsp), %r9
movq 0x18(%rsp), %r13
movq %r13, %rdi
movq 0x10(%rsp), %rsi
movl $0x9, %edx
movq %r15, %rcx
movq %rbp, %r8
movq %r9, %r15
pushq %r12
pushq $0x1
pushq %r14
callq 0x2b507
addq $0x20, %rsp
movq %rax, %rbx
movq %r15, %rdi
callq 0x2f843
movq 0x48(%r13), %rax
movb $0x1, 0xe0(%rax)
jmp 0x1a3d5
movq (%r15), %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x12eda
xorl %r14d, %r14d
cmpl $0x0, (%r12)
jne 0x1a34e
movq %r13, %rdi
callq 0x12ad0
movq %rax, %rbx
leaq 0x120(%rsp), %rdx
movq %r15, %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rcx
callq 0x1a89c
xorl %r14d, %r14d
cmpl $0x0, (%r12)
jne 0x1a34e
movq %r15, 0x10(%rsp)
movb $0x1, %al
movl %eax, 0x4(%rsp)
jmp 0x1a420
movq %rbp, 0x10(%rsp)
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x1aca3
movq %rax, %rbp
cmpl $0x0, (%r12)
je 0x1a6cf
xorl %ebx, %ebx
jmp 0x1a355
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x1ad39
movq %rax, %rbx
cmpl $0x0, (%r12)
jne 0x1a355
jmp 0x1a476
leaq 0x20(%rsp), %rsi
leaq 0x120(%rsp), %r8
movq %rbp, %rdi
movq %r14, %rdx
movq 0x8(%rsp), %rcx
movq %r12, %r9
callq 0x1a93b
cmpl $0x0, (%r12)
jne 0x1a34e
testq %r14, %r14
je 0x1a734
xorl %ebx, %ebx
movq 0x20(%rsp,%rbx,8), %rdi
callq 0x2b4c3
incq %rbx
cmpq %rbx, %r14
jne 0x1a722
leaq 0x20(%rsp), %rdx
movl $0x20, %ecx
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %r8
callq 0x1f290
movq %rax, %r14
cmpl $0x0, (%r12)
jne 0x1a34e
movq %rbp, %rbx
movq (%rbp), %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x12eda
cmpl $0x0, (%r12)
jne 0x1a34e
movq %rbx, %rbp
jmp 0x1a5c2