// File: /workspace/github_cpp_makefile_star2_O3/marxn[P]pupp/src/parser/statement.cpp
// Function: VarDefinitionStatement::Invoke(NodeContext*)
int VarDefinitionStatement::Invoke(NodeContext * context)
{
        string name = *(this->Ident);
        Variable * var = context->GetVariable(1, this->VarDef->GetVarIndex());

        if(var==NULL)
        {
                cerr<<"pupp runtime error: cannot find variable:"<<name<<endl;
                return NODE_RET_ERROR;
        }

        if(this->VarType->GetVarType()==Array)
        {
                list<Expression*> * dim = this->VarType->GetDimentions();
                vector<long> desc;
                long size = 1;

                list<Expression*>::iterator i;
                for(i = dim->begin(); i!= dim->end(); i++)
                {
                        ConstValue * dsize = (*i)->Calculate(context);
                        if(dsize->GetType()!=Integer || static_cast<IntegerValue*>(dsize)->GetValue()<=0)
                        {
                                cerr<<"pupp runtime error: Size of an array must be a positive integer."<<endl;
                                delete dsize;
                                return NODE_RET_ERROR;
                        }

                        delete dsize;

                        long n = static_cast<IntegerValue*>(dsize)->GetValue();
                        size *= n;
                        desc.push_back(n);
                }

                ArrayValue * val = new ArrayValue(this->VarType->GetElementType(), desc, size);
                var->SetRef(val);
                return NODE_RET_NORMAL;
        }

        if(this->InitExpr!=NULL)
        {
                ConstValue * value = this->InitExpr->Calculate(context);
                if(value==NULL)
                {
                        return NODE_RET_ERROR;
                }

                if(value->GetType()==Null)
                {
                        cerr<<"pupp runtime error: variable type cannot be determined."<<endl;
                        delete value;
                        return NODE_RET_ERROR;
                }
                var->SetVarType(value->GetType());
                var->SetRef(value);
        }

        return NODE_RET_NORMAL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r15
movq %rdi, %r14
movq 0x70(%rdi), %rax
leaq 0x28(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x18(%rsp), %rdi
callq 0x99a6
movq 0x60(%r14), %rdi
callq 0x189a0
movl $0x1, %esi
movq %r15, %rdi
movq %rax, %rdx
callq 0xc7ec
movq %rax, %rbx
testq %rax, %rax
je 0x1751d
movq 0x78(%r14), %rbp
cmpl $0x7, (%rbp)
jne 0x1757f
movq %rbx, 0x38(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x8(%rbp), %rbx
addq $0x8, %rbp
movl $0x1, %r12d
cmpq %rbp, %rbx
je 0x175d5
movq 0x10(%rbx), %rdi
movq (%rdi), %rax
movq %r15, %rsi
callq *0x10(%rax)
movq %rax, %r13
movq %rax, %rdi
callq 0x7da6
cmpl $0x1, %eax
jne 0x1760d
movq %r13, %rdi
callq 0x8160
testq %rax, %rax
jle 0x1760d
movq (%r13), %rax
movq %r13, %rdi
callq *0x8(%rax)
movq %r13, %rdi
callq 0x8160
movq %rax, %r13
movq %rax, 0x40(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x17504
movq %r13, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x17511
movq %rsp, %rdi
leaq 0x40(%rsp), %rdx
callq 0x17d06
imulq %r13, %r12
movq (%rbx), %rbx
jmp 0x17495
movq 0x2facc(%rip), %rdi     # 0x46ff0
leaq 0x1dc15(%rip), %rsi     # 0x35140
movl $0x29, %edx
callq 0x62f0
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x2faaa(%rip), %rdi     # 0x46ff0
callq 0x62f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x6220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x6040
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x61b0
jmp 0x176d3
movq 0x68(%r14), %rdi
xorl %ebp, %ebp
testq %rdi, %rdi
je 0x176d3
movq (%rdi), %rax
movq %r15, %rsi
callq *0x10(%rax)
movq %rax, %r14
testq %rax, %rax
je 0x176ce
movq %r14, %rdi
callq 0x7da6
testl %eax, %eax
je 0x1767f
movq %r14, %rdi
callq 0x7da6
movq %rbx, %rdi
movl %eax, %esi
callq 0x18712
movq %rbx, %rdi
movq %r14, %rsi
callq 0x185b4
jmp 0x176d3
movl $0x38, %edi
leaq 0x28(%rsp), %r13
callq 0x6260
movq %rax, %r15
movq 0x78(%r14), %rax
movl 0x4(%rax), %esi
movq %rsp, %rdx
movq %r15, %rdi
movq %r12, %rcx
callq 0x90da
xorl %ebp, %ebp
movq 0x38(%rsp), %rdi
movq %r15, %rsi
callq 0x185b4
jmp 0x17667
movq 0x2f9dc(%rip), %rbx     # 0x46ff0
leaq 0x1f876(%rip), %rsi     # 0x36e91
movl $0x40, %edx
movq %rbx, %rdi
callq 0x62f0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x6220
movsbl %al, %esi
movq 0x2f9aa(%rip), %rdi     # 0x46ff0
callq 0x6040
movq %rax, %rdi
callq 0x61b0
movq (%r13), %rax
movq %r13, %rdi
callq *0x8(%rax)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
leaq 0x28(%rsp), %r13
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x176d3
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x6270
jmp 0x176d3
movq 0x2f96a(%rip), %rbx     # 0x46ff0
leaq 0x1f845(%rip), %rsi     # 0x36ed2
movl $0x37, %edx
movq %rbx, %rdi
callq 0x62f0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x6220
movsbl %al, %esi
movq 0x2f938(%rip), %rdi     # 0x46ff0
callq 0x6040
movq %rax, %rdi
callq 0x61b0
movq (%r14), %rax
movq %r14, %rdi
callq *0x8(%rax)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x176ea
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x6270
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x38, %esi
movq %r15, %rdi
callq 0x6270
jmp 0x1771d
jmp 0x1771a
jmp 0x1771a
jmp 0x17715
jmp 0x1771a
movq %rax, %rbx
jmp 0x17733
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x17733
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x6270
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x1774f
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x6270
movq %rbx, %rdi
callq 0x6460
nop