// File: /workspace/github_c_makefile_star2_O2/Encryptr[P]O-plus-plus/opp/compiler/compile_stmt.c
// Function: opp_compile_call
Opp_Obj opp_compile_call(struct Opp_Context* opp, struct Opp_Node* call, bool stmt)
{
	assert(call->call_expr.callee->type != EDOT);

	if (call->call_expr.callee->type == EUNARY) {
		struct Opp_Bucket* b = call->call_expr.callee->unary_expr.bidx;

		for (int i = call->call_expr.args->length-1; i >= 0; i--) {
			Opp_Obj t = opp_compile_expr(opp, call->call_expr.args->list[i]);

			opp_type_cast(opp, &b->args->args[i].var_stmt.type, &t);
		}
		
		OPCODE_START();
			OPCODE_TYPE(OPCODE_MOV_ARG);
			opp->ir.opcodes[opp->ir.instr_idx].arg.stop = true;
		OPCODE_END();

		int Iidx = 0;
		int Fidx = 0;
		for (int i = 0; i < call->call_expr.args->length; i++) {
			int idx = 0;

			if ((b->args->args[i].var_stmt.type.decl->t_type == TYPE_FLOAT || 
				b->args->args[i].var_stmt.type.decl->t_type == TYPE_DOUBLE) &&
				b->args->args[i].var_stmt.type.depth == 0)
				idx = Fidx++;
			else
				idx = Iidx++;


			OPCODE_START();
				OPCODE_TYPE(OPCODE_MOV_ARG);
				opp->ir.opcodes[opp->ir.instr_idx].arg.idx = idx;
				opp->ir.opcodes[opp->ir.instr_idx].arg.type = 
					opp_type_to_ir(&b->args->args[i].var_stmt.type);
			OPCODE_END();
		}

		OPCODE_START();
			OPCODE_TYPE(OPCODE_CALL);
			opp->ir.opcodes[opp->ir.instr_idx].call.name = 
				call->call_expr.callee->unary_expr.val.strval;
			opp->ir.opcodes[opp->ir.instr_idx].call.imm = 1;
			if (b->sym_type.decl->t_type == TYPE_VOID) {
				opp->ir.opcodes[opp->ir.instr_idx].call.ret = 0;
			}
			else {
				opp->ir.opcodes[opp->ir.instr_idx].call.ret = stmt;
				opp->ir.opcodes[opp->ir.instr_idx].call.ret_type = 
					opp_type_to_ir(&b->sym_type);
			}
			opp->ir.opcodes[opp->ir.instr_idx].call.extra_args = 
				call->call_expr.args->length;
		OPCODE_END();

		return b->sym_type;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq 0x10(%rsi), %rax
movl (%rax), %ecx
cmpl $0x5, %ecx
je 0x5074
cmpl $0xd, %ecx
je 0x5259
jmp 0x524a
movq %rsi, %rbp
movq %rdi, %rbx
movl %edx, 0x4(%rsp)
movq 0x20(%rax), %r12
movq 0x18(%rsi), %rax
movl (%rax), %r13d
decq %r13
leaq 0x18(%rsp), %r15
testl %r13d, %r13d
js 0x50e3
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl %r13d, %r14d
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
movq (%rax,%r14,8), %rsi
movq %rbx, %rdi
callq 0x3abc
movq %rax, 0x18(%rsp)
movq %rdx, 0x20(%rsp)
movq 0x28(%r12), %rax
movq 0x28(%rax), %rax
imulq $0x48, %r14, %rcx
leaq (%rax,%rcx), %rsi
addq $0x10, %rsi
movq %rbx, %rdi
movq %r15, %rdx
callq 0x37e2
decq %r13
jmp 0x5091
movq %rbp, 0x10(%rsp)
movq %rbx, %rdi
callq 0x3725
movq 0x58(%rbx), %rax
imulq $0x28, 0x48(%rbx), %rcx
movl $0x4, (%rax,%rcx)
movb $0x1, 0x10(%rax,%rcx)
incq 0x48(%rbx)
xorl %r15d, %r15d
pushq $0x10
popq %r13
xorl %ebp, %ebp
movq $0x0, 0x8(%rsp)
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movl (%rax), %eax
cmpq %rax, %r15
jae 0x51b4
movq 0x28(%r12), %rax
movq 0x28(%rax), %rax
movq (%rax,%r13), %rcx
movl 0x8(%rcx), %ecx
addl $-0x5, %ecx
cmpl $0x1, %ecx
ja 0x5150
cmpw $0x0, 0x8(%rax,%r13)
je 0x51a1
leal 0x1(%rbp), %r14d
movq %rbx, %rdi
callq 0x3725
movq 0x58(%rbx), %rax
imulq $0x28, 0x48(%rbx), %rcx
movl $0x4, (%rax,%rcx)
movl %ebp, 0xc(%rax,%rcx)
movq 0x28(%r12), %rax
movq 0x28(%rax), %rdi
addq %r13, %rdi
callq 0x3766
movq 0x58(%rbx), %rcx
imulq $0x28, 0x48(%rbx), %rdx
movl %eax, 0x8(%rcx,%rdx)
incq 0x48(%rbx)
incq %r15
addq $0x48, %r13
movl %r14d, %ebp
jmp 0x511b
movl %ebp, %r14d
movq 0x8(%rsp), %rax
movl %eax, %ebp
incl %eax
movq %rax, 0x8(%rsp)
jmp 0x5154
movq %rbx, %rdi
callq 0x3725
imulq $0x28, 0x48(%rbx), %rax
movq 0x58(%rbx), %rcx
movl $0x1, (%rcx,%rax)
movq 0x10(%rsp), %r14
movq 0x10(%r14), %rdx
movq 0x18(%rdx), %rdx
movq %rdx, 0x18(%rcx,%rax)
movq 0x58(%rbx), %rax
imulq $0x28, 0x48(%rbx), %rcx
movb $0x1, 0xc(%rax,%rcx)
movq 0x10(%r12), %rax
imulq $0x28, 0x48(%rbx), %rcx
cmpl $0x0, 0x8(%rax)
movq 0x58(%rbx), %rax
leaq 0x8(%rax,%rcx), %rax
je 0x5225
leaq 0x10(%r12), %rdi
movl 0x4(%rsp), %ecx
movb %cl, 0x5(%rax)
callq 0x3766
movq 0x58(%rbx), %rcx
imulq $0x28, 0x48(%rbx), %rdx
movl %eax, 0x8(%rcx,%rdx)
jmp 0x5229
movb $0x0, 0x5(%rax)
movq 0x18(%r14), %rax
movl (%rax), %eax
movq 0x58(%rbx), %rcx
imulq $0x28, 0x48(%rbx), %rdx
movl %eax, 0x10(%rcx,%rdx)
incq 0x48(%rbx)
movq 0x10(%r12), %rax
movq 0x18(%r12), %rdx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5f7c(%rip), %rdi      # 0xb1dc
leaq 0x5f9a(%rip), %rsi      # 0xb201
leaq 0x5faf(%rip), %rcx      # 0xb21d
pushq $0x55
popq %rdx
callq 0x1100
nop