// File: IsaacLaw12[P]RayTracer/./src/Model.cpp
// Function: Model::load_model()
void Model::load_model(){
    std::ifstream in(original_file);
    if (!in){
        std::cerr << "Could not open model file " << original_file << std::endl;
        load_successful = false;
        return;
    }
    std::string obj_line;
    std::string line_type = "";
    double vx, vy, vz;
    int f1, f2, f3;
    std::string s1, s2, s3;
    while (std::getline(in, obj_line)){
        if(obj_line.empty()){
            continue;
        }
        std::stringstream obj_read(obj_line);
        obj_read >> line_type;
        if (line_type[0] == 'v' && line_type.size() == 1){
            obj_read >> vx >> vy >> vz;
            add_vertex(vx, vy, vz);
        }
        if (line_type[0] == 'f'){
            obj_read >> f1 >> s1;
            obj_read >> f2 >> s2 ;
            obj_read >> f3 >> s3 ;
            add_face(f1, f2, f3);
        }
        // Materials line starts with mtllib
        if (line_type[0] == 'm'){
            std::string file_name;
            obj_read >> file_name;
            load_material(file_name);
        }
    }
    in.close();
}

// Assembly:
subq $0x538, %rsp            # imm = 0x538
movq %rdi, 0x530(%rsp)
movq 0x530(%rsp), %rsi
movq %rsi, 0x70(%rsp)
addq $0x210, %rsi            # imm = 0x210
leaq 0x328(%rsp), %rdi
movl $0x8, %edx
callq 0x4530
movq 0x328(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x328(%rsp,%rax), %rdi
callq 0x4150
movb %al, 0x7f(%rsp)
jmp 0x1a534
movb 0x7f(%rsp), %al
testb $0x1, %al
jne 0x1a53e
jmp 0x1a5bd
movq 0x80aab(%rip), %rdi     # 0x9aff0
leaq 0x47bbc(%rip), %rsi     # 0x62108
callq 0x4360
movq %rax, 0x68(%rsp)
jmp 0x1a558
movq 0x68(%rsp), %rdi
movq 0x70(%rsp), %rsi
addq $0x210, %rsi            # imm = 0x210
callq 0x4340
movq %rax, 0x60(%rsp)
jmp 0x1a575
movq 0x60(%rsp), %rdi
movq 0x80a0f(%rip), %rsi     # 0x9af90
callq 0x43a0
jmp 0x1a588
movq 0x70(%rsp), %rax
movb $0x0, 0x250(%rax)
movl $0x1, 0x318(%rsp)
jmp 0x1aa06
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x320(%rsp)
movl %eax, 0x31c(%rsp)
jmp 0x1aa5c
leaq 0x2f8(%rsp), %rdi
callq 0x4490
leaq 0x2d7(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x45f0
movq 0x58(%rsp), %rdx
leaq 0x47816(%rip), %rsi     # 0x61dfe
leaq 0x2d8(%rsp), %rdi
callq 0x11e60
jmp 0x1a5f7
leaq 0x2d7(%rsp), %rdi
callq 0x43c0
leaq 0x288(%rsp), %rdi
callq 0x4490
leaq 0x268(%rsp), %rdi
callq 0x4490
leaq 0x248(%rsp), %rdi
callq 0x4490
leaq 0x328(%rsp), %rdi
leaq 0x2f8(%rsp), %rsi
callq 0x4090
movq %rax, 0x50(%rsp)
jmp 0x1a647
movq 0x50(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x4440
movb %al, 0x4f(%rsp)
jmp 0x1a661
movb 0x4f(%rsp), %al
testb $0x1, %al
jne 0x1a66e
jmp 0x1a9ab
leaq 0x2f8(%rsp), %rdi
callq 0x4570
testb $0x1, %al
jne 0x1a681
jmp 0x1a6c2
jmp 0x1a62b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x320(%rsp)
movl %eax, 0x31c(%rsp)
leaq 0x2d7(%rsp), %rdi
callq 0x43c0
jmp 0x1aa4f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x320(%rsp)
movl %eax, 0x31c(%rsp)
jmp 0x1aa1b
movl $0x10, %edi
movl $0x8, %esi
callq 0x11e40
movl %eax, 0x48(%rsp)
jmp 0x1a6d7
movl 0x48(%rsp), %edx
leaq 0xc0(%rsp), %rdi
leaq 0x2f8(%rsp), %rsi
callq 0x4520
jmp 0x1a6f2
leaq 0xc0(%rsp), %rdi
leaq 0x2d8(%rsp), %rsi
callq 0x4450
jmp 0x1a709
xorl %eax, %eax
movl %eax, %esi
leaq 0x2d8(%rsp), %rdi
callq 0x4680
movq %rax, 0x40(%rsp)
jmp 0x1a721
movq 0x40(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x76, %eax
jne 0x1a7d4
leaq 0x2d8(%rsp), %rdi
callq 0x4260
cmpq $0x1, %rax
jne 0x1a7d4
leaq 0xc0(%rsp), %rdi
leaq 0x2c8(%rsp), %rsi
callq 0x42e0
movq %rax, 0x38(%rsp)
jmp 0x1a765
movq 0x38(%rsp), %rdi
leaq 0x2c0(%rsp), %rsi
callq 0x42e0
movq %rax, 0x30(%rsp)
jmp 0x1a77e
movq 0x30(%rsp), %rdi
leaq 0x2b8(%rsp), %rsi
callq 0x42e0
jmp 0x1a792
movq 0x70(%rsp), %rdi
movsd 0x2c8(%rsp), %xmm0
movsd 0x2c0(%rsp), %xmm1
movsd 0x2b8(%rsp), %xmm2
callq 0x1af70
jmp 0x1a7b9
jmp 0x1a7d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x320(%rsp)
movl %eax, 0x31c(%rsp)
jmp 0x1a99c
xorl %eax, %eax
movl %eax, %esi
leaq 0x2d8(%rsp), %rdi
callq 0x4680
movq %rax, 0x28(%rsp)
jmp 0x1a7ec
movq 0x28(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x66, %eax
jne 0x1a8b0
leaq 0xc0(%rsp), %rdi
leaq 0x2b4(%rsp), %rsi
callq 0x41f0
movq %rax, 0x20(%rsp)
jmp 0x1a819
movq 0x20(%rsp), %rdi
leaq 0x288(%rsp), %rsi
callq 0x4450
jmp 0x1a82d
leaq 0xc0(%rsp), %rdi
leaq 0x2b0(%rsp), %rsi
callq 0x41f0
movq %rax, 0x18(%rsp)
jmp 0x1a849
movq 0x18(%rsp), %rdi
leaq 0x268(%rsp), %rsi
callq 0x4450
jmp 0x1a85d
leaq 0xc0(%rsp), %rdi
leaq 0x2ac(%rsp), %rsi
callq 0x41f0
movq %rax, 0x10(%rsp)
jmp 0x1a879
movq 0x10(%rsp), %rdi
leaq 0x248(%rsp), %rsi
callq 0x4450
jmp 0x1a88d
movq 0x70(%rsp), %rdi
movl 0x2b4(%rsp), %esi
movl 0x2b0(%rsp), %edx
movl 0x2ac(%rsp), %ecx
callq 0x1b0a0
jmp 0x1a8ae
jmp 0x1a8b0
xorl %eax, %eax
movl %eax, %esi
leaq 0x2d8(%rsp), %rdi
callq 0x4680
movq %rax, 0x8(%rsp)
jmp 0x1a8c8
movq 0x8(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x6d, %eax
jne 0x1a98a
leaq 0xa0(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x4490
movq (%rsp), %rsi
leaq 0xc0(%rsp), %rdi
callq 0x4450
jmp 0x1a8fd
leaq 0x80(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x4130
jmp 0x1a914
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x43230
jmp 0x1a928
leaq 0x80(%rsp), %rdi
callq 0x4200
leaq 0xa0(%rsp), %rdi
callq 0x4200
jmp 0x1a98a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x320(%rsp)
movl %eax, 0x31c(%rsp)
jmp 0x1a97b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x320(%rsp)
movl %eax, 0x31c(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x4200
leaq 0xa0(%rsp), %rdi
callq 0x4200
jmp 0x1a99c
leaq 0xc0(%rsp), %rdi
callq 0x4290
jmp 0x1a62b
leaq 0xc0(%rsp), %rdi
callq 0x4290
jmp 0x1aa1b
leaq 0x328(%rsp), %rdi
callq 0x40a0
jmp 0x1a9ba
leaq 0x248(%rsp), %rdi
callq 0x4200
leaq 0x268(%rsp), %rdi
callq 0x4200
leaq 0x288(%rsp), %rdi
callq 0x4200
leaq 0x2d8(%rsp), %rdi
callq 0x4200
leaq 0x2f8(%rsp), %rdi
callq 0x4200
movl $0x0, 0x318(%rsp)
leaq 0x328(%rsp), %rdi
callq 0x40c0
addq $0x538, %rsp            # imm = 0x538
retq
leaq 0x248(%rsp), %rdi
callq 0x4200
leaq 0x268(%rsp), %rdi
callq 0x4200
leaq 0x288(%rsp), %rdi
callq 0x4200
leaq 0x2d8(%rsp), %rdi
callq 0x4200
leaq 0x2f8(%rsp), %rdi
callq 0x4200
leaq 0x328(%rsp), %rdi
callq 0x40c0
movq 0x320(%rsp), %rdi
callq 0x45e0
nopw %cs:(%rax,%rax)