// File: /workspace/github_cpp_makefile_star2_O3/shinerd[P]BriefRenderer/model.cpp
// Function: Model::Model(char const*)
Model::Model(const char *filename) : verts_(), faces_() {                       // Q: Where verts_() and faces_() came from? (model.h - line 9, 10 mean variables, not functions). Maybe, they are constructors of vector and the class inherits them, but why?
    std::ifstream in;                                                           // make a new filestream
    in.open (filename, std::ifstream::in);                                      // open the object file
    if (in.fail()) return;
    std::string line;                                                           // a new string for get lines from the object file
    while (!in.eof()) {                                                         // before meet end of file
        std::getline(in, line);                                                 // get a line and put in the string
        std::istringstream iss(line.c_str());                                   // make a sequence of characters be access directly as a string object using member str
                                                                                // c_str() returns a pointer to an array that contains a null-terminated sequence of characters representing the current value of the string object.
        
        char trash;                                                             // Q: line 18~34
        if (!line.compare(0, 2, "v ")) {                                        // my guess: if 'v' push to verts
            iss >> trash;
            Vec3f v;
            for (int i=0;i<3;i++) iss >> v.raw[i];
            verts_.push_back(v);
        } else if (!line.compare(0, 2, "f ")) {                                 // else if 'f' push to f
            std::vector<int> f;
            int itrash, idx;
            iss >> trash;
            while (iss >> idx >> trash >> itrash >> trash >> itrash) {
                idx--; // in wavefront obj all indices start at 1, not zero
                f.push_back(idx);
            }
            faces_.push_back(f);
        }
    }                                                                           // but I still don't know what the face and the verts mean
    
    std::cerr << "# v# " << verts_.size() << " f# "  << faces_.size() << std::endl;  // error
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3f8, %rsp            # imm = 0x3F8
movq %rsi, %rbx
leaq 0x18(%rdi), %rax
movq %rax, 0x40(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x10(%rdi)
movq %rdi, 0x38(%rsp)
movups %xmm0, (%rdi)
leaq 0x70(%rsp), %rdi
callq 0x21c0
leaq 0x70(%rsp), %rdi
movq %rbx, %rsi
movl $0x8, %edx
callq 0x2130
movq 0x70(%rsp), %rax
movq -0x18(%rax), %rcx
testb $0x5, 0x90(%rsp,%rcx)
jne 0x2ee8
leaq 0x58(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
movq -0x18(%rax), %rax
testb $0x2, 0x90(%rsp,%rax)
jne 0x2e34
leaq (%rsp,%rax), %rdi
addq $0x70, %rdi
leaq 0x20(%rsp), %r13
leaq 0x6c(%rsp), %rbp
leaq 0x278(%rsp), %r14
leaq 0xb(%rsp), %r15
leaq 0xc(%rsp), %rbx
movl $0xa, %esi
callq 0x21a0
movsbl %al, %edx
leaq 0x70(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x22f0
movq 0x48(%rsp), %rsi
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rdx
callq 0x20c0
movq %r14, %rdi
movq %r12, %rsi
movl $0x8, %edx
callq 0x22a0
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x2ca5
callq 0x2190
movl $0x2, %edx
leaq 0x48(%rsp), %rdi
xorl %esi, %esi
leaq 0x2398(%rip), %rcx      # 0x5050
callq 0x2230
testl %eax, %eax
je 0x2d7c
movl $0x2, %edx
leaq 0x48(%rsp), %rdi
xorl %esi, %esi
leaq 0x237b(%rip), %rcx      # 0x5053
callq 0x2230
testl %eax, %eax
jne 0x2e11
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x2220
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2120
movq %rax, %rdi
movq %r15, %rsi
callq 0x2220
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2120
movq %rax, %rdi
movq %r15, %rsi
callq 0x2220
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2120
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2ddf
movl 0xc(%rsp), %eax
decl %eax
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x2d6d
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x2d01
leaq 0x10(%rsp), %rdi
movq %rbx, %rdx
callq 0x32b8
jmp 0x2d01
movq %r14, %rdi
movq %r15, %rsi
callq 0x2220
movq 0x38(%rsp), %r13
movq $0x0, 0x10(%rsp)
movl $0x0, 0x18(%rsp)
xorl %r12d, %r12d
leaq (%rsp,%r12), %rsi
addq $0x10, %rsi
movq %r14, %rdi
callq 0x2300
addq $0x4, %r12
cmpq $0xc, %r12
jne 0x2da0
movq 0x8(%r13), %rsi
cmpq 0x10(%r13), %rsi
je 0x2dff
movl 0x18(%rsp), %eax
movl %eax, 0x8(%rsi)
movq 0x10(%rsp), %rax
movq %rax, (%rsi)
addq $0xc, 0x8(%r13)
leaq 0x20(%rsp), %r13
jmp 0x2e11
movq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x303e
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2e11
callq 0x2190
jmp 0x2e11
movq %r13, %rdi
leaq 0x10(%rsp), %rdx
callq 0x3130
leaq 0x20(%rsp), %r13
movq %r14, %rdi
callq 0x20f0
movq 0x70(%rsp), %rax
movq -0x18(%rax), %rax
leaq (%rsp,%rax), %rdi
addq $0x70, %rdi
testb $0x2, 0x20(%rdi)
je 0x2c55
movq 0x51b5(%rip), %rdi      # 0x7ff0
leaq 0x2214(%rip), %rsi      # 0x5056
movl $0x5, %edx
callq 0x21d0
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rsi
subq (%rax), %rsi
sarq $0x2, %rsi
movabsq $-0x5555555555555555, %r14 # imm = 0xAAAAAAAAAAAAAAAB
imulq %r14, %rsi
movq 0x517f(%rip), %rdi      # 0x7ff0
callq 0x2140
movq %rax, %rbx
leaq 0x21dc(%rip), %rsi      # 0x505c
movl $0x4, %edx
movq %rax, %rdi
callq 0x21d0
movq 0x38(%rsp), %rax
movq 0x20(%rax), %rsi
subq 0x18(%rax), %rsi
sarq $0x3, %rsi
imulq %r14, %rsi
movq %rbx, %rdi
callq 0x2140
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x2ee8
callq 0x2190
leaq 0x70(%rsp), %rdi
callq 0x2080
addq $0x3f8, %rsp            # imm = 0x3F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2f33
movq %rax, %rbx
jmp 0x2f6b
movq %rax, %rbx
jmp 0x2f75
jmp 0x2f2e
jmp 0x2f38
jmp 0x2f2e
jmp 0x2f2e
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x2f57
callq 0x2190
jmp 0x2f57
jmp 0x2f33
movq %rax, %rbx
jmp 0x2f57
movq %rax, %rbx
jmp 0x2f4a
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2f4a
callq 0x2190
leaq 0x278(%rsp), %rdi
callq 0x20f0
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x2f6b
callq 0x2190
leaq 0x70(%rsp), %rdi
callq 0x2080
movq 0x40(%rsp), %rdi
callq 0x306a
movq 0x38(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x2f91
callq 0x2190
movq %rbx, %rdi
callq 0x22e0
movq %rax, %rdi
callq 0x2b9c
nop