// File: /workspace/github_cpp_makefile_star2_O1/kryffin[P]software-rasterizer/./parser.cpp
// Function: Model::Model(char const*)
Model (const char* filename) {
		std::ifstream in;
	    in.open(filename, std::ifstream::in);
	    if (in.fail()) {
	        std::cerr << "Failed to open " << filename << std::endl;
	        return;
	    }

	    std::string line;
	    while (!in.eof()) {

	        std::getline(in, line);
	        std::istringstream iss(line.c_str());
	        char trash;
	        if (!line.compare(0, 2, "v ")) { //vertices

	            iss >> trash;
	            Vec3f v;
	            iss >> v.x; iss >> v.y; iss >> v.z;
	            vertices.push_back(v);

	        } else if (!line.compare(0, 2, "f ")) { //triangles (f for faces)

	            Vec3i t;
	            std::string str, token;
	            int idx, cnt = 0;
	            iss >> trash;
	            while (iss >> str) {
	                token = str.std::string::substr(0, str.std::string::find('/'));
	                idx = std::stoi(token);
	                idx--; // in wavefront obj all indices start at 1, not zero
	                if (cnt == 0) t.x = idx;
	                if (cnt == 1) t.y = idx;
	                if (cnt == 2) t.z = idx;
	                cnt++;
	            }
	            if (cnt == 3) triangles.push_back(t);

	        } else if (!line.compare(0, 3, "vn ")) { //vertices normals

	            iss >> trash;
	            iss >> trash;
	            Vec3f n;
	            iss >> n.x; iss >> n.y; iss >> n.z;
	            normals.push_back(n);

	        }

	    }
	    std::cout << "# v# " << vertices.size() << " f# "  << triangles.size() << " vn# " << normals.size() << std::endl;
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x438, %rsp            # imm = 0x438
movq %rsi, %r14
movq %rdi, %r15
leaq 0x18(%rdi), %rax
movq %rax, -0x70(%rbp)
leaq 0x30(%rdi), %rax
movq %rax, -0x78(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rdi)
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x10(%rdi)
movups %xmm0, (%rdi)
movq $0x0, 0x40(%rdi)
leaq -0x460(%rbp), %rdi
callq 0x21b0
leaq -0x460(%rbp), %rdi
movq %r14, %rsi
movl $0x8, %edx
callq 0x20e0
movq -0x460(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x440(%rbp,%rax)
je 0x4162
movq 0x2eca(%rip), %rbx      # 0x6ff0
leaq 0x103c(%rip), %rsi      # 0x5169
movl $0xf, %edx
movq %rbx, %rdi
callq 0x21c0
testq %r14, %r14
je 0x4638
movq %r14, %rdi
callq 0x20a0
movq 0x2e9e(%rip), %rdi      # 0x6ff0
movq %r14, %rsi
movq %rax, %rdx
callq 0x21c0
jmp 0x464f
leaq -0xa8(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq -0x460(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x2, -0x440(%rbp,%rax)
jne 0x4559
leaq (%rax,%rbp), %rdi
addq $-0x460, %rdi           # imm = 0xFBA0
leaq -0x50(%rbp), %r14
leaq -0xd8(%rbp), %rbx
movq %r15, -0x68(%rbp)
movl $0xa, %esi
callq 0x2180
movsbl %al, %edx
leaq -0x460(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x2300
movq -0xb8(%rbp), %rsi
movq %r14, %rdi
leaq -0x98(%rbp), %rdx
callq 0x2090
leaq -0x258(%rbp), %rdi
movq %r14, %rsi
movl $0x8, %edx
callq 0x22a0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x4207
callq 0x2170
movl $0x2, %edx
leaq -0xb8(%rbp), %rdi
xorl %esi, %esi
leaq 0xf5d(%rip), %rcx       # 0x5179
callq 0x2210
testl %eax, %eax
je 0x42f0
movl $0x2, %edx
leaq -0xb8(%rbp), %rdi
xorl %esi, %esi
leaq 0xf3e(%rip), %rcx       # 0x517c
callq 0x2210
testl %eax, %eax
je 0x4363
movl $0x3, %edx
leaq -0xb8(%rbp), %rdi
xorl %esi, %esi
leaq 0xf1f(%rip), %rcx       # 0x517f
callq 0x2210
testl %eax, %eax
jne 0x451a
leaq -0x258(%rbp), %rdi
leaq -0x29(%rbp), %rsi
callq 0x2200
leaq -0x258(%rbp), %rdi
leaq -0x29(%rbp), %rsi
callq 0x2200
movq $0x0, -0x50(%rbp)
movl $0x0, -0x48(%rbp)
leaq -0x258(%rbp), %rdi
movq %r14, %rsi
callq 0x2310
leaq -0x258(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x2310
leaq -0x258(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x2310
movq 0x38(%r15), %rsi
cmpq 0x40(%r15), %rsi
je 0x44d5
movl -0x48(%rbp), %eax
movl %eax, 0x8(%rsi)
movq -0x50(%rbp), %rax
movq %rax, (%rsi)
addq $0xc, 0x38(%r15)
jmp 0x451a
leaq -0x258(%rbp), %rdi
leaq -0x29(%rbp), %rsi
callq 0x2200
movq $0x0, -0x50(%rbp)
movl $0x0, -0x48(%rbp)
leaq -0x258(%rbp), %rdi
movq %r14, %rsi
callq 0x2310
leaq -0x258(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x2310
leaq -0x258(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x2310
movq 0x8(%r15), %rsi
cmpq 0x10(%r15), %rsi
je 0x44c8
movl -0x48(%rbp), %eax
movl %eax, 0x8(%rsi)
movq -0x50(%rbp), %rax
movq %rax, (%rsi)
addq $0xc, 0x8(%r15)
jmp 0x451a
xorl %ecx, %ecx
movq %rcx, -0x5c(%rbp)
movl $0x0, -0x54(%rbp)
leaq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movq %rcx, -0x48(%rbp)
movb %cl, -0x40(%rbp)
leaq -0x88(%rbp), %rax
movq %rax, -0x98(%rbp)
movq %rcx, -0x90(%rbp)
movb %cl, -0x88(%rbp)
leaq -0x258(%rbp), %rdi
leaq -0x29(%rbp), %rsi
callq 0x2200
xorl %r15d, %r15d
leaq -0x258(%rbp), %rdi
movq %r14, %rsi
callq 0x21e0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x44a0
movq %r14, %rdi
movl $0x2f, %esi
xorl %edx, %edx
callq 0x21f0
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x21a0
leaq -0x98(%rbp), %rdi
movq %rbx, %r13
movq %rbx, %rsi
callq 0x21d0
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x4417
callq 0x2170
movq -0x98(%rbp), %r14
callq 0x2040
movq %rax, %rbx
movl (%rax), %r12d
movl $0x0, (%rax)
movq %r14, %rdi
movq %r13, %rsi
movl $0xa, %edx
callq 0x2220
cmpq %r14, -0xd8(%rbp)
je 0x46a4
movslq %eax, %rcx
cmpq %rax, %rcx
jne 0x4698
movl (%rbx), %ecx
cmpl $0x22, %ecx
je 0x4698
testl %ecx, %ecx
jne 0x446a
movl %r12d, (%rbx)
decl %eax
cmpl $0x2, %r15d
je 0x448e
cmpl $0x1, %r15d
movq %r13, %rbx
leaq -0x50(%rbp), %r14
je 0x4489
testl %r15d, %r15d
jne 0x4498
movl %eax, -0x5c(%rbp)
jmp 0x4498
movl %eax, -0x58(%rbp)
jmp 0x4498
movl %eax, -0x54(%rbp)
movq %r13, %rbx
leaq -0x50(%rbp), %r14
incl %r15d
jmp 0x43ad
cmpl $0x3, %r15d
movq -0x68(%rbp), %r15
jne 0x44f0
movq 0x20(%r15), %rsi
cmpq 0x28(%r15), %rsi
je 0x44e3
movl -0x54(%rbp), %eax
movl %eax, 0x8(%rsi)
movq -0x5c(%rbp), %rax
movq %rax, (%rsi)
addq $0xc, 0x20(%r15)
jmp 0x44f0
movq %r15, %rdi
movq %r14, %rdx
callq 0x4864
jmp 0x451a
movq -0x78(%rbp), %rdi
movq %r14, %rdx
callq 0x4864
jmp 0x451a
movq -0x70(%rbp), %rdi
leaq -0x5c(%rbp), %rdx
callq 0x49ec
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x4508
callq 0x2170
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x451a
callq 0x2170
leaq -0x258(%rbp), %rdi
movq 0x2aa0(%rip), %rsi      # 0x6fc8
callq 0x2240
leaq -0x1e0(%rbp), %rdi
callq 0x2070
movq -0x460(%rbp), %rax
movq -0x18(%rax), %rax
leaq (%rax,%rbp), %rdi
addq $-0x460, %rdi           # imm = 0xFBA0
testb $0x2, 0x20(%rdi)
je 0x41ab
movq 0x2a70(%rip), %rdi      # 0x6fd0
leaq 0xc1c(%rip), %rsi       # 0x5183
movl $0x5, %edx
callq 0x21c0
movq 0x8(%r15), %rsi
subq (%r15), %rsi
sarq $0x2, %rsi
movabsq $-0x5555555555555555, %r14 # imm = 0xAAAAAAAAAAAAAAAB
imulq %r14, %rsi
movq 0x2a3f(%rip), %rdi      # 0x6fd0
callq 0x2100
movq %rax, %rbx
leaq 0xbe9(%rip), %rsi       # 0x5189
movl $0x4, %edx
movq %rax, %rdi
callq 0x21c0
movq 0x20(%r15), %rsi
subq 0x18(%r15), %rsi
sarq $0x2, %rsi
imulq %r14, %rsi
movq %rbx, %rdi
callq 0x2100
movq %rax, %rbx
leaq 0xbbf(%rip), %rsi       # 0x518e
movl $0x5, %edx
movq %rax, %rdi
callq 0x21c0
movq 0x38(%r15), %rsi
subq 0x30(%r15), %rsi
sarq $0x2, %rsi
imulq %r14, %rsi
movq %rbx, %rdi
callq 0x2100
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0x467a
callq 0x2170
jmp 0x467a
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x22b0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq 0x2983(%rip), %rdi      # 0x6ff0
callq 0x2030
movq %rax, %rdi
callq 0x2110
leaq -0x460(%rbp), %rdi
callq 0x2060
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb0f(%rip), %rdi       # 0x51ae
callq 0x2250
leaq 0xb03(%rip), %rdi       # 0x51ae
callq 0x20d0
movq %rax, %r14
jmp 0x4771
movq %rax, %r14
jmp 0x4704
jmp 0x46e9
jmp 0x46e4
movq %rax, %r14
jmp 0x4765
jmp 0x46e4
movq %rax, %r14
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x474d
callq 0x2170
jmp 0x474d
jmp 0x46e9
movq %rax, %r14
jmp 0x474d
movq %rax, %r14
jmp 0x472e
jmp 0x46f0
movq %rax, %r14
jmp 0x4700
movq %rax, %r14
cmpl $0x0, (%rbx)
jne 0x4700
movl %r12d, (%rbx)
movq -0x68(%rbp), %r15
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x471c
callq 0x2170
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x472e
callq 0x2170
movq 0x2893(%rip), %rsi      # 0x6fc8
leaq -0x258(%rbp), %rdi
callq 0x2240
leaq -0x1e0(%rbp), %rdi
callq 0x2070
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0x4765
callq 0x2170
leaq -0x460(%rbp), %rdi
callq 0x2060
movq -0x78(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x4782
callq 0x2170
movq -0x70(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x4793
callq 0x2170
movq (%r15), %rdi
testq %rdi, %rdi
je 0x47a0
callq 0x2170
movq %r14, %rdi
callq 0x22e0