// File: /workspace/github_c_makefile_star2_O3/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, 0x10(%rsp)
leaq 0x120(%rsp), %rdx
movl $0x8, (%rdx)
xorl %ecx, %ecx
movq %r12, %r8
callq 0x1a764
movq %rax, (%rsp)
cmpl $0x0, (%r12)
je 0x1a2e7
xorl %r14d, %r14d
xorl %edi, %edi
xorl %esi, %esi
callq 0x1afb9
xorl %ebx, %ebx
xorl %ebp, %ebp
movq (%rsp), %r13
jmp 0x1a4df
movq (%r15), %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x12edc
cmpl $0x0, (%r12)
je 0x1a329
movq 0x10(%rsp), %r15
xorl %ebp, %ebp
xorl %edi, %edi
xorl %esi, %esi
callq 0x1afb9
movl $0x0, %ebx
movl $0x0, %r14d
testq %r15, %r15
movq (%rsp), %r13
jne 0x1a4d7
jmp 0x1a4df
movq %r13, %rdi
callq 0x12ad0
xorl %r14d, %r14d
cmpl $0x2, (%r13)
movq %rax, %rsi
movl $0x0, %eax
movl $0x0, %ebx
movl $0x0, %ebp
jne 0x1a421
movb (%rsi), %dl
cmpb $0x7b, %dl
jne 0x1a3ec
xorl %r14d, %r14d
cmpb $0x0, 0x1(%rsi)
movl $0x0, %eax
movl $0x0, %ebx
movl $0x0, %ebp
jne 0x1a421
movb %dl, 0x8(%rsp)
movq (%r15), %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x12edc
cmpl $0x0, (%r12)
jne 0x1a2fc
movq %r13, %rdi
callq 0x12ad0
cmpl $0x2, (%r13)
jne 0x1a3b3
cmpb $0x7d, (%rax)
jne 0x1a3b3
cmpb $0x0, 0x1(%rax)
je 0x1a61f
movq (%r15), %rcx
movq 0x30(%rcx), %r8
movl 0x38(%rcx), %r9d
leaq 0x5928e(%rip), %r10     # 0x73653
leaq 0x59284(%rip), %rdx     # 0x73650
movq %r12, %rdi
movl $0x1d, %esi
movq %rax, %rcx
pushq $0x1a2                  # imm = 0x1A2
pushq %r10
callq 0x143da
addq $0x10, %rsp
jmp 0x1a2fc
movl %edx, %ecx
xorl %r14d, %r14d
movl $0x0, %eax
movl $0x0, %ebx
movl $0x0, %ebp
cmpb $0x28, %cl
jne 0x1a421
xorl %r14d, %r14d
cmpb $0x0, 0x1(%rsi)
movl $0x0, %eax
movl $0x0, %ebx
movl $0x0, %ebp
je 0x1a573
movq %rax, 0x8(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1aea2
leaq 0x120(%rsp), %rsi
movq (%rsp), %rdi
movq %r12, %rdx
callq 0x1aedc
movq %rax, %r13
cmpl $0x0, (%r12)
jne 0x1a47a
movq 0x10(%rsp), %rcx
leaq 0x120(%rsp), %rdi
movq %r14, %rsi
movq 0x8(%rsp), %rbx
movq %rbx, %rdx
movq %r12, %r8
callq 0x2f284
cmpl $0x0, (%r12)
je 0x1a51e
xorl %ebx, %ebx
testq %r14, %r14
je 0x1a496
xorl %r15d, %r15d
movq 0x20(%rsp,%r15,8), %rdi
callq 0x2b166
incq %r15
cmpq %r15, %r14
jne 0x1a484
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x1afb9
movq 0x10(%rsp), %r15
testq %r15, %r15
je 0x1a4df
testq %r14, %r14
je 0x1a4d4
movq %r13, (%rsp)
movq %r15, %r12
movq %r14, %r13
movq (%r12), %rdi
callq 0x122c0
addq $0x10, %r12
decq %r13
jne 0x1a4bc
movq (%rsp), %r13
jmp 0x1a4d7
xorl %r14d, %r14d
movq %r15, %rdi
callq 0x122c0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1aea2
movq %rbp, %rdi
callq 0x122c0
movq %r13, %rdi
callq 0x122c0
leaq 0x120(%rsp), %rdi
callq 0x2f56e
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 %rbx, %rdi
movq %r14, %rsi
movq %rax, %rbx
callq 0x1afb9
subq $0x8, %rsp
movq %r13, %rsi
leaq 0x128(%rsp), %r13
movq %r15, %rdi
movl $0x9, %edx
movq %rbx, %rcx
movq %rbp, %r8
movq %r13, %r9
pushq %r12
pushq $0x1
pushq %r14
callq 0x2b1aa
addq $0x20, %rsp
movq %rax, %rbx
movq %r13, %rdi
callq 0x2f56e
movq 0x48(%r15), %rax
movb $0x1, 0xe0(%rax)
jmp 0x1a509
movl %edx, %ebx
leaq 0x20(%rsp), %rdx
movl $0x20, %ecx
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %r8
callq 0x1f31a
movq %rax, %r14
cmpl $0x0, (%r12)
jne 0x1a5ac
movq (%r15), %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x12edc
cmpl $0x0, (%r12)
je 0x1a5c2
movq $0x0, 0x8(%rsp)
xorl %ebx, %ebx
xorl %ebp, %ebp
movq (%rsp), %r13
jmp 0x1a47c
movq %r13, %rdi
callq 0x12ad0
cmpb $0x7b, %bl
je 0x1a5e5
cmpl $0x2, (%r13)
jne 0x1a5e5
cmpb $0x28, (%rax)
jne 0x1a5e5
cmpb $0x0, 0x1(%rax)
je 0x1a6dd
leaq 0x20(%rsp), %rsi
leaq 0x10(%rsp), %rcx
movq %r15, %rdi
movq %r14, %rdx
movq %r12, %r8
callq 0x1aa2e
movq %rax, %rbx
cmpl $0x0, (%r12)
movq (%rsp), %r13
je 0x1a694
movq $0x0, 0x8(%rsp)
xorl %ebp, %ebp
jmp 0x1a47c
movq (%r15), %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x12edc
cmpl $0x0, (%r12)
jne 0x1a2fc
movq %r13, %rdi
callq 0x12ad0
movq %rax, 0x18(%rsp)
leaq 0x120(%rsp), %rdx
movq %r15, %rdi
movq (%rsp), %rsi
movq %r12, %rcx
callq 0x1a882
cmpl $0x0, (%r12)
jne 0x1a2fc
xorl %r14d, %r14d
cmpl $0x2, (%r13)
movl $0x0, %eax
movl $0x0, %ebx
movl $0x0, %ebp
movb 0x8(%rsp), %dl
movq 0x18(%rsp), %rsi
jne 0x1a421
movb (%rsi), %cl
jmp 0x1a3ee
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x1ad99
movq %rax, %rbp
cmpl $0x0, (%r12)
je 0x1a6ba
movq $0x0, 0x8(%rsp)
jmp 0x1a47c
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x1ae23
cmpl $0x0, (%r12)
je 0x1a421
movq %rax, 0x8(%rsp)
jmp 0x1a5b9
leaq 0x20(%rsp), %rsi
leaq 0x120(%rsp), %r8
movq %r15, %rdi
movq %r14, %rdx
movq (%rsp), %rcx
movq %r12, %r9
callq 0x1a921
cmpl $0x0, (%r12)
jne 0x1a5ac
testq %r14, %r14
je 0x1a720
xorl %ebx, %ebx
movq 0x20(%rsp,%rbx,8), %rdi
callq 0x2b166
incq %rbx
cmpq %rbx, %r14
jne 0x1a70e
leaq 0x20(%rsp), %rdx
movl $0x20, %ecx
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %r8
callq 0x1f31a
movq %rax, %r14
cmpl $0x0, (%r12)
jne 0x1a5ac
movq (%r15), %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x12edc
cmpl $0x0, (%r12)
jne 0x1a5ac
jmp 0x1a5e5