// File: /workspace/github_c_makefile_star2_O3/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 $0x18, %rsp
movq %r9, %r14
movq %r8, %r15
movq %rcx, 0x8(%rsp)
movl %edx, %r12d
movq %rsi, (%rsp)
movq %rdi, %r13
movq 0x60(%rsp), %rbp
movq 0x50(%rsp), %rcx
cmpl $0x8, (%r9)
jne 0x2b1f3
movq 0x48(%r13), %rdi
movq %rcx, %rsi
movq %r15, %rdx
movq %rbp, %rcx
callq 0x2ce96
xorl %ebx, %ebx
jmp 0x2b207
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %rbp, %r8
callq 0x37552
movq %rax, %rbx
cmpl $0x0, (%rbp)
jne 0x2b27c
movq %rbp, %rcx
movq 0x48(%r13), %rax
movzbl 0x60(%rax), %edx
shll $0x5, %edx
movq 0x30(%rdx,%rax), %rax
movq %rax, 0x10(%rsp)
cmpb $0x0, 0x58(%rsp)
movq %rbp, %r15
movq %r12, %rbp
je 0x2b265
cmpl $0x9, %ebp
je 0x2b251
movl %ebp, %eax
imulq $0x688, %rax, %rax      # imm = 0x688
leaq 0x72469(%rip), %rdx     # 0x9d6b0
cmpb $0x1, 0x680(%rdx,%rax)
jne 0x2b265
movq %r13, %rdi
movq %rcx, %rsi
callq 0x2b01f
movq %r15, %rcx
cmpl $0x0, (%r15)
jne 0x2b279
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x2b422
cmpl $0x0, (%r15)
je 0x2b2c3
xorl %r15d, %r15d
xorl %ebp, %ebp
movq (%rsp), %r12
movq 0x8(%rsp), %r14
movq %rbx, %rdi
callq 0x2b166
movq %r15, %rdi
callq 0x122c0
movq %rbp, %rdi
callq 0x35a74
movq %r14, %rdi
callq 0x2f4fb
movq %r12, %rdi
callq 0x122c0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %r10
cmpl $0x9, %ebp
je 0x2b349
movl %ebp, %edi
movq %r10, %rsi
callq 0x304a0
movq %rax, %r14
cmpl $0x0, (%r15)
je 0x2b2f1
movq %r14, %rdi
callq 0x2f4fb
movq %r15, %r10
cmpl $0x0, (%r15)
jne 0x2b279
jmp 0x2b349
movq 0x58(%r13), %rdi
movl 0xb0(%r13), %eax
movl 0xb4(%r13), %r10d
subq $0x8, %rsp
xorl %r11d, %r11d
leaq 0x4881f(%rip), %r9      # 0x73b30
movq 0x8(%rsp), %rsi
xorl %edx, %edx
movq %r14, %rcx
movl %ebp, %r8d
pushq %r15
pushq %r11
pushq %r10
pushq %rax
pushq %r11
callq 0x2c1a2
movq %r15, %r10
addq $0x30, %rsp
movl (%r15), %eax
testl %eax, %eax
je 0x2b349
cmpl $0x20, %eax
jne 0x2b2de
movq %r10, %rdi
callq 0x143b4
jmp 0x2b2e6
movq 0x10(%rsp), %rsi
decq %rsi
movq (%r13), %rax
movq 0x48(%r13), %rdi
movzbl 0x60(%rdi), %edx
movl 0x38(%rax), %r9d
movq (%rsp), %r12
movq %r12, %rcx
movq 0x8(%rsp), %r14
movq %r14, %r8
pushq %r10
pushq %rbp
callq 0x359f4
addq $0x10, %rsp
movq %rax, %rbp
cmpl $0x0, (%r15)
je 0x2b38d
xorl %r15d, %r15d
jmp 0x2b287
movq 0x80(%r13), %r14
cmpq 0x88(%r13), %r14
jne 0x2b3d4
movq 0x90(%r13), %rdi
leaq 0x200(,%r14,8), %rsi
callq 0x12210
testq %rax, %rax
je 0x2b404
addq $0x40, %r14
movq %rax, 0x90(%r13)
movq %r14, 0x88(%r13)
movq 0x80(%r13), %r14
movq %r15, %rdx
jmp 0x2b3de
movq %r15, %rdx
movq 0x90(%r13), %rax
leaq 0x1(%r14), %rcx
movq %rcx, 0x80(%r13)
movq %rbp, (%rax,%r14,8)
cmpl $0x0, (%rdx)
je 0x2b2b1
xorl %r15d, %r15d
xorl %r14d, %r14d
xorl %r12d, %r12d
jmp 0x2b287
leaq 0x4870f(%rip), %rdx     # 0x73b1a
movq %r15, %rdi
movl $0x1, %esi
movl $0x26, %ecx
callq 0x145a4
movq %r15, %rdx
jmp 0x2b3ed