// File: srajangarg[P]raytracer/src/core/MeshInfo.cpp
// Function: TriangleMesh::load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
bool
TriangleMesh::load(std::string const & path)
{
  clear();

  std::ifstream f(path.c_str());
  if (!f)
  {
    std::cerr << "Mesh: Couldn't load file " << path << std::endl;
    return false;
  }

  std::string line;
  // int normals = 0;

  while (std::getline(f, line))
  {
    std::istringstream linestream(line);
    std::string op;
    linestream >> op;

    if (op[0] == '#')
      continue;

    if (op == "v")
    {
      Vec3 v;
      linestream >> v;
      vertices.push_back(new MeshVertex(v));
    }

    if (op == "f")   // extract a face as a triangle fan
    {
      int first, second, third;

      if (!getFirstValue(linestream, first))
        continue;

      if (!getFirstValue(linestream, second))
        continue;

      while (getFirstValue(linestream, third))
      {
        triangles.push_back(new MeshTriangle(first - 1, second - 1, third - 1));
        second = third;
      }
    }
  }

  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4b0, %rsp            # imm = 0x4B0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x450(%rbp)
callq 0x66e0
movq -0x18(%rbp), %rdi
callq 0x51a0
movq %rax, %rsi
leaq -0x220(%rbp), %rdi
movl $0x8, %edx
callq 0x5760
movq -0x220(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x220(%rbp,%rax), %rdi
callq 0x51e0
movb %al, -0x441(%rbp)
jmp 0x6980
movb -0x441(%rbp), %al
testb $0x1, %al
jne 0x698c
jmp 0x6a00
movq 0x5565d(%rip), %rdi     # 0x5bff0
leaq 0x406ea(%rip), %rsi     # 0x47084
callq 0x53e0
movq %rax, -0x458(%rbp)
jmp 0x69a8
movq -0x458(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x53c0
movq %rax, -0x460(%rbp)
jmp 0x69c1
movq -0x460(%rbp), %rdi
movq 0x555e1(%rip), %rsi     # 0x5bfb0
callq 0x5440
jmp 0x69d6
movb $0x0, -0x1(%rbp)
movl $0x1, -0x230(%rbp)
jmp 0x6dc5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0x6ddf
leaq -0x250(%rbp), %rdi
callq 0x55a0
leaq -0x220(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x50e0
movq %rax, -0x468(%rbp)
jmp 0x6a28
movq -0x468(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x5500
movb %al, -0x469(%rbp)
jmp 0x6a46
movb -0x469(%rbp), %al
testb $0x1, %al
jne 0x6a55
jmp 0x6d9b
leaq -0x3d0(%rbp), %rdi
leaq -0x250(%rbp), %rsi
movl $0x8, %edx
callq 0x56a0
jmp 0x6a6f
leaq -0x3f0(%rbp), %rdi
movq %rdi, -0x478(%rbp)
callq 0x55a0
movq -0x478(%rbp), %rsi
leaq -0x3d0(%rbp), %rdi
callq 0x5510
jmp 0x6a97
xorl %eax, %eax
movl %eax, %esi
leaq -0x3f0(%rbp), %rdi
callq 0x57d0
movq %rax, -0x480(%rbp)
jmp 0x6ab0
movq -0x480(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x6afc
movl $0x2, -0x230(%rbp)
jmp 0x6d53
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0x6db7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0x6d81
leaq 0x4059b(%rip), %rsi     # 0x4709e
leaq -0x3f0(%rbp), %rdi
callq 0x64f0
movb %al, -0x481(%rbp)
jmp 0x6b17
movb -0x481(%rbp), %al
testb $0x1, %al
jne 0x6b26
jmp 0x6be1
leaq -0x408(%rbp), %rdi
callq 0x6fc0
jmp 0x6b34
leaq -0x3d0(%rbp), %rdi
leaq -0x408(%rbp), %rsi
callq 0x6fd0
jmp 0x6b49
movq -0x450(%rbp), %rax
movq %rax, -0x498(%rbp)
movl $0x18, %edi
callq 0x5400
movq %rax, -0x490(%rbp)
jmp 0x6b6a
leaq -0x428(%rbp), %rdi
leaq -0x408(%rbp), %rsi
callq 0x71a0
jmp 0x6b7f
movq -0x490(%rbp), %rdi
leaq -0x428(%rbp), %rsi
callq 0x71e0
jmp 0x6b94
movq -0x498(%rbp), %rdi
movq -0x490(%rbp), %rax
movq %rax, -0x410(%rbp)
leaq -0x410(%rbp), %rsi
callq 0x7170
jmp 0x6bb7
jmp 0x6be1
movq -0x490(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
movl $0x18, %esi
callq 0x5410
jmp 0x6d81
leaq 0x40995(%rip), %rsi     # 0x4757d
leaq -0x3f0(%rbp), %rdi
callq 0x64f0
movb %al, -0x499(%rbp)
jmp 0x6bfc
movb -0x499(%rbp), %al
testb $0x1, %al
jne 0x6c0b
jmp 0x6d49
leaq -0x3d0(%rbp), %rdi
leaq -0x42c(%rbp), %rsi
callq 0x67c0
movb %al, -0x49a(%rbp)
jmp 0x6c26
movb -0x49a(%rbp), %al
testb $0x1, %al
jne 0x6c41
jmp 0x6c32
movl $0x2, -0x230(%rbp)
jmp 0x6d53
leaq -0x3d0(%rbp), %rdi
leaq -0x430(%rbp), %rsi
callq 0x67c0
movb %al, -0x49b(%rbp)
jmp 0x6c5c
movb -0x49b(%rbp), %al
testb $0x1, %al
jne 0x6c77
jmp 0x6c68
movl $0x2, -0x230(%rbp)
jmp 0x6d53
jmp 0x6c79
leaq -0x3d0(%rbp), %rdi
leaq -0x434(%rbp), %rsi
callq 0x67c0
movb %al, -0x49c(%rbp)
jmp 0x6c94
movb -0x49c(%rbp), %al
testb $0x1, %al
jne 0x6ca3
jmp 0x6d47
movq -0x450(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x4b0(%rbp)
movl $0xc, %edi
callq 0x5400
movq %rax, -0x4a8(%rbp)
jmp 0x6cc8
movq -0x4a8(%rbp), %rdi
movl -0x42c(%rbp), %esi
decl %esi
movl -0x430(%rbp), %edx
decl %edx
movl -0x434(%rbp), %ecx
decl %ecx
callq 0x7230
jmp 0x6cee
movq -0x4b0(%rbp), %rdi
movq -0x4a8(%rbp), %rax
movq %rax, -0x440(%rbp)
leaq -0x440(%rbp), %rsi
callq 0x7200
jmp 0x6d11
movl -0x434(%rbp), %eax
movl %eax, -0x430(%rbp)
jmp 0x6c79
movq -0x4a8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
movl $0xc, %esi
callq 0x5410
jmp 0x6d81
jmp 0x6d49
movl $0x0, -0x230(%rbp)
leaq -0x3f0(%rbp), %rdi
callq 0x5290
leaq -0x3d0(%rbp), %rdi
callq 0x51f0
movl -0x230(%rbp), %eax
testl %eax, %eax
je 0x6d7c
jmp 0x6d77
jmp 0x6a0c
jmp 0x6a0c
leaq -0x3f0(%rbp), %rdi
callq 0x5290
leaq -0x3d0(%rbp), %rdi
callq 0x51f0
jmp 0x6db7
movb $0x1, -0x1(%rbp)
movl $0x1, -0x230(%rbp)
leaq -0x250(%rbp), %rdi
callq 0x5290
jmp 0x6dc5
leaq -0x250(%rbp), %rdi
callq 0x5290
jmp 0x6ddf
leaq -0x220(%rbp), %rdi
callq 0x5120
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x4b0, %rsp            # imm = 0x4B0
popq %rbp
retq
leaq -0x220(%rbp), %rdi
callq 0x5120
movq -0x228(%rbp), %rdi
callq 0x5720
nopw (%rax,%rax)