// File: 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
subq $0x820, %rsp            # imm = 0x820
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
jge 0x3f42
movq 0x12196(%rip), %rdi     # 0x15fc0
leaq 0xb580(%rip), %rsi      # 0xf3b1
callq 0x3290
movq %rax, %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x3290
movq %rax, %rdi
leaq 0xb56a(%rip), %rsi      # 0xf3b9
callq 0x3290
movq %rax, %rdi
movq 0x12152(%rip), %rsi     # 0x15fb0
callq 0x32e0
movq 0x12446(%rip), %rsi     # 0x162b0
movq 0x1214f(%rip), %rdi     # 0x15fc0
callq 0x3290
movq 0x12143(%rip), %rdi     # 0x15fc0
leaq 0xb550(%rip), %rsi      # 0xf3d4
callq 0x3290
movq %rax, %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x3290
movq %rax, %rdi
leaq 0xb542(%rip), %rsi      # 0xf3e4
callq 0x3290
movq %rax, %rdi
movq 0x120ff(%rip), %rsi     # 0x15fb0
callq 0x32e0
movq 0x12103(%rip), %rdi     # 0x15fc0
leaq 0xb510(%rip), %rsi      # 0xf3d4
callq 0x3290
movq %rax, %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x3290
movq %rax, %rdi
leaq 0xb4f7(%rip), %rsi      # 0xf3d9
callq 0x3290
movq %rax, %rdi
movq 0x120bf(%rip), %rsi     # 0x15fb0
callq 0x32e0
movq 0x120c3(%rip), %rdi     # 0x15fc0
leaq 0xb4d0(%rip), %rsi      # 0xf3d4
callq 0x3290
movq %rax, %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x3290
movq %rax, %rdi
leaq 0xb4d1(%rip), %rsi      # 0xf3f3
callq 0x3290
movq %rax, %rdi
movq 0x1207f(%rip), %rsi     # 0x15fb0
callq 0x32e0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4520
leaq -0x30(%rbp), %rdi
callq 0x33d0
movl $0x1, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x40f7
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x7a8(%rbp)
leaq -0x59(%rbp), %rdi
movq %rdi, -0x7a0(%rbp)
callq 0x34c0
movq -0x7a8(%rbp), %rsi
movq -0x7a0(%rbp), %rdx
leaq -0x58(%rbp), %rdi
callq 0x4540
jmp 0x3f9a
leaq -0x59(%rbp), %rdi
callq 0x3300
leaq 0xb45e(%rip), %rsi      # 0xf408
xorl %eax, %eax
movl %eax, %edx
leaq -0x58(%rbp), %rdi
callq 0x3480
movq %rax, -0x7b0(%rbp)
jmp 0x3fc0
movq -0x7b0(%rbp), %rax
cmpq $0x0, %rax
jne 0x40ba
leaq -0x58(%rbp), %rdi
leaq 0xb42f(%rip), %rsi      # 0xf40b
xorl %eax, %eax
movl %eax, %edx
callq 0x3520
movq %rax, -0x78(%rbp)
cmpq $-0x1, -0x78(%rbp)
je 0x408a
movq -0x78(%rbp), %rax
incq %rax
movq %rax, -0x7b8(%rbp)
leaq -0x58(%rbp), %rdi
movq %rdi, -0x7c0(%rbp)
callq 0x31d0
movq -0x7c0(%rbp), %rsi
movq -0x7b8(%rbp), %rdx
movq -0x78(%rbp), %rcx
notq %rcx
addq %rax, %rcx
leaq -0x98(%rbp), %rdi
callq 0x32d0
jmp 0x4038
leaq -0x30(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x3360
leaq -0x98(%rbp), %rdi
callq 0x31a0
jmp 0x40b8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x59(%rbp), %rdi
callq 0x3300
jmp 0x4515
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x31a0
jmp 0x4515
movl -0x34(%rbp), %eax
addl $0x1, %eax
cmpl -0x8(%rbp), %eax
jge 0x40b6
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl %ecx, %edx
incl %edx
movl %edx, -0x34(%rbp)
movq 0x8(%rax,%rcx,8), %rsi
leaq -0x30(%rbp), %rdi
callq 0x33c0
jmp 0x40b4
jmp 0x40b6
jmp 0x40b8
jmp 0x40c6
movl $0x2, -0x9c(%rbp)
jmp 0x40d0
movl $0x0, -0x9c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x31a0
movl -0x9c(%rbp), %eax
testl %eax, %eax
je 0x40e7
jmp 0x40e5
jmp 0x40f7
jmp 0x40e9
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x3f52
leaq -0x2a0(%rbp), %rdi
callq 0x3490
jmp 0x4105
leaq -0x30(%rbp), %rdi
callq 0x31d0
cmpq $0x0, %rax
je 0x414f
leaq -0x2a0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x10, %edx
callq 0x3150
jmp 0x412b
jmp 0x414f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x4515
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x4509
leaq -0x30(%rbp), %rdi
callq 0x31d0
cmpq $0x0, %rax
je 0x416e
leaq -0x2a0(%rbp), %rax
movq %rax, -0x7c8(%rbp)
jmp 0x417e
movq 0x11e4b(%rip), %rax     # 0x15fc0
movq %rax, -0x7c8(%rbp)
jmp 0x417e
movq -0x7c8(%rbp), %rax
movq %rax, -0x2a8(%rbp)
movq -0x2a8(%rbp), %rdi
leaq 0xb26b(%rip), %rsi      # 0xf405
callq 0x3290
movq %rax, -0x7d0(%rbp)
jmp 0x41a8
movq -0x7d0(%rbp), %rdi
movq 0x11dfa(%rip), %rsi     # 0x15fb0
callq 0x32e0
movq %rax, -0x7d8(%rbp)
jmp 0x41c4
movq -0x7d8(%rbp), %rdi
leaq 0xb23b(%rip), %rsi      # 0xf40d
callq 0x3290
movq %rax, -0x7e0(%rbp)
jmp 0x41e0
movq -0x7e0(%rbp), %rdi
movq 0x11dc2(%rip), %rsi     # 0x15fb0
callq 0x32e0
movq %rax, -0x7e8(%rbp)
jmp 0x41fc
movq -0x7e8(%rbp), %rdi
leaq 0xb238(%rip), %rsi      # 0xf442
callq 0x3290
movq %rax, -0x7f0(%rbp)
jmp 0x4218
movq -0x7f0(%rbp), %rdi
movq 0x11d8a(%rip), %rsi     # 0x15fb0
callq 0x32e0
movq %rax, -0x7f8(%rbp)
jmp 0x4234
movq -0x7f8(%rbp), %rdi
leaq 0xb22b(%rip), %rsi      # 0xf46d
callq 0x3290
movq %rax, -0x800(%rbp)
jmp 0x4250
movq -0x800(%rbp), %rdi
movq 0x11d52(%rip), %rsi     # 0x15fb0
callq 0x32e0
movq %rax, -0x808(%rbp)
jmp 0x426c
movq -0x808(%rbp), %rdi
movq 0x11d36(%rip), %rsi     # 0x15fb0
callq 0x32e0
jmp 0x4281
movl -0x34(%rbp), %eax
movl %eax, -0x2ac(%rbp)
movl -0x2ac(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x44e1
movq -0x10(%rbp), %rax
movslq -0x2ac(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x818(%rbp)
leaq -0x2d1(%rbp), %rdi
movq %rdi, -0x810(%rbp)
callq 0x34c0
movq -0x818(%rbp), %rsi
movq -0x810(%rbp), %rdx
leaq -0x2d0(%rbp), %rdi
callq 0x4540
jmp 0x42de
leaq -0x2d1(%rbp), %rdi
callq 0x3300
leaq -0x2d0(%rbp), %rdi
movl $0x2f, %esi
movq $-0x1, %rdx
callq 0x3500
movq %rax, -0x2e0(%rbp)
cmpq $-0x1, -0x2e0(%rbp)
jne 0x4351
leaq -0x2d0(%rbp), %rdi
movl $0x5c, %esi
movq $-0x1, %rdx
callq 0x3500
movq %rax, -0x2e0(%rbp)
jmp 0x4351
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x2d1(%rbp), %rdi
callq 0x3300
jmp 0x4509
cmpq $-0x1, -0x2e0(%rbp)
je 0x436f
movq -0x2e0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2e0(%rbp)
jmp 0x437a
movq $0x0, -0x2e0(%rbp)
movq -0x2e0(%rbp), %rdx
leaq -0x2d0(%rbp), %rdi
movl $0x2e, %esi
callq 0x3390
movq %rax, -0x2e8(%rbp)
cmpq $-0x1, -0x2e8(%rbp)
jne 0x43b6
leaq -0x2d0(%rbp), %rdi
callq 0x31d0
movq %rax, -0x2e8(%rbp)
movq -0x2e0(%rbp), %rdx
movq -0x2e8(%rbp), %rcx
subq %rdx, %rcx
leaq -0x308(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
callq 0x32d0
jmp 0x43dc
leaq -0x510(%rbp), %rdi
leaq -0x2d0(%rbp), %rsi
movl $0x8, %edx
callq 0x3450
jmp 0x43f6
leaq -0x798(%rbp), %rdi
leaq -0x510(%rbp), %rsi
callq 0x45f0
jmp 0x440b
leaq -0x798(%rbp), %rdi
callq 0x4c60
jmp 0x4419
movq -0x2a8(%rbp), %rsi
leaq -0x798(%rbp), %rdi
leaq -0x308(%rbp), %rdx
callq 0x4d80
jmp 0x4435
leaq -0x798(%rbp), %rdi
callq 0x5cc0
leaq -0x510(%rbp), %rdi
callq 0x30a0
leaq -0x308(%rbp), %rdi
callq 0x31a0
leaq -0x2d0(%rbp), %rdi
callq 0x31a0
movl -0x2ac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2ac(%rbp)
jmp 0x428a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x44d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x44c7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x44bb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x798(%rbp), %rdi
callq 0x5cc0
leaq -0x510(%rbp), %rdi
callq 0x30a0
leaq -0x308(%rbp), %rdi
callq 0x31a0
leaq -0x2d0(%rbp), %rdi
callq 0x31a0
jmp 0x4509
movl $0x0, -0x4(%rbp)
movl $0x1, -0x9c(%rbp)
leaq -0x2a0(%rbp), %rdi
callq 0x3400
leaq -0x30(%rbp), %rdi
callq 0x31a0
jmp 0x4520
leaq -0x2a0(%rbp), %rdi
callq 0x3400
leaq -0x30(%rbp), %rdi
callq 0x31a0
jmp 0x452c
movl -0x4(%rbp), %eax
addq $0x820, %rsp            # imm = 0x820
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x34b0
nopw %cs:(%rax,%rax)
nop