// File: /workspace/github_c_makefile_star2_O3/lucvoo[P]sparse-dev/compile-i386.c
// Function: x86_call_expression
static struct storage *x86_call_expression(struct expression *expr)
{
	struct function *f = current_func;
	struct symbol *direct;
	struct expression *arg, *fn;
	struct storage *retval, *fncall;
	int framesize;
	char s[64];

	if (!expr->ctype) {
		warning(expr->pos, "\tcall with no type!");
		return NULL;
	}

	framesize = 0;
	FOR_EACH_PTR_REVERSE(expr->args, arg) {
		struct storage *new = x86_expression(arg);
		int size = arg->ctype->bit_size;

		/*
		 * FIXME: i386 SysV ABI dictates that values
		 * smaller than 32 bits should be placed onto
		 * the stack as 32-bit objects.  We should not
		 * blindly do a 32-bit push on objects smaller
		 * than 32 bits.
		 */
		if (size < 32)
			size = 32;
		insn("pushl", new, NULL,
		     !framesize ? "begin function call" : NULL);

		framesize += bits_to_bytes(size);
	} END_FOR_EACH_PTR_REVERSE(arg);

	fn = expr->fn;

	/* Remove dereference, if any */
	direct = NULL;
	if (fn->type == EXPR_PREOP) {
		if (fn->unop->type == EXPR_SYMBOL) {
			struct symbol *sym = fn->unop->symbol;
			if (sym->ctype.base_type->type == SYM_FN)
				direct = sym;
		}
	}
	if (direct) {
		struct storage *direct_stor = new_storage(STOR_SYM);
		direct_stor->flags |= STOR_WANTS_FREE;
		direct_stor->sym = direct;
		insn("call", direct_stor, NULL, NULL);
	} else {
		fncall = x86_expression(fn);
		emit_move(fncall, REG_EAX, fn->ctype, NULL);

		strcpy(s, "\tcall\t*%eax\n");
		push_text_atom(f, s);
	}

	/* FIXME: pay attention to BITS_IN_POINTER */
	if (framesize) {
		struct storage *val = new_storage(STOR_VALUE);
		val->value = (long long) framesize;
		val->flags = STOR_WANTS_FREE;
		insn("addl", val, REG_ESP, NULL);
	}

	retval = stack_alloc(4);
	emit_move(REG_EAX, retval, NULL, "end function call");

	return retval;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
cmpq $0x0, 0x10(%rdi)
je 0x41e51
movq 0x54d17(%rip), %rax     # 0x969d8
movq %rax, (%rsp)
movq %rdi, 0x8(%rsp)
movq 0x28(%rdi), %r14
xorl %r13d, %r13d
testq %r14, %r14
je 0x41d62
leaq 0xd2f4(%rip), %r15      # 0x4efd5
movq %r14, %rbp
movq 0x8(%rbp), %rbp
movsbq (%rbp), %rbx
movl %ebx, %ebx
testl %ebx, %ebx
jle 0x41d5d
movq 0x10(%rbp,%rbx,8), %r12
decq %rbx
cmpw $0x100, (%rbp)          # imm = 0x100
jb 0x41d08
testq %r12, %r12
je 0x41cef
movq %r12, %rdi
callq 0x40caf
movq 0x10(%r12), %rcx
movl 0x50(%rcx), %r12d
cmpl $0x21, %r12d
movl $0x20, %ecx
cmovll %ecx, %r12d
testl %r13d, %r13d
movl $0x0, %ecx
leaq 0xd2a6(%rip), %rdx      # 0x4efdb
cmoveq %rdx, %rcx
movq %r15, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x4151d
leaq 0x26653(%rip), %rax     # 0x683a0
movl (%rax), %ecx
leal (%r12,%rcx), %eax
decl %eax
cltd
idivl %ecx
addl %eax, %r13d
jmp 0x41ced
cmpq %r14, %rbp
jne 0x41ce4
movq 0x8(%rsp), %rax
movq 0x20(%rax), %r14
cmpb $0x9, (%r14)
jne 0x41dae
movq 0x20(%r14), %rax
cmpb $0x3, (%rax)
jne 0x41dae
movq 0x20(%rax), %rbx
movq 0x60(%rbx), %rax
cmpb $0x5, (%rax)
jne 0x41dae
movl $0x2, %edi
callq 0x414f4
orb $0x2, 0x8(%rax)
movq %rbx, 0x20(%rax)
leaq 0xb24e(%rip), %rdi      # 0x4cfee
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x4151d
jmp 0x41df4
movq %r14, %rdi
callq 0x40caf
movq 0x10(%r14), %rdx
leaq 0x27a0f(%rip), %rsi     # 0x697d0
movq %rax, %rdi
xorl %ecx, %ecx
callq 0x415bd
movabsq $0xa786165252a09, %rax  # imm = 0xA786165252A09
leaq 0x10(%rsp), %rsi
movq %rax, 0x5(%rsi)
movabsq $0x252a096c6c616309, %rax # imm = 0x252A096C6C616309
movq %rax, (%rsi)
movq (%rsp), %rdi
callq 0x41a0d
testl %r13d, %r13d
je 0x41e2a
movl $0x4, %edi
callq 0x414f4
movslq %r13d, %rcx
movq %rcx, 0x20(%rax)
movq $0x2, 0x8(%rax)
leaq 0xd0d4(%rip), %rdi      # 0x4eeed
leaq 0x27b00(%rip), %rdx     # 0x69920
movq %rax, %rsi
xorl %ecx, %ecx
callq 0x4151d
movl $0x4, %edi
callq 0x41736
movq %rax, %rbx
leaq 0x27992(%rip), %rdi     # 0x697d0
leaq 0xd1aa(%rip), %rcx      # 0x4efef
movq %rax, %rsi
xorl %edx, %edx
callq 0x415bd
jmp 0x41e65
movq 0x8(%rdi), %rdi
leaq 0x66e4(%rip), %rsi      # 0x48540
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x11a90
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq