// File: /workspace/github_cpp_makefile_star2_O3/srajangarg[P]raytracer/src/main.cpp
// Function: importSceneToWorld(SceneInstance*, Mat4, int)
void
importSceneToWorld(SceneInstance * inst, Mat4 localToWorld, int time)
{
  if (inst == NULL)
    return;

  Mat4 nodeXform;
  inst->computeTransform(nodeXform, time);
  localToWorld = localToWorld * nodeXform;
  SceneGroup * g = inst->getChild();

  if (g == NULL)   // for example if the whole scene fails to load
  {
    std::cout << "ERROR: We arrived at an instance with no child?!" << std::endl;
    return;
  }

  int ccount = g->getChildCount();

  for (int i = 0; i < ccount; i++)
  {
    importSceneToWorld(g->getChild(i), localToWorld, 0);
  }

  CameraInfo f;

  if (g->computeCamera(f, time))
  {
    viewToWorld = localToWorld;

    if (view != NULL)
      delete view;

    Vec3 eye(0.0, 0.0, 0.0);
    Vec3 LL(f.sides[FRUS_LEFT], f.sides[FRUS_BOTTOM], -f.sides[FRUS_NEAR]);
    Vec3 UL(f.sides[FRUS_LEFT], f.sides[FRUS_TOP], -f.sides[FRUS_NEAR]);
    Vec3 LR(f.sides[FRUS_RIGHT], f.sides[FRUS_BOTTOM], -f.sides[FRUS_NEAR]);
    Vec3 UR(f.sides[FRUS_RIGHT], f.sides[FRUS_TOP], -f.sides[FRUS_NEAR]);
    view = new View(eye, LL, UL, LR, UR, IMAGE_WIDTH, IMAGE_HEIGHT, RAYS_PER_PIXEL_EDGE);
  }

  LightInfo l;

  if (g->computeLight(l, time))
  {
    if (l.type == LIGHT_AMBIENT)
    {
      RGB amb = world->getAmbientLightColor();
      world->setAmbientLightColor(amb + l.color);
    }
    else if (l.type == LIGHT_DIRECTIONAL)
    {
      DirectionalLight * li = new DirectionalLight(l.color);
      Vec3 dir(0, 0, -1);
      li->setDirection(localToWorld * dir);
      world->addLight(li);
    }
    else if (l.type == LIGHT_POINT)
    {
      PointLight * li = new PointLight(l.color, l.falloff, l.deadDistance);
      Vec3 pos(0, 0, 0);
      li->setPosition(localToWorld * pos);
      world->addLight(li);
    }
    else if (l.type == LIGHT_AREA)
    { 
      AreaLight * li = new AreaLight(l.color, l.falloff, l.deadDistance, l.offset);
      Vec3 pos(0, 0, 0);
      li->setPosition(localToWorld * pos);
      world->addLight(li);
    }
    else if (l.type == LIGHT_SPOT)
    {
      throw "oh no";
    }
  }

  double r;
  MaterialInfo m;

  if (g->computeSphere(r, m, time))
  {
    Material mat(m.k[0], m.k[1], m.k[2], m.k[3], m.k[4], m.k[MAT_MS], m.k[5], m.k[6]);
    Sphere * sph = new Sphere(r, m.color, mat, localToWorld);
    world->addPrimitive(sph);
  }

  TriangleMesh * t;
  unordered_map<MeshVertex*, vector<pair<Triangle*, int>> > vertexToTriangles;

  if (g->computeMesh(t, m, time))
  {
    Material mat(m.k[0], m.k[1], m.k[2], m.k[3], m.k[4], m.k[MAT_MS], m.k[5], m.k[6]);

    for (auto it = t->triangles.begin(); it != t->triangles.end(); ++it)
    {
      Triangle * tri = new Triangle(
        t->vertices[ (**it).ind[0] ]->pos,
        t->vertices[ (**it).ind[1] ]->pos,
        t->vertices[ (**it).ind[2] ]->pos,
        m.color, mat, localToWorld, smooth_normals);
      world->addPrimitive(tri);

      if (smooth_normals)
      {
        // map vertex to which triangles this verttex belongs to
        for (int i = 0; i < 3; ++i)
        {
          if(vertexToTriangles.find(t->vertices[(**it).ind[i]]) == vertexToTriangles.end())
            vertexToTriangles[t->vertices[(**it).ind[i]]] = {make_pair(tri, i)};
          else
            vertexToTriangles[t->vertices[(**it).ind[i]]].push_back(make_pair(tri, i));
        }
      }
    }

    if (smooth_normals)
    {
      // calculate average normal at each vertex, and place them at norms
      // in each of the respective triangles
      for (auto it : vertexToTriangles)
      { 
          Vec3 res(0, 0, 0);

          for (auto tripair : it.second)
            res += tripair.first->calculateFaceNormal();
          res.normalize();
          for (auto tripair : it.second)
              tripair.first->norms[tripair.second] = res;
      }
    }
  }

  std::cout << "Imported scene file" << std::endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x338, %rsp            # imm = 0x338
testq %rdi, %rdi
je 0x2a230
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x2b0(%rsp), %r15
movq %r15, %rsi
callq 0x664c
movsd (%rbx), %xmm0
movsd 0x8(%rbx), %xmm7
movsd 0x10(%rbx), %xmm2
movsd 0x18(%rbx), %xmm5
unpcklpd %xmm7, %xmm7            # xmm7 = xmm7[0,0]
movapd (%r15), %xmm8
movapd %xmm8, 0x150(%rsp)
movapd 0x20(%r15), %xmm4
movapd %xmm4, 0x30(%rsp)
movapd 0x40(%r15), %xmm1
movapd %xmm1, 0xb0(%rsp)
movapd 0x60(%r15), %xmm6
movapd %xmm6, 0x160(%rsp)
movapd %xmm7, %xmm3
mulpd %xmm4, %xmm3
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
movapd %xmm0, %xmm4
mulpd %xmm8, %xmm4
addpd %xmm3, %xmm4
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
movapd %xmm2, %xmm3
mulpd %xmm1, %xmm3
addpd %xmm4, %xmm3
unpcklpd %xmm5, %xmm5            # xmm5 = xmm5[0,0]
movapd %xmm5, %xmm1
mulpd %xmm6, %xmm1
addpd %xmm3, %xmm1
movsd 0x28(%rbx), %xmm8
movsd 0x20(%rbx), %xmm3
movsd 0x30(%rbx), %xmm4
movsd 0x38(%rbx), %xmm6
movsd 0x48(%rbx), %xmm15
movsd 0x40(%rbx), %xmm14
movsd 0x50(%rbx), %xmm12
movsd 0x58(%rbx), %xmm13
movsd 0x68(%rbx), %xmm9
movaps %xmm9, 0x170(%rsp)
movsd 0x60(%rbx), %xmm9
movsd 0x70(%rbx), %xmm11
movsd 0x78(%rbx), %xmm10
movupd %xmm1, (%rbx)
movapd 0x30(%r15), %xmm1
movapd %xmm1, 0x90(%rsp)
mulpd %xmm1, %xmm7
movapd 0x10(%r15), %xmm1
movapd %xmm1, 0xd0(%rsp)
mulpd %xmm1, %xmm0
addpd %xmm7, %xmm0
movapd 0x50(%r15), %xmm1
movapd %xmm1, 0xc0(%rsp)
mulpd %xmm1, %xmm2
addpd %xmm0, %xmm2
movapd 0x70(%r15), %xmm0
movapd %xmm0, 0x140(%rsp)
mulpd %xmm0, %xmm5
addpd %xmm2, %xmm5
movupd %xmm5, 0x10(%rbx)
unpcklpd %xmm8, %xmm8            # xmm8 = xmm8[0,0]
movapd 0x30(%rsp), %xmm0
mulpd %xmm8, %xmm0
unpcklpd %xmm3, %xmm3            # xmm3 = xmm3[0,0]
movapd %xmm3, %xmm1
movapd 0x150(%rsp), %xmm7
mulpd %xmm7, %xmm1
addpd %xmm0, %xmm1
unpcklpd %xmm4, %xmm4            # xmm4 = xmm4[0,0]
movapd %xmm4, %xmm0
movapd 0xb0(%rsp), %xmm5
mulpd %xmm5, %xmm0
addpd %xmm1, %xmm0
unpcklpd %xmm6, %xmm6            # xmm6 = xmm6[0,0]
movapd %xmm6, %xmm1
movapd 0x160(%rsp), %xmm2
mulpd %xmm2, %xmm1
addpd %xmm0, %xmm1
movupd %xmm1, 0x20(%rbx)
mulpd 0x90(%rsp), %xmm8
mulpd 0xd0(%rsp), %xmm3
addpd %xmm8, %xmm3
mulpd 0xc0(%rsp), %xmm4
addpd %xmm3, %xmm4
movapd 0x140(%rsp), %xmm3
mulpd %xmm3, %xmm6
addpd %xmm4, %xmm6
movupd %xmm6, 0x30(%rbx)
unpcklpd %xmm15, %xmm15          # xmm15 = xmm15[0,0]
movapd 0x30(%rsp), %xmm6
movapd %xmm6, %xmm0
mulpd %xmm15, %xmm0
unpcklpd %xmm14, %xmm14          # xmm14 = xmm14[0,0]
movapd %xmm14, %xmm1
mulpd %xmm7, %xmm1
movapd %xmm7, %xmm4
addpd %xmm0, %xmm1
unpcklpd %xmm12, %xmm12          # xmm12 = xmm12[0,0]
movapd %xmm12, %xmm0
mulpd %xmm5, %xmm0
addpd %xmm1, %xmm0
unpcklpd %xmm13, %xmm13          # xmm13 = xmm13[0,0]
movapd %xmm13, %xmm1
mulpd %xmm2, %xmm1
addpd %xmm0, %xmm1
movupd %xmm1, 0x40(%rbx)
movapd 0x90(%rsp), %xmm7
mulpd %xmm7, %xmm15
movapd 0xd0(%rsp), %xmm8
mulpd %xmm8, %xmm14
addpd %xmm15, %xmm14
movapd 0xc0(%rsp), %xmm15
mulpd %xmm15, %xmm12
addpd %xmm14, %xmm12
mulpd %xmm3, %xmm13
addpd %xmm12, %xmm13
movupd %xmm13, 0x50(%rbx)
movapd 0x170(%rsp), %xmm0
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
movapd %xmm6, %xmm1
mulpd %xmm0, %xmm1
movapd %xmm0, %xmm5
unpcklpd %xmm9, %xmm9            # xmm9 = xmm9[0,0]
movapd %xmm4, %xmm0
mulpd %xmm9, %xmm0
addpd %xmm1, %xmm0
movapd %xmm0, %xmm1
unpcklpd %xmm11, %xmm11          # xmm11 = xmm11[0,0]
movapd 0xb0(%rsp), %xmm0
mulpd %xmm11, %xmm0
addpd %xmm1, %xmm0
unpcklpd %xmm10, %xmm10          # xmm10 = xmm10[0,0]
movapd %xmm2, %xmm1
mulpd %xmm10, %xmm1
addpd %xmm0, %xmm1
movupd %xmm1, 0x60(%rbx)
mulpd %xmm7, %xmm5
mulpd %xmm8, %xmm9
addpd %xmm5, %xmm9
mulpd %xmm15, %xmm11
addpd %xmm9, %xmm11
mulpd %xmm3, %xmm10
addpd %xmm11, %xmm10
movupd %xmm10, 0x70(%rbx)
movq %r14, %rdi
callq 0x6578
testq %rax, %rax
je 0x29adb
movq %rax, %r14
movq %rax, %rdi
callq 0x5d9e
testl %eax, %eax
jle 0x298cd
movl %eax, %r15d
xorl %r12d, %r12d
leaq 0x210(%rsp), %r13
movq %r14, %rdi
movl %r12d, %esi
callq 0x5dac
movups (%rbx), %xmm0
movaps %xmm0, 0x210(%rsp)
movups 0x10(%rbx), %xmm0
movaps %xmm0, 0x220(%rsp)
movups 0x20(%rbx), %xmm0
movaps %xmm0, 0x230(%rsp)
movups 0x30(%rbx), %xmm0
movaps %xmm0, 0x240(%rsp)
movups 0x40(%rbx), %xmm0
movaps %xmm0, 0x250(%rsp)
movups 0x50(%rbx), %xmm0
movaps %xmm0, 0x260(%rsp)
movups 0x60(%rbx), %xmm0
movaps %xmm0, 0x270(%rsp)
movupd 0x70(%rbx), %xmm0
movapd %xmm0, 0x280(%rsp)
movq %rax, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x294f3
incl %r12d
cmpl %r12d, %r15d
jne 0x29848
leaq 0x1d8(%rsp), %rsi
movq %r14, %rdi
movl %ebp, %edx
callq 0x5f42
testb %al, %al
je 0x29a34
movl %ebp, 0x30(%rsp)
movups (%rbx), %xmm0
movaps %xmm0, 0xdc2b(%rip)     # 0x37520
movups 0x10(%rbx), %xmm0
movaps %xmm0, 0xdc30(%rip)     # 0x37530
movups 0x20(%rbx), %xmm0
movaps %xmm0, 0xdc35(%rip)     # 0x37540
movups 0x30(%rbx), %xmm0
movaps %xmm0, 0xdc3a(%rip)     # 0x37550
movups 0x40(%rbx), %xmm0
movaps %xmm0, 0xdc3f(%rip)     # 0x37560
movups 0x50(%rbx), %xmm0
movaps %xmm0, 0xdc44(%rip)     # 0x37570
movups 0x60(%rbx), %xmm0
movaps %xmm0, 0xdc49(%rip)     # 0x37580
movups 0x70(%rbx), %xmm0
movaps %xmm0, 0xdc4e(%rip)     # 0x37590
movq 0xdbcf(%rip), %rdi      # 0x37518
testq %rdi, %rdi
je 0x29954
movq (%rdi), %rax
callq *0x8(%rax)
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rax
movaps %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movsd 0x1e0(%rsp), %xmm0
movsd 0x200(%rsp), %xmm1
xorpd 0x17df(%rip), %xmm1     # 0x2b160
leaq 0x100(%rsp), %rax
movsd %xmm0, (%rax)
movupd 0x1e8(%rsp), %xmm2
leaq 0xe0(%rsp), %rbp
movapd %xmm2, (%rbp)
leaq 0x10(%rsp), %r15
movlpd %xmm2, (%r15)
shufpd $0x1, %xmm1, %xmm2      # xmm2 = xmm2[1],xmm1[0]
movupd %xmm2, 0x8(%rax)
movsd 0x1f8(%rsp), %xmm2
leaq 0x1a0(%rsp), %r12
movsd %xmm0, (%r12)
movsd %xmm2, 0x8(%r12)
movlpd %xmm1, 0x10(%r12)
movlpd %xmm1, 0x10(%rbp)
movsd %xmm2, 0x8(%r15)
movlpd %xmm1, 0x10(%r15)
movl $0x90, %edi
callq 0x4300
movq %rax, %r13
subq $0x8, %rsp
movl $0x200, %eax            # imm = 0x200
movq %r13, %rdi
leaq 0x48(%rsp), %rsi
leaq 0x108(%rsp), %rdx
movq %r12, %rcx
movq %rbp, %r8
movq %r15, %r9
pushq $0x2
pushq %rax
pushq %rax
callq 0x27dc4
addq $0x20, %rsp
movq %r13, 0xdae8(%rip)      # 0x37518
movl 0x30(%rsp), %ebp
xorpd %xmm0, %xmm0
leaq 0x100(%rsp), %rsi
movupd %xmm0, 0x8(%rsi)
movq $0x0, 0x18(%rsi)
movq %r14, %rdi
movl %ebp, %edx
callq 0x5ede
testb %al, %al
je 0x29e0c
movl 0x100(%rsp), %eax
cmpq $0x4, %rax
ja 0x29e0c
leaq 0x108(%rsp), %r12
leaq 0x3af5(%rip), %rcx      # 0x2d574
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0xda81(%rip), %rsi      # 0x37510
leaq 0x40(%rsp), %r15
movq %r15, %rdi
callq 0x28288
movsd 0x10(%r15), %xmm0
addsd 0x118(%rsp), %xmm0
movupd 0x108(%rsp), %xmm1
addpd (%r15), %xmm1
movq 0xda50(%rip), %rdi      # 0x37510
leaq 0x290(%rsp), %rsi
movapd %xmm1, (%rsi)
movsd %xmm0, 0x10(%rsi)
callq 0x2827e
jmp 0x29e0c
movq 0xd4ee(%rip), %rbx      # 0x36fd0
leaq 0x3a9f(%rip), %rsi      # 0x2d588
movl $0x30, %edx
movq %rbx, %rdi
callq 0x4360
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x42e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4050
movq %rax, %rdi
callq 0x4220
jmp 0x2a230
movl $0x50, %edi
callq 0x4300
movq %rax, %r15
movsd 0x120(%rsp), %xmm0
movsd 0x130(%rsp), %xmm1
movq %rax, %rdi
movq %r12, %rsi
callq 0x2611a
movsd (%rbx), %xmm1
movsd 0x8(%rbx), %xmm2
movsd 0x10(%rbx), %xmm3
movsd 0x18(%rbx), %xmm0
movhpd 0x28(%rbx), %xmm2       # xmm2 = xmm2[0],mem[0]
xorpd %xmm4, %xmm4
mulpd %xmm4, %xmm2
movhpd 0x20(%rbx), %xmm1       # xmm1 = xmm1[0],mem[0]
mulpd %xmm4, %xmm1
addpd %xmm2, %xmm1
movhpd 0x30(%rbx), %xmm3       # xmm3 = xmm3[0],mem[0]
mulpd %xmm4, %xmm3
addpd %xmm1, %xmm3
movhpd 0x38(%rbx), %xmm0       # xmm0 = xmm0[0],mem[0]
addpd %xmm3, %xmm0
xorpd %xmm2, %xmm2
movsd 0x48(%rbx), %xmm1
mulsd %xmm2, %xmm1
movsd 0x40(%rbx), %xmm3
mulsd %xmm2, %xmm3
addsd %xmm1, %xmm3
movsd 0x50(%rbx), %xmm1
mulsd %xmm2, %xmm1
addsd %xmm3, %xmm1
addsd 0x58(%rbx), %xmm1
movsd 0x68(%rbx), %xmm3
mulsd %xmm2, %xmm3
movsd 0x60(%rbx), %xmm4
mulsd %xmm2, %xmm4
addsd %xmm3, %xmm4
movsd 0x70(%rbx), %xmm3
mulsd %xmm2, %xmm3
addsd %xmm4, %xmm3
addsd 0x78(%rbx), %xmm3
movapd %xmm0, 0x40(%rsp)
movsd %xmm1, 0x50(%rsp)
ucomisd %xmm2, %xmm3
jne 0x29bf7
jnp 0x29c0f
divsd %xmm3, %xmm1
unpcklpd %xmm3, %xmm3            # xmm3 = xmm3[0,0]
divpd %xmm3, %xmm0
movapd %xmm0, 0x40(%rsp)
movsd %xmm1, 0x50(%rsp)
leaq 0x40(%rsp), %rsi
movq %r15, %rdi
callq 0x261e6
jmp 0x29dfd
movl $0x58, %edi
callq 0x4300
movq %rax, %r15
movsd 0x120(%rsp), %xmm0
movsd 0x130(%rsp), %xmm1
movsd 0x138(%rsp), %xmm2
movq %rax, %rdi
movq %r12, %rsi
callq 0x26304
movsd (%rbx), %xmm1
movsd 0x8(%rbx), %xmm2
movsd 0x10(%rbx), %xmm3
movsd 0x18(%rbx), %xmm0
movhpd 0x28(%rbx), %xmm2       # xmm2 = xmm2[0],mem[0]
xorpd %xmm4, %xmm4
mulpd %xmm4, %xmm2
movhpd 0x20(%rbx), %xmm1       # xmm1 = xmm1[0],mem[0]
mulpd %xmm4, %xmm1
addpd %xmm2, %xmm1
movhpd 0x30(%rbx), %xmm3       # xmm3 = xmm3[0],mem[0]
mulpd %xmm4, %xmm3
addpd %xmm1, %xmm3
movhpd 0x38(%rbx), %xmm0       # xmm0 = xmm0[0],mem[0]
addpd %xmm3, %xmm0
xorpd %xmm2, %xmm2
movsd 0x48(%rbx), %xmm1
mulsd %xmm2, %xmm1
movsd 0x40(%rbx), %xmm3
mulsd %xmm2, %xmm3
addsd %xmm1, %xmm3
movsd 0x50(%rbx), %xmm1
mulsd %xmm2, %xmm1
addsd %xmm3, %xmm1
addsd 0x58(%rbx), %xmm1
movsd 0x68(%rbx), %xmm3
mulsd %xmm2, %xmm3
movsd 0x60(%rbx), %xmm4
mulsd %xmm2, %xmm4
addsd %xmm3, %xmm4
movsd 0x70(%rbx), %xmm3
mulsd %xmm2, %xmm3
addsd %xmm4, %xmm3
addsd 0x78(%rbx), %xmm3
movapd %xmm0, 0x40(%rsp)
movsd %xmm1, 0x50(%rsp)
ucomisd %xmm2, %xmm3
jne 0x29cff
jnp 0x29d17
divsd %xmm3, %xmm1
unpcklpd %xmm3, %xmm3            # xmm3 = xmm3[0,0]
divpd %xmm3, %xmm0
movapd %xmm0, 0x40(%rsp)
movsd %xmm1, 0x50(%rsp)
leaq 0x40(%rsp), %rsi
movq %r15, %rdi
callq 0x263d4
jmp 0x29dfd
movl $0x50, %edi
callq 0x4300
movq %rax, %r15
movq %rax, %rdi
movq %r12, %rsi
callq 0x2657e
movsd (%rbx), %xmm1
movsd 0x8(%rbx), %xmm2
movsd 0x10(%rbx), %xmm3
movhpd 0x28(%rbx), %xmm2       # xmm2 = xmm2[0],mem[0]
movsd 0x18(%rbx), %xmm0
xorpd %xmm4, %xmm4
movhpd 0x20(%rbx), %xmm1       # xmm1 = xmm1[0],mem[0]
mulpd %xmm4, %xmm2
mulpd %xmm4, %xmm1
movhpd 0x30(%rbx), %xmm3       # xmm3 = xmm3[0],mem[0]
addpd %xmm2, %xmm1
subpd %xmm3, %xmm1
movhpd 0x38(%rbx), %xmm0       # xmm0 = xmm0[0],mem[0]
xorpd %xmm3, %xmm3
movsd 0x48(%rbx), %xmm4
mulsd %xmm3, %xmm4
movsd 0x40(%rbx), %xmm2
mulsd %xmm3, %xmm2
addsd %xmm4, %xmm2
subsd 0x50(%rbx), %xmm2
addpd %xmm1, %xmm0
addsd 0x58(%rbx), %xmm2
movsd 0x68(%rbx), %xmm4
mulsd %xmm3, %xmm4
movsd 0x60(%rbx), %xmm1
mulsd %xmm3, %xmm1
addsd %xmm4, %xmm1
subsd 0x70(%rbx), %xmm1
addsd 0x78(%rbx), %xmm1
movapd %xmm0, 0x40(%rsp)
movsd %xmm2, 0x50(%rsp)
ucomisd %xmm3, %xmm1
jne 0x29dd8
jnp 0x29df0
divsd %xmm1, %xmm2
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
divpd %xmm1, %xmm0
movapd %xmm0, 0x40(%rsp)
movsd %xmm2, 0x50(%rsp)
leaq 0x40(%rsp), %rsi
movq %r15, %rdi
callq 0x265b6
movq 0xd70c(%rip), %rdi      # 0x37510
movq %r15, %rsi
callq 0x28254
leaq 0x78(%rsp), %rax
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq $0x0, 0x10(%rax)
leaq 0xa8(%rsp), %rsi
leaq 0x40(%rsp), %rdx
movq %r14, %rdi
movl %ebp, %ecx
callq 0x5e4e
testb %al, %al
je 0x29ec2
xorps %xmm0, %xmm0
cvtsd2ss 0x60(%rsp), %xmm0
movupd 0x50(%rsp), %xmm1
cvtpd2ps %xmm1, %xmm1
movupd 0x68(%rsp), %xmm2
cvtpd2ps 0x40(%rsp), %xmm3
unpcklpd %xmm1, %xmm3            # xmm3 = xmm3[0],xmm1[0]
leaq 0x1a0(%rsp), %r12
movapd %xmm3, (%r12)
movss %xmm0, 0x10(%r12)
movss %xmm1, 0x14(%r12)
cvtpd2ps %xmm2, %xmm0
movlpd %xmm0, 0x18(%r12)
movl $0x148, %edi            # imm = 0x148
callq 0x4300
movq %rax, %r15
movsd 0xa8(%rsp), %xmm0
movq %rax, %rdi
leaq 0x78(%rsp), %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x26b74
movq 0xd656(%rip), %rdi      # 0x37510
movq %r15, %rsi
callq 0x2822a
leaq 0x1d0(%rsp), %rax
movq %rax, -0x30(%rax)
movq $0x1, -0x28(%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, -0x20(%rax)
movl $0x3f800000, -0x10(%rax) # imm = 0x3F800000
movupd %xmm0, -0x8(%rax)
leaq 0x8(%rsp), %rsi
leaq 0x40(%rsp), %rdx
movq %r14, %rdi
movl %ebp, %ecx
callq 0x5ddc
testb %al, %al
je 0x2a1dd
xorps %xmm0, %xmm0
cvtsd2ss 0x60(%rsp), %xmm0
movupd 0x50(%rsp), %xmm1
cvtpd2ps %xmm1, %xmm1
cvtpd2ps 0x40(%rsp), %xmm2
movupd 0x68(%rsp), %xmm3
unpcklpd %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0]
movapd %xmm2, 0xe0(%rsp)
movss %xmm0, 0xf0(%rsp)
movss %xmm1, 0xf4(%rsp)
cvtpd2ps %xmm3, %xmm0
movlpd %xmm0, 0xf8(%rsp)
movq 0x8(%rsp), %r14
movq 0x18(%r14), %r12
cmpq 0x20(%r14), %r12
je 0x2a0a3
leaq 0x1a0(%rsp), %r13
leaq 0x10(%rsp), %rbp
movl $0x1d8, %edi            # imm = 0x1D8
callq 0x4300
movq %rax, %r15
movq (%r12), %rax
movslq (%rax), %rcx
movq (%r14), %rdi
movq (%rdi,%rcx,8), %rsi
movslq 0x4(%rax), %rcx
movq (%rdi,%rcx,8), %rdx
movslq 0x8(%rax), %rax
movq (%rdi,%rax,8), %rcx
movzbl 0xd604(%rip), %eax      # 0x375a8
movq %r15, %rdi
leaq 0x78(%rsp), %r8
leaq 0xe0(%rsp), %r9
pushq %rax
pushq %rbx
callq 0x27102
addq $0x10, %rsp
movq 0xd54a(%rip), %rdi      # 0x37510
movq %r15, %rsi
callq 0x2822a
cmpb $0x1, 0xd5d3(%rip)      # 0x375a8
jne 0x2a090
xorl %r14d, %r14d
movq 0x8(%rsp), %rax
movq (%r12), %rcx
movslq (%rcx,%r14,4), %rsi
shlq $0x3, %rsi
addq (%rax), %rsi
movq %r13, %rdi
callq 0x2a772
testq %rax, %rax
je 0x2a040
movq 0x8(%rsp), %rax
movq (%r12), %rcx
movslq (%rcx,%r14,4), %rsi
shlq $0x3, %rsi
addq (%rax), %rsi
movq %r13, %rdi
callq 0x2a7ce
movq %r15, 0x10(%rsp)
movl %r14d, 0x18(%rsp)
movq 0x8(%rax), %rsi
cmpq 0x10(%rax), %rsi
je 0x2a078
movupd 0x10(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x10, 0x8(%rax)
jmp 0x2a083
movq %r15, 0x10(%rsp)
movl %r14d, 0x18(%rsp)
movq 0x8(%rsp), %rax
movq (%r12), %rcx
movslq (%rcx,%r14,4), %rsi
shlq $0x3, %rsi
addq (%rax), %rsi
movq %r13, %rdi
callq 0x2a7ce
movq %rax, %rdi
movq %rbp, %rsi
leaq 0x20(%rsp), %rdx
callq 0x2aab8
jmp 0x2a083
movq %rax, %rdi
movq %rbp, %rdx
callq 0x2abe4
incq %r14
cmpq $0x3, %r14
jne 0x29fde
addq $0x8, %r12
movq 0x8(%rsp), %r14
cmpq 0x20(%r14), %r12
jne 0x29f72
cmpb $0x0, 0xd4fe(%rip)      # 0x375a8
je 0x2a1dd
movq 0x1b0(%rsp), %r15
testq %r15, %r15
je 0x2a1dd
leaq 0x18(%rsp), %rbx
leaq 0x180(%rsp), %r14
movq 0x8(%r15), %rax
movq %rax, 0x10(%rsp)
leaq 0x10(%r15), %rsi
movq %rbx, %rdi
callq 0x2a642
movq 0x18(%rsp), %r12
movq 0x20(%rsp), %r13
xorpd %xmm3, %xmm3
xorpd %xmm2, %xmm2
cmpq %r13, %r12
je 0x2a14b
movapd %xmm3, 0x90(%rsp)
movsd %xmm2, 0x30(%rsp)
movq (%r12), %rsi
movq %r14, %rdi
callq 0x27a7c
movapd 0x90(%rsp), %xmm3
addpd 0x180(%rsp), %xmm3
movsd 0x30(%rsp), %xmm2
addsd 0x190(%rsp), %xmm2
addq $0x10, %r12
cmpq %r13, %r12
jne 0x2a0fa
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %r12
jmp 0x2a14e
movq %r12, %rdi
cmpq %r12, %rdi
je 0x2a1bf
movapd %xmm3, %xmm0
mulpd %xmm3, %xmm0
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
movapd %xmm3, %xmm1
mulsd %xmm3, %xmm1
addsd %xmm0, %xmm1
movapd %xmm2, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
xorps %xmm1, %xmm1
sqrtsd %xmm0, %xmm1
movsd 0xfc2(%rip), %xmm0      # 0x2b148
divsd %xmm1, %xmm0
mulsd %xmm0, %xmm2
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd %xmm3, %xmm0
movq %rdi, %rax
movq (%rax), %rcx
movslq 0x8(%rax), %rdx
leaq (%rdx,%rdx,2), %rdx
movupd %xmm0, 0x140(%rcx,%rdx,8)
movsd %xmm2, 0x150(%rcx,%rdx,8)
addq $0x10, %rax
cmpq %r12, %rax
jne 0x2a199
testq %rdi, %rdi
je 0x2a1d1
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x4310
movq (%r15), %r15
testq %r15, %r15
jne 0x2a0ce
movq 0xcdec(%rip), %rbx      # 0x36fd0
leaq 0x33d4(%rip), %rsi      # 0x2d5bf
movl $0x13, %edx
movq %rbx, %rdi
callq 0x4360
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x42e0
movsbl %al, %esi
movq 0xcdba(%rip), %rdi      # 0x36fd0
callq 0x4050
movq %rax, %rdi
callq 0x4220
leaq 0x1a0(%rsp), %rdi
callq 0x2a6d6
addq $0x338, %rsp            # imm = 0x338
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x8, %edi
callq 0x4190
leaq 0x3366(%rip), %rcx      # 0x2d5b9
movq %rcx, (%rax)
movq 0xcd5b(%rip), %rsi      # 0x36fb8
movq %rax, %rdi
xorl %edx, %edx
callq 0x4560
jmp 0x2a273
movq %rax, %rbx
movl $0x58, %esi
jmp 0x2a285
movq %rax, %rbx
movl $0x50, %esi
jmp 0x2a285
movq %rax, %rbx
movl $0x148, %esi            # imm = 0x148
movq %r15, %rdi
jmp 0x2a295
movq %rax, %rbx
movl $0x90, %esi
movq %r13, %rdi
callq 0x4310
jmp 0x2a2e1
jmp 0x2a2d1
jmp 0x2a2d1
movq %rax, %rbx
movl $0x1d8, %esi            # imm = 0x1D8
movq %r15, %rdi
jmp 0x2a2c6
jmp 0x2a2d1
jmp 0x2a2d1
movq %rax, %rbx
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x2a2d4
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x4310
jmp 0x2a2d4
jmp 0x2a2d1
jmp 0x2a2d1
movq %rax, %rbx
leaq 0x1a0(%rsp), %rdi
callq 0x2a6d6
movq %rbx, %rdi
callq 0x45b0