// File: /workspace/github_cpp_makefile_star2_O1/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 0x7653
movq (%r15), %rsi
leaq 0x189f0(%rip), %rdi     # 0x20004
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x6050
leaq 0x18a2f(%rip), %rdi     # 0x20054
callq 0x63d0
leaq 0x18a43(%rip), %rdi     # 0x20074
callq 0x63d0
leaq 0x18a55(%rip), %rdi     # 0x20092
callq 0x63d0
leaq 0x18a69(%rip), %rdi     # 0x200b2
callq 0x63d0
jmp 0x777d
movl %edi, %r13d
movq 0x8(%r15), %rbx
movq %rbx, %rdi
callq 0x1cff0
movq %rbx, %r14
testb %al, %al
jne 0x772a
leaq 0x1946a(%rip), %rdx     # 0x20ade
movl %r13d, %edi
movq %r15, %rsi
callq 0x758c
testl %eax, %eax
je 0x768c
cltq
movq 0x8(%r15,%rax,8), %r14
jmp 0x768f
xorl %r14d, %r14d
leaq 0x19d7a(%rip), %rdx     # 0x21410
movl %r13d, %edi
movq %r15, %rsi
callq 0x758c
movl %eax, %r12d
leaq 0x18977(%rip), %rdx     # 0x20022
movl %r13d, %edi
movq %r15, %rsi
callq 0x758c
movl %eax, %ebp
leaq 0x18b29(%rip), %rdx     # 0x201e8
movl %r13d, %edi
movq %r15, %rsi
callq 0x758c
testl %eax, %eax
je 0x76e9
testq %r14, %r14
leaq 0x1894c(%rip), %rax     # 0x20024
cmoveq %rax, %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x19e4e
jmp 0x771c
leaq 0x19d16(%rip), %rdx     # 0x21406
movl %r13d, %edi
movq %r15, %rsi
callq 0x758c
testl %eax, %eax
je 0x7792
testq %r14, %r14
leaq 0x1891f(%rip), %rax     # 0x2002c
cmoveq %rax, %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1b820
xorb $0x1, %al
movzbl %al, %r13d
xorl %r12d, %r12d
testb %r12b, %r12b
je 0x777d
leaq 0x40(%rsp), %r15
movq %r15, %rdi
callq 0x9a64
movq %r15, %rdi
movq %r14, %rsi
callq 0xaa94
testb %al, %al
je 0x7755
cmpq %r14, %rbx
je 0x7766
movq %r14, %rdi
callq 0x6470
jmp 0x7766
leaq 0x188e8(%rip), %rdi     # 0x20044
movq %r14, %rsi
xorl %eax, %eax
callq 0x6050
leaq 0x40(%rsp), %rdi
callq 0xac08
leaq 0x40(%rsp), %rdi
callq 0x79d0
xorl %r13d, %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 0x1c34c
testb %al, %al
je 0x78e5
testl %r12d, %r12d
je 0x77c9
testq %r14, %r14
leaq 0x18865(%rip), %rax     # 0x2002c
jmp 0x77db
testl %ebp, %ebp
je 0x78c8
testq %r14, %r14
leaq 0x18849(%rip), %rax     # 0x20024
cmoveq %rax, %r14
leaq 0x18(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x1850c
leaq 0x10(%rsp), %rdi
leaq 0x18(%rsp), %rsi
movl %ebp, 0x4(%rsp)
callq 0x1851c
movq 0x10(%rsp), %r15
callq 0xda74
movq (%r15), %rax
movq %r15, %rdi
xorl %esi, %esi
callq *0x8(%rax)
movq (%r15), %rax
movq %r15, %rdi
xorl %esi, %esi
callq *0x10(%rax)
movq %r14, %r13
testl %ebp, %ebp
je 0x7837
leaq 0x27a41(%rip), %r13     # 0x2f270
movq %r13, %rdi
callq 0x60f0
leaq 0x189b8(%rip), %rsi     # 0x201f6
movq %r13, 0x8(%rsp)
movq %r13, %rdi
callq 0x62d0
movq %rax, %rbp
leaq 0x27fb3(%rip), %rax     # 0x2f808
movq %rbp, (%rax)
movq (%r15), %rax
xorl %r13d, %r13d
movq %r15, %rdi
xorl %esi, %esi
callq *0x18(%rax)
movq %rbp, %rdi
callq 0x6210
testl %r12d, %r12d
jne 0x789e
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x19e4e
cmpl $0x0, 0x4(%rsp)
sete %r12b
andb %al, %r12b
jne 0x78a1
xorb $0x1, %al
movzbl %al, %r13d
movq 0x8(%rsp), %rdi
callq 0x6470
xorl %r12d, %r12d
testq %r15, %r15
je 0x78af
movq (%r15), %rax
movq %r15, %rdi
callq *0x28(%rax)
leaq 0x20(%rsp), %rdi
callq 0x7a90
leaq 0x40(%rsp), %rdi
callq 0x1c380
jmp 0x7725
testq %r14, %r14
jne 0x77df
leaq 0x27998(%rip), %r14     # 0x2f270
movq %r14, %rdi
callq 0x60f0
jmp 0x77df
movq 0x276ec(%rip), %rax     # 0x2efd8
movq (%rax), %rdi
leaq 0x1873e(%rip), %rsi     # 0x20034
xorl %r12d, %r12d
movq %rbx, %rdx
xorl %eax, %eax
callq 0x6390
movl $0x1, %r13d
jmp 0x78b9
jmp 0x790d
movq %rax, %r12
jmp 0x7931
movq %rax, %r12
xorl %r15d, %r15d
jmp 0x7931
jmp 0x791c
movq %rax, %r12
leaq 0x40(%rsp), %rdi
callq 0x1c380
jmp 0x79bd
movq %rax, %r12
cmpl $0x1, %edx
jne 0x798b
movq %r12, %rdi
callq 0x6120
movq 0x27693(%rip), %rcx     # 0x2efd8
movq (%rcx), %rsi
movq %rax, %rdi
callq 0x7c8e
cmpl $0x0, 0x4(%rsp)
je 0x7961
movq 0x8(%rsp), %rdi
callq 0x6470
cmpq %r14, %rbx
je 0x796e
movq %r14, %rdi
callq 0x6470
callq 0x6420
movl $0x1, %r13d
jmp 0x789e
movq %rax, %r12
jmp 0x798b
movq %rax, %r12
callq 0x6420
testq %r15, %r15
je 0x7999
movq (%r15), %rax
movq %r15, %rdi
callq *0x28(%rax)
leaq 0x20(%rsp), %rdi
callq 0x7a90
jmp 0x791f
movq %rax, %rdi
callq 0x79c5
movq %rax, %r12
leaq 0x40(%rsp), %rdi
callq 0x79d0
movq %r12, %rdi
callq 0x6450