// File: marxn[P]pupp/src/pupp.cpp
// Function: main
int main(int argc, char * argv[])
{
        FILE * fp = NULL;

        if(argc==1)
        {
                fp = stdin;
        }
        else
        {
                fp = fopen(argv[1],"r");
                if(fp==NULL)
                {
                        fprintf(stderr, "Could not open file: '%s'\n", argv[1]);
                        return -1;
                }
        }

        yyin = fp;

        ContainerNode * bean = parse();

        if(bean == NULL)
        {
                return -1;
        }

        MapValue * para = new MapValue();

        for(int i = 0; i<argc; i++)
        {
                IntegerValue * key = new IntegerValue(i);
                StringValue * value = new StringValue(string(argv[i]));

                ValueBox * vb = new ValueBox(value);
                KVValue * kv = new KVValue(key, vb);
                para->AddKV(kv);

                delete kv;
                delete vb;
                delete value;
                delete key;
        }

        string   para_name = "args";
        VariableType para_type(Map, Null);

        VarDefinitionStatement * defstmt = new VarDefinitionStatement(&para_name, &para_type);
        defstmt->SetParentNode(bean);
        defstmt->SetInitExpr(new ConstValueExpression(para));

        bean->AddNode(defstmt);

        if(bean->Provision()==false || bean->Check()==false)
        {
                return -2;
        }

        NodeContext context;
        context.AddFrame(bean);

        bean->Execute(&context);

        fclose(fp);

        int ret = 0;

        ConstValue * retval = context.FunctionRet;

        if(retval!=NULL && retval->GetType()==Integer)
        {
                ret = static_cast<int>(static_cast<IntegerValue*>(retval)->GetValue());
        }

        return ret;
}

// Assembly:
subq $0x1e8, %rsp            # imm = 0x1E8
movl $0x0, 0x1e4(%rsp)
movl %edi, 0x1e0(%rsp)
movq %rsi, 0x1d8(%rsp)
movq $0x0, 0x1d0(%rsp)
cmpl $0x1, 0x1e0(%rsp)
jne 0x6afb
movq 0x6f4da(%rip), %rax     # 0x75fc8
movq (%rax), %rax
movq %rax, 0x1d0(%rsp)
jmp 0x6b5c
movq 0x1d8(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x59eb3(%rip), %rsi     # 0x609c1
callq 0x63d0
movq %rax, 0x1d0(%rsp)
cmpq $0x0, 0x1d0(%rsp)
jne 0x6b5a
movq 0x6f4a3(%rip), %rax     # 0x75fd0
movq (%rax), %rdi
movq 0x1d8(%rsp), %rax
movq 0x8(%rax), %rdx
leaq 0x584c1(%rip), %rsi     # 0x5f004
movb $0x0, %al
callq 0x6490
movl $0xffffffff, 0x1e4(%rsp) # imm = 0xFFFFFFFF
jmp 0x721d
jmp 0x6b5c
movq 0x1d0(%rsp), %rcx
leaq 0x6f805(%rip), %rax     # 0x76370
movq %rcx, (%rax)
callq 0x28eb0
movq %rax, 0x1c8(%rsp)
cmpq $0x0, 0x1c8(%rsp)
jne 0x6b96
movl $0xffffffff, 0x1e4(%rsp) # imm = 0xFFFFFFFF
jmp 0x721d
movl $0x40, %edi
callq 0x62f0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x88(%rsp)
callq 0x91d0
jmp 0x6bb5
movq 0x88(%rsp), %rax
movq %rax, 0x1c0(%rsp)
movl $0x0, 0x1b0(%rsp)
movl 0x1b0(%rsp), %eax
cmpl 0x1e0(%rsp), %eax
jge 0x6ee0
movl $0x18, %edi
callq 0x62f0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x80(%rsp)
movslq 0x1b0(%rsp), %rsi
callq 0x7eb0
jmp 0x6c0b
movq 0x80(%rsp), %rax
movq %rax, 0x1a8(%rsp)
movl $0x30, %edi
callq 0x62f0
movq %rax, 0x68(%rsp)
movb $0x1, 0x17e(%rsp)
movq 0x1d8(%rsp), %rax
movslq 0x1b0(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x70(%rsp)
leaq 0x17f(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0x6560
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
leaq 0x180(%rsp), %rdi
callq 0x7240
jmp 0x6c76
movq 0x68(%rsp), %rdi
leaq 0x180(%rsp), %rsi
callq 0x7c00
jmp 0x6c8a
movb $0x0, 0x17e(%rsp)
leaq 0x180(%rsp), %rdi
callq 0x61e0
leaq 0x17f(%rsp), %rdi
callq 0x6350
movq 0x68(%rsp), %rax
movq %rax, 0x1a0(%rsp)
movl $0x10, %edi
callq 0x62f0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x60(%rsp)
movq 0x1a0(%rsp), %rsi
callq 0x78a0
jmp 0x6cdd
movq 0x60(%rsp), %rax
movq %rax, 0x170(%rsp)
movl $0x20, %edi
callq 0x62f0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x58(%rsp)
movq 0x1a8(%rsp), %rsi
movq 0x170(%rsp), %rdx
callq 0x8e80
jmp 0x6d16
movq 0x58(%rsp), %rax
movq %rax, 0x168(%rsp)
movq 0x1c0(%rsp), %rdi
movq 0x168(%rsp), %rsi
callq 0x94d0
movq 0x168(%rsp), %rax
movq %rax, 0x50(%rsp)
cmpq $0x0, %rax
je 0x6d56
movq 0x50(%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x170(%rsp), %rax
movq %rax, 0x48(%rsp)
cmpq $0x0, %rax
je 0x6d82
movq 0x48(%rsp), %rdi
callq 0x78f0
movq 0x48(%rsp), %rdi
movl $0x10, %esi
callq 0x6300
movq 0x1a0(%rsp), %rax
movq %rax, 0x40(%rsp)
cmpq $0x0, %rax
je 0x6da0
movq 0x40(%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x1a8(%rsp), %rax
movq %rax, 0x38(%rsp)
cmpq $0x0, %rax
je 0x6dbe
movq 0x38(%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x6dc0
movl 0x1b0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1b0(%rsp)
jmp 0x6bd0
movq 0x88(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
movl $0x40, %esi
callq 0x6300
jmp 0x722c
movq 0x80(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
movl $0x18, %esi
callq 0x6300
jmp 0x722c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
jmp 0x6e63
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
leaq 0x180(%rsp), %rdi
callq 0x61e0
leaq 0x17f(%rsp), %rdi
callq 0x6350
testb $0x1, 0x17e(%rsp)
jne 0x6e7c
jmp 0x6e8b
movq 0x68(%rsp), %rdi
movl $0x30, %esi
callq 0x6300
jmp 0x722c
movq 0x60(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
movl $0x10, %esi
callq 0x6300
jmp 0x722c
movq 0x58(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
movl $0x20, %esi
callq 0x6300
jmp 0x722c
leaq 0x147(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x6560
movq 0x30(%rsp), %rdx
leaq 0x58121(%rip), %rsi     # 0x5f01f
leaq 0x148(%rsp), %rdi
callq 0x7240
jmp 0x6f0d
leaq 0x147(%rsp), %rdi
callq 0x6350
leaq 0x120(%rsp), %rdi
movl $0x6, %esi
xorl %edx, %edx
callq 0x2e080
jmp 0x6f30
movl $0x80, %edi
callq 0x62f0
movq %rax, 0x28(%rsp)
jmp 0x6f41
movq 0x28(%rsp), %rdi
leaq 0x148(%rsp), %rsi
leaq 0x120(%rsp), %rdx
callq 0x2e160
jmp 0x6f5d
movq 0x28(%rsp), %rax
movq %rax, 0x118(%rsp)
movq 0x118(%rsp), %rdi
movq 0x1c8(%rsp), %rsi
callq 0x14180
jmp 0x6f81
movq 0x118(%rsp), %rax
movq %rax, 0x18(%rsp)
movl $0x20, %edi
callq 0x62f0
movq %rax, 0x20(%rsp)
jmp 0x6f9f
movq 0x20(%rsp), %rdi
movq 0x1c0(%rsp), %rsi
callq 0xdab0
jmp 0x6fb3
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdi
callq 0x2e750
jmp 0x6fc4
movq 0x1c8(%rsp), %rdi
movq 0x118(%rsp), %rsi
callq 0xd300
jmp 0x6fdb
movq 0x1c8(%rsp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movb %al, 0x17(%rsp)
jmp 0x6ff2
movb 0x17(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x7029
movq 0x1c8(%rsp), %rdi
movq (%rdi), %rax
movq 0x18(%rax), %rax
callq *%rax
movb %al, 0x16(%rsp)
jmp 0x7017
movb 0x16(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x70ec
movl $0xfffffffe, 0x1e4(%rsp) # imm = 0xFFFFFFFE
movl $0x1, 0x114(%rsp)
jmp 0x71e5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
leaq 0x147(%rsp), %rdi
callq 0x6350
jmp 0x722c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
jmp 0x720e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
jmp 0x7201
movq 0x28(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
movl $0x80, %esi
callq 0x6300
jmp 0x7201
movq 0x20(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
movl $0x20, %esi
callq 0x6300
jmp 0x7201
leaq 0xa0(%rsp), %rdi
callq 0x14530
jmp 0x70fb
movq 0x1c8(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
callq 0x146f0
jmp 0x7112
movq 0x1c8(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x14130
jmp 0x7129
movq 0x1d0(%rsp), %rdi
callq 0x62e0
jmp 0x7138
movl $0x0, 0x9c(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x90(%rsp)
cmpq $0x0, 0x90(%rsp)
je 0x71bf
movq 0x90(%rsp), %rdi
callq 0x7870
movl %eax, 0x10(%rsp)
jmp 0x7171
movl 0x10(%rsp), %eax
cmpl $0x1, %eax
jne 0x71bf
movq 0x90(%rsp), %rdi
callq 0x7fe0
movq %rax, 0x8(%rsp)
jmp 0x718e
movq 0x8(%rsp), %rax
movl %eax, 0x9c(%rsp)
jmp 0x71bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x145b0
jmp 0x7201
movl 0x9c(%rsp), %eax
movl %eax, 0x1e4(%rsp)
movl $0x1, 0x114(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x145b0
leaq 0x120(%rsp), %rdi
callq 0x7300
leaq 0x148(%rsp), %rdi
callq 0x61e0
jmp 0x721d
leaq 0x120(%rsp), %rdi
callq 0x7300
leaq 0x148(%rsp), %rdi
callq 0x61e0
jmp 0x722c
movl 0x1e4(%rsp), %eax
addq $0x1e8, %rsp            # imm = 0x1E8
retq
movq 0x1b8(%rsp), %rdi
callq 0x6550
nopl (%rax)