// File: /workspace/github_cpp_makefile_star2_O2/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, %rbx
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 %rdi, -0x38(%rbp)
andq $0x0, 0x40(%rdi)
leaq -0x2e0(%rbp), %rdi
callq 0x21a0
leaq -0x2e0(%rbp), %rdi
pushq $0x8
popq %rdx
movq %rbx, %rsi
callq 0x20e0
movq -0x2e0(%rbp), %rax
movq -0x18(%rax), %rcx
testb $0x5, -0x2c0(%rbp,%rcx)
je 0x3d52
movq 0x42c2(%rip), %rdi      # 0x7ff0
leaq 0x1434(%rip), %rsi      # 0x5169
callq 0x2170
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movq %rax, %rdi
callq 0x20b0
jmp 0x4060
leaq -0x88(%rbp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
leaq -0x2e0(%rbp), %rbx
leaq -0x68(%rbp), %r12
leaq -0xb8(%rbp), %r13
leaq -0x460(%rbp), %r14
leaq -0xd8(%rbp), %r15
movq -0x18(%rax), %rax
testb $0x2, -0x2c0(%rbp,%rax)
jne 0x3fc5
movq %rbx, %rdi
leaq -0x98(%rbp), %rsi
callq 0x2050
movq -0x98(%rbp), %rsi
movq %r12, %rdi
movq %r13, %rdx
callq 0x2080
movq %r14, %rdi
movq %r12, %rsi
pushq $0x8
popq %rdx
callq 0x2260
movq %r12, %rdi
callq 0x2090
leaq -0x98(%rbp), %rdi
xorl %esi, %esi
pushq $0x2
popq %rdx
leaq 0x1398(%rip), %rcx      # 0x5179
callq 0x21f0
testl %eax, %eax
je 0x3e83
leaq -0x98(%rbp), %rdi
xorl %esi, %esi
pushq $0x2
popq %rdx
leaq 0x137b(%rip), %rcx      # 0x517c
callq 0x21f0
testl %eax, %eax
je 0x3ecc
leaq -0x98(%rbp), %rdi
xorl %esi, %esi
pushq $0x3
popq %rdx
leaq 0x135e(%rip), %rcx      # 0x517f
callq 0x21f0
testl %eax, %eax
jne 0x3fb1
movq %r14, %rdi
leaq -0x29(%rbp), %rsi
callq 0x21e0
movq %r14, %rdi
leaq -0x29(%rbp), %rsi
callq 0x21e0
andq $0x0, -0x68(%rbp)
andl $0x0, -0x60(%rbp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x22a0
movq %r14, %rdi
leaq -0x64(%rbp), %rsi
callq 0x22a0
movq %r14, %rdi
leaq -0x60(%rbp), %rsi
callq 0x22a0
movq -0x78(%rbp), %rdi
movq %r12, %rsi
callq 0x41ee
jmp 0x3fb1
movq %r14, %rdi
leaq -0x29(%rbp), %rsi
callq 0x21e0
andq $0x0, -0x68(%rbp)
andl $0x0, -0x60(%rbp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x22a0
movq %r14, %rdi
leaq -0x64(%rbp), %rsi
callq 0x22a0
movq %r14, %rdi
leaq -0x60(%rbp), %rsi
callq 0x22a0
movq -0x38(%rbp), %rdi
movq %r12, %rsi
callq 0x41ee
jmp 0x3fb1
andq $0x0, -0x44(%rbp)
andl $0x0, -0x3c(%rbp)
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
andq $0x0, -0x60(%rbp)
xorl %ecx, %ecx
movb %cl, -0x58(%rbp)
leaq -0xa8(%rbp), %rax
movq %rax, -0xb8(%rbp)
andq $0x0, -0xb0(%rbp)
movb %cl, -0xa8(%rbp)
movq %r14, %rdi
leaq -0x29(%rbp), %rsi
callq 0x21e0
xorl %ebx, %ebx
movq %r14, %rdi
movq %r12, %rsi
callq 0x21c0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3f88
movq %r12, %rdi
pushq $0x2f
popq %rsi
xorl %edx, %edx
callq 0x21d0
movq %r15, %rdi
movq %r12, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x2190
movq %r13, %rdi
movq %r15, %rsi
callq 0x21b0
movq %r15, %rdi
callq 0x2090
movq %r13, %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x4218
decl %eax
cmpl $0x2, %ebx
je 0x3f81
cmpl $0x1, %ebx
je 0x3f7c
testl %ebx, %ebx
jne 0x3f84
movl %eax, -0x44(%rbp)
jmp 0x3f84
movl %eax, -0x40(%rbp)
jmp 0x3f84
movl %eax, -0x3c(%rbp)
incl %ebx
jmp 0x3f11
cmpl $0x3, %ebx
jne 0x3f9a
movq -0x70(%rbp), %rdi
leaq -0x44(%rbp), %rsi
callq 0x423a
movq %r13, %rdi
callq 0x2090
movq %r12, %rdi
callq 0x2090
leaq -0x2e0(%rbp), %rbx
movq %r14, %rdi
callq 0x20a0
movq -0x2e0(%rbp), %rax
jmp 0x3d85
movq 0x3ffc(%rip), %rdi      # 0x7fc8
leaq 0x11b0(%rip), %rsi      # 0x5183
callq 0x2170
movq %rax, %rdi
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
pushq $0xc
popq %rbx
cqto
idivq %rbx
movq %rax, %rsi
callq 0x2100
leaq 0x118c(%rip), %rsi      # 0x5189
movq %rax, %rdi
callq 0x2170
movq %rax, %rdi
movq -0x38(%rbp), %rcx
movq 0x20(%rcx), %rax
subq 0x18(%rcx), %rax
cqto
idivq %rbx
movq %rax, %rsi
callq 0x2100
leaq 0x1166(%rip), %rsi      # 0x518e
movq %rax, %rdi
callq 0x2170
movq %rax, %rdi
movq -0x38(%rbp), %rcx
movq 0x38(%rcx), %rax
subq 0x30(%rcx), %rax
cqto
idivq %rbx
movq %rax, %rsi
callq 0x2100
movq %rax, %rdi
callq 0x20b0
leaq -0x98(%rbp), %rdi
callq 0x2090
leaq -0x2e0(%rbp), %rdi
callq 0x2060
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x40e8
jmp 0x409e
movq %rax, %rbx
jmp 0x40dc
jmp 0x40ac
jmp 0x40a5
jmp 0x409e
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x2090
jmp 0x40d0
movq %rax, %rbx
jmp 0x40d0
jmp 0x40a5
movq %rax, %rbx
jmp 0x40c4
jmp 0x40ac
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x2090
leaq -0x68(%rbp), %rdi
callq 0x2090
leaq -0x460(%rbp), %rdi
callq 0x20a0
leaq -0x98(%rbp), %rdi
callq 0x2090
leaq -0x2e0(%rbp), %rdi
callq 0x2060
movq -0x78(%rbp), %rdi
callq 0x4622
movq -0x70(%rbp), %rdi
callq 0x4636
movq -0x38(%rbp), %rdi
callq 0x4622
movq %rbx, %rdi
callq 0x2290
nop