// File: 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
movq %rsp, %rbp
subq $0x4c0, %rsp            # imm = 0x4C0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x438(%rbp)
movq %rdi, %rax
movq %rax, -0x440(%rbp)
callq 0x39b0
movq -0x438(%rbp), %rdi
addq $0x18, %rdi
movq %rdi, -0x430(%rbp)
callq 0x39d0
jmp 0x3316
leaq -0x228(%rbp), %rdi
callq 0x2200
jmp 0x3324
movq -0x10(%rbp), %rsi
leaq -0x228(%rbp), %rdi
movl $0x8, %edx
callq 0x2160
jmp 0x333b
movq -0x228(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x228(%rbp,%rax), %rdi
callq 0x2030
movb %al, -0x441(%rbp)
jmp 0x335b
movb -0x441(%rbp), %al
testb $0x1, %al
jne 0x3367
jmp 0x33a9
movl $0x1, -0x22c(%rbp)
jmp 0x37fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x3842
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x3832
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x3822
leaq -0x250(%rbp), %rdi
callq 0x2280
jmp 0x33b7
jmp 0x33b9
movq -0x228(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x228(%rbp,%rax), %rdi
callq 0x2370
movb %al, -0x442(%rbp)
jmp 0x33d9
movb -0x442(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x33ea
jmp 0x3730
leaq -0x228(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x2070
jmp 0x33ff
leaq -0x250(%rbp), %rdi
callq 0x2100
movq %rax, -0x450(%rbp)
jmp 0x3414
leaq -0x3f1(%rbp), %rdi
movq %rdi, -0x458(%rbp)
callq 0x2360
movq -0x450(%rbp), %rsi
movq -0x458(%rbp), %rdx
leaq -0x3f0(%rbp), %rdi
callq 0x2270
jmp 0x3443
leaq -0x3d0(%rbp), %rdi
leaq -0x3f0(%rbp), %rsi
movl $0x8, %edx
callq 0x2310
jmp 0x345d
leaq -0x3f0(%rbp), %rdi
callq 0x2150
jmp 0x346b
leaq -0x3f1(%rbp), %rdi
callq 0x21f0
leaq 0x4bc2(%rip), %rcx      # 0x8040
xorl %eax, %eax
movl %eax, %esi
leaq -0x250(%rbp), %rdi
movl $0x2, %edx
callq 0x2260
movl %eax, -0x45c(%rbp)
jmp 0x349b
movl -0x45c(%rbp), %eax
cmpl $0x0, %eax
jne 0x358b
leaq -0x3d0(%rbp), %rdi
leaq -0x3f2(%rbp), %rsi
callq 0x2250
jmp 0x34bf
leaq -0x400(%rbp), %rdi
callq 0x39f0
jmp 0x34cd
movl $0x0, -0x404(%rbp)
cmpl $0x3, -0x404(%rbp)
jge 0x3571
movslq -0x404(%rbp), %rax
leaq -0x400(%rbp,%rax,4), %rsi
leaq -0x3d0(%rbp), %rdi
callq 0x2080
jmp 0x3501
jmp 0x3503
movl -0x404(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x404(%rbp)
jmp 0x34d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x3812
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x354f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x3f0(%rbp), %rdi
callq 0x2150
jmp 0x354d
jmp 0x354f
leaq -0x3f1(%rbp), %rdi
callq 0x21f0
jmp 0x3812
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x371d
movq -0x440(%rbp), %rdi
leaq -0x400(%rbp), %rsi
callq 0x3a20
jmp 0x3586
jmp 0x370a
leaq 0x4ab1(%rip), %rcx      # 0x8043
xorl %eax, %eax
movl %eax, %esi
leaq -0x250(%rbp), %rdi
movl $0x2, %edx
callq 0x2260
movl %eax, -0x460(%rbp)
jmp 0x35af
movl -0x460(%rbp), %eax
cmpl $0x0, %eax
jne 0x3708
leaq -0x420(%rbp), %rdi
callq 0x3a90
jmp 0x35cc
leaq -0x3d0(%rbp), %rdi
leaq -0x3f2(%rbp), %rsi
callq 0x2250
jmp 0x35e1
jmp 0x35e3
leaq -0x3d0(%rbp), %rdi
leaq -0x428(%rbp), %rsi
callq 0x2140
movq %rax, -0x468(%rbp)
jmp 0x35ff
movq -0x468(%rbp), %rdi
leaq -0x3f2(%rbp), %rsi
callq 0x2250
movq %rax, -0x470(%rbp)
jmp 0x361b
movq -0x470(%rbp), %rdi
leaq -0x424(%rbp), %rsi
callq 0x2140
movq %rax, -0x478(%rbp)
jmp 0x3637
movq -0x478(%rbp), %rdi
leaq -0x3f2(%rbp), %rsi
callq 0x2250
movq %rax, -0x480(%rbp)
jmp 0x3653
movq -0x480(%rbp), %rdi
leaq -0x424(%rbp), %rsi
callq 0x2140
movq %rax, -0x488(%rbp)
jmp 0x366f
movq -0x488(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x22d0
movq %rax, -0x490(%rbp)
jmp 0x368e
movq -0x490(%rbp), %rax
cmpq $0x0, %rax
je 0x36dd
movl -0x428(%rbp), %eax
decl %eax
movl %eax, -0x428(%rbp)
leaq -0x420(%rbp), %rdi
leaq -0x428(%rbp), %rsi
callq 0x3ab0
jmp 0x36be
jmp 0x35e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x420(%rbp), %rdi
callq 0x3070
jmp 0x3706
movq -0x440(%rbp), %rdi
addq $0x18, %rdi
leaq -0x420(%rbp), %rsi
callq 0x3b20
jmp 0x36f6
leaq -0x420(%rbp), %rdi
callq 0x3070
jmp 0x3704
jmp 0x3708
jmp 0x371d
jmp 0x370a
leaq -0x3d0(%rbp), %rdi
callq 0x2110
jmp 0x3718
jmp 0x33b9
leaq -0x3d0(%rbp), %rdi
callq 0x2110
jmp 0x372b
jmp 0x3812
movq 0x88b9(%rip), %rdi      # 0xbff0
leaq 0x4908(%rip), %rsi      # 0x8046
callq 0x21c0
movq %rax, -0x498(%rbp)
jmp 0x374c
movq -0x440(%rbp), %rdi
callq 0x3b90
movq %rax, -0x4a0(%rbp)
jmp 0x3761
movq -0x4a0(%rbp), %rsi
movq -0x498(%rbp), %rdi
callq 0x20a0
movq %rax, -0x4a8(%rbp)
jmp 0x377d
movq -0x4a8(%rbp), %rdi
leaq 0x48c1(%rip), %rsi      # 0x804c
callq 0x21c0
movq %rax, -0x4b0(%rbp)
jmp 0x3799
movq -0x440(%rbp), %rdi
addq $0x18, %rdi
callq 0x3bc0
movq %rax, -0x4b8(%rbp)
jmp 0x37b2
movq -0x4b8(%rbp), %rsi
movq -0x4b0(%rbp), %rdi
callq 0x20a0
movq %rax, -0x4c0(%rbp)
jmp 0x37ce
movq -0x4c0(%rbp), %rdi
movq 0x87ec(%rip), %rsi      # 0xbfc8
callq 0x21e0
jmp 0x37e3
leaq -0x250(%rbp), %rdi
callq 0x2150
jmp 0x37f1
movl $0x0, -0x22c(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x20b0
jmp 0x3809
addq $0x4c0, %rsp            # imm = 0x4C0
popq %rbp
retq
leaq -0x250(%rbp), %rdi
callq 0x2150
jmp 0x3820
jmp 0x3822
leaq -0x228(%rbp), %rdi
callq 0x20b0
jmp 0x3830
jmp 0x3832
movq -0x430(%rbp), %rdi
callq 0x3bf0
jmp 0x3840
jmp 0x3842
movq -0x438(%rbp), %rdi
callq 0x3c70
jmp 0x3850
jmp 0x3852
movq -0x18(%rbp), %rdi
callq 0x2350
movq %rax, %rdi
callq 0x30f0
nopw %cs:(%rax,%rax)