// File: /workspace/github_cpp_makefile_star2_O2/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, 0x18(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x10(%rdi)
movq %rdi, 0x8(%rsp)
movups %xmm0, (%rdi)
leaq 0x70(%rsp), %rdi
callq 0x21c0
leaq 0x70(%rsp), %rdi
pushq $0x8
popq %rdx
movq %rbx, %rsi
callq 0x2140
movq 0x70(%rsp), %rax
movq -0x18(%rax), %rcx
testb $0x5, 0x90(%rsp,%rcx)
jne 0x2ca6
leaq 0x60(%rsp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
leaq 0x70(%rsp), %r12
leaq 0x20(%rsp), %r13
leaq 0x4c(%rsp), %rbp
leaq 0x278(%rsp), %r14
leaq 0x7(%rsp), %r15
leaq 0x14(%rsp), %rbx
movq -0x18(%rax), %rax
testb $0x2, 0x90(%rsp,%rax)
jne 0x2c33
movq %r12, %rdi
leaq 0x50(%rsp), %rsi
callq 0x2060
movq 0x50(%rsp), %rsi
movq %r13, %rdi
movq %rbp, %rdx
callq 0x20d0
movq %r14, %rdi
movq %r13, %rsi
pushq $0x8
popq %rdx
callq 0x22a0
movq %r13, %rdi
callq 0x21e0
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
pushq $0x2
popq %rdx
leaq 0x2527(%rip), %rcx      # 0x5050
callq 0x2230
testl %eax, %eax
je 0x2bc3
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
pushq $0x2
popq %rdx
leaq 0x250c(%rip), %rcx      # 0x5053
callq 0x2230
testl %eax, %eax
jne 0x2c21
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x2220
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2130
movq %rax, %rdi
movq %r15, %rsi
callq 0x2220
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2130
movq %rax, %rdi
movq %r15, %rsi
callq 0x2220
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2130
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2c0c
decl 0x14(%rsp)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2dfa
jmp 0x2b6d
movq %r14, %rdi
movq %r15, %rsi
callq 0x2220
andq $0x0, 0x20(%rsp)
andl $0x0, 0x28(%rsp)
xorl %r12d, %r12d
cmpq $0xc, %r12
je 0x2bf8
leaq (%rsp,%r12), %rsi
addq $0x20, %rsi
movq %r14, %rdi
callq 0x22e0
addq $0x4, %r12
jmp 0x2bdc
movq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x2dd6
leaq 0x70(%rsp), %r12
jmp 0x2c21
movq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0x2e18
movq %r13, %rdi
callq 0x2a30
movq %r14, %rdi
callq 0x20f0
movq 0x70(%rsp), %rax
jmp 0x2ad3
movq 0x53b6(%rip), %rdi      # 0x7ff0
leaq 0x2415(%rip), %rsi      # 0x5056
callq 0x21a0
movq %rax, %rdi
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
pushq $0xc
popq %rcx
cqto
idivq %rcx
movq %rax, %rsi
callq 0x2150
leaq 0x23f0(%rip), %rsi      # 0x505c
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
movq 0x8(%rsp), %rcx
movq 0x20(%rcx), %rax
subq 0x18(%rcx), %rax
pushq $0x18
popq %rcx
cqto
idivq %rcx
movq %rax, %rsi
callq 0x2150
movq %rax, %rdi
callq 0x2100
leaq 0x50(%rsp), %rdi
callq 0x21e0
leaq 0x70(%rsp), %rdi
callq 0x2090
addq $0x3f8, %rsp            # imm = 0x3F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2cc4
movq %rax, %rbx
jmp 0x2d19
jmp 0x2ceb
movq %rax, %rbx
jmp 0x2d23
jmp 0x2cf0
jmp 0x2cf0
jmp 0x2cf5
jmp 0x2ceb
jmp 0x2ceb
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x21e0
jmp 0x2d0f
jmp 0x2cf0
movq %rax, %rbx
jmp 0x2d0f
movq %rax, %rbx
jmp 0x2d02
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2a30
leaq 0x278(%rsp), %rdi
callq 0x20f0
leaq 0x50(%rsp), %rdi
callq 0x21e0
leaq 0x70(%rsp), %rdi
callq 0x2090
movq 0x18(%rsp), %rdi
callq 0x2e44
movq 0x8(%rsp), %rdi
callq 0x2ed0
movq %rbx, %rdi
callq 0x22d0
movq %rax, %rdi
callq 0x2a25
nop