// File: /workspace/github_c_makefile_star2_O1/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 0x2b550
movq 0x48(%r13), %rdi
movq %rcx, %rsi
movq %r15, %rdx
movq %rbp, %rcx
callq 0x2d207
xorl %ebx, %ebx
jmp 0x2b564
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %rbp, %r8
callq 0x37694
movq %rax, %rbx
cmpl $0x0, (%rbp)
jne 0x2b5d9
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 0x2b5c2
cmpl $0x9, %ebp
je 0x2b5ae
movl %ebp, %eax
imulq $0x688, %rax, %rax      # imm = 0x688
leaq 0x7210c(%rip), %rdx     # 0x9d6b0
cmpb $0x1, 0x680(%rdx,%rax)
jne 0x2b5c2
movq %r13, %rdi
movq %rcx, %rsi
callq 0x2b37c
movq %r15, %rcx
cmpl $0x0, (%r15)
jne 0x2b5d6
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x2b791
cmpl $0x0, (%r15)
je 0x2b620
xorl %r15d, %r15d
xorl %ebp, %ebp
movq (%rsp), %r12
movq 0x8(%rsp), %r14
movq %rbx, %rdi
callq 0x2b4c3
movq %r15, %rdi
callq 0x122c0
movq %rbp, %rdi
callq 0x35bcf
movq %r14, %rdi
callq 0x2f7d2
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 0x2b650
movl %ebp, %edi
movq %r10, %rsi
callq 0x3075c
movq %rax, %r14
cmpl $0x0, (%r15)
je 0x2b70d
movq %r14, %rdi
callq 0x2f7d2
movq %r15, %r10
cmpl $0x0, (%r10)
jne 0x2b5d6
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 0x35b58
addq $0x10, %rsp
movq %rax, %rbp
cmpl $0x0, (%r15)
je 0x2b694
xorl %r15d, %r15d
jmp 0x2b5e4
movq %r15, %rsi
movq 0x88(%r13), %r14
cmpq %r14, 0x80(%r13)
jne 0x2b6d9
movq 0x90(%r13), %rdi
leaq 0x200(,%r14,8), %rsi
callq 0x12210
testq %rax, %rax
je 0x2b770
addq $0x40, %r14
movq %rax, 0x90(%r13)
movq %r14, 0x88(%r13)
movq %r15, %rsi
movq 0x80(%r13), %rax
movq 0x90(%r13), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x80(%r13)
movq %rbp, (%rcx,%rax,8)
cmpl $0x0, (%rsi)
je 0x2b60e
xorl %r15d, %r15d
xorl %r14d, %r14d
xorl %r12d, %r12d
jmp 0x2b5e4
movq 0x58(%r13), %rdi
movl 0xb0(%r13), %eax
movl 0xb4(%r13), %r10d
subq $0x8, %rsp
xorl %r11d, %r11d
leaq 0x483eb(%rip), %r9      # 0x73b18
movq 0x8(%rsp), %rsi
xorl %edx, %edx
movq %r14, %rcx
movl %ebp, %r8d
pushq %r15
pushq %r11
pushq %r10
pushq %rax
pushq %r11
callq 0x2c522
movq %r15, %r10
addq $0x30, %rsp
movl (%r15), %eax
testl %eax, %eax
je 0x2b64a
cmpl $0x20, %eax
jne 0x2b63f
movq %r10, %rdi
callq 0x14404
jmp 0x2b647
leaq 0x4838b(%rip), %rdx     # 0x73b02
movq %r15, %rdi
movl $0x1, %esi
movl $0x26, %ecx
callq 0x145f4
movq %r15, %rsi
jmp 0x2b6f6