// File: /workspace/github_cpp_makefile_star2_O2/tcannon686[P]obj2webgl/./obj_parser.hpp
// Function: ObjParser<std::basic_ifstream<char, std::char_traits<char>>>::writeWebGlCode(std::ostream&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) const
void ObjParser<Stream>::writeWebGlCode(
        std::ostream &out,
        const std::string &name) const
{
    assert(done);
    /* Change the separate indices to one set of vertex indices. */

    /* Maps old vIndices, tIndices, nIndices tuple to new index. */
    std::unordered_map<std::string, unsigned int> index_table;

    /* Vertex array buffer */
    std::vector<unsigned int> index_array;

    /* Vertex buffer format: vvvttnnn */
    std::vector<float> data;
    int cur_index = 0;

    for(std::size_t i = 0; i < vIndices.size(); i ++)
    {
        std::string table_index =
            std::to_string(vIndices[i])
            + "/" + (tIndices.size() > 0 ?
                    std::to_string(tIndices[i])
                    : "")
            + "/" + (nIndices.size() > 0 ?
                    std::to_string(nIndices[i])
                    : "");

        auto in_table = index_table.find(table_index);

        /* If the vertex has not been added yet, add it. */
        if(in_table == end(index_table))
        {
            /* Add the data. */
            for(int j = 0; j < 3; j ++)
                data.push_back(vertices[vIndices[i]][j]);
            if(tIndices.size() > 0)
            {
                for(int j = 0; j < 2; j ++)
                    data.push_back(texCos[tIndices[i]][j]);
            }
            if(nIndices.size() > 0)
            {
                for(int j = 0; j < 3; j ++)
                    data.push_back(normals[nIndices[i]][j]);
            }

            index_table[table_index] = cur_index;
            cur_index ++;
        }
        index_array.push_back(index_table[table_index]);
    }

    const std::size_t vertex_size = 3 * sizeof(float);
    const std::size_t normal_size = (
            nIndices.size() > 0? 3 * sizeof(float) : 0);
    const std::size_t texco_size = (
            tIndices.size() > 0? 2 * sizeof(float) : 0);
    const std::size_t stride = vertex_size + normal_size + texco_size;


    out << "const " << name << "={};";

    out << name << ".data=new Float32Array([";
    for(auto it = begin(data); it != end(data); it ++)
    {
        out << *it;
        if(it + 1 != end(data))
            out << ",";
    }
    out << "]);";

    out << name << ".indexData=new Uint16Array([";
    for(auto it = begin(index_array); it != end(index_array); it ++)
    {
        out << *it;
        if(it + 1 != end(index_array))
            out << ",";
    }
    out << "]);";

    out << name << ".init=function(){";
    out << name << ".vbo=gl.createBuffer();";
    out << name << ".ibo=gl.createBuffer();";

    out << "gl.bindBuffer(gl.ARRAY_BUFFER," << name << ".vbo);";
    out << "gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER," << name << ".ibo);";

    out << "gl.bufferData(gl.ARRAY_BUFFER,"
        << name << ".data,gl.STATIC_DRAW);";

    out << "gl.bufferData(gl.ELEMENT_ARRAY_BUFFER,"
        << name << ".indexData,gl.STATIC_DRAW);"
        << "};";

    out << name << ".render=function(a_Position,a_Normal,a_TexCo){";
    out << "gl.bindBuffer(gl.ARRAY_BUFFER," << name << ".vbo);";
    out << "gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER," << name << ".ibo);";
    out << "gl.vertexAttribPointer(a_Position,3,gl.FLOAT,false,"
        << stride << ",null);";
    
    out << "gl.enableVertexAttribArray(a_Position);";
    
    if(tIndices.size() > 0)
    {
        out << "if(a_TexCo!==undefined) {";
        out << "gl.vertexAttribPointer(a_TexCo,2,gl.FLOAT,false,"
            << stride << "," << vertex_size << ");";

        out << "gl.enableVertexAttribArray(a_TexCo);";
        out << "}";
    }

    if(nIndices.size() > 0)
    {
        out << "if(a_Normal!==undefined){";
        out << "gl.vertexAttribPointer(a_Normal,3,gl.FLOAT,false,"
            << stride << "," << vertex_size + texco_size << ");";

        out << "gl.enableVertexAttribArray(a_Normal);";
        out << "}";
    }

    out << "gl.drawElements(gl.TRIANGLES,"
        << index_array.size()
        << ",gl.UNSIGNED_SHORT,0);";
    out << "};";
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movq %rdx, -0x38(%rbp)
movq %rsi, -0x30(%rbp)
cmpb $0x0, 0x99(%rdi)
je 0x373f
movq %rdi, %r14
leaq -0x120(%rbp), %rax
movq %rax, -0x30(%rax)
movq $0x1, -0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, -0x10(%rax) # imm = 0x3F800000
movups %xmm0, -0x8(%rax)
leaq -0x80(%rbp), %rax
andq $0x0, 0x10(%rax)
leaq -0x60(%rbp), %rcx
andq $0x0, 0x10(%rcx)
movaps %xmm0, (%rax)
movaps %xmm0, (%rcx)
xorl %r12d, %r12d
leaq -0xf8(%rbp), %rbx
movl $0x0, -0x40(%rbp)
movq 0x50(%r14), %rax
movq 0x58(%r14), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rcx, %r12
jae 0x32f2
movl (%rax,%r12,4), %esi
leaq -0x190(%rbp), %r15
movq %r15, %rdi
callq 0x52ff
movq %rbx, %rdi
movq %r15, %rsi
leaq 0x33bf(%rip), %rdx      # 0x646b
callq 0x52d6
movq 0x80(%r14), %rax
movq 0x88(%r14), %rcx
movq %rcx, -0x90(%rbp)
cmpq %rax, %rcx
movq %rax, -0x98(%rbp)
je 0x30e7
movl (%rax,%r12,4), %esi
leaq -0xd8(%rbp), %r13
movq %r13, %rdi
callq 0x52ff
jmp 0x3101
leaq -0xd8(%rbp), %r13
movq %r13, %rdi
leaq 0x32b4(%rip), %rsi      # 0x63ac
leaq -0x3a(%rbp), %rdx
callq 0x2be2
leaq -0x1b0(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x5265
leaq -0x190(%rbp), %r13
leaq -0x118(%rbp), %rdi
movq %r15, %rsi
leaq 0x333d(%rip), %rdx      # 0x646b
callq 0x52d6
movq 0x68(%r14), %r15
movq 0x70(%r14), %rax
movq %rax, -0x88(%rbp)
cmpq %r15, %rax
je 0x315c
movl (%r15,%r12,4), %esi
leaq -0x170(%rbp), %rbx
movq %rbx, %rdi
callq 0x52ff
jmp 0x3176
leaq -0x170(%rbp), %rbx
movq %rbx, %rdi
leaq 0x323f(%rip), %rsi      # 0x63ac
leaq -0x39(%rbp), %rdx
callq 0x2be2
leaq -0xb8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
movq %rbx, %rdx
callq 0x5265
movq %rbx, %rdi
callq 0x20f0
cmpq %r15, -0x88(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x20f0
leaq -0x1b0(%rbp), %rdi
callq 0x20f0
leaq -0xd8(%rbp), %rdi
callq 0x20f0
movq -0x90(%rbp), %rax
cmpq -0x98(%rbp), %rax
leaq -0xf8(%rbp), %rbx
movq %rbx, %rdi
callq 0x20f0
movq %r13, %rdi
callq 0x20f0
leaq -0x150(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x5456
testq %rax, %rax
jne 0x32bf
xorl %ebx, %ebx
cmpq $0xc, %rbx
je 0x322a
movq 0x50(%r14), %rax
movslq (%rax,%r12,4), %rsi
shlq $0x4, %rsi
addq 0x8(%r14), %rsi
addq %rbx, %rsi
leaq -0x60(%rbp), %rdi
callq 0x5360
addq $0x4, %rbx
jmp 0x3202
movq 0x88(%r14), %rax
cmpq 0x80(%r14), %rax
je 0x3267
xorl %ebx, %ebx
cmpq $0x8, %rbx
je 0x3267
movq 0x80(%r14), %rax
movslq (%rax,%r12,4), %rsi
shlq $0x3, %rsi
addq 0x38(%r14), %rsi
addq %rbx, %rsi
leaq -0x60(%rbp), %rdi
callq 0x5360
addq $0x4, %rbx
jmp 0x323c
movq 0x70(%r14), %rax
cmpq 0x68(%r14), %rax
je 0x329b
xorl %ebx, %ebx
cmpq $0xc, %rbx
je 0x329b
movq 0x68(%r14), %rax
movslq (%rax,%r12,4), %rax
imulq $0xc, %rax, %rsi
addq 0x20(%r14), %rsi
addq %rbx, %rsi
leaq -0x60(%rbp), %rdi
callq 0x5360
addq $0x4, %rbx
jmp 0x3273
leaq -0x150(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x56ce
leaq -0xf8(%rbp), %rbx
movl -0x40(%rbp), %ecx
movl %ecx, (%rax)
incl %ecx
movl %ecx, -0x40(%rbp)
leaq -0x150(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x56ce
leaq -0x80(%rbp), %rdi
movq %rax, %rsi
callq 0x538a
leaq -0xb8(%rbp), %rdi
callq 0x20f0
incq %r12
jmp 0x3074
movq 0x70(%r14), %rax
movq 0x88(%r14), %rcx
xorl %r12d, %r12d
cmpq 0x80(%r14), %rcx
setne %r12b
shll $0x3, %r12d
leaq 0x18(%r12), %r13
addq $0xc, %r12
cmpq 0x68(%r14), %rax
cmoveq %r12, %r13
leaq 0x348a(%rip), %rsi      # 0x67b1
movq -0x30(%rbp), %rdi
callq 0x2200
movq %rax, %rdi
movq -0x38(%rbp), %rsi
callq 0x21f0
leaq 0x3475(%rip), %rsi      # 0x67b8
movq %rax, %rdi
callq 0x2200
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x21f0
leaq 0x345e(%rip), %rsi      # 0x67bd
movq %rax, %rdi
callq 0x2200
movq -0x60(%rbp), %r15
leaq 0x3538(%rip), %rbx      # 0x68aa
cmpq -0x58(%rbp), %r15
je 0x339e
movss (%r15), %xmm0
movq -0x30(%rbp), %rdi
callq 0x21a0
addq $0x4, %r15
cmpq -0x58(%rbp), %r15
je 0x3372
movq -0x30(%rbp), %rdi
movq %rbx, %rsi
callq 0x2200
jmp 0x3372
leaq 0x3431(%rip), %rsi      # 0x67d6
movq -0x30(%rbp), %rdi
callq 0x2200
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x21f0
leaq 0x3418(%rip), %rsi      # 0x67da
movq %rax, %rdi
callq 0x2200
movq -0x80(%rbp), %r15
leaq 0x34d5(%rip), %rbx      # 0x68aa
cmpq -0x78(%rbp), %r15
je 0x33ff
movl (%r15), %esi
movq -0x30(%rbp), %rdi
callq 0x2170
addq $0x4, %r15
cmpq -0x78(%rbp), %r15
je 0x33d5
movq -0x30(%rbp), %rdi
movq %rbx, %rsi
callq 0x2200
jmp 0x33d5
leaq 0x33d0(%rip), %rsi      # 0x67d6
movq -0x30(%rbp), %rdi
callq 0x2200
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x21f0
leaq 0x33d4(%rip), %rsi      # 0x67f7
movq %rax, %rdi
callq 0x2200
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x21f0
leaq 0x33ca(%rip), %rsi      # 0x6809
movq %rax, %rdi
callq 0x2200
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x21f0
leaq 0x33c6(%rip), %rsi      # 0x6821
movq %rax, %rdi
callq 0x2200
leaq 0x33cf(%rip), %rsi      # 0x6839
movq -0x30(%rbp), %rdi
callq 0x2200
movq %rax, %rdi
movq -0x38(%rbp), %rsi
callq 0x21f0
leaq 0x33d2(%rip), %rsi      # 0x6858
movq %rax, %rdi
callq 0x2200
leaq 0x33ca(%rip), %rsi      # 0x685f
movq -0x30(%rbp), %rdi
callq 0x2200
movq %rax, %rdi
movq -0x38(%rbp), %rsi
callq 0x21f0
leaq 0x33d5(%rip), %rsi      # 0x6886
movq %rax, %rdi
callq 0x2200
leaq 0x33cd(%rip), %rsi      # 0x688d
movq -0x30(%rbp), %rdi
callq 0x2200
movq %rax, %rdi
movq -0x38(%rbp), %rsi
callq 0x21f0
leaq 0x33d0(%rip), %rsi      # 0x68ac
movq %rax, %rdi
callq 0x2200
leaq 0x33d8(%rip), %rsi      # 0x68c3
movq -0x30(%rbp), %rdi
callq 0x2200
movq %rax, %rdi
movq -0x38(%rbp), %rsi
callq 0x21f0
leaq 0x33e3(%rip), %rsi      # 0x68ea
movq %rax, %rdi
callq 0x2200
leaq 0x32a4(%rip), %rsi      # 0x67ba
movq %rax, %rdi
callq 0x2200
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x21f0
leaq 0x33d4(%rip), %rsi      # 0x6906
movq %rax, %rdi
callq 0x2200
leaq 0x32f8(%rip), %rsi      # 0x6839
movq -0x30(%rbp), %rdi
callq 0x2200
movq %rax, %rdi
movq -0x38(%rbp), %rsi
callq 0x21f0
leaq 0x32fb(%rip), %rsi      # 0x6858
movq %rax, %rdi
callq 0x2200
leaq 0x32f3(%rip), %rsi      # 0x685f
movq -0x30(%rbp), %rdi
callq 0x2200
movq %rax, %rdi
movq -0x38(%rbp), %rsi
callq 0x21f0
leaq 0x32fe(%rip), %rsi      # 0x6886
movq %rax, %rdi
callq 0x2200
leaq 0x339e(%rip), %rsi      # 0x6935
movq -0x30(%rbp), %rdi
callq 0x2200
movq %rax, %rdi
movq %r13, %rsi
callq 0x2170
leaq 0x33b7(%rip), %rsi      # 0x6969
movq %rax, %rdi
callq 0x2200
leaq 0x33b0(%rip), %rsi      # 0x6971
movq -0x30(%rbp), %rdi
callq 0x2200
movq 0x88(%r14), %rax
cmpq 0x80(%r14), %rax
je 0x364e
leaq 0x33b8(%rip), %rsi      # 0x6999
movq -0x30(%rbp), %rdi
callq 0x2200
leaq 0x33c2(%rip), %rsi      # 0x69b3
movq -0x30(%rbp), %rdi
callq 0x2200
movq %rax, %rdi
movq %r13, %rsi
callq 0x2170
leaq 0x329e(%rip), %rsi      # 0x68aa
movq %rax, %rdi
callq 0x2200
pushq $0xc
popq %rsi
movq %rax, %rdi
callq 0x2170
leaq 0x3210(%rip), %rsi      # 0x6836
movq %rax, %rdi
callq 0x2200
leaq 0x33af(%rip), %rsi      # 0x69e4
movq -0x30(%rbp), %rdi
callq 0x2200
leaq 0x33c4(%rip), %rsi      # 0x6a09
movq -0x30(%rbp), %rdi
callq 0x2200
movq 0x70(%r14), %rax
cmpq 0x68(%r14), %rax
je 0x36cc
leaq 0x33ac(%rip), %rsi      # 0x6a0b
movq -0x30(%rbp), %rdi
callq 0x2200
leaq 0x33b6(%rip), %rsi      # 0x6a25
movq -0x30(%rbp), %rdi
callq 0x2200
movq %rax, %rdi
movq %r13, %rsi
callq 0x2170
leaq 0x3220(%rip), %rsi      # 0x68aa
movq %rax, %rdi
callq 0x2200
movq %rax, %rdi
movq %r12, %rsi
callq 0x2170
leaq 0x3192(%rip), %rsi      # 0x6836
movq %rax, %rdi
callq 0x2200
leaq 0x33a4(%rip), %rsi      # 0x6a57
movq -0x30(%rbp), %rdi
callq 0x2200
leaq 0x3346(%rip), %rsi      # 0x6a09
movq -0x30(%rbp), %rdi
callq 0x2200
leaq 0x33aa(%rip), %rsi      # 0x6a7d
movq -0x30(%rbp), %rdi
callq 0x2200
movq -0x78(%rbp), %rsi
subq -0x80(%rbp), %rsi
sarq $0x2, %rsi
movq %rax, %rdi
callq 0x2170
leaq 0x33a4(%rip), %rsi      # 0x6a9b
movq %rax, %rdi
callq 0x2200
leaq 0x30b4(%rip), %rsi      # 0x67ba
movq -0x30(%rbp), %rdi
callq 0x2200
leaq -0x60(%rbp), %rdi
callq 0x5c7c
leaq -0x80(%rbp), %rdi
callq 0x5c9e
leaq -0x150(%rbp), %rdi
callq 0x5cc0
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2fdc(%rip), %rdi      # 0x6722
leaq 0x2e36(%rip), %rsi      # 0x6583
leaq 0x2fd3(%rip), %rcx      # 0x6727
movl $0x203, %edx            # imm = 0x203
callq 0x2160
jmp 0x3762
jmp 0x3767
movq %rax, %r14
jmp 0x378c
movq %rax, %r14
jmp 0x37be
movq %rax, %r14
jmp 0x3798
movq %rax, %r14
jmp 0x37a4
movq %rax, %r14
leaq -0x170(%rbp), %rdi
callq 0x20f0
cmpq %r15, -0x88(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x20f0
leaq -0x1b0(%rbp), %rdi
callq 0x20f0
leaq -0xd8(%rbp), %rdi
callq 0x20f0
movq -0x90(%rbp), %rax
cmpq -0x98(%rbp), %rax
leaq -0xf8(%rbp), %rdi
callq 0x20f0
leaq -0x190(%rbp), %rdi
jmp 0x37f3
jmp 0x37de
movq %rax, %r14
jmp 0x37ca
jmp 0x37de
jmp 0x37de
movq %rax, %r14
jmp 0x37f8
jmp 0x37e9
jmp 0x37e9
jmp 0x37e9
movq %rax, %r14
leaq -0xb8(%rbp), %rdi
callq 0x20f0
leaq -0x60(%rbp), %rdi
callq 0x5c7c
leaq -0x80(%rbp), %rdi
callq 0x5c9e
leaq -0x150(%rbp), %rdi
callq 0x5cc0
movq %r14, %rdi
callq 0x23a0