// File: /workspace/github_c_makefile_star2_O2/Encryptr[P]O-plus-plus/opp/analysis/analysis.c
// Function: opp_analize_call
static Opp_Obj opp_analize_call(struct Opp_Analize* ctx, struct Opp_Node* node)
{
	Opp_Obj ret_type;

	ret_type = opp_analize_expr(ctx, node->call_expr.callee);

	// Immidiate func call
	if (node->call_expr.callee->type == EUNARY) {
		if (node->call_expr.callee->unary_expr.type != TIDENT)
			opp_semantics_error(ctx, node, "Expected identifier before '()' for a call expr");

		struct Opp_Bucket* bucket = env_get_item(ctx->curr_ns, 
			node->call_expr.callee->unary_expr.val.strval);

		if (bucket == NULL)
			opp_semantics_error(ctx, node, "Attempting to call undefined symbol'%s'",
				node->call_expr.callee->unary_expr.val.strval);

		node->call_expr.callee->unary_expr.bidx = bucket;

		char* fn_name = bucket->key;

		if (bucket->type == TYPE_FUNC || bucket->type == TYPE_EXTERN) {
			if (bucket->args->len != node->call_expr.args->length)
				opp_semantics_error(ctx, node, 
					"Invalid amount of args provided in function call to '%s' (expected %d)", 
					fn_name, bucket->args->len);
		}
		else if (bucket->sym_type.depth == 0)
			opp_semantics_error(ctx, node, "Calling a invalid callee '%s'", fn_name);

		for (unsigned int i = 0; i < node->call_expr.args->length; i++) 
		{
			ret_type = opp_analize_expr(ctx, node->call_expr.args->list[i]);

			if (bucket->type == TYPE_FUNC || bucket->type == TYPE_EXTERN)
				if (ret_type.depth != bucket->args->args[i].var_stmt.type.depth) 
					opp_warning(ctx, node, 
						"Invalid pointer argument provided to function call '%s'", fn_name);
		}
		return bucket->sym_type;
	}
	if (node->call_expr.args->length > 0)
		printf("ADD FN POINTER ARGS\n");

	return ret_type;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movq 0x10(%rsi), %rsi
callq 0x28ea
movq %rax, %r15
movq 0x10(%rbx), %rax
cmpl $0x5, (%rax)
jne 0x2803
cmpl $0x1, 0x10(%rax)
jne 0x28ac
movq 0x18(%r14), %rdi
movq 0x18(%rax), %rsi
callq 0x9d69
movq %rax, %r12
movq 0x10(%rbx), %rax
testq %r12, %r12
je 0x28c0
movq %r12, 0x20(%rax)
movq (%r12), %r15
movl 0x8(%r12), %eax
cmpl $0x4, %eax
je 0x27da
cmpl $0x2, %eax
jne 0x2821
movq 0x28(%r12), %rax
movl 0x20(%rax), %r8d
movq 0x18(%rbx), %rax
cmpl (%rax), %r8d
je 0x282e
leaq 0x8109(%rip), %rdx      # 0xa8fc
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rcx
xorl %eax, %eax
callq 0x2228
movq %rdx, %r12
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax)
je 0x2897
leaq 0x8731(%rip), %rdi      # 0xaf4b
callq 0x1060
jmp 0x2897
cmpw $0x0, 0x18(%r12)
je 0x28d3
pushq $0x3
popq %rbp
xorl %r13d, %r13d
movq 0x18(%rbx), %rax
movl (%rax), %ecx
cmpq %rcx, %r13
jae 0x288d
movq 0x8(%rax), %rax
movq (%rax,%r13,8), %rsi
movq %r14, %rdi
callq 0x28ea
movl 0x8(%r12), %eax
cmpl $0x4, %eax
je 0x285e
cmpl $0x2, %eax
jne 0x2884
movq 0x28(%r12), %rax
movq 0x28(%rax), %rax
cmpw %dx, (%rax,%rbp,8)
je 0x2884
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x80e7(%rip), %rdx      # 0xa961
movq %r15, %rcx
xorl %eax, %eax
callq 0x2532
incq %r13
addq $0x9, %rbp
jmp 0x2834
movq 0x10(%r12), %r15
movq 0x18(%r12), %r12
movq %r15, %rax
movq %r12, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7ff1(%rip), %rdx      # 0xa8a4
movq %r14, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2228
movq 0x18(%rax), %rcx
leaq 0x8009(%rip), %rdx      # 0xa8d4
movq %r14, %rdi
movq %rbx, %rsi
jmp 0x28e3
leaq 0x8069(%rip), %rdx      # 0xa943
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rcx
xorl %eax, %eax
callq 0x2228