// File: ingowald[P]closestSurfacePointQueries/examples/benchmark.cpp
// Function: loadTriangles(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void loadTriangles(const std::string &fileName)
{
  FILE *file = fopen(fileName.c_str(),"r");
  if (!file) throw std::runtime_error("could not open "+fileName);

  char line[1000];

  if (fscanf(file,"NSURFPTS=%12li NTRI=%12li\n",&numVertices,&numTriangles)!=2) 
    throw std::runtime_error("could not parse num vertices/num trianlges from "+fileName);
  std::cout << "num vertices " << numVertices << std::endl;
  std::cout << "num triangles " << numTriangles << std::endl;
  fgets(line,1000,file);

  double x,y,z;
  int ID,i,j,k;

  // parse vertices
  for (int vtxID=0;vtxID<numVertices;vtxID++) {
    if (fscanf(file,"%i %lf %lf %lf\n",&ID,&x,&y,&z)!=4) 
      throw std::runtime_error("couldn't read vertex no "+std::to_string(vtxID));
    if (ID != vtxID+1)
      throw std::runtime_error("invalid vertex line "+std::to_string(vtxID));
    // printf(" vtx %i -> %f %f %f\n",ID,x,y,z);
    vertex_x.push_back(x);
    vertex_y.push_back(y);
    vertex_z.push_back(z);
  }
  std::cout << "loaded " << vertex_x.size() << " vertices" << std::endl;

  // parse indices
  for (int idxID=0;idxID<numTriangles;idxID++) {
    if (fscanf(file,"%i %i %i %i\n",&ID,&i,&j,&k)!=4) 
      throw std::runtime_error("couldn't read triangles indices for tri no "+std::to_string(idxID)
                               +" in "+fileName);
    if (ID != idxID+1)
      throw std::runtime_error("invalid vertex line "+std::to_string(idxID));
    // printf(" idx %i -> %i %i %i\n",idxID,i,j,k);
    index_x.push_back(i-1);
    index_y.push_back(j-1);
    index_z.push_back(k-1);
  }
  std::cout << "loaded " << index_x.size() << " triangles" << std::endl;

  fclose(file);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x630, %rsp            # imm = 0x630
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x30f0
movq %rax, %rdi
leaq 0xd61e(%rip), %rsi      # 0x11040
callq 0x3300
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x3ad2
movb $0x1, -0x3d(%rbp)
movl $0x10, %edi
callq 0x3130
movq %rax, -0x5f8(%rbp)
movq -0x8(%rbp), %rdx
leaq 0xd5ec(%rip), %rsi      # 0x11042
leaq -0x30(%rbp), %rdi
callq 0x5b70
jmp 0x3a61
movq -0x5f8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3390
jmp 0x3a73
movq -0x5f8(%rbp), %rdi
movb $0x0, -0x3d(%rbp)
movq 0x1456b(%rip), %rsi     # 0x17ff0
movq 0x1453c(%rip), %rdx     # 0x17fc8
callq 0x33c0
jmp 0x4265
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x3ab9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x3180
testb $0x1, -0x3d(%rbp)
jne 0x3ac1
jmp 0x3acd
movq -0x5f8(%rbp), %rdi
callq 0x31d0
jmp 0x425c
movq -0x10(%rbp), %rdi
leaq 0xd575(%rip), %rsi      # 0x11052
leaq 0x14944(%rip), %rdx     # 0x18428
leaq 0x14935(%rip), %rcx     # 0x18420
movb $0x0, %al
callq 0x3420
cmpl $0x2, %eax
je 0x3ba9
movb $0x1, -0x451(%rbp)
movl $0x10, %edi
callq 0x3130
movq %rax, -0x600(%rbp)
movq -0x8(%rbp), %rdx
leaq 0xd54f(%rip), %rsi      # 0x1106d
leaq -0x450(%rbp), %rdi
callq 0x5b70
jmp 0x3b2c
movq -0x600(%rbp), %rdi
leaq -0x450(%rbp), %rsi
callq 0x3390
jmp 0x3b41
movq -0x600(%rbp), %rdi
movb $0x0, -0x451(%rbp)
movq 0x1449a(%rip), %rsi     # 0x17ff0
movq 0x1446b(%rip), %rdx     # 0x17fc8
callq 0x33c0
jmp 0x4265
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x3b8d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x450(%rbp), %rdi
callq 0x3180
testb $0x1, -0x451(%rbp)
jne 0x3b98
jmp 0x3ba4
movq -0x600(%rbp), %rdi
callq 0x31d0
jmp 0x425c
movq 0x14420(%rip), %rdi     # 0x17fd0
leaq 0xd4e7(%rip), %rsi      # 0x1109e
callq 0x3260
movq %rax, %rdi
movq 0x14862(%rip), %rsi     # 0x18428
callq 0x3080
movq %rax, %rdi
movq 0x143e3(%rip), %rsi     # 0x17fb8
callq 0x32a0
movq 0x143ef(%rip), %rdi     # 0x17fd0
leaq 0xd4c4(%rip), %rsi      # 0x110ac
callq 0x3260
movq %rax, %rdi
movq 0x14829(%rip), %rsi     # 0x18420
callq 0x3080
movq %rax, %rdi
movq 0x143b2(%rip), %rsi     # 0x17fb8
callq 0x32a0
leaq -0x430(%rbp), %rdi
movq -0x10(%rbp), %rdx
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x3380
movl $0x0, -0x484(%rbp)
movslq -0x484(%rbp), %rax
cmpq 0x147f0(%rip), %rax     # 0x18428
jae 0x3e97
movq -0x10(%rbp), %rdi
leaq 0xd472(%rip), %rsi      # 0x110bb
leaq -0x474(%rbp), %rdx
leaq -0x460(%rbp), %rcx
leaq -0x468(%rbp), %r8
leaq -0x470(%rbp), %r9
movb $0x0, %al
callq 0x3420
cmpl $0x4, %eax
je 0x3d54
movb $0x1, -0x4c9(%rbp)
movl $0x10, %edi
callq 0x3130
movq %rax, -0x608(%rbp)
movl -0x484(%rbp), %esi
leaq -0x4c8(%rbp), %rdi
callq 0x5cd0
jmp 0x3ca1
leaq 0xd423(%rip), %rsi      # 0x110cb
leaq -0x4a8(%rbp), %rdi
leaq -0x4c8(%rbp), %rdx
callq 0x5c80
jmp 0x3cbd
movq -0x608(%rbp), %rdi
leaq -0x4a8(%rbp), %rsi
callq 0x3390
jmp 0x3cd2
movq -0x608(%rbp), %rdi
movb $0x0, -0x4c9(%rbp)
movq 0x14309(%rip), %rsi     # 0x17ff0
movq 0x142da(%rip), %rdx     # 0x17fc8
callq 0x33c0
jmp 0x4265
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x3d38
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x3d2c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x4a8(%rbp), %rdi
callq 0x3180
leaq -0x4c8(%rbp), %rdi
callq 0x3180
testb $0x1, -0x4c9(%rbp)
jne 0x3d43
jmp 0x3d4f
movq -0x608(%rbp), %rdi
callq 0x31d0
jmp 0x425c
movl -0x474(%rbp), %eax
movl -0x484(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
je 0x3e4a
movb $0x1, -0x511(%rbp)
movl $0x10, %edi
callq 0x3130
movq %rax, -0x610(%rbp)
movl -0x484(%rbp), %esi
leaq -0x510(%rbp), %rdi
callq 0x5cd0
jmp 0x3d97
leaq 0xd346(%rip), %rsi      # 0x110e4
leaq -0x4f0(%rbp), %rdi
leaq -0x510(%rbp), %rdx
callq 0x5c80
jmp 0x3db3
movq -0x610(%rbp), %rdi
leaq -0x4f0(%rbp), %rsi
callq 0x3390
jmp 0x3dc8
movq -0x610(%rbp), %rdi
movb $0x0, -0x511(%rbp)
movq 0x14213(%rip), %rsi     # 0x17ff0
movq 0x141e4(%rip), %rdx     # 0x17fc8
callq 0x33c0
jmp 0x4265
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x3e2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x3e22
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x4f0(%rbp), %rdi
callq 0x3180
leaq -0x510(%rbp), %rdi
callq 0x3180
testb $0x1, -0x511(%rbp)
jne 0x3e39
jmp 0x3e45
movq -0x610(%rbp), %rdi
callq 0x31d0
jmp 0x425c
leaq 0x14467(%rip), %rdi     # 0x182b8
leaq -0x460(%rbp), %rsi
callq 0x5df0
leaq 0x1446c(%rip), %rdi     # 0x182d0
leaq -0x468(%rbp), %rsi
callq 0x5df0
leaq 0x14471(%rip), %rdi     # 0x182e8
leaq -0x470(%rbp), %rsi
callq 0x5df0
movl -0x484(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x484(%rbp)
jmp 0x3c2a
movq 0x14132(%rip), %rdi     # 0x17fd0
leaq 0xd254(%rip), %rsi      # 0x110f9
callq 0x3260
movq %rax, -0x618(%rbp)
leaq 0x14400(%rip), %rdi     # 0x182b8
callq 0x5e60
movq -0x618(%rbp), %rdi
movq %rax, %rsi
callq 0x3080
movq %rax, %rdi
leaq 0xd22b(%rip), %rsi      # 0x11101
callq 0x3260
movq %rax, %rdi
movq 0x140d3(%rip), %rsi     # 0x17fb8
callq 0x32a0
movl $0x0, -0x518(%rbp)
movslq -0x518(%rbp), %rax
cmpq 0x1451e(%rip), %rax     # 0x18420
jae 0x41f7
movq -0x10(%rbp), %rdi
leaq 0xd1f8(%rip), %rsi      # 0x1110b
leaq -0x474(%rbp), %rdx
leaq -0x478(%rbp), %rcx
leaq -0x47c(%rbp), %r8
leaq -0x480(%rbp), %r9
movb $0x0, %al
callq 0x3420
cmpl $0x4, %eax
je 0x4087
movb $0x1, -0x599(%rbp)
movl $0x10, %edi
callq 0x3130
movq %rax, -0x620(%rbp)
movl -0x518(%rbp), %esi
leaq -0x598(%rbp), %rdi
callq 0x5cd0
jmp 0x3f6b
leaq 0xd1a6(%rip), %rsi      # 0x11118
leaq -0x578(%rbp), %rdi
leaq -0x598(%rbp), %rdx
callq 0x5c80
jmp 0x3f87
leaq 0xd1b6(%rip), %rdx      # 0x11144
leaq -0x558(%rbp), %rdi
leaq -0x578(%rbp), %rsi
callq 0x5ed0
jmp 0x3fa3
movq -0x8(%rbp), %rdx
leaq -0x538(%rbp), %rdi
leaq -0x558(%rbp), %rsi
callq 0x5e80
jmp 0x3fbc
movq -0x620(%rbp), %rdi
leaq -0x538(%rbp), %rsi
callq 0x3390
jmp 0x3fd1
movq -0x620(%rbp), %rdi
movb $0x0, -0x599(%rbp)
movq 0x1400a(%rip), %rsi     # 0x17ff0
movq 0x13fdb(%rip), %rdx     # 0x17fc8
callq 0x33c0
jmp 0x4265
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x406b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x405f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x4053
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x4047
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x538(%rbp), %rdi
callq 0x3180
leaq -0x558(%rbp), %rdi
callq 0x3180
leaq -0x578(%rbp), %rdi
callq 0x3180
leaq -0x598(%rbp), %rdi
callq 0x3180
testb $0x1, -0x599(%rbp)
jne 0x4076
jmp 0x4082
movq -0x620(%rbp), %rdi
callq 0x31d0
jmp 0x425c
movl -0x474(%rbp), %eax
movl -0x518(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
je 0x417d
movb $0x1, -0x5e1(%rbp)
movl $0x10, %edi
callq 0x3130
movq %rax, -0x628(%rbp)
movl -0x518(%rbp), %esi
leaq -0x5e0(%rbp), %rdi
callq 0x5cd0
jmp 0x40ca
leaq 0xd013(%rip), %rsi      # 0x110e4
leaq -0x5c0(%rbp), %rdi
leaq -0x5e0(%rbp), %rdx
callq 0x5c80
jmp 0x40e6
movq -0x628(%rbp), %rdi
leaq -0x5c0(%rbp), %rsi
callq 0x3390
jmp 0x40fb
movq -0x628(%rbp), %rdi
movb $0x0, -0x5e1(%rbp)
movq 0x13ee0(%rip), %rsi     # 0x17ff0
movq 0x13eb1(%rip), %rdx     # 0x17fc8
callq 0x33c0
jmp 0x4265
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x4161
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x4155
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x5c0(%rbp), %rdi
callq 0x3180
leaq -0x5e0(%rbp), %rdi
callq 0x3180
testb $0x1, -0x5e1(%rbp)
jne 0x416c
jmp 0x4178
movq -0x628(%rbp), %rdi
callq 0x31d0
jmp 0x425c
movl -0x478(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x5e8(%rbp)
leaq 0x1416d(%rip), %rdi     # 0x18300
leaq -0x5e8(%rbp), %rsi
callq 0x5f20
movl -0x47c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x5ec(%rbp)
leaq 0x14163(%rip), %rdi     # 0x18318
leaq -0x5ec(%rbp), %rsi
callq 0x5f20
movl -0x480(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x5f0(%rbp)
leaq 0x14159(%rip), %rdi     # 0x18330
leaq -0x5f0(%rbp), %rsi
callq 0x5f20
movl -0x518(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x518(%rbp)
jmp 0x3ef4
movq 0x13dd2(%rip), %rdi     # 0x17fd0
leaq 0xcef4(%rip), %rsi      # 0x110f9
callq 0x3260
movq %rax, -0x630(%rbp)
leaq 0x140e8(%rip), %rdi     # 0x18300
callq 0x5f50
movq -0x630(%rbp), %rdi
movq %rax, %rsi
callq 0x3080
movq %rax, %rdi
leaq 0xcf13(%rip), %rsi      # 0x11149
callq 0x3260
movq %rax, %rdi
movq 0x13d73(%rip), %rsi     # 0x17fb8
callq 0x32a0
movq -0x10(%rbp), %rdi
callq 0x3270
addq $0x630, %rsp            # imm = 0x630
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x33e0
nopw %cs:(%rax,%rax)