// File: /workspace/github_cpp_makefile_star2_O2/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 0x73b9
movq (%r15), %rsi
leaq 0x15c8a(%rip), %rdi     # 0x1d004
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x6050
leaq 0x15cc9(%rip), %rdi     # 0x1d054
callq 0x63d0
leaq 0x15cdd(%rip), %rdi     # 0x1d074
callq 0x63d0
leaq 0x15cef(%rip), %rdi     # 0x1d092
callq 0x63d0
leaq 0x15d03(%rip), %rdi     # 0x1d0b2
callq 0x63d0
jmp 0x74d2
movl %edi, %r13d
movq 0x8(%r15), %rbx
movq %rbx, %rdi
callq 0x19bac
movq %rbx, %r14
testb %al, %al
je 0x73fa
leaq 0x40(%rsp), %r15
movq %r15, %rdi
callq 0x8f9a
movq %r15, %rdi
movq %r14, %rsi
callq 0x9a10
testb %al, %al
je 0x7419
cmpq %r14, %rbx
je 0x742a
movq %r14, %rdi
callq 0x6480
jmp 0x742a
leaq 0x166ad(%rip), %rdx     # 0x1daae
movl %r13d, %edi
movq %r15, %rsi
callq 0x72fc
testl %eax, %eax
je 0x7446
cltq
movq 0x8(%r15,%rax,8), %r14
jmp 0x7449
leaq 0x15c24(%rip), %rdi     # 0x1d044
movq %r14, %rsi
xorl %eax, %eax
callq 0x6050
leaq 0x40(%rsp), %rdi
callq 0x9b54
leaq 0x40(%rsp), %rdi
callq 0x7732
xorl %r13d, %r13d
jmp 0x74d2
xorl %r14d, %r14d
leaq 0x16f8c(%rip), %rdx     # 0x1e3dc
movl %r13d, %edi
movq %r15, %rsi
callq 0x72fc
movl %eax, %r12d
leaq 0x15bbd(%rip), %rdx     # 0x1d022
movl %r13d, %edi
movq %r15, %rsi
callq 0x72fc
movl %eax, %ebp
leaq 0x15d47(%rip), %rdx     # 0x1d1c0
movl %r13d, %edi
movq %r15, %rsi
callq 0x72fc
testl %eax, %eax
je 0x74a0
testq %r14, %r14
leaq 0x15b92(%rip), %rsi     # 0x1d024
cmovneq %r14, %rsi
movq %rbx, %rdi
callq 0x16c76
jmp 0x74cc
leaq 0x16f2b(%rip), %rdx     # 0x1e3d2
movl %r13d, %edi
movq %r15, %rsi
callq 0x72fc
testl %eax, %eax
je 0x74e7
testq %r14, %r14
leaq 0x15b6c(%rip), %rsi     # 0x1d02c
cmovneq %r14, %rsi
movq %rbx, %rdi
callq 0x18934
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)
andl $0x0, 0x20(%rdi)
movq %rbx, %rsi
callq 0x19160
testb %al, %al
je 0x7637
testl %r12d, %r12d
je 0x751b
testq %r14, %r14
leaq 0x15b13(%rip), %rax     # 0x1d02c
jmp 0x752d
testl %ebp, %ebp
je 0x761d
testq %r14, %r14
leaq 0x15af7(%rip), %rax     # 0x1d024
cmoveq %rax, %r14
leaq 0x18(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x159d2
leaq 0x10(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x159e2
movq 0x10(%rsp), %r13
movq %r13, (%rsp)
callq 0xc788
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, %rax
testl %ebp, %ebp
je 0x7588
callq 0x7342
leaq 0x27cf8(%rip), %rax     # 0x2f280
leaq 0x15c3f(%rip), %rsi     # 0x1d1ce
movq %rax, 0x8(%rsp)
movq %rax, %rdi
callq 0x62c0
movq %rax, %r15
leaq 0x28272(%rip), %rax     # 0x2f818
movq %r15, (%rax)
movq (%r13), %rax
movq %r13, %rdi
xorl %r13d, %r13d
xorl %esi, %esi
callq *0x18(%rax)
movq %r15, %rdi
callq 0x6220
testl %r12d, %r12d
jne 0x75ee
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x16c76
testl %ebp, %ebp
sete %cl
movb $0x1, %r15b
testb %al, %cl
jne 0x75f1
xorb $0x1, %al
movzbl %al, %r13d
movq 0x8(%rsp), %rdi
callq 0x6480
xorl %r15d, %r15d
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
leaq 0x20(%rsp), %rdi
callq 0x776c
leaq 0x40(%rsp), %rdi
callq 0x19194
testb %r15b, %r15b
jne 0x73cf
jmp 0x74d2
testq %r14, %r14
jne 0x7531
callq 0x7342
leaq 0x27c4e(%rip), %r14     # 0x2f280
jmp 0x7531
movq 0x2799a(%rip), %rax     # 0x2efd8
movq (%rax), %rdi
leaq 0x159ec(%rip), %rsi     # 0x1d034
xorl %r15d, %r15d
movq %rbx, %rdx
xorl %eax, %eax
callq 0x6390
pushq $0x1
popq %r13
jmp 0x7605
jmp 0x765d
movq %rax, %r12
jmp 0x7686
movq %rax, %r12
movq $0x0, (%rsp)
jmp 0x7686
jmp 0x7671
movq %rax, %r12
leaq 0x40(%rsp), %rdi
callq 0x19194
jmp 0x771e
movq %rax, %r12
cmpl $0x1, %edx
jne 0x76e9
movq %r12, %rdi
callq 0x6100
movq 0x2793e(%rip), %rcx     # 0x2efd8
movq (%rcx), %rsi
movq %rax, %rdi
callq 0x7a2e
testl %ebp, %ebp
je 0x76b3
movq 0x8(%rsp), %rdi
callq 0x6480
cmpq %r14, %rbx
je 0x76c0
movq %r14, %rdi
callq 0x6480
callq 0x6420
pushq $0x1
popq %r13
xorl %r15d, %r15d
cmpq $0x0, (%rsp)
jne 0x75f1
jmp 0x75fb
movq %rax, %r12
jmp 0x76e9
movq %rax, %r12
callq 0x6420
cmpq $0x0, (%rsp)
je 0x76fa
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
leaq 0x20(%rsp), %rdi
callq 0x776c
jmp 0x7674
movq %rax, %rdi
callq 0x7726
movq %rax, %r12
leaq 0x40(%rsp), %rdi
callq 0x7732
movq %r12, %rdi
callq 0x6460