// File: /workspace/github_cpp_makefile_star2_O2/tcannon686[P]obj2webgl/main.cpp
// Function: main
int main(int argc, char *argv[])
{
    if(argc < 2)
    {
        cout << "Usage: " << argv[0] << " [OPTION]... [FILE].obj..." << endl;
        cout << usage;
        cout << "    " << argv[0] << " objs/Cube.obj" << endl;
        cout << "    " << argv[0] << " -o Cube.js objs/Cube.obj" << endl;
        cout << "    " << argv[0] << " -o shapes.js objs/*" << endl;
        return -1;
    }

    string outpath;
    /* Parse arguments. */
    int index;
    for(index = 1; index < argc; index ++)
    {
        string arg(argv[index]);
        if(arg.rfind("-o", 0) == 0)
        {
            auto split = arg.find("=", 0);
            if(split != string::npos)
                outpath = arg.substr(split + 1, arg.size() - split - 1);
            else
            {
                if(index + 1 < argc)
                {
                    outpath = argv[++ index];
                }
            }
        }
        else
            break;
    }

    ofstream outfile;
    if(outpath.size())
        outfile.open(outpath);

    ostream &out(outpath.size() ? outfile : cout);

    /* Write header. */
    out << "/*" << std::endl
        << " * This code was generated using the obj2webgl tool:" << std::endl
        << " * https://github.com/tcannon686/obj2webgl" << std::endl
        << " */" << std::endl << std::endl;

    /* Read the files. */
    for(int i = index; i < argc; i ++)
    {
        string path(argv[i]);
        /* Figure out a name for it. */
        auto base = path.rfind('/');
        if(base == string::npos)
            base = path.rfind('\\');
        if(base != string::npos)
            base ++;
        else
            base = 0;
        auto extension = path.find('.', base);
        if(extension == string::npos)
            extension = path.size();

        string name(path.substr(base, extension - base));

        /* Open the file. */
        ifstream input(path);
        ObjParser<ifstream> parser(input);
        parser.parse();
        parser.writeWebGlCode(out, name);
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x708, %rsp            # imm = 0x708
movq %rsi, %r15
movl %edi, -0x30(%rbp)
cmpl $0x1, %edi
jg 0x28bc
movq 0x77da(%rip), %rbx      # 0x9fc0
leaq 0x3bc0(%rip), %rsi      # 0x63ad
movq %rbx, %rdi
callq 0x2200
movq (%r15), %rsi
movq %rax, %rdi
callq 0x2200
leaq 0x3bae(%rip), %rsi      # 0x63b5
movq %rax, %rdi
callq 0x2200
movq %rax, %rdi
callq 0x2110
movq 0x79fa(%rip), %rsi      # 0xa218
movq %rbx, %rdi
callq 0x2200
leaq 0x3ba3(%rip), %r14      # 0x63d0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2200
movq (%r15), %rsi
movq %rax, %rdi
callq 0x2200
leaq 0x3b96(%rip), %rsi      # 0x63e0
movq %rax, %rdi
callq 0x2200
movq %rax, %rdi
callq 0x2110
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2200
movq (%r15), %rsi
movq %rax, %rdi
callq 0x2200
leaq 0x3b5e(%rip), %rsi      # 0x63d5
movq %rax, %rdi
callq 0x2200
movq %rax, %rdi
callq 0x2110
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2200
movq (%r15), %rsi
movq %rax, %rdi
callq 0x2200
leaq 0x3b4b(%rip), %rsi      # 0x63ef
movq %rax, %rdi
callq 0x2200
movq %rax, %rdi
callq 0x2110
pushq $-0x1
popq %rax
jmp 0x2b4e
movq %r15, -0x38(%rbp)
leaq -0x48(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
pushq $0x1
popq %r12
leaq -0x320(%rbp), %rbx
leaq -0x728(%rbp), %r15
cmpl -0x30(%rbp), %r12d
jge 0x299b
movslq %r12d, %rax
movq -0x38(%rbp), %rcx
movq (%rcx,%rax,8), %rsi
movq %rbx, %rdi
movq %r15, %rdx
callq 0x2be2
movq %rbx, %rdi
leaq 0x3af8(%rip), %rsi      # 0x6404
xorl %edx, %edx
callq 0x2370
movq %rax, %r13
testq %rax, %rax
jne 0x2986
movq %rbx, %rdi
leaq 0x3ae2(%rip), %rsi      # 0x6407
xorl %edx, %edx
callq 0x2400
cmpq $-0x1, %rax
je 0x2964
leaq 0x1(%rax), %rdx
notq %rax
addq -0x318(%rbp), %rax
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rcx
callq 0x2240
leaq -0x58(%rbp), %rdi
movq %r15, %rsi
callq 0x2280
movq %r15, %rdi
callq 0x20f0
jmp 0x2986
leal 0x1(%r12), %r14d
cmpl -0x30(%rbp), %r14d
jge 0x2986
movslq %r14d, %rax
movq -0x38(%rbp), %rcx
movq (%rcx,%rax,8), %rsi
leaq -0x58(%rbp), %rdi
callq 0x23d0
movl %r14d, %r12d
movq %rbx, %rdi
callq 0x20f0
testq %r13, %r13
jne 0x299b
incl %r12d
jmp 0x28e2
leaq -0x520(%rbp), %rdi
callq 0x2380
cmpq $0x0, -0x50(%rbp)
je 0x29cb
leaq -0x520(%rbp), %r13
leaq -0x58(%rbp), %rsi
pushq $0x10
popq %rdx
movq %r13, %rdi
callq 0x2100
cmpq $0x0, -0x50(%rbp)
jne 0x29d2
movq 0x75ee(%rip), %r13      # 0x9fc0
leaq 0x3a28(%rip), %rsi      # 0x6401
movq %r13, %rdi
callq 0x2200
movq %rax, %rdi
callq 0x2110
leaq 0x3a19(%rip), %rsi      # 0x6409
movq %rax, %rdi
callq 0x2200
movq %rax, %rdi
callq 0x2110
leaq 0x3a37(%rip), %rsi      # 0x643e
movq %rax, %rdi
callq 0x2200
movq %rax, %rdi
callq 0x2110
leaq 0x3a4b(%rip), %rsi      # 0x6469
movq %rax, %rdi
callq 0x2200
movq %rax, %rdi
callq 0x2110
movq %rax, %rdi
callq 0x2110
movslq %r12d, %rbx
movl -0x30(%rbp), %eax
movq %rax, -0x30(%rbp)
cmpq -0x30(%rbp), %rbx
jge 0x2b37
movq %r13, %r15
movq -0x38(%rbp), %rax
movq (%rax,%rbx,8), %rsi
leaq -0x78(%rbp), %r14
movq %r14, %rdi
leaq -0x320(%rbp), %rdx
callq 0x2be2
movq %r14, %rdi
pushq $0x2f
popq %rsi
pushq $-0x1
popq %rdx
callq 0x23f0
movq %rax, %r13
cmpq $-0x1, %rax
jne 0x2a90
movq %r14, %rdi
pushq $0x5c
popq %rsi
pushq $-0x1
popq %rdx
callq 0x23f0
movq %rax, %r13
incq %r13
movq %r14, %rdi
pushq $0x2e
popq %rsi
movq %r13, %rdx
callq 0x22a0
cmpq $-0x1, %rax
jne 0x2aab
movq -0x70(%rbp), %rax
subq %r13, %rax
leaq -0x98(%rbp), %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %rax, %rcx
callq 0x2240
leaq -0x728(%rbp), %r12
movq %r12, %rdi
movq %r14, %rsi
pushq $0x8
popq %rdx
callq 0x2340
movq %r15, %r13
leaq -0x320(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x2c1e
movq %r14, %rdi
callq 0x2f46
leaq -0x98(%rbp), %r15
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x2ffa
movq %r14, %rdi
callq 0x381e
leaq -0x728(%rbp), %rdi
callq 0x2060
movq %r15, %rdi
callq 0x20f0
leaq -0x78(%rbp), %rdi
callq 0x20f0
incq %rbx
jmp 0x2a40
leaq -0x520(%rbp), %rdi
callq 0x22f0
leaq -0x58(%rbp), %rdi
callq 0x20f0
xorl %eax, %eax
addq $0x708, %rsp            # imm = 0x708
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2b80
jmp 0x2b7b
jmp 0x2b6a
jmp 0x2b6a
jmp 0x2b80
movq %rax, %rbx
leaq -0x320(%rbp), %rdi
callq 0x20f0
jmp 0x2bd0
movq %rax, %rbx
jmp 0x2bd0
movq %rax, %rbx
jmp 0x2bc4
movq %rax, %rbx
jmp 0x2baf
movq %rax, %rbx
jmp 0x2ba3
movq %rax, %rbx
jmp 0x2bbb
movq %rax, %rbx
leaq -0x320(%rbp), %rdi
callq 0x381e
leaq -0x728(%rbp), %rdi
callq 0x2060
leaq -0x98(%rbp), %rdi
callq 0x20f0
leaq -0x78(%rbp), %rdi
callq 0x20f0
leaq -0x520(%rbp), %rdi
callq 0x22f0
leaq -0x58(%rbp), %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x23a0
nop