// File: /workspace/github_c_makefile_star2_O1/lucvoo[P]sparse-dev/linearize.c
// Function: linearize_call_expression
static pseudo_t linearize_call_expression(struct entrypoint *ep, struct expression *expr)
{
	struct expression *arg, *fn;
	struct instruction *insn;
	pseudo_t retval, call;
	struct ctype *ctype = NULL;
	struct symbol *fntype;
	struct context *context;

	if (!expr->ctype)
		return VOID;

	fn = expr->fn;
	fntype = fn->ctype;

	// handle builtins
	if (fntype->op && fntype->op->linearize) {
		retval = fntype->op->linearize(ep, expr);
		if (retval)
			return retval;
	}

	ctype = &fntype->ctype;

	insn = alloc_typed_instruction(OP_CALL, expr->ctype);
	add_symbol(&insn->fntypes, fntype);
	FOR_EACH_PTR(expr->args, arg) {
		pseudo_t new = linearize_expression(ep, arg);
		use_pseudo(insn, new, add_pseudo(&insn->arguments, new));
		add_symbol(&insn->fntypes, arg->ctype);
	} END_FOR_EACH_PTR(arg);

	if (fn->type == EXPR_PREOP && fn->op == '*' && is_func_type(fn->ctype))
		fn = fn->unop;

	if (fn->type == EXPR_SYMBOL) {
		call = symbol_pseudo(ep, fn->symbol);
	} else {
		call = linearize_expression(ep, fn);
	}
	use_pseudo(insn, call, &insn->func);
	retval = VOID;
	if (expr->ctype != &void_ctype)
		retval = alloc_pseudo(insn);
	insn->target = retval;
	add_one_insn(ep, insn);

	if (ctype) {
		FOR_EACH_PTR(ctype->contexts, context) {
			int in = context->in;
			int out = context->out;
			int check = 0;
			int context_diff;
			if (in < 0) {
				check = 1;
				in = 0;
			}
			if (out < 0) {
				check = 0;
				out = 0;
			}
			context_diff = out - in;
			if (check || context_diff) {
				insn = alloc_instruction(OP_CONTEXT, 0);
				insn->increment = context_diff;
				insn->check = check;
				insn->context_expr = context->context;
				add_one_insn(ep, insn);
			}
		} END_FOR_EACH_PTR(context);

		if (ctype->modifiers & MOD_NORETURN)
			add_unreachable(ep);
	}

	return retval;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, 0x8(%rsp)
cmpq $0x0, 0x10(%rsi)
je 0x15794
movq %rsi, %r14
movq 0x20(%rsi), %r15
movq 0x10(%r15), %rbx
movq 0x40(%rbx), %rax
testq %rax, %rax
je 0x15655
movq 0x20(%rax), %rax
testq %rax, %rax
je 0x15655
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq *%rax
testq %rax, %rax
jne 0x15971
movq %r15, 0x38(%rsp)
movq 0x10(%r14), %rsi
movl $0x4a, %edi
callq 0x13602
movq %rax, 0x10(%rsp)
movq %rax, 0x20(%rsp)
leaq 0x40(%rax), %rdi
movq %rdi, 0x18(%rsp)
movq %rbx, 0x28(%rsp)
movq %rbx, %rsi
callq 0x2285b
movq %r14, 0x40(%rsp)
movq 0x28(%r14), %rax
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x15762
movq 0x20(%rsp), %rax
leaq 0x38(%rax), %r13
movq 0x30(%rsp), %rbx
movzwl (%rbx), %eax
testb %al, %al
jle 0x15753
xorl %r14d, %r14d
movq 0x18(%rbx,%r14,8), %r15
movzwl %ax, %eax
cmpl $0x100, %eax            # imm = 0x100
jb 0x156cf
testq %r15, %r15
je 0x15741
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x1447d
movq %rax, %rbp
movq %r13, %rdi
movq %rax, %rsi
callq 0x2285b
movq %rbp, (%rax)
testq %rbp, %rbp
je 0x15733
movq %rax, %r12
movl 0x4(%rbp), %eax
cmpl $0x6, %eax
ja 0x15707
movl $0x43, %ecx
btl %eax, %ecx
jb 0x15733
leaq 0x4baa2(%rip), %rdi     # 0x611b0
movl $0x10, %esi
callq 0x2fd3c
movq %r12, 0x8(%rax)
movq 0x10(%rsp), %rcx
movq %rcx, (%rax)
addq $0x8, %rbp
movq %rbp, %rdi
movq %rax, %rsi
callq 0x2285b
movq 0x10(%r15), %rsi
movq 0x18(%rsp), %rdi
callq 0x2285b
incq %r14
movl (%rbx), %eax
movsbq %al, %rcx
cmpq %rcx, %r14
jl 0x156bb
movq 0x10(%rbx), %rbx
cmpq 0x30(%rsp), %rbx
jne 0x156ad
movq 0x38(%rsp), %rsi
cmpb $0x9, (%rsi)
jne 0x157a0
cmpl $0x2a, 0x4(%rsi)
movq 0x10(%rsp), %r15
movq 0x20(%rsp), %r12
jne 0x157aa
movq 0x10(%rsi), %rax
cmpb $0x3, (%rax)
jne 0x15789
movq 0x60(%rax), %rax
cmpb $0x5, (%rax)
jne 0x157aa
movq 0x20(%rsi), %rsi
jmp 0x157aa
leaq 0x51235(%rip), %rax     # 0x669d0
jmp 0x15971
movq 0x10(%rsp), %r15
movq 0x20(%rsp), %r12
addq $0x30, %r12
cmpb $0x3, (%rsi)
jne 0x157c3
movq 0x20(%rsi), %rsi
movq 0x8(%rsp), %rdi
callq 0x16810
jmp 0x157cd
movq 0x8(%rsp), %rdi
callq 0x1447d
movq %rax, %r14
movq 0x28(%rsp), %rbx
movq %rax, (%r12)
testq %rax, %rax
je 0x15818
movl 0x4(%r14), %eax
cmpl $0x6, %eax
ja 0x157f1
movl $0x43, %ecx
btl %eax, %ecx
jb 0x15818
leaq 0x4b9b8(%rip), %rdi     # 0x611b0
movl $0x10, %esi
callq 0x2fd3c
movq %r12, 0x8(%rax)
movq %r15, (%rax)
addq $0x8, %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0x2285b
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
cmpq 0x4b710(%rip), %rax     # 0x60f38
je 0x1584e
xorl %edi, %edi
callq 0x303a3
movl $0x3, 0x4(%rax)
movl 0x52312(%rip), %ecx     # 0x67b50
incl %ecx
movl %ecx, 0x5230a(%rip)     # 0x67b50
movl %ecx, (%rax)
movq %r15, 0x18(%rax)
jmp 0x15855
leaq 0x5117b(%rip), %rax     # 0x669d0
movq %rax, 0x10(%rsp)
movq %rax, 0x20(%r15)
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rdi
testq %rdi, %rdi
je 0x1587c
movq %rdi, 0x8(%r15)
addq $0x28, %rdi
movq %r15, %rsi
callq 0x2285b
movq 0x78(%rbx), %rax
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x15957
xorl %r15d, %r15d
movq 0x18(%rsp), %r12
movzwl (%r12), %eax
testb %al, %al
jle 0x15947
xorl %ebx, %ebx
movq 0x18(%r12,%rbx,8), %r13
movzwl %ax, %eax
cmpl $0x100, %eax            # imm = 0x100
jb 0x158b9
testq %r13, %r13
je 0x15933
movl 0x8(%r13), %r14d
movl 0xc(%r13), %ebp
testl %r14d, %r14d
movl $0x0, %eax
cmovgl %r14d, %eax
shrl $0x1f, %r14d
testl %ebp, %ebp
cmovlel %r15d, %ebp
cmovsl %r15d, %r14d
movl %ebp, %ecx
xorl %eax, %ecx
orl %r14d, %ecx
je 0x15933
subl %eax, %ebp
xorl %edi, %edi
callq 0x302dd
movl (%rax), %ecx
movl $0x80, %edx
andl %edx, %ecx
orl $0x4f, %ecx
movl %ecx, (%rax)
movq 0x52466(%rip), %rcx     # 0x67d68
movq %rcx, 0x10(%rax)
movl %ebp, 0x30(%rax)
movl %r14d, 0x34(%rax)
movq (%r13), %rcx
movq %rcx, 0x38(%rax)
movq 0x8(%rsp), %rcx
movq 0x20(%rcx), %rdi
testq %rdi, %rdi
je 0x15933
movq %rdi, 0x8(%rax)
addq $0x28, %rdi
movq %rax, %rsi
callq 0x2285b
incq %rbx
movl (%r12), %eax
movsbq %al, %rcx
cmpq %rcx, %rbx
jl 0x158a5
movq 0x10(%r12), %r12
cmpq 0x18(%rsp), %r12
jne 0x15896
movq 0x28(%rsp), %rax
testb $0x10, 0x6b(%rax)
je 0x1596c
movq 0x8(%rsp), %rdi
callq 0x17568
movq 0x10(%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq