// File: /workspace/github_cpp_makefile_star2_O1/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 $0x58, %rsp
movq %rsi, %r15
movq %rdi, %r12
movq 0x70(%rdi), %rax
leaq 0x30(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x20(%rsp), %rdi
callq 0x99e8
movq 0x60(%r12), %rdi
callq 0x18cf4
movl $0x1, %esi
movq %r15, %rdi
movq %rax, %rdx
callq 0xc886
movq %rax, %rbx
testq %rax, %rax
je 0x1788e
movq 0x78(%r12), %r14
cmpl $0x7, (%r14)
jne 0x178f0
movq %r12, 0x48(%rsp)
movq %rbx, 0x40(%rsp)
addq $0x8, %r14
xorps %xmm0, %xmm0
movq %rsp, %rax
movaps %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movl $0x1, %r12d
movq 0x30842(%rip), %rbp     # 0x47ff0
movq %r14, %r13
movq (%r13), %r13
cmpq %r14, %r13
je 0x17943
movq 0x10(%r13), %rdi
movq (%rdi), %rax
movq %r15, %rsi
callq *0x10(%rax)
movq %rax, %rbx
movq %rax, %rdi
callq 0x7dee
cmpl $0x1, %eax
jne 0x1781b
movq %rbx, %rdi
callq 0x81ae
testq %rax, %rax
jle 0x1781b
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
movq %rbx, %rdi
callq 0x81ae
movq %rax, %rbx
movq %rax, 0x50(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x17864
movq %rbx, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x17871
movl $0x40, %edx
movq %rbp, %rdi
leaq 0x2066b(%rip), %rsi     # 0x37e95
callq 0x62f0
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x6220
movsbl %al, %esi
movq %rbp, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x61b0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
xorl %eax, %eax
jmp 0x17877
movq %rsp, %rdi
leaq 0x50(%rsp), %rdx
callq 0x18016
imulq %rbx, %r12
movb $0x1, %al
testb %al, %al
jne 0x177b1
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
leaq 0x30(%rsp), %r13
jmp 0x1797e
movq 0x3075b(%rip), %rdi     # 0x47ff0
leaq 0x1e8a4(%rip), %rsi     # 0x36140
movl $0x29, %edx
callq 0x62f0
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq 0x30739(%rip), %rdi     # 0x47ff0
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 0x179ea
movq 0x68(%r12), %rdi
xorl %ebp, %ebp
testq %rdi, %rdi
je 0x179ea
movq (%rdi), %rax
movq %r15, %rsi
callq *0x10(%rax)
movq %rax, %r14
testq %rax, %rax
je 0x179e5
movq %r14, %rdi
callq 0x7dee
testl %eax, %eax
je 0x17996
movq %r14, %rdi
callq 0x7dee
movq %rbx, %rdi
movl %eax, %esi
callq 0x18a68
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1890c
jmp 0x179ea
movl $0x38, %edi
leaq 0x30(%rsp), %r13
callq 0x6260
movq %rax, %r15
movq 0x48(%rsp), %rax
movq 0x78(%rax), %rax
movl 0x4(%rax), %esi
movq %rsp, %rdx
movq %r15, %rdi
movq %r12, %rcx
callq 0x9122
xorl %ebp, %ebp
movq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x1890c
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x179ea
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x6270
jmp 0x179ea
movq 0x30653(%rip), %rbx     # 0x47ff0
leaq 0x20532(%rip), %rsi     # 0x37ed6
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 0x30621(%rip), %rdi     # 0x47ff0
callq 0x6040
movq %rax, %rdi
callq 0x61b0
movq (%r14), %rax
movq %r14, %rdi
callq *0x8(%rax)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x20(%rsp), %rdi
cmpq %r13, %rdi
je 0x17a01
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x6270
movl %ebp, %eax
addq $0x58, %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 0x17a32
jmp 0x17a2f
jmp 0x17a2a
jmp 0x17a2f
movq %rax, %rbx
jmp 0x17a48
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x17a48
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x6270
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x17a64
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x6270
movq %rbx, %rdi
callq 0x6470