// File: /workspace/github_c_makefile_star2_O0/Encryptr[P]O-plus-plus/opp/analysis/analysis.c
// Function: opp_analize_var
static void opp_analize_var(struct Opp_Analize* ctx, struct Opp_Node* node)
{
	struct Opp_Stmt_Var* var = &node->var_stmt;
	struct Opp_Node* name = NULL;
	bool assign = false;

	unsigned int size = get_type_size(&var->type);
	if (size == 0)
		opp_semantics_error(ctx, node, "Cannot use type 'void' to declare a variable");

	switch (var->var->type)
	{
		case EUNARY: {
			name = var->var;
			break;
		}

		case EELEMENT: {
			name = var->var->elem_expr.name;

			while (name->type != EUNARY) {
				if (name->type != EELEMENT)
					opp_semantics_error(ctx, node, 
						"Unexpected token in array declaration");

				if (name->elem_expr.loc->unary_expr.type != TINTEGER)
					opp_semantics_error(ctx, node,
						"Non constant values not allowed in array declaration");
				size *= name->elem_expr.loc->unary_expr.val.i64val;				
				name = name->elem_expr.name;
			}

			if (var->var->elem_expr.loc->unary_expr.type != TINTEGER)
				opp_semantics_error(ctx, node,
					"Non constant values not allowed in array declaration '%s'", name->unary_expr.val.strval);

			size *= var->var->elem_expr.loc->unary_expr.val.i64val;
			var->type.depth = 1;
			var->type.size = size;
			var->var = name;
			break;
		}

		case EASSIGN: {
			name = var->var->assign_expr.ident;

			if (var->var->assign_expr.ident->type == EELEMENT)
				opp_semantics_error(ctx, node, "Assigning array type variables not allowed");

			assign = true;
			break;
		}

		default: break;
	}

	struct Opp_Bucket* bucket = env_add_item(ctx->curr_ns, name->unary_expr.val.strval);

	if (bucket == NULL)
		opp_semantics_error(ctx, node, "Redeclaration of variable '%s'",
			name->unary_expr.val.strval);

	ctx->debug.res_name = name->unary_expr.val.strval;

	bucket->key = name->unary_expr.val.strval;
	bucket->type = ctx->curr_ns == ctx->ns ? TYPE_GLOBAL : TYPE_LOCAL;
	bucket->sym_type = var->type;
	var->bidx = bucket;

	if (assign)
		opp_analize_assign(ctx, var->var);
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq 0x38(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movb $0x0, 0x27(%rsp)
movq 0x30(%rsp), %rdi
callq 0x52e0
movl %eax, 0x20(%rsp)
cmpl $0x0, 0x20(%rsp)
jne 0x2527
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
leaq 0x11922(%rip), %rdx     # 0x13e42
movb $0x0, %al
callq 0x2b10
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movl (%rax), %eax
movl %eax, 0x4(%rsp)
subl $0x4, %eax
je 0x2677
jmp 0x2541
movl 0x4(%rsp), %eax
subl $0x5, %eax
je 0x255a
jmp 0x254c
movl 0x4(%rsp), %eax
subl $0x7, %eax
je 0x256d
jmp 0x26ba
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x28(%rsp)
jmp 0x26bc
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpl $0x5, (%rax)
je 0x25fb
movq 0x28(%rsp), %rax
cmpl $0x7, (%rax)
je 0x25ab
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
leaq 0x118cb(%rip), %rdx     # 0x13e6f
movb $0x0, %al
callq 0x2b10
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
cmpl $0x2, 0x10(%rax)
je 0x25d2
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
leaq 0x118ca(%rip), %rdx     # 0x13e95
movb $0x0, %al
callq 0x2b10
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rcx
movl 0x20(%rsp), %eax
imulq %rcx, %rax
movl %eax, 0x20(%rsp)
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x28(%rsp)
jmp 0x257f
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax), %rax
cmpl $0x2, 0x10(%rax)
je 0x262f
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rcx
leaq 0x118a2(%rip), %rdx     # 0x13eca
movb $0x0, %al
callq 0x2b10
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rcx
movl 0x20(%rsp), %eax
imulq %rcx, %rax
movl %eax, 0x20(%rsp)
movq 0x30(%rsp), %rax
movw $0x1, 0x8(%rax)
movl 0x20(%rsp), %eax
movw %ax, %cx
movq 0x30(%rsp), %rax
movw %cx, 0xa(%rax)
movq 0x28(%rsp), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x10(%rax)
jmp 0x26bc
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x20(%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x20(%rax), %rax
cmpl $0x7, (%rax)
jne 0x26b3
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
leaq 0x11858(%rip), %rdx     # 0x13f04
movb $0x0, %al
callq 0x2b10
movb $0x1, 0x27(%rsp)
jmp 0x26bc
jmp 0x26bc
movq 0x40(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rsi
callq 0x12a70
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
jne 0x2701
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rcx
leaq 0x11835(%rip), %rdx     # 0x13f2f
movb $0x0, %al
callq 0x2b10
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x40(%rax)
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x18(%rsp), %rax
movq %rcx, (%rax)
movq 0x40(%rsp), %rax
movq 0x18(%rax), %rdx
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rsi
movl $0x1, %ecx
xorl %eax, %eax
cmpq %rsi, %rdx
cmovel %eax, %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0x8(%rax)
movq 0x18(%rsp), %rax
movq 0x30(%rsp), %rcx
movq (%rcx), %rdx
movq %rdx, 0x10(%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x18(%rax)
movq 0x18(%rsp), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x18(%rax)
testb $0x1, 0x27(%rsp)
je 0x2796
movq 0x40(%rsp), %rdi
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0x3130
movq %rax, 0x8(%rsp)
movq %rdx, 0x10(%rsp)
addq $0x48, %rsp
retq
nopl (%rax,%rax)