// File: /workspace/github_c_makefile_star2_O3/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 0x2961
movq %rax, %r15
movq 0x10(%rbx), %rax
cmpl $0x5, (%rax)
jne 0x286b
cmpl $0x1, 0x10(%rax)
jne 0x2923
movq 0x18(%r14), %rdi
movq 0x18(%rax), %rsi
callq 0xa36c
movq %rax, %r12
movq 0x10(%rbx), %rax
testq %r12, %r12
je 0x2937
movq %r12, 0x20(%rax)
movq (%r12), %r15
movl 0x8(%r12), %eax
cmpl $0x4, %eax
je 0x2842
cmpl $0x2, %eax
jne 0x288c
movq 0x28(%r12), %rax
movl 0x20(%rax), %r8d
movq 0x18(%rbx), %rax
cmpl (%rax), %r8d
je 0x28a0
leaq 0x90a1(%rip), %rdx      # 0xb8fc
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rcx
xorl %eax, %eax
callq 0x2286
movq %rdx, %r12
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax)
je 0x290e
leaq 0x96c9(%rip), %rdi      # 0xbf4b
callq 0x1060
jmp 0x290e
cmpw $0x0, 0x18(%r12)
je 0x294a
movq 0x18(%rbx), %rax
movl (%rax), %r8d
testl %r8d, %r8d
je 0x2904
movl $0x3, %ebp
xorl %r13d, %r13d
movq 0x8(%rax), %rax
movq (%rax,%r13,8), %rsi
movq %r14, %rdi
callq 0x2961
movl 0x8(%r12), %eax
cmpl $0x4, %eax
je 0x28cc
cmpl $0x2, %eax
jne 0x28f2
movq 0x28(%r12), %rax
movq 0x28(%rax), %rax
cmpw %dx, (%rax,%rbp,8)
je 0x28f2
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x9079(%rip), %rdx      # 0xb961
movq %r15, %rcx
xorl %eax, %eax
callq 0x2598
incq %r13
movq 0x18(%rbx), %rax
movl (%rax), %ecx
addq $0x9, %rbp
cmpq %rcx, %r13
jb 0x28ad
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 0x8f7a(%rip), %rdx      # 0xb8a4
movq %r14, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2286
movq 0x18(%rax), %rcx
leaq 0x8f92(%rip), %rdx      # 0xb8d4
movq %r14, %rdi
movq %rbx, %rsi
jmp 0x295a
leaq 0x8ff2(%rip), %rdx      # 0xb943
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rcx
xorl %eax, %eax
callq 0x2286