// File: /workspace/github_cpp_makefile_star2_O3/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), %rcx
testb $0x5, -0x440(%rbp,%rcx)
je 0x4066
movq 0x2fc6(%rip), %rbx      # 0x6ff0
leaq 0x1138(%rip), %rsi      # 0x5169
movl $0xf, %edx
movq %rbx, %rdi
callq 0x21c0
testq %r14, %r14
je 0x4535
movq %r14, %rdi
callq 0x20a0
movq 0x2f9a(%rip), %rdi      # 0x6ff0
movq %r14, %rsi
movq %rax, %rdx
callq 0x21c0
jmp 0x454c
leaq -0xa8(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
movq -0x18(%rax), %rax
testb $0x2, -0x440(%rbp,%rax)
jne 0x4456
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 0x22f0
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 0x4104
callq 0x2170
movl $0x2, %edx
leaq -0xb8(%rbp), %rdi
xorl %esi, %esi
leaq 0x1060(%rip), %rcx      # 0x5179
callq 0x2210
testl %eax, %eax
je 0x41ed
movl $0x2, %edx
leaq -0xb8(%rbp), %rdi
xorl %esi, %esi
leaq 0x1041(%rip), %rcx      # 0x517c
callq 0x2210
testl %eax, %eax
je 0x4260
movl $0x3, %edx
leaq -0xb8(%rbp), %rdi
xorl %esi, %esi
leaq 0x1022(%rip), %rcx      # 0x517f
callq 0x2210
testl %eax, %eax
jne 0x4417
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 0x2300
leaq -0x258(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x2300
leaq -0x258(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x2300
movq 0x38(%r15), %rsi
cmpq 0x40(%r15), %rsi
je 0x43d2
movl -0x48(%rbp), %eax
movl %eax, 0x8(%rsi)
movq -0x50(%rbp), %rax
movq %rax, (%rsi)
addq $0xc, 0x38(%r15)
jmp 0x4417
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 0x2300
leaq -0x258(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x2300
leaq -0x258(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x2300
movq 0x8(%r15), %rsi
cmpq 0x10(%r15), %rsi
je 0x43c5
movl -0x48(%rbp), %eax
movl %eax, 0x8(%rsi)
movq -0x50(%rbp), %rax
movq %rax, (%rsi)
addq $0xc, 0x8(%r15)
jmp 0x4417
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 0x439d
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, %r14
movq %rbx, %rsi
callq 0x21d0
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x4314
callq 0x2170
movq -0x98(%rbp), %r12
callq 0x2040
movq %rax, %rbx
movl (%rax), %r13d
movl $0x0, (%rax)
movq %r12, %rdi
movq %r14, %rsi
movl $0xa, %edx
callq 0x2220
cmpq %r12, -0xd8(%rbp)
je 0x45a1
movslq %eax, %rcx
cmpq %rax, %rcx
jne 0x4595
movl (%rbx), %ecx
cmpl $0x22, %ecx
je 0x4595
testl %ecx, %ecx
jne 0x4367
movl %r13d, (%rbx)
decl %eax
cmpl $0x2, %r15d
je 0x438b
cmpl $0x1, %r15d
movq %r14, %rbx
leaq -0x50(%rbp), %r14
je 0x4386
testl %r15d, %r15d
jne 0x4395
movl %eax, -0x5c(%rbp)
jmp 0x4395
movl %eax, -0x58(%rbp)
jmp 0x4395
movl %eax, -0x54(%rbp)
movq %r14, %rbx
leaq -0x50(%rbp), %r14
incl %r15d
jmp 0x42aa
cmpl $0x3, %r15d
movq -0x68(%rbp), %r15
jne 0x43ed
movq 0x20(%r15), %rsi
cmpq 0x28(%r15), %rsi
je 0x43e0
movl -0x54(%rbp), %eax
movl %eax, 0x8(%rsi)
movq -0x5c(%rbp), %rax
movq %rax, (%rsi)
addq $0xc, 0x20(%r15)
jmp 0x43ed
movq %r15, %rdi
movq %r14, %rdx
callq 0x4762
jmp 0x4417
movq -0x78(%rbp), %rdi
movq %r14, %rdx
callq 0x4762
jmp 0x4417
movq -0x70(%rbp), %rdi
leaq -0x5c(%rbp), %rdx
callq 0x48ea
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x4405
callq 0x2170
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x4417
callq 0x2170
leaq -0x258(%rbp), %rdi
movq 0x2ba3(%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 0x40a8
movq 0x2b73(%rip), %rdi      # 0x6fd0
leaq 0xd1f(%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 0x2b42(%rip), %rdi      # 0x6fd0
callq 0x2100
movq %rax, %rbx
leaq 0xcec(%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 0xcc2(%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 0x4577
callq 0x2170
jmp 0x4577
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 0x2a86(%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 0xc12(%rip), %rdi       # 0x51ae
callq 0x2250
leaq 0xc06(%rip), %rdi       # 0x51ae
callq 0x20d0
movq %rax, %r14
jmp 0x466e
movq %rax, %r14
jmp 0x4601
jmp 0x45e6
jmp 0x45e1
movq %rax, %r14
jmp 0x4662
jmp 0x45e1
movq %rax, %r14
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x464a
callq 0x2170
jmp 0x464a
jmp 0x45e6
movq %rax, %r14
jmp 0x464a
movq %rax, %r14
jmp 0x462b
jmp 0x45ed
movq %rax, %r14
jmp 0x45fd
movq %rax, %r14
cmpl $0x0, (%rbx)
jne 0x45fd
movl %r13d, (%rbx)
movq -0x68(%rbp), %r15
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x4619
callq 0x2170
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x462b
callq 0x2170
movq 0x2996(%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 0x4662
callq 0x2170
leaq -0x460(%rbp), %rdi
callq 0x2060
movq -0x78(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x467f
callq 0x2170
movq -0x70(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x4690
callq 0x2170
movq (%r15), %rdi
testq %rdi, %rdi
je 0x469d
callq 0x2170
movq %r14, %rdi
callq 0x22e0
nop