// File: /workspace/github_cpp_makefile_star2_O3/Eronana[P]strawberry/src/main.cpp
// Function: main
int main(int argc,char *argv[])
{
    if(argc==1)
    {
        printf("Usage: %s filename [options]\n",argv[0]);
        printf("\t -s compile script to assembly\n");
        printf("\t -x compile script to binary\n");
        printf("\t -c compile assembly to binary\n");
        printf("\t -o set output filename\n");
        return 0;
    }
    char *in=argv[1];
    const char *out=NULL;
    if(CodeData::check(in))
    {
        out=in;
    }
    else
    {
        int opt;
        if((opt=GETOPT("o")))out=argv[opt+1];
        bool s=GETOPT("s"),x=GETOPT("x"),c=GETOPT("c"),d=GETOPT("d");

        if(c)
        {
            SETOUT("out.bin")
            if(assemble(in,out))return 0;
            return 1;
        }
        if(d)
        {
            SETOUT("out.asm")
            if(disassemble(in,out))return 0;
            return 1;
        }
        Lexer lexer;
        if(!lexer.load(in))
        {
            fprintf(stderr,"cannot open %s\n",in);
            return 1;
        }
        if(s)SETOUT("out.asm")
        else if(x) SETOUT("out.bin")
        else SETOUT(tmpname())
        Parser parser(lexer);
        AST_PTR ast;
        const char *asm_out;
        try
        {
            ast=parser.parse();
            astMethodInit();
            ast->fill(nullptr);
            ast->check(nullptr);

            if(!x)asm_out=out;
            else asm_out=tmpname();
            FILE *fp=fopen(asm_out,"w");
            AST::fp=fp;
            ast->codeGen(nullptr);
            fclose(fp);
            if(s)return 0;
            int result=assemble(asm_out,out)?0:1;
            if(x||result)
            {
                remove(asm_out);
                return result;
            }
        }
        catch(Exception &e)
        {
            e.print(stderr);
            if(x)remove(asm_out);
            if(in!=out)remove(out);
            return 1;
        }

    }
    VirtualMachine vm;
    if(!vm.load(out))printf("cannot load %s\n",out);
    else if(in!=out)remove(out);;
    vm.run();
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x548, %rsp            # imm = 0x548
movq %rsi, %r15
cmpl $0x1, %edi
jne 0x7633
movq (%r15), %rsi
leaq 0x18a10(%rip), %rdi     # 0x20004
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x6050
leaq 0x18a4f(%rip), %rdi     # 0x20054
callq 0x63d0
leaq 0x18a63(%rip), %rdi     # 0x20074
callq 0x63d0
leaq 0x18a75(%rip), %rdi     # 0x20092
callq 0x63d0
leaq 0x18a89(%rip), %rdi     # 0x200b2
callq 0x63d0
jmp 0x774c
movl %edi, %r13d
movq 0x8(%r15), %rbx
movq %rbx, %rdi
callq 0x1ca28
movq %rbx, %r14
testb %al, %al
je 0x7674
leaq 0x40(%rsp), %r15
movq %r15, %rdi
callq 0x9a76
movq %r15, %rdi
movq %r14, %rsi
callq 0xaaa6
testb %al, %al
je 0x7693
cmpq %r14, %rbx
je 0x76a4
movq %r14, %rdi
callq 0x6470
jmp 0x76a4
leaq 0x19463(%rip), %rdx     # 0x20ade
movl %r13d, %edi
movq %r15, %rsi
callq 0x756c
testl %eax, %eax
je 0x76c0
cltq
movq 0x8(%r15,%rax,8), %r14
jmp 0x76c3
leaq 0x189aa(%rip), %rdi     # 0x20044
movq %r14, %rsi
xorl %eax, %eax
callq 0x6050
leaq 0x40(%rsp), %rdi
callq 0xac1a
leaq 0x40(%rsp), %rdi
callq 0x79c2
xorl %r13d, %r13d
jmp 0x774c
xorl %r14d, %r14d
leaq 0x19d62(%rip), %rdx     # 0x2142c
movl %r13d, %edi
movq %r15, %rsi
callq 0x756c
movl %eax, %r12d
leaq 0x18943(%rip), %rdx     # 0x20022
movl %r13d, %edi
movq %r15, %rsi
callq 0x756c
movl %eax, %ebp
leaq 0x18af5(%rip), %rdx     # 0x201e8
movl %r13d, %edi
movq %r15, %rsi
callq 0x756c
testl %eax, %eax
je 0x771a
testq %r14, %r14
leaq 0x18918(%rip), %rsi     # 0x20024
cmovneq %r14, %rsi
movq %rbx, %rdi
callq 0x1988c
jmp 0x7746
leaq 0x19d01(%rip), %rdx     # 0x21422
movl %r13d, %edi
movq %r15, %rsi
callq 0x756c
testl %eax, %eax
je 0x7761
testq %r14, %r14
leaq 0x188f2(%rip), %rsi     # 0x2002c
cmovneq %r14, %rsi
movq %rbx, %rdi
callq 0x1b22c
xorb $0x1, %al
movzbl %al, %r13d
movl %r13d, %eax
addq $0x548, %rsp            # imm = 0x548
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rdi
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
movl $0x0, 0x20(%rdi)
movq %rbx, %rsi
callq 0x1bd88
testb %al, %al
je 0x78ba
testl %r12d, %r12d
je 0x7798
testq %r14, %r14
leaq 0x18896(%rip), %rax     # 0x2002c
jmp 0x77aa
testl %ebp, %ebp
je 0x789d
testq %r14, %r14
leaq 0x1887a(%rip), %rax     # 0x20024
cmoveq %rax, %r14
leaq 0x18(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x17f2e
leaq 0x10(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x17f3e
movq 0x10(%rsp), %r13
movq %r13, (%rsp)
callq 0xda60
movq (%r13), %rax
movq %r13, %rdi
xorl %esi, %esi
callq *0x8(%rax)
movq (%r13), %rax
movq %r13, %rdi
xorl %esi, %esi
callq *0x10(%rax)
movq %r14, %r15
testl %ebp, %ebp
je 0x7808
leaq 0x27a70(%rip), %r15     # 0x2f270
movq %r15, %rdi
callq 0x60f0
leaq 0x189e7(%rip), %rsi     # 0x201f6
movq %r15, 0x8(%rsp)
movq %r15, %rdi
callq 0x62d0
movq %rax, %r15
leaq 0x27fe2(%rip), %rax     # 0x2f808
movq %r15, (%rax)
movq (%r13), %rax
movq %r13, %rdi
xorl %r13d, %r13d
xorl %esi, %esi
callq *0x18(%rax)
movq %r15, %rdi
callq 0x6210
testl %r12d, %r12d
jne 0x786e
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x1988c
testl %ebp, %ebp
sete %cl
movb $0x1, %r15b
testb %al, %cl
jne 0x7871
xorb $0x1, %al
movzbl %al, %r13d
movq 0x8(%rsp), %rdi
callq 0x6470
xorl %r15d, %r15d
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
leaq 0x20(%rsp), %rdi
callq 0x7a82
leaq 0x40(%rsp), %rdi
callq 0x1bdbc
testb %r15b, %r15b
jne 0x7649
jmp 0x774c
testq %r14, %r14
jne 0x77ae
leaq 0x279c3(%rip), %r14     # 0x2f270
movq %r14, %rdi
callq 0x60f0
jmp 0x77ae
movq 0x27717(%rip), %rax     # 0x2efd8
movq (%rax), %rdi
leaq 0x18769(%rip), %rsi     # 0x20034
movq %rbx, %rdx
xorl %eax, %eax
callq 0x6390
leaq 0x40(%rsp), %rdi
callq 0x1bdbc
movl $0x1, %r13d
jmp 0x774c
jmp 0x78ec
movq %rax, %r12
jmp 0x7915
movq %rax, %r12
movq $0x0, (%rsp)
jmp 0x7915
jmp 0x7900
movq %rax, %r12
leaq 0x40(%rsp), %rdi
callq 0x1bdbc
jmp 0x79af
movq %rax, %r12
cmpl $0x1, %edx
jne 0x797a
movq %r12, %rdi
callq 0x6120
movq 0x276af(%rip), %rcx     # 0x2efd8
movq (%rcx), %rsi
movq %rax, %rdi
callq 0x7c8a
testl %ebp, %ebp
je 0x7942
movq 0x8(%rsp), %rdi
callq 0x6470
cmpq %r14, %rbx
je 0x794f
movq %r14, %rdi
callq 0x6470
callq 0x6420
movl $0x1, %r13d
xorl %r15d, %r15d
cmpq $0x0, (%rsp)
jne 0x7871
jmp 0x787b
movq %rax, %r12
jmp 0x797a
movq %rax, %r12
callq 0x6420
cmpq $0x0, (%rsp)
je 0x798b
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
leaq 0x20(%rsp), %rdi
callq 0x7a82
jmp 0x7903
movq %rax, %rdi
callq 0x79b7
movq %rax, %r12
leaq 0x40(%rsp), %rdi
callq 0x79c2
movq %r12, %rdi
callq 0x6450