// File: /workspace/github_cpp_makefile_star2_O1/marxn[P]pupp/src/parser/statement.cpp
// Function: AssignStatement::Invoke(NodeContext*)
int AssignStatement::Invoke(NodeContext * context)
{
        Variable * var = context->GetVariable(this->VarLayer, this->VarDef->GetVarIndex());
        if(var==NULL)
        {
                cerr<<"pupp runtime error: cannot find variable: "<<this->VarDef->GetVarName()<<endl;
                return NODE_RET_ERROR;
        }

        if(var->GetVarType()!=Array && var->GetVarType()!=Map && this->Reference->GetExpsList()->size()>0)
        {
                cerr<<"pupp runtime error: Variable "<<this->Reference->GetVarName()<<" is neither an array nor a set."<<endl;
                return false;
        }

        ValueBox * result = var->GetVBox();
        
        if(this->Reference->GetExpsList()->size()==0 && var->GetVarType()==Array)
        {
                cerr<<"pupp runtime error: cannot assign for an array"<<var->GetVarName()<<endl;
                return NODE_RET_ERROR;
        }
        
        bool need_convert = true;
        list<list<Expression*>*> * exprslist = this->Reference->GetExpsList();
        
        for(list<list<Expression*>*>::iterator gitor = exprslist->begin(); gitor!=exprslist->end(); gitor++)
        {
                list<Expression*>* exprlist = *gitor;
                
                if(result==NULL)
                {
                        cerr<<"pupp runtime error: cannot find key for variable "<<var->GetVarName()<<endl;
                        return NODE_RET_ERROR;
                }
                else if(result->GetVal()->GetType()==Array)
                {
                        if(static_cast<ArrayValue*>(result->GetVal())->GetDimensionNum()!=exprlist->size())
                        {
                                cerr<<"pupp runtime error: wrong dimension variable: "<<var->GetVarName()<<endl;
                                return NODE_RET_ERROR;
                        }

                        vector<long> desc;
                        
                        for(list<Expression*>::iterator i = exprlist->begin(); i!=exprlist->end(); i++)
                        {
                                ConstValue * value = (*i)->Calculate(context);
                                if(value->GetType()!=Integer)
                                {
                                        ConstValue * thevalue = ConstValueCast(value, Integer);
                                        delete value;

                                        if(thevalue==NULL)
                                        {
                                                cerr<<"pupp runtime error: invalid index type for variable: "<<var->GetVarName()<<endl;
                                                return NODE_RET_ERROR;
                                        }
                                        
                                        value = thevalue;
                                        
                                }
                                
                                desc.push_back(static_cast<IntegerValue*>(value)->GetValue());
                                delete value;
                        }

                        ArrayValue * val = static_cast<ArrayValue*>(result->GetVal());
                        
                        result = val->GetElementBox(desc);
                }
                else if(result->GetVal()->GetType()==Map)
                {
                        need_convert = false;
                        
                        if(exprlist->size() > 1)
                        {
                                cerr<<"pupp runtime error: invalid key list for a collection"<<endl;
                                return NODE_RET_ERROR;
                        }
                        
                        ConstValue * key = exprlist->front()->Calculate(context);
                        if(key==NULL)
                        {
                                cerr<<"pupp runtime error: invalid key for a collection"<<endl;
                                return NODE_RET_ERROR;
                        }
                        
                        MapValue * val = static_cast<MapValue*>(result->GetVal());
                        result = val->FindByKey(key->toString());
                        
                        if(result==NULL)
                        {
                                MapValue * value = new MapValue();
                                ValueBox * vb = new ValueBox(value);
                                KVValue * kv = new KVValue(key, vb);
                                val->AddKV(kv);

                                delete kv;
                                delete vb;
                                delete value;
                                
                                result = val->FindByKey(key->toString());
                        }
                        
                        delete key;
                }
                else
                {
                        cerr<<"pupp runtime error: cannot accept a non-collection variable: "<<var->GetVarName()<<endl;
                        return NODE_RET_ERROR;
                }
        }
        
        ConstValue * value = Expr->Calculate(context);
        
        if(value==NULL)
        {
                cerr<<"pupp runtime error: cannot calculate the value for the expression"<<endl;
                return NODE_RET_ERROR;
        }

        if(result->GetVal()->GetType()!=value->GetType() && need_convert)
        {
                ConstValue * thevalue = ConstValueCast(value, var->GetVarType());
                delete value;
                value = thevalue;

                if(value==NULL)
                {
                        cerr<<"pupp runtime error: data type mismatch while assigning "<<endl;
                        return NODE_RET_ERROR;
                }
        }
        
        this->AdjustValue(result, value, this->OperType);
                
        return NODE_RET_NORMAL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, %r14
movq %rdi, %r12
movq 0x78(%rdi), %rdi
movq 0x80(%r12), %rbx
callq 0x18cf4
movq %r14, 0x38(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0xc886
testq %rax, %rax
je 0x171b1
movq %rax, %r14
movq %rax, %rdi
callq 0x18a6c
cmpl $0x7, %eax
je 0x16ac5
movq %r14, %rdi
callq 0x18a6c
cmpl $0x6, %eax
je 0x16ac5
movq 0x68(%r12), %rax
movq 0x20(%rax), %rax
cmpq $0x0, 0x10(%rax)
je 0x16ac5
movq 0x315ce(%rip), %rbx     # 0x47ff0
leaq 0x21268(%rip), %rsi     # 0x37c91
movl $0x1d, %edx
movq %rbx, %rdi
callq 0x62f0
movq 0x68(%r12), %rax
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
movq %rsp, %r14
movq %r14, %rdi
callq 0x99e8
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %rbx, %rdi
callq 0x62f0
movq %rax, %rbx
leaq 0x2123d(%rip), %rsi     # 0x37caf
movl $0x1f, %edx
movq %rax, %rdi
callq 0x62f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x6220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x61b0
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x171aa
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6270
jmp 0x171aa
movq %r14, %rdi
callq 0x18906
movq %rax, %rbx
movq 0x68(%r12), %rax
movq 0x20(%rax), %rax
cmpq $0x0, 0x10(%rax)
jne 0x16b54
movq %r14, %rdi
callq 0x18a6c
cmpl $0x7, %eax
jne 0x16b54
movq 0x314fc(%rip), %rbx     # 0x47ff0
leaq 0x211d4(%rip), %rsi     # 0x37ccf
movl $0x2e, %edx
movq %rbx, %rdi
callq 0x62f0
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x188d4
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq %rbx, %rdi
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
movq %rax, %rdi
callq 0x61b0
jmp 0x17215
movq %rbx, 0x20(%rsp)
movq 0x68(%r12), %rax
movq 0x20(%rax), %rax
leaq 0x10(%rsp), %r13
movb $0x1, %cl
movl %ecx, 0x2c(%rsp)
movq %rax, 0x70(%rsp)
movq %rax, %r15
movq %r12, 0x40(%rsp)
movq %r14, 0x48(%rsp)
movq (%r15), %r15
cmpq 0x70(%rsp), %r15
je 0x1711a
movq 0x20(%rsp), %rbp
testq %rbp, %rbp
je 0x16d76
movq %r15, 0x30(%rsp)
movq 0x10(%r15), %r15
movq %rbp, %rdi
callq 0x7ec4
movq %rax, %rdi
callq 0x7dee
movl %eax, %ebx
movq %rbp, %rdi
callq 0x7ec4
movq %rax, %rdi
cmpl $0x7, %ebx
jne 0x16dfd
callq 0x956e
cmpq 0x10(%r15), %rax
jne 0x16e65
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
movq (%r15), %r14
cmpq %r15, %r14
sete %r13b
je 0x16d20
movq 0x38(%rsp), %r12
movq 0x10(%r14), %rdi
movq (%rdi), %rax
movq %r12, %rsi
callq *0x10(%rax)
movq %rax, %rbx
movq %rax, %rdi
callq 0x7dee
cmpl $0x1, %eax
je 0x16cd4
movq %rbx, %rdi
movl $0x1, %esi
callq 0x957b
movq %rax, %rbp
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
movq %rbp, %rax
testq %rbp, %rbp
jne 0x16ccc
movl $0x35, %edx
movq 0x3139f(%rip), %rdi     # 0x47ff0
leaq 0x210d8(%rip), %rsi     # 0x37d30
callq 0x62f0
movq %rsp, %rdi
movq 0x48(%rsp), %rsi
callq 0x188d4
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0x31376(%rip), %rdi     # 0x47ff0
callq 0x62f0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x6220
movsbl %al, %esi
movq %r12, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x61b0
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x16cc4
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6270
movq %rbx, %rax
movq 0x38(%rsp), %r12
movq %rax, %rbx
testq %rbp, %rbp
je 0x16d3c
movq %rbx, %rdi
callq 0x81ae
movq %rax, (%rsp)
movq 0x58(%rsp), %rsi
cmpq 0x60(%rsp), %rsi
je 0x16cfa
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x58(%rsp)
jmp 0x16d07
leaq 0x50(%rsp), %rdi
movq %rsp, %rdx
callq 0xbb28
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
movq (%r14), %r14
cmpq %r15, %r14
sete %r13b
jne 0x16bff
movq 0x20(%rsp), %rdi
callq 0x7ec4
movq %rax, %rdi
leaq 0x50(%rsp), %rsi
callq 0x92b0
movq %rax, 0x20(%rsp)
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x16d53
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x6270
testb $0x1, %r13b
je 0x170a1
movq 0x40(%rsp), %r12
movq 0x48(%rsp), %r14
leaq 0x10(%rsp), %r13
movq 0x30(%rsp), %r15
jmp 0x17110
movl $0x31, %edx
movq 0x3126e(%rip), %rbx     # 0x47ff0
movq %rbx, %rdi
leaq 0x20f72(%rip), %rsi     # 0x37cfe
callq 0x62f0
movq %rsp, %rdi
movq %r14, %rsi
callq 0x188d4
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %rbx, %rdi
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
movq %rax, %rdi
callq 0x61b0
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x16ded
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6270
movq $0x0, 0x20(%rsp)
xorl %eax, %eax
jmp 0x17112
callq 0x7dee
cmpl $0x6, %eax
jne 0x16ec8
cmpq $0x2, 0x10(%r15)
jb 0x16f4b
movl $0x35, %edx
movq 0x311ce(%rip), %rbx     # 0x47ff0
movq %rbx, %rdi
leaq 0x20f3a(%rip), %rsi     # 0x37d66
callq 0x62f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x6220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x61b0
movl $0x0, 0x2c(%rsp)
jmp 0x16f3f
movl $0x2e, %edx
movq 0x3117f(%rip), %rbx     # 0x47ff0
movq %rbx, %rdi
leaq 0x1f2ef(%rip), %rsi     # 0x3616a
callq 0x62f0
movq %rsp, %rdi
movq %r14, %rsi
callq 0x188d4
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %rbx, %rdi
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
movq %rax, %rdi
callq 0x61b0
jmp 0x16f29
movl $0x3d, %edx
movq 0x3111c(%rip), %rbx     # 0x47ff0
movq %rbx, %rdi
leaq 0x20eef(%rip), %rsi     # 0x37dcd
callq 0x62f0
movq %rsp, %rdi
movq %r14, %rsi
callq 0x188d4
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %rbx, %rdi
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
movq %rax, %rdi
callq 0x61b0
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x16f3f
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6270
xorl %eax, %eax
movq 0x30(%rsp), %r15
jmp 0x17112
movq (%r15), %rax
movq 0x10(%rax), %rdi
movq (%rdi), %rax
movq 0x38(%rsp), %rsi
callq *0x10(%rax)
movq %rax, %rbx
testq %rax, %rax
je 0x170b7
movq 0x20(%rsp), %rdi
callq 0x7ec4
movq %rax, %rbp
movq (%rbx), %rax
leaq 0x98(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq *0x18(%rax)
movq %rbp, %rdi
movq %r15, %rsi
callq 0x8d58
movq %rax, 0x20(%rsp)
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x16fbf
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x6270
cmpq $0x0, 0x20(%rsp)
jne 0x17096
movl $0x40, %edi
callq 0x6260
movq %rax, %r12
movq %rax, %rdi
callq 0x8a9a
movl $0x10, %edi
callq 0x6260
movq %rax, %r13
movq %rax, %rdi
movq %r12, %r15
movq %r12, %rsi
callq 0x7e02
movl $0x20, %edi
callq 0x6260
movq %rax, %r12
movq %rax, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x886e
movq %rbp, %rdi
movq %r12, %rsi
callq 0x8c26
movq (%r12), %rax
movq %r12, %rdi
callq *0x8(%rax)
movq %r13, %rdi
callq 0x7e28
movl $0x10, %esi
movq %r13, %rdi
callq 0x6270
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
movq (%rbx), %rax
leaq 0x78(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq *0x18(%rax)
movq %rbp, %rdi
movq %r12, %rsi
callq 0x8d58
movq %rax, 0x20(%rsp)
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
movq 0x40(%rsp), %r12
leaq 0x10(%rsp), %r13
je 0x17096
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x6270
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
jmp 0x170f9
xorl %eax, %eax
movq 0x40(%rsp), %r12
movq 0x48(%rsp), %r14
leaq 0x10(%rsp), %r13
jmp 0x16f41
movl $0x30, %edx
movq 0x30f2d(%rip), %r15     # 0x47ff0
movq %r15, %rdi
leaq 0x20ccf(%rip), %rsi     # 0x37d9c
callq 0x62f0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x6220
movsbl %al, %esi
movq %r15, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x61b0
movl $0x0, 0x2c(%rsp)
movl $0x0, %eax
testq %rbx, %rbx
movq 0x30(%rsp), %r15
je 0x17112
movb $0x1, %al
testb %al, %al
jne 0x16b7f
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpq 0x70(%rsp), %r15
jne 0x17235
movq 0x70(%r12), %rdi
movq (%rdi), %rax
movq 0x38(%rsp), %rsi
callq *0x10(%rax)
testq %rax, %rax
je 0x17249
movq %rax, %r15
movq 0x20(%rsp), %r13
movq %r13, %rdi
callq 0x7ec4
movq %rax, %rdi
callq 0x7dee
movl %eax, %ebp
movq %r15, %rdi
callq 0x7dee
cmpl %eax, %ebp
je 0x1719a
testb $0x1, 0x2c(%rsp)
je 0x1719a
movq %r14, %rdi
callq 0x18a6c
movq %r15, %rdi
movl %eax, %esi
callq 0x957b
movq %rax, %r14
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
movq %r14, %r15
testq %r14, %r14
je 0x1728d
movl 0x60(%r12), %ecx
movq %r13, %rsi
movq %r15, %rdx
callq 0x173b0
xorl %ebx, %ebx
jmp 0x17235
movq 0x30e38(%rip), %rbx     # 0x47ff0
leaq 0x1f25e(%rip), %rsi     # 0x3641d
movl $0x2a, %edx
movq %rbx, %rdi
callq 0x62f0
movq 0x78(%r12), %rsi
movq %rsp, %r14
movq %r14, %rdi
callq 0x18cc0
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %rbx, %rdi
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
movq %rax, %rdi
callq 0x61b0
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x17230
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6270
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x20bbb(%rip), %rsi     # 0x37e0b
movl $0x41, %edx
movq 0x30d94(%rip), %r14     # 0x47ff0
movq %r14, %rdi
callq 0x62f0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x6220
movsbl %al, %esi
movq %r14, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x61b0
jmp 0x17235
movq 0x30d5c(%rip), %r14     # 0x47ff0
leaq 0x20bb2(%rip), %rsi     # 0x37e4d
movl $0x37, %edx
movq %r14, %rdi
callq 0x62f0
movq %r14, %rdi
callq 0x6140
jmp 0x17235
movq %rax, %rbx
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x173a7
movq 0x88(%rsp), %rsi
jmp 0x17366
movq %rax, %rbx
movl $0x20, %esi
jmp 0x172fa
movq %rax, %rbx
movl $0x10, %esi
movq %r13, %rdi
jmp 0x173a2
movq %rax, %rbx
movl $0x40, %esi
movq %r12, %rdi
jmp 0x173a2
movq %rax, %rbx
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x173a7
movq 0xa8(%rsp), %rsi
jmp 0x17366
jmp 0x17338
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
jne 0x17361
jmp 0x173a7
movq %rax, %rbx
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x17361
jmp 0x173a7
jmp 0x1738d
jmp 0x1738d
jmp 0x17355
jmp 0x17355
jmp 0x1738d
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x173a7
movq 0x10(%rsp), %rsi
incq %rsi
jmp 0x173a2
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x17390
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6270
jmp 0x17390
jmp 0x1738d
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x173a7
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x6270
movq %rbx, %rdi
callq 0x6470
nop