// File: /workspace/github_c_makefile_star2_O1/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 0x297d
movq %rax, %r15
movq 0x10(%rbx), %rax
cmpl $0x5, (%rax)
jne 0x288d
cmpl $0x1, 0x10(%rax)
jne 0x293f
movq 0x18(%r14), %rdi
movq 0x10(%rbx), %rax
movq 0x18(%rax), %rsi
callq 0xa4d8
movq %rax, %r12
movq 0x10(%rbx), %rax
testq %r12, %r12
je 0x2953
movq %r12, 0x20(%rax)
movq (%r12), %r15
movl 0x8(%r12), %eax
cmpl $0x4, %eax
je 0x2864
cmpl $0x2, %eax
jne 0x28ab
movq 0x28(%r12), %rax
movl 0x20(%rax), %r8d
movq 0x18(%rbx), %rax
cmpl (%rax), %r8d
je 0x28b8
leaq 0x907f(%rip), %rdx      # 0xb8fc
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rcx
xorl %eax, %eax
callq 0x2285
movq %rdx, %r12
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax)
je 0x292a
leaq 0x96a7(%rip), %rdi      # 0xbf4b
callq 0x1060
jmp 0x292a
cmpw $0x0, 0x18(%r12)
je 0x2966
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax)
je 0x2920
movl $0x3, %ebp
xorl %r13d, %r13d
movq 0x8(%rax), %rax
movq (%rax,%r13,8), %rsi
movq %r14, %rdi
callq 0x297d
movl 0x8(%r12), %eax
cmpl $0x4, %eax
je 0x28e8
cmpl $0x2, %eax
jne 0x290e
movq 0x28(%r12), %rax
movq 0x28(%rax), %rax
cmpw %dx, (%rax,%rbp,8)
je 0x290e
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x905d(%rip), %rdx      # 0xb961
movq %r15, %rcx
xorl %eax, %eax
callq 0x259e
incq %r13
movq 0x18(%rbx), %rax
movl (%rax), %ecx
addq $0x9, %rbp
cmpq %rcx, %r13
jb 0x28c9
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 0x8f5e(%rip), %rdx      # 0xb8a4
movq %r14, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2285
movq 0x18(%rax), %rcx
leaq 0x8f76(%rip), %rdx      # 0xb8d4
movq %r14, %rdi
movq %rbx, %rsi
jmp 0x2976
leaq 0x8fd6(%rip), %rdx      # 0xb943
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rcx
xorl %eax, %eax
callq 0x2285