// File: marxn[P]pupp/src/parser/loop.cpp
// Function: LoopNode::Invoke(NodeContext*)
int LoopNode::Invoke(NodeContext * context)
{
        if(this->PreLoopStatement(context)==false)
        {
                return NODE_RET_ERROR;
        }

        int runnable = this->Evaluate(context);
        if(runnable==-1)
        {
                return NODE_RET_ERROR;
        }

        while(runnable==1)
        {
                list<Node*>::iterator i;
                for(i = subnodelist->begin(); i != subnodelist->end(); i++)
                {
                        if((*i)->Type==Function)
                        {
                                continue;
                        }

                        context->AddFrame(*i);
                        int ret = (*i)->Execute(context);
                        context->PopFrame();

                        if(ret==NODE_RET_NEEDBREAK)
                        {
                                return NODE_RET_NORMAL;
                        }
                        else if(ret==NODE_RET_NEEDCONTINUE)
                        {
                                break;
                        }
                        else if(ret==NODE_RET_ERROR)
                        {
                                return ret;
                        }
                }

                if(this->PerOnceStatement(context)==false)
                {
                        return NODE_RET_ERROR;
                }

                runnable = this->Evaluate(context);
                if(runnable==-1)
                {
                        return NODE_RET_ERROR;
                }

        }

        return NODE_RET_NORMAL;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movq %rsi, 0x40(%rsp)
movq 0x48(%rsp), %rdi
movq %rdi, 0x8(%rsp)
movq 0x40(%rsp), %rsi
movq (%rdi), %rax
callq *0x30(%rax)
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x31afa
movl $0xffffffff, 0x54(%rsp) # imm = 0xFFFFFFFF
jmp 0x31c7a
movq 0x8(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq (%rdi), %rax
callq *0x40(%rax)
movl %eax, 0x3c(%rsp)
cmpl $-0x1, 0x3c(%rsp)
jne 0x31b22
movl $0xffffffff, 0x54(%rsp) # imm = 0xFFFFFFFF
jmp 0x31c7a
jmp 0x31b24
cmpl $0x1, 0x3c(%rsp)
jne 0x31c72
leaq 0x30(%rsp), %rdi
callq 0xd4a0
movq 0x8(%rsp), %rax
movq 0x60(%rax), %rdi
callq 0xd4c0
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x8(%rsp), %rax
movq 0x60(%rax), %rdi
callq 0xd510
movq %rax, 0x20(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0xd4f0
testb $0x1, %al
jne 0x31b81
jmp 0x31c24
leaq 0x30(%rsp), %rdi
callq 0xd540
movq (%rax), %rax
cmpl $0x1, 0x8(%rax)
jne 0x31b96
jmp 0x31c0e
movq 0x40(%rsp), %rax
movq %rax, (%rsp)
leaq 0x30(%rsp), %rdi
callq 0xd540
movq (%rsp), %rdi
movq (%rax), %rsi
callq 0x146f0
leaq 0x30(%rsp), %rdi
callq 0xd540
movq (%rax), %rdi
movq 0x40(%rsp), %rsi
callq 0x14130
movl %eax, 0x1c(%rsp)
movq 0x40(%rsp), %rdi
callq 0x14610
cmpl $0x1, 0x1c(%rsp)
jne 0x31bee
movl $0x0, 0x54(%rsp)
jmp 0x31c7a
cmpl $0x2, 0x1c(%rsp)
jne 0x31bf7
jmp 0x31c24
cmpl $-0x1, 0x1c(%rsp)
jne 0x31c08
movl 0x1c(%rsp), %eax
movl %eax, 0x54(%rsp)
jmp 0x31c7a
jmp 0x31c0a
jmp 0x31c0c
jmp 0x31c0e
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
callq 0xd570
movq %rax, 0x10(%rsp)
jmp 0x31b56
movq 0x8(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq (%rdi), %rax
callq *0x38(%rax)
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x31c48
movl $0xffffffff, 0x54(%rsp) # imm = 0xFFFFFFFF
jmp 0x31c7a
movq 0x8(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq (%rdi), %rax
callq *0x40(%rax)
movl %eax, 0x3c(%rsp)
cmpl $-0x1, 0x3c(%rsp)
jne 0x31c6d
movl $0xffffffff, 0x54(%rsp) # imm = 0xFFFFFFFF
jmp 0x31c7a
jmp 0x31b24
movl $0x0, 0x54(%rsp)
movl 0x54(%rsp), %eax
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)