// File: tomfunkhouser[P]gaps/apps/conf2img/conf2img.cpp
// Function: RenderMesh(gaps::R3Mesh const&, int, gaps::R3Point const&, gaps::R3Vector const&, gaps::R3Vector const&)
static void
RenderMesh(const R3Mesh& mesh, int rendering_scheme,
  const R3Point& viewpoint, const R3Vector& towards, const R3Vector& up)
{
  // Clear window
  glViewport(0, 0, width, height);
  glClearColor(0, 0, 0, 0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glEnable(GL_DEPTH_TEST);
  RNLoadRgb(1.0, 1.0, 1.0);

  // Get world to camera matrix
  R3CoordSystem cs(viewpoint, R3Triad(towards, up));
  R4Matrix world_to_camera = cs.InverseMatrix();

  // Draw mesh
  RNGrfxBegin(RN_GRFX_TRIANGLES);
  for (int i = 0; i < mesh.NFaces(); i++) {
    R3MeshFace *face = mesh.Face(i);
    if (skip_removed_faces) {
      // This is a hack to skip faces marked for removal in the matterport dataset
      int category_index = mesh.FaceCategory(face);
      if (category_index == 9) continue;
      if (category_index == 64) continue;
    }
    if ((rendering_scheme >= CAMERA_PX_RENDERING) && (rendering_scheme <= WORLD_PZ_RENDERING)) {
      // Set color per vertex
      for (int j = 0; j < 3; j++) {
        R3MeshVertex *vertex = mesh.VertexOnFace(face, j);
        RNScalar position_coordinate = 0;
        const R3Point& world_position = mesh.VertexPosition(vertex);
        R3Point camera_position = world_to_camera * world_position;
        if (rendering_scheme == CAMERA_PX_RENDERING) position_coordinate = camera_position.X();
        else if (rendering_scheme == CAMERA_PY_RENDERING) position_coordinate = camera_position.Y();
        else if (rendering_scheme == CAMERA_PZ_RENDERING) position_coordinate = camera_position.Z();
        else if (rendering_scheme == WORLD_PX_RENDERING) position_coordinate = world_position.X() - viewpoint.X();
        else if (rendering_scheme == WORLD_PY_RENDERING) position_coordinate = world_position.Y() - viewpoint.Y();
        else if (rendering_scheme == WORLD_PZ_RENDERING) position_coordinate = world_position.Z() - viewpoint.Z();
        int position_value = png_distance_scale * position_coordinate + 32768;
        if (position_value < 0) position_value = 0;
        else if (position_value > 65535) position_value = 65535;
        LoadInteger(position_value);
        R3LoadPoint(world_position);
      }
    }
    else if (((rendering_scheme >= CAMERA_NX_RENDERING) && (rendering_scheme <= CAMERA_NZ_RENDERING)) ||
             ((rendering_scheme >= WORLD_NX_RENDERING) && (rendering_scheme <= WORLD_NZ_RENDERING))) {
      // Set color per face based on normal
      RNScalar normal_coordinate = 0;
      R3Vector world_normal = mesh.FaceNormal(face);
      R3Vector camera_normal = world_to_camera * world_normal; camera_normal.Normalize();
      if (rendering_scheme == CAMERA_NX_RENDERING) normal_coordinate = camera_normal.X();
      else if (rendering_scheme == CAMERA_NY_RENDERING) normal_coordinate = camera_normal.Y();
      else if (rendering_scheme == CAMERA_NZ_RENDERING) normal_coordinate = camera_normal.Z();
      else if (rendering_scheme == WORLD_NX_RENDERING) normal_coordinate = world_normal.X();
      else if (rendering_scheme == WORLD_NY_RENDERING) normal_coordinate = world_normal.Y();
      else if (rendering_scheme == WORLD_NZ_RENDERING) normal_coordinate = world_normal.Z();
      int normal_value = 32768 * (normal_coordinate + 1.0);
      if (normal_value < 0) normal_value = 0;
      else if (normal_value > 65535) normal_value = 65535;
      LoadInteger(normal_value);
      for (int j = 0; j < 3; j++) {
        R3MeshVertex *vertex = mesh.VertexOnFace(face, j);
        const R3Point& position = mesh.VertexPosition(vertex);
        R3LoadPoint(position);
      }
    }
    else if ((rendering_scheme == CAMERA_ND_RENDERING) || (rendering_scheme == WORLD_ND_RENDERING)) {
      RNScalar offset_coordinate = 0;
      R3Vector world_normal = mesh.FaceNormal(face);
      R3Point world_position = mesh.FaceCentroid(face);
      if (rendering_scheme == CAMERA_ND_RENDERING) {
        R3Point camera_position = world_to_camera * world_position;
        R3Vector camera_normal = world_to_camera * world_normal; camera_normal.Normalize();
        offset_coordinate = -camera_position.X()*camera_normal.X() - camera_position.Y()*camera_normal.Y() - camera_position.Z()*camera_normal.Z();
      }
      else if (rendering_scheme == WORLD_ND_RENDERING) {
        offset_coordinate = -world_position.X()*world_normal.X() - world_position.Y()*world_normal.Y() - world_position.Z()*world_normal.Z();
      }
      int offset_value = png_distance_scale * offset_coordinate + 32768;
      if (offset_value < 0) offset_value = 0;
      else if (offset_value > 65535) offset_value = 65535;
      LoadInteger(offset_value);
      for (int j = 0; j < 3; j++) {
        R3MeshVertex *vertex = mesh.VertexOnFace(face, j);
        const R3Point& position = mesh.VertexPosition(vertex);
        R3LoadPoint(position);
      }
    }
    else if (rendering_scheme == NDOTV_RENDERING) {
      // Set color per vertex
      for (int j = 0; j < 3; j++) {
        R3MeshVertex *vertex = mesh.VertexOnFace(face, j);
        const R3Point& world_position = mesh.VertexPosition(vertex);
        R3Vector n = mesh.FaceNormal(face);
        R3Vector v = viewpoint - world_position; v.Normalize();
        RNScalar ndotv = n.Dot(v);
        int ndotv_value = 32768 * (ndotv + 1.0);
        if (ndotv_value < 0) ndotv_value = 0;
        else if (ndotv_value > 65535) ndotv_value = 65535;
        LoadInteger(ndotv_value);
        R3LoadPoint(world_position);
      }
    }
    else if ((rendering_scheme >= FACE_INDEX_RENDERING) && (rendering_scheme <= FACE_CATEGORY_RENDERING)) {
      // Set color per face based on face attributes
      if (rendering_scheme == FACE_INDEX_RENDERING) LoadInteger(mesh.FaceID(face)+1);
      else if (rendering_scheme == FACE_MATERIAL_RENDERING) LoadInteger((mesh.FaceMaterial(face)+1) % 65536);
      else if (rendering_scheme == FACE_SEGMENT_RENDERING) LoadInteger((mesh.FaceSegment(face)+1) % 65536);
      else if (rendering_scheme == FACE_CATEGORY_RENDERING) LoadInteger((mesh.FaceCategory(face)+1) % 65536);
      for (int j = 0; j < 3; j++) {
        R3MeshVertex *vertex = mesh.VertexOnFace(face, j);
        const R3Point& position = mesh.VertexPosition(vertex);
        R3LoadPoint(position);
      }
    }
    else if (rendering_scheme >= COLOR_RENDERING){
      for (int j = 0; j < 3; j++) {
        R3MeshVertex *vertex = mesh.VertexOnFace(face, j);
        const R3Point& position = mesh.VertexPosition(vertex);
        const RNRgb& color = mesh.VertexColor(vertex);
        RNLoadRgb(color);
        R3LoadPoint(position);
      }
    }
    else {
      LoadInteger(0);
      for (int j = 0; j < 3; j++) {
        R3MeshVertex *vertex = mesh.VertexOnFace(face, j);
        const R3Point& position = mesh.VertexPosition(vertex);
        R3LoadPoint(position);
      }
    }
  }
  RNGrfxEnd();
}

// Assembly:
subq $0x388, %rsp            # imm = 0x388
movq %rdi, 0x380(%rsp)
movl %esi, 0x37c(%rsp)
movq %rdx, 0x370(%rsp)
movq %rcx, 0x368(%rsp)
movq %r8, 0x360(%rsp)
movl 0x2273c8(%rip), %edx    # 0x255d9c
movl 0x2273c6(%rip), %ecx    # 0x255da0
xorl %esi, %esi
movl %esi, %edi
callq 0x24230
xorps %xmm3, %xmm3
movaps %xmm3, %xmm0
movaps %xmm3, %xmm1
movaps %xmm3, %xmm2
callq 0x24fe0
movl $0x4100, %edi           # imm = 0x4100
callq 0x24210
movl $0xb71, %edi            # imm = 0xB71
callq 0x24920
movsd 0x1b0618(%rip), %xmm2   # 0x1df028
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x30c80
movq 0x370(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x368(%rsp), %rsi
movq 0x360(%rsp), %rdx
leaq 0x2b8(%rsp), %rdi
callq 0xfc470
movq 0x70(%rsp), %rsi
leaq 0x300(%rsp), %rdi
leaq 0x2b8(%rsp), %rdx
callq 0xfbc80
leaq 0x238(%rsp), %rdi
leaq 0x300(%rsp), %rsi
callq 0xfbd50
movl $0x4, %edi
callq 0x30cb0
movl $0x0, 0x234(%rsp)
movl 0x234(%rsp), %eax
movl %eax, 0x6c(%rsp)
movq 0x380(%rsp), %rdi
callq 0x30660
movl %eax, %ecx
movl 0x6c(%rsp), %eax
cmpl %ecx, %eax
jge 0x2f771
movq 0x380(%rsp), %rdi
movl 0x234(%rsp), %esi
callq 0x30a50
movq %rax, 0x228(%rsp)
cmpl $0x0, 0x2272c2(%rip)    # 0x255d94
je 0x2eb10
movq 0x380(%rsp), %rdi
movq 0x228(%rsp), %rsi
callq 0x30950
movl %eax, 0x224(%rsp)
cmpl $0x9, 0x224(%rsp)
jne 0x2eaff
jmp 0x2f75b
cmpl $0x40, 0x224(%rsp)
jne 0x2eb0e
jmp 0x2f75b
jmp 0x2eb10
cmpl $0x6, 0x37c(%rsp)
jl 0x2ed80
cmpl $0xb, 0x37c(%rsp)
jg 0x2ed80
movl $0x0, 0x220(%rsp)
cmpl $0x3, 0x220(%rsp)
jge 0x2ed7b
movq 0x380(%rsp), %rdi
movq 0x228(%rsp), %rsi
movl 0x220(%rsp), %edx
callq 0x30cd0
movq %rax, 0x218(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x210(%rsp)
movq 0x380(%rsp), %rdi
movq 0x218(%rsp), %rsi
callq 0x30cf0
movq %rax, 0x208(%rsp)
movq 0x208(%rsp), %rdx
leaq 0x1f0(%rsp), %rdi
leaq 0x238(%rsp), %rsi
callq 0x102940
cmpl $0x6, 0x37c(%rsp)
jne 0x2ebd4
leaq 0x1f0(%rsp), %rdi
callq 0x30d10
movsd %xmm0, 0x210(%rsp)
jmp 0x2ecef
cmpl $0x7, 0x37c(%rsp)
jne 0x2ebf9
leaq 0x1f0(%rsp), %rdi
callq 0x30d20
movsd %xmm0, 0x210(%rsp)
jmp 0x2eced
cmpl $0x8, 0x37c(%rsp)
jne 0x2ec1e
leaq 0x1f0(%rsp), %rdi
callq 0x30d30
movsd %xmm0, 0x210(%rsp)
jmp 0x2eceb
cmpl $0x9, 0x37c(%rsp)
jne 0x2ec63
movq 0x208(%rsp), %rdi
callq 0x30d10
movsd %xmm0, 0x60(%rsp)
movq 0x370(%rsp), %rdi
callq 0x30d10
movaps %xmm0, %xmm1
movsd 0x60(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x210(%rsp)
jmp 0x2ece9
cmpl $0xa, 0x37c(%rsp)
jne 0x2eca5
movq 0x208(%rsp), %rdi
callq 0x30d20
movsd %xmm0, 0x58(%rsp)
movq 0x370(%rsp), %rdi
callq 0x30d20
movaps %xmm0, %xmm1
movsd 0x58(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x210(%rsp)
jmp 0x2ece7
cmpl $0xb, 0x37c(%rsp)
jne 0x2ece5
movq 0x208(%rsp), %rdi
callq 0x30d30
movsd %xmm0, 0x50(%rsp)
movq 0x370(%rsp), %rdi
callq 0x30d30
movaps %xmm0, %xmm1
movsd 0x50(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x210(%rsp)
jmp 0x2ece7
jmp 0x2ece9
jmp 0x2eceb
jmp 0x2eced
jmp 0x2ecef
movsd 0x220db1(%rip), %xmm0   # 0x24faa8
movsd 0x210(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x1b0324(%rip), %xmm1   # 0x1df030
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x1ec(%rsp)
cmpl $0x0, 0x1ec(%rsp)
jge 0x2ed32
movl $0x0, 0x1ec(%rsp)
jmp 0x2ed4c
cmpl $0xffff, 0x1ec(%rsp) # imm = 0xFFFF
jle 0x2ed4a
movl $0xffff, 0x1ec(%rsp) # imm = 0xFFFF
jmp 0x2ed4c
movl 0x1ec(%rsp), %edi
callq 0x302e0
movq 0x208(%rsp), %rdi
callq 0x30d40
movl 0x220(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x220(%rsp)
jmp 0x2eb37
jmp 0x2f759
cmpl $0xc, 0x37c(%rsp)
jl 0x2ed94
cmpl $0xe, 0x37c(%rsp)
jle 0x2edb0
cmpl $0x10, 0x37c(%rsp)
jl 0x2efc5
cmpl $0x12, 0x37c(%rsp)
jg 0x2efc5
xorps %xmm0, %xmm0
movsd %xmm0, 0x1e0(%rsp)
movq 0x380(%rsp), %rdi
movq 0x228(%rsp), %rsi
callq 0x30d60
movq %rax, %rsi
leaq 0x1c8(%rsp), %rdi
callq 0x106aa0
leaq 0x1b0(%rsp), %rdi
leaq 0x238(%rsp), %rsi
leaq 0x1c8(%rsp), %rdx
callq 0x1026d0
leaq 0x1b0(%rsp), %rdi
callq 0x1071c0
cmpl $0xc, 0x37c(%rsp)
jne 0x2ee30
leaq 0x1b0(%rsp), %rdi
callq 0x30d90
movsd %xmm0, 0x1e0(%rsp)
jmp 0x2eee5
cmpl $0xd, 0x37c(%rsp)
jne 0x2ee55
leaq 0x1b0(%rsp), %rdi
callq 0x30da0
movsd %xmm0, 0x1e0(%rsp)
jmp 0x2eee3
cmpl $0xe, 0x37c(%rsp)
jne 0x2ee77
leaq 0x1b0(%rsp), %rdi
callq 0x30db0
movsd %xmm0, 0x1e0(%rsp)
jmp 0x2eee1
cmpl $0x10, 0x37c(%rsp)
jne 0x2ee99
leaq 0x1c8(%rsp), %rdi
callq 0x30d90
movsd %xmm0, 0x1e0(%rsp)
jmp 0x2eedf
cmpl $0x11, 0x37c(%rsp)
jne 0x2eebb
leaq 0x1c8(%rsp), %rdi
callq 0x30da0
movsd %xmm0, 0x1e0(%rsp)
jmp 0x2eedd
cmpl $0x12, 0x37c(%rsp)
jne 0x2eedb
leaq 0x1c8(%rsp), %rdi
callq 0x30db0
movsd %xmm0, 0x1e0(%rsp)
jmp 0x2eedd
jmp 0x2eedf
jmp 0x2eee1
jmp 0x2eee3
jmp 0x2eee5
movsd 0x1b013b(%rip), %xmm1   # 0x1df028
addsd 0x1e0(%rsp), %xmm1
movsd 0x1b0132(%rip), %xmm0   # 0x1df030
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x1ac(%rsp)
cmpl $0x0, 0x1ac(%rsp)
jge 0x2ef24
movl $0x0, 0x1ac(%rsp)
jmp 0x2ef3e
cmpl $0xffff, 0x1ac(%rsp) # imm = 0xFFFF
jle 0x2ef3c
movl $0xffff, 0x1ac(%rsp) # imm = 0xFFFF
jmp 0x2ef3e
movl 0x1ac(%rsp), %edi
callq 0x302e0
movl $0x0, 0x1a8(%rsp)
cmpl $0x3, 0x1a8(%rsp)
jge 0x2efc0
movq 0x380(%rsp), %rdi
movq 0x228(%rsp), %rsi
movl 0x1a8(%rsp), %edx
callq 0x30cd0
movq %rax, 0x1a0(%rsp)
movq 0x380(%rsp), %rdi
movq 0x1a0(%rsp), %rsi
callq 0x30cf0
movq %rax, 0x198(%rsp)
movq 0x198(%rsp), %rdi
callq 0x30d40
movl 0x1a8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1a8(%rsp)
jmp 0x2ef55
jmp 0x2f757
cmpl $0xf, 0x37c(%rsp)
je 0x2efdd
cmpl $0x13, 0x37c(%rsp)
jne 0x2f35b
xorps %xmm0, %xmm0
movsd %xmm0, 0x190(%rsp)
movq 0x380(%rsp), %rdi
movq 0x228(%rsp), %rsi
callq 0x30d60
movq %rax, %rsi
leaq 0x178(%rsp), %rdi
callq 0x106aa0
movq 0x380(%rsp), %rsi
movq 0x228(%rsp), %rdx
leaq 0x160(%rsp), %rdi
callq 0xb8260
cmpl $0xf, 0x37c(%rsp)
jne 0x2f177
leaq 0x148(%rsp), %rdi
leaq 0x238(%rsp), %rsi
leaq 0x160(%rsp), %rdx
callq 0x102940
leaq 0x130(%rsp), %rdi
leaq 0x238(%rsp), %rsi
leaq 0x178(%rsp), %rdx
callq 0x1026d0
leaq 0x130(%rsp), %rdi
callq 0x1071c0
leaq 0x148(%rsp), %rdi
callq 0x30d10
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, 0x38(%rsp)
leaq 0x130(%rsp), %rdi
callq 0x30d90
movsd %xmm0, 0x30(%rsp)
leaq 0x148(%rsp), %rdi
callq 0x30d20
movsd %xmm0, 0x28(%rsp)
leaq 0x130(%rsp), %rdi
callq 0x30da0
movsd 0x28(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movaps %xmm0, %xmm3
movsd 0x38(%rsp), %xmm0
mulsd %xmm3, %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
leaq 0x148(%rsp), %rdi
callq 0x30d30
movsd %xmm0, 0x48(%rsp)
leaq 0x130(%rsp), %rdi
callq 0x30db0
movsd 0x40(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x48(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x190(%rsp)
jmp 0x2f277
cmpl $0x13, 0x37c(%rsp)
jne 0x2f275
leaq 0x160(%rsp), %rdi
callq 0x30d10
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x178(%rsp), %rdi
callq 0x30d90
movsd %xmm0, 0x8(%rsp)
leaq 0x160(%rsp), %rdi
callq 0x30d20
movsd %xmm0, (%rsp)
leaq 0x178(%rsp), %rdi
callq 0x30da0
movsd (%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
movaps %xmm0, %xmm3
movsd 0x10(%rsp), %xmm0
mulsd %xmm3, %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
leaq 0x160(%rsp), %rdi
callq 0x30d30
movsd %xmm0, 0x20(%rsp)
leaq 0x178(%rsp), %rdi
callq 0x30db0
movsd 0x18(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x20(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x190(%rsp)
jmp 0x2f277
movsd 0x220829(%rip), %xmm0   # 0x24faa8
movsd 0x190(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x1afd9c(%rip), %xmm1   # 0x1df030
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x12c(%rsp)
cmpl $0x0, 0x12c(%rsp)
jge 0x2f2ba
movl $0x0, 0x12c(%rsp)
jmp 0x2f2d4
cmpl $0xffff, 0x12c(%rsp) # imm = 0xFFFF
jle 0x2f2d2
movl $0xffff, 0x12c(%rsp) # imm = 0xFFFF
jmp 0x2f2d4
movl 0x12c(%rsp), %edi
callq 0x302e0
movl $0x0, 0x128(%rsp)
cmpl $0x3, 0x128(%rsp)
jge 0x2f356
movq 0x380(%rsp), %rdi
movq 0x228(%rsp), %rsi
movl 0x128(%rsp), %edx
callq 0x30cd0
movq %rax, 0x120(%rsp)
movq 0x380(%rsp), %rdi
movq 0x120(%rsp), %rsi
callq 0x30cf0
movq %rax, 0x118(%rsp)
movq 0x118(%rsp), %rdi
callq 0x30d40
movl 0x128(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x128(%rsp)
jmp 0x2f2eb
jmp 0x2f755
cmpl $0x14, 0x37c(%rsp)
jne 0x2f4bd
movl $0x0, 0x114(%rsp)
cmpl $0x3, 0x114(%rsp)
jge 0x2f4b8
movq 0x380(%rsp), %rdi
movq 0x228(%rsp), %rsi
movl 0x114(%rsp), %edx
callq 0x30cd0
movq %rax, 0x108(%rsp)
movq 0x380(%rsp), %rdi
movq 0x108(%rsp), %rsi
callq 0x30cf0
movq %rax, 0x100(%rsp)
movq 0x380(%rsp), %rdi
movq 0x228(%rsp), %rsi
callq 0x30d60
movq %rax, %rsi
leaq 0xe8(%rsp), %rdi
callq 0x106aa0
movq 0x370(%rsp), %rsi
movq 0x100(%rsp), %rdx
leaq 0xd0(%rsp), %rdi
callq 0x105c60
leaq 0xd0(%rsp), %rdi
callq 0x1071c0
leaq 0xe8(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x107070
movsd %xmm0, 0xc8(%rsp)
movsd 0x1afbf0(%rip), %xmm1   # 0x1df028
addsd 0xc8(%rsp), %xmm1
movsd 0x1afbe7(%rip), %xmm0   # 0x1df030
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0xc4(%rsp)
cmpl $0x0, 0xc4(%rsp)
jge 0x2f46f
movl $0x0, 0xc4(%rsp)
jmp 0x2f489
cmpl $0xffff, 0xc4(%rsp) # imm = 0xFFFF
jle 0x2f487
movl $0xffff, 0xc4(%rsp) # imm = 0xFFFF
jmp 0x2f489
movl 0xc4(%rsp), %edi
callq 0x302e0
movq 0x100(%rsp), %rdi
callq 0x30d40
movl 0x114(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x114(%rsp)
jmp 0x2f374
jmp 0x2f753
cmpl $0x2, 0x37c(%rsp)
jl 0x2f61f
cmpl $0x5, 0x37c(%rsp)
jg 0x2f61f
cmpl $0x2, 0x37c(%rsp)
jne 0x2f507
movq 0x380(%rsp), %rdi
movq 0x228(%rsp), %rsi
callq 0x308f0
movl %eax, %edi
addl $0x1, %edi
callq 0x302e0
jmp 0x2f5a4
cmpl $0x3, 0x37c(%rsp)
jne 0x2f53a
movq 0x380(%rsp), %rdi
movq 0x228(%rsp), %rsi
callq 0x30910
addl $0x1, %eax
movl $0x10000, %ecx          # imm = 0x10000
cltd
idivl %ecx
movl %edx, %edi
callq 0x302e0
jmp 0x2f5a2
cmpl $0x4, 0x37c(%rsp)
jne 0x2f56d
movq 0x380(%rsp), %rdi
movq 0x228(%rsp), %rsi
callq 0x30930
addl $0x1, %eax
movl $0x10000, %ecx          # imm = 0x10000
cltd
idivl %ecx
movl %edx, %edi
callq 0x302e0
jmp 0x2f5a0
cmpl $0x5, 0x37c(%rsp)
jne 0x2f59e
movq 0x380(%rsp), %rdi
movq 0x228(%rsp), %rsi
callq 0x30950
addl $0x1, %eax
movl $0x10000, %ecx          # imm = 0x10000
cltd
idivl %ecx
movl %edx, %edi
callq 0x302e0
jmp 0x2f5a0
jmp 0x2f5a2
jmp 0x2f5a4
movl $0x0, 0xc0(%rsp)
cmpl $0x3, 0xc0(%rsp)
jge 0x2f61a
movq 0x380(%rsp), %rdi
movq 0x228(%rsp), %rsi
movl 0xc0(%rsp), %edx
callq 0x30cd0
movq %rax, 0xb8(%rsp)
movq 0x380(%rsp), %rdi
movq 0xb8(%rsp), %rsi
callq 0x30cf0
movq %rax, 0xb0(%rsp)
movq 0xb0(%rsp), %rdi
callq 0x30d40
movl 0xc0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc0(%rsp)
jmp 0x2f5af
jmp 0x2f751
cmpl $0x1, 0x37c(%rsp)
jl 0x2f6d6
movl $0x0, 0xac(%rsp)
cmpl $0x3, 0xac(%rsp)
jge 0x2f6d4
movq 0x380(%rsp), %rdi
movq 0x228(%rsp), %rsi
movl 0xac(%rsp), %edx
callq 0x30cd0
movq %rax, 0xa0(%rsp)
movq 0x380(%rsp), %rdi
movq 0xa0(%rsp), %rsi
callq 0x30cf0
movq %rax, 0x98(%rsp)
movq 0x380(%rsp), %rdi
movq 0xa0(%rsp), %rsi
callq 0x30dc0
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rdi
callq 0x30de0
movq 0x98(%rsp), %rdi
callq 0x30d40
movl 0xac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xac(%rsp)
jmp 0x2f638
jmp 0x2f74f
xorl %edi, %edi
callq 0x302e0
movl $0x0, 0x8c(%rsp)
cmpl $0x3, 0x8c(%rsp)
jge 0x2f74d
movq 0x380(%rsp), %rdi
movq 0x228(%rsp), %rsi
movl 0x8c(%rsp), %edx
callq 0x30cd0
movq %rax, 0x80(%rsp)
movq 0x380(%rsp), %rdi
movq 0x80(%rsp), %rsi
callq 0x30cf0
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rdi
callq 0x30d40
movl 0x8c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8c(%rsp)
jmp 0x2f6e8
jmp 0x2f74f
jmp 0x2f751
jmp 0x2f753
jmp 0x2f755
jmp 0x2f757
jmp 0x2f759
jmp 0x2f75b
movl 0x234(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x234(%rsp)
jmp 0x2ea89
callq 0x30e30
addq $0x388, %rsp            # imm = 0x388
retq
nop