// File: /workspace/github_cpp_makefile_star2_O2/logicx24[P]RayTracer/raytracer.cpp
// Function: parseObj(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::vector<Polygon*, std::allocator<Polygon*>>*, std::vector<mat4, std::allocator<mat4>>*, Material&)
void parseObj(string fileName, vector<Polygon*> *sceneObjects, vector<mat4> *transforms, Material &curMat) {
	vector<vec3> verts;
	vector<vec3>normals;
	verts.push_back(vec3(0, 0, 0)); // Kill index 0, since vertices are numbered 1 ... n
	normals.push_back(vec3(0, 0, 0)); // Kill index 0, since normals are numbered 1 ... n
	ifstream objFile(fileName);
	string currentLine;
	string argument;
    if (!objFile.is_open()) {
    	cerr << "Error opening obj file" << endl;
    	return;
    }
    while (getline(objFile, currentLine)) {
    	istringstream iss;
    	iss.str(currentLine);
    	iss >> argument;
        if (currentLine.empty() || argumentMatches(argument, "#")) {
        	continue;
        } else if (argumentMatches(argument, "v")) {
        	float args[3];
            parseArgs(args, &iss, 3, "Incorrect number of arguments for vertex in obj file.");
            verts.push_back(vec3(args[0], args[1], args[2]));
        } else if (argumentMatches(argument, "vn")) {
        	float args[3];
            parseArgs(args, &iss, 3, "Incorrect number of arguments for vertex normal in obj file.");
            vec3 norm = vec3(args[0], args[1], args[2]);
            normals.push_back(norm);
        } else if (argumentMatches(argument, "f")) {
        	bool normalSpecified = false;
            int vertArgs[3];
            int normalArgs[3];
            string temp;
            int index = 0;
            while (iss >> temp) {
            	normalSpecified = (temp.find("//") != string::npos);
                /*
            	std::string s = "scott>=tiger>=mushroom";
            	std::string delimiter = ">=";

            	size_t pos = 0;
            	std::string token;
                while ((pos = s.find(delimiter)) != std::string::npos) {
                	    token = s.substr(0, pos);
                	        std::cout << token << std::endl;
                	            s.erase(0, pos + delimiter.length());

                }
                std::cout << s << std::endl;
                */
                if (normalSpecified) {
                	string delimeter = "//";
                	int pos = temp.find(delimeter);
                    string face = temp.substr(0, pos);
                    vertArgs[index] = stoi(face);
                    temp.erase(0, pos + delimeter.length());
                    normalArgs[index] = stoi(temp);
                } else {
                    vertArgs[index] = atoi(temp.c_str());
                }
                index++;
            }
            Triangle *t;
            mat4 currentTransform = reduceTransforms(transforms);
            if (normalSpecified) {
            	vec3 n1 = normals[normalArgs[0]];
            	vec3 n2 = normals[normalArgs[1]];
            	vec3 n3 = normals[normalArgs[2]];
                t = new Triangle(verts[vertArgs[0]], verts[vertArgs[1]], verts[vertArgs[2]], 
                              curMat, currentTransform, n1, n2, n3);
            } else {
                t = new Triangle(verts[vertArgs[0]], verts[vertArgs[1]], verts[vertArgs[2]], 
                                    curMat, currentTransform);
            }
            sceneObjects->push_back(t);
        } else {
        	cerr << "Unknown input in obj file: " << fileName << "." << endl;
        }
    }
    objFile.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x708, %rsp            # imm = 0x708
movq %rcx, %rbx
movq %rdx, -0xd0(%rbp)
movq %rsi, -0xc8(%rbp)
movq %rdi, %r14
xorps %xmm0, %xmm0
leaq -0xb0(%rbp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movaps %xmm0, -0x90(%rbp)
andq $0x0, -0x80(%rbp)
leaq -0x730(%rbp), %rsi
movaps %xmm0, (%rsi)
andq $0x0, 0x10(%rsi)
callq 0x8f2e
leaq -0x730(%rbp), %rsi
xorps %xmm0, %xmm0
movaps %xmm0, (%rsi)
andq $0x0, 0x10(%rsi)
leaq -0x90(%rbp), %rdi
callq 0x8f2e
leaq -0x730(%rbp), %rdi
pushq $0x8
popq %rdx
movq %r14, %rsi
callq 0x3380
leaq -0x1a0(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq -0xe0(%rbp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
xorl %edx, %edx
movb %dl, (%rax)
movb %dl, (%rcx)
leaq -0x6b8(%rbp), %rdi
callq 0x30a0
testb %al, %al
je 0x40ae
movq %r14, -0xc0(%rbp)
leaq -0x170(%rbp), %r13
movq %rbx, -0xb8(%rbp)
leaq -0x730(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x3060
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x40cb
leaq -0x520(%rbp), %rdi
callq 0x3180
leaq -0x510(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x3330
leaq -0x520(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x3290
cmpq $0x0, -0x1a8(%rbp)
je 0x409d
leaq -0x3a0(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x32d0
leaq -0x3a0(%rbp), %r14
movq %r14, %rdi
leaq 0xf5c8(%rip), %rsi      # 0x130bd
callq 0x390d
movl %eax, %r12d
movq %r14, %rdi
callq 0x3100
testb %r12b, %r12b
jne 0x409d
leaq -0x380(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x32d0
leaq -0x380(%rbp), %r14
movq %r14, %rdi
leaq 0xf58d(%rip), %rsi      # 0x130bf
callq 0x390d
movl %eax, %r12d
movq %r14, %rdi
callq 0x3100
testb %r12b, %r12b
je 0x3bb9
leaq -0x360(%rbp), %r14
movq %r14, %rdi
leaq 0xf569(%rip), %rsi      # 0x130c1
movq %r13, %rdx
callq 0x5b12
leaq -0x58(%rbp), %rdi
leaq -0x520(%rbp), %rsi
pushq $0x3
popq %rdx
movq %r14, %rcx
callq 0x37b3
movq %r14, %rdi
callq 0x3100
cvtss2sd -0x58(%rbp), %xmm0
cvtss2sd -0x54(%rbp), %xmm1
cvtss2sd -0x50(%rbp), %xmm2
movsd %xmm0, -0x170(%rbp)
movsd %xmm1, -0x168(%rbp)
movsd %xmm2, -0x160(%rbp)
leaq -0xb0(%rbp), %rdi
movq %r13, %rsi
callq 0x8f2e
jmp 0x409d
leaq -0x340(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x32d0
leaq -0x340(%rbp), %r14
movq %r14, %rdi
leaq 0xf51a(%rip), %rsi      # 0x130f7
callq 0x390d
movl %eax, %r12d
movq %r14, %rdi
callq 0x3100
testb %r12b, %r12b
je 0x3c67
leaq -0x320(%rbp), %r15
movq %r15, %rdi
leaq 0xf4f7(%rip), %rsi      # 0x130fa
movq %r13, %r14
movq %r13, %rdx
callq 0x5b12
leaq -0x58(%rbp), %rdi
leaq -0x520(%rbp), %rsi
pushq $0x3
popq %rdx
movq %r15, %rcx
callq 0x37b3
movq %r15, %rdi
callq 0x3100
cvtss2sd -0x58(%rbp), %xmm0
cvtss2sd -0x54(%rbp), %xmm1
cvtss2sd -0x50(%rbp), %xmm2
movsd %xmm0, -0x170(%rbp)
movsd %xmm1, -0x168(%rbp)
movsd %xmm2, -0x160(%rbp)
leaq -0x90(%rbp), %rdi
movq %r14, %rsi
callq 0x5b4e
jmp 0x409d
leaq -0x300(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x32d0
leaq -0x300(%rbp), %r14
movq %r14, %rdi
leaq 0xf4ac(%rip), %rsi      # 0x13137
callq 0x390d
movl %eax, %r12d
movq %r14, %rdi
callq 0x3100
testb %r12b, %r12b
je 0x3daa
leaq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
andq $0x0, -0x50(%rbp)
movb $0x0, -0x48(%rbp)
xorl %ebx, %ebx
movq $0x0, -0x60(%rbp)
leaq 0xf473(%rip), %r14      # 0x13139
leaq -0x520(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x3290
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3de8
leaq -0x58(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x3470
cmpq $-0x1, %rax
setne %al
movq %rax, -0x60(%rbp)
je 0x3d94
movq %r13, %r12
movq %r13, %rdi
movq %r14, %rsi
leaq -0x190(%rbp), %r15
movq %r15, %rdx
callq 0x5b12
leaq -0x58(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x3480
movslq %eax, %r12
movq %r15, %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %r12, %rcx
callq 0x3210
movq %r15, %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x5b8b
movl %eax, -0x34(%rbp,%rbx)
addq -0x168(%rbp), %r12
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x3090
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x5b8b
movl %eax, -0x6c(%rbp,%rbx)
movq %r15, %rdi
callq 0x3100
movq %r13, %rdi
callq 0x3100
leaq 0xf3a7(%rip), %r14      # 0x13139
jmp 0x3da1
movq -0x58(%rbp), %rdi
callq 0x3360
movl %eax, -0x34(%rbp,%rbx)
addq $0x4, %rbx
jmp 0x3cc6
movq 0x1623f(%rip), %rdi     # 0x19ff0
leaq 0xf384(%rip), %rsi      # 0x1313c
callq 0x31d0
movq %rax, %rdi
movq -0xc0(%rbp), %rsi
callq 0x31c0
movq %rax, %rdi
leaq 0xf608(%rip), %rsi      # 0x133de
callq 0x31d0
movq %rax, %rdi
callq 0x3120
jmp 0x409d
movq %r13, %rdi
movq -0xd0(%rbp), %rsi
callq 0x3920
movq -0xb8(%rbp), %rbx
leaq -0x190(%rbp), %r14
testb $0x1, -0x60(%rbp)
je 0x3fa3
movslq -0x6c(%rbp), %rax
movq -0x90(%rbp), %rcx
imulq $0x18, %rax, %rax
movsd (%rcx,%rax), %xmm0
movsd %xmm0, -0x190(%rbp)
movsd 0x8(%rcx,%rax), %xmm0
movsd %xmm0, -0x188(%rbp)
movsd 0x10(%rcx,%rax), %xmm0
movsd %xmm0, -0x180(%rbp)
movslq -0x68(%rbp), %rax
imulq $0x18, %rax, %rax
movsd (%rcx,%rax), %xmm0
movsd %xmm0, -0x1e0(%rbp)
movsd 0x8(%rcx,%rax), %xmm0
movsd %xmm0, -0x1d8(%rbp)
movsd 0x10(%rcx,%rax), %xmm0
movsd %xmm0, -0x1d0(%rbp)
movslq -0x64(%rbp), %rax
imulq $0x18, %rax, %rax
movsd (%rcx,%rax), %xmm0
movsd %xmm0, -0x1c8(%rbp)
movsd 0x8(%rcx,%rax), %xmm0
movsd %xmm0, -0x1c0(%rbp)
movsd 0x10(%rcx,%rax), %xmm0
movsd %xmm0, -0x1b8(%rbp)
movl $0x2b8, %edi            # imm = 0x2B8
callq 0x31f0
movq %rax, %r15
movslq -0x34(%rbp), %rax
movq -0xb0(%rbp), %rdi
imulq $0x18, %rax, %rsi
addq %rdi, %rsi
movslq -0x30(%rbp), %rax
imulq $0x18, %rax, %rdx
addq %rdi, %rdx
movslq -0x2c(%rbp), %rax
imulq $0x18, %rax, %rcx
addq %rdi, %rcx
movsd -0x170(%rbp), %xmm0
movsd %xmm0, -0x2e0(%rbp)
movups -0x168(%rbp), %xmm0
movups %xmm0, -0x2d8(%rbp)
movups -0x158(%rbp), %xmm0
movups %xmm0, -0x2c8(%rbp)
movups -0x148(%rbp), %xmm0
movups %xmm0, -0x2b8(%rbp)
movups -0x138(%rbp), %xmm0
movups %xmm0, -0x2a8(%rbp)
movsd -0x128(%rbp), %xmm0
movsd %xmm0, -0x298(%rbp)
movsd -0x120(%rbp), %xmm0
movsd %xmm0, -0x290(%rbp)
movsd -0x118(%rbp), %xmm0
movsd %xmm0, -0x288(%rbp)
movups -0x110(%rbp), %xmm0
movups %xmm0, -0x280(%rbp)
movups -0x100(%rbp), %xmm0
movups %xmm0, -0x270(%rbp)
subq $0x8, %rsp
movq %r15, %rdi
movq %rbx, %r8
leaq -0x2e0(%rbp), %r9
leaq -0x1c8(%rbp), %rax
pushq %rax
leaq -0x1e0(%rbp), %rax
pushq %rax
pushq %r14
callq 0x5c50
addq $0x20, %rsp
jmp 0x407e
movl $0x2b8, %edi            # imm = 0x2B8
callq 0x31f0
movq %rax, %r15
movslq -0x34(%rbp), %rax
movq -0xb0(%rbp), %rdi
imulq $0x18, %rax, %rsi
addq %rdi, %rsi
movslq -0x30(%rbp), %rax
imulq $0x18, %rax, %rdx
addq %rdi, %rdx
movslq -0x2c(%rbp), %rax
imulq $0x18, %rax, %rcx
addq %rdi, %rcx
movsd -0x170(%rbp), %xmm0
movsd %xmm0, -0x260(%rbp)
movups -0x168(%rbp), %xmm0
movups %xmm0, -0x258(%rbp)
movups -0x158(%rbp), %xmm0
movups %xmm0, -0x248(%rbp)
movups -0x148(%rbp), %xmm0
movups %xmm0, -0x238(%rbp)
movups -0x138(%rbp), %xmm0
movups %xmm0, -0x228(%rbp)
movsd -0x128(%rbp), %xmm0
movsd %xmm0, -0x218(%rbp)
movsd -0x120(%rbp), %xmm0
movsd %xmm0, -0x210(%rbp)
movsd -0x118(%rbp), %xmm0
movsd %xmm0, -0x208(%rbp)
movups -0x110(%rbp), %xmm0
movups %xmm0, -0x200(%rbp)
movups -0x100(%rbp), %xmm0
movups %xmm0, -0x1f0(%rbp)
movq %r15, %rdi
movq %rbx, %r8
leaq -0x260(%rbp), %r9
callq 0x5de0
movq %r15, -0x190(%rbp)
movq -0xc8(%rbp), %rdi
movq %r14, %rsi
callq 0x932a
leaq -0x58(%rbp), %rdi
callq 0x3100
leaq -0x520(%rbp), %rdi
callq 0x3110
jmp 0x3a6c
movq 0x15f3b(%rip), %rdi     # 0x19ff0
leaq 0xefea(%rip), %rsi      # 0x130a6
callq 0x31d0
movq %rax, %rdi
callq 0x3120
jmp 0x40d7
leaq -0x730(%rbp), %rdi
callq 0x3070
leaq -0xf0(%rbp), %rdi
callq 0x3100
leaq -0x1b0(%rbp), %rdi
callq 0x3100
leaq -0x730(%rbp), %rdi
callq 0x30b0
leaq -0x90(%rbp), %rdi
callq 0x8f06
leaq -0xb0(%rbp), %rdi
callq 0x8f06
addq $0x708, %rsp            # imm = 0x708
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4127
movq %rax, %rbx
movl $0x2b8, %esi            # imm = 0x2B8
movq %r15, %rdi
callq 0x3200
jmp 0x419b
jmp 0x417b
jmp 0x417b
jmp 0x417b
jmp 0x4143
jmp 0x4143
movq %rax, %rbx
jmp 0x41d9
jmp 0x41a6
jmp 0x41a6
movq %rax, %rbx
leaq -0x320(%rbp), %rdi
jmp 0x419f
jmp 0x4176
jmp 0x41a6
movq %rax, %rbx
leaq -0x360(%rbp), %rdi
jmp 0x419f
jmp 0x41a6
jmp 0x417b
movq %rax, %rbx
jmp 0x418f
jmp 0x4176
movq %rax, %rbx
jmp 0x41b5
movq %rax, %rbx
jmp 0x419b
movq %rax, %rbx
leaq -0x190(%rbp), %rdi
callq 0x3100
leaq -0x170(%rbp), %rdi
callq 0x3100
leaq -0x58(%rbp), %rdi
callq 0x3100
jmp 0x41a9
movq %rax, %rbx
leaq -0x520(%rbp), %rdi
callq 0x3110
leaq -0xf0(%rbp), %rdi
callq 0x3100
leaq -0x1b0(%rbp), %rdi
callq 0x3100
leaq -0x730(%rbp), %rdi
callq 0x30b0
leaq -0x90(%rbp), %rdi
callq 0x8f06
leaq -0xb0(%rbp), %rdi
callq 0x8f06
movq %rbx, %rdi
callq 0x33f0