// File: /workspace/github_c_makefile_star2_O2/markdryan[P]subtilis/frontend/expression.c
// Function: subtilis_exp_add_call
subtilis_exp_t *subtilis_exp_add_call(subtilis_parser_t *p, char *name,
				      subtilis_builtin_type_t ftype,
				      subtilis_type_section_t *stype,
				      subtilis_ir_arg_t *args,
				      const subtilis_type_t *fn_type,
				      size_t num_params, bool check_error,
				      subtilis_error_t *err)
{
	size_t call_site;
	subtilis_exp_t *e = NULL;
	subtilis_parser_call_t *call = NULL;

	if (fn_type->type == SUBTILIS_TYPE_VOID)
		subtilis_ir_section_add_call(p->current, num_params, args, err);
	else
		e = subtilis_type_if_call(p, fn_type, args, num_params, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto on_error;
	args = NULL;

	/* For calls made inside handlers we will add the offset from the start
	 * of the handler section and fix it up later on when checking the
	 * calls.
	 */

	call_site = p->current->in_error_handler ? p->current->error_len
						 : p->current->len;
	call_site--;

	/*
	 * We don't check for errors after calls to builtin functions that do
	 * not generate errors.  Doing so is wasteful and can also cause problem
	 * when a builtin, like deref, is called in a place where we don't want
	 * to check for errors, e.g., when unwinding the stack.  IR builtins
	 * are indistinguishable from normal functions, but the check_error
	 * flag can be used to disable error checking for those functions.
	 */

	if (check_error && ((ftype == SUBTILIS_BUILTINS_MAX) ||
			    subtilis_builtin_list[ftype].generates_error)) {
		subtilis_exp_handle_errors(p, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto on_error;
	}

	prv_tmp_ref_return(p, fn_type, e, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto on_error;

	if (ftype != SUBTILIS_BUILTINS_MAX) {
		prv_add_builtin(p, name, ftype, err);
		if (err->type != SUBTILIS_ERROR_OK)
			goto on_error;
	}

	call = subtilis_parser_call_new(p->current, call_site,
					p->current->in_error_handler, name,
					stype, p->l->line, ftype, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto on_error;
	name = NULL;
	stype = NULL;

	prv_add_call(p, call, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto on_error;

	return e;

on_error:

	subtilis_exp_delete(e);
	free(args);
	subtilis_parser_call_delete(call);
	subtilis_type_section_delete(stype);
	free(name);

	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, %r14
movq %r8, %r15
movq %rcx, 0x38(%rsp)
movl %edx, %r12d
movq %rsi, 0x30(%rsp)
movq %rdi, %r13
movq 0x90(%rsp), %rbp
movq 0x80(%rsp), %rcx
cmpl $0x8, (%r9)
jne 0x29e1c
movq 0x48(%r13), %rdi
movq %rcx, %rsi
movq %r15, %rdx
movq %rbp, %rcx
callq 0x2b960
xorl %ebx, %ebx
jmp 0x29e30
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %rbp, %r8
callq 0x35673
movq %rax, %rbx
cmpl $0x0, (%rbp)
jne 0x29ea7
movq %rbp, %rcx
movq 0x48(%r13), %rax
movzbl 0x60(%rax), %edx
shll $0x5, %edx
movq 0x30(%rdx,%rax), %rax
movq %rax, 0x40(%rsp)
cmpb $0x0, 0x88(%rsp)
movq %rbp, %r15
je 0x29e90
cmpl $0x9, %r12d
je 0x29e7c
movl %r12d, %eax
imulq $0x688, %rax, %rax      # imm = 0x688
leaq 0x7383e(%rip), %rdx     # 0x9d6b0
cmpb $0x1, 0x680(%rdx,%rax)
jne 0x29e90
movq %r13, %rdi
movq %rcx, %rsi
callq 0x29c49
movq %r15, %rcx
cmpl $0x0, (%r15)
jne 0x29ea4
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x2a057
cmpl $0x0, (%r15)
je 0x29eef
xorl %r15d, %r15d
xorl %ebp, %ebp
movq 0x30(%rsp), %r12
movq 0x38(%rsp), %r14
movq %rbx, %rdi
callq 0x29d88
movq %r15, %rdi
callq 0x122c0
movq %rbp, %rdi
callq 0x33af2
movq %r14, %rdi
callq 0x2dc17
movq %r12, %rdi
callq 0x122c0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rsi
cmpl $0x9, %r12d
je 0x29f7c
movl %r12d, %edi
callq 0x2eaa0
movq %rax, %r14
cmpl $0x0, (%r15)
je 0x29f20
movq %r14, %rdi
callq 0x2dc17
movq %r15, %rsi
cmpl $0x0, (%r15)
jne 0x29ea4
jmp 0x29f7c
movq 0x58(%r13), %rdi
movl 0xb0(%r13), %eax
movl 0xb4(%r13), %ecx
movq %r15, 0x20(%rsp)
andq $0x0, 0x18(%rsp)
movl %ecx, 0x10(%rsp)
andq $0x0, (%rsp)
movl %eax, 0x8(%rsp)
leaq 0x43b97(%rip), %r9      # 0x6dae8
movq 0x30(%rsp), %rsi
xorl %edx, %edx
movq %r14, %rcx
movl %r12d, %r8d
callq 0x2acef
movq %r15, %rsi
movl (%r15), %eax
testl %eax, %eax
je 0x29f7c
cmpl $0x20, %eax
jne 0x29f0d
movq %rsi, %rdi
callq 0x140a4
jmp 0x29f15
movq 0x40(%rsp), %rcx
decq %rcx
movq (%r13), %rax
movq 0x48(%r13), %rdi
movzbl 0x60(%rdi), %edx
movl 0x38(%rax), %r9d
movq %rsi, 0x8(%rsp)
movl %r12d, (%rsp)
movq %rcx, %rsi
movq 0x30(%rsp), %r12
movq %r12, %rcx
movq 0x38(%rsp), %r14
movq %r14, %r8
callq 0x33a78
movq %rax, %rbp
cmpl $0x0, (%r15)
je 0x29fc6
xorl %r15d, %r15d
jmp 0x29eb3
movq 0x80(%r13), %r14
cmpq 0x88(%r13), %r14
jne 0x2a00d
movq 0x90(%r13), %rdi
leaq 0x200(,%r14,8), %rsi
callq 0x12210
testq %rax, %rax
je 0x2a03d
addq $0x40, %r14
movq %rax, 0x90(%r13)
movq %r14, 0x88(%r13)
movq 0x80(%r13), %r14
movq %r15, %rdx
jmp 0x2a017
movq %r15, %rdx
movq 0x90(%r13), %rax
leaq 0x1(%r14), %rcx
movq %rcx, 0x80(%r13)
movq %rbp, (%rax,%r14,8)
cmpl $0x0, (%rdx)
je 0x29edd
xorl %r15d, %r15d
xorl %r14d, %r14d
xorl %r12d, %r12d
jmp 0x29eb3
leaq 0x43a8e(%rip), %rdx     # 0x6dad2
pushq $0x1
popq %rsi
pushq $0x26
popq %rcx
movq %r15, %rdi
callq 0x1429e
movq %r15, %rdx
jmp 0x2a026