// File: /workspace/github_c_makefile_star2_O0/archer1357[P]Offline-Raytracer/main.c
// Function: initScene
bool initScene(struct Scene *scene) {

  struct KdNode *rootNode;
  float minBound[3],maxBound[3];
  struct Triangle *triangles=0;
  struct Sphere *spheres=0;
  struct PointLight *pointLights=0;
  int trianglesNum=0;
  int spheresNum=0;
  int pointLightsNum=0;

  struct BoundingBox *bounds;
  int boundsNum;

  //
#ifdef RUN_TEST
  if(!loadMesh_old("data/sibenik_test.oldmesh",&triangles,&trianglesNum)) {
    return false;
  }
#else
  if(!loadMesh_old("data/sibenik.oldmesh",&triangles,&trianglesNum)) {
    return false;
  }
#endif

  spheresNum=1;
  spheres=(struct Sphere*)malloc(sizeof(struct Sphere)*spheresNum);

  spheres[0].material.col[0]=0.6f;
  spheres[0].material.col[1]=0.7f;
  spheres[0].material.col[2]=0.9f;
  spheres[0].material.reflectAmount=0.2f;
  spheres[0].material.shininess=0.1f;
  spheres[0].material.intensity=0.9f;
  spheres[0].material.diffuseRefl=0.3f;
  spheres[0].pos[0]=2.0f;
  spheres[0].pos[1]=-8.0f;
  spheres[0].pos[2]=-12.2f;
  spheres[0].radius=2.0f;

  boundsNum=trianglesNum+spheresNum;

  if(boundsNum==0) {

    return false;
  }

  bounds=(struct BoundingBox*)malloc(sizeof(struct BoundingBox)*boundsNum);
  calcBounds(triangles,trianglesNum,spheres,spheresNum,
             minBound,maxBound,bounds);

  //
  int kdtreeMaxDepth;
  kdtreeMaxDepth=calcApropiateKdtreeDepth(boundsNum);

  rootNode=buildKdTree(bounds,boundsNum,
                       minBound,maxBound,
                       kdtreeMaxDepth);


  if(!rootNode) {
    return false;
  }

  //
  pointLightsNum=2;
  pointLights=(struct PointLight*)
    malloc(sizeof(struct PointLight)*pointLightsNum);

  pointLights[0].col[0]=1.0f;
  pointLights[0].col[1]=1.0f;
  pointLights[0].col[2]=1.0f;
  pointLights[0].pos[0]=3.0f;//-22.0;
  pointLights[0].pos[1]=10.0f;//13.0;
  pointLights[0].pos[2]=-10.0f;//25.0;
  pointLights[0].constAtten=0.8f;
  pointLights[0].linAtten=0.1f;
  pointLights[0].quadAtten=0.0001f;


  pointLights[1].col[0]=1.0f;
  pointLights[1].col[1]=1.0f;
  pointLights[1].col[2]=1.0f;
  pointLights[1].pos[0]=3.0f;//-22.0;
  pointLights[1].pos[1]=10.0f;//13.0;
  pointLights[1].pos[2]=24.0f;//25.0;
  pointLights[1].constAtten=0.8f;
  pointLights[1].linAtten=0.1f;
  pointLights[1].quadAtten=0.0001f;


  //
  scene->triangles=triangles;
  scene->spheres=spheres;
  scene->pointLights=pointLights;
  scene->trianglesNum=trianglesNum;
  scene->spheresNum=spheresNum;
  scene->pointLightsNum=pointLightsNum;

  scene->rootNode=rootNode;
  scene->kdtreeDepth=kdtreeMaxDepth;

  memcpy(scene->minBound,minBound,sizeof(minBound));
  memcpy(scene->maxBound,maxBound,sizeof(maxBound));
  //


  //
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
leaq 0xd897c(%rip), %rdi     # 0x4e4a8c
leaq -0x38(%rbp), %rsi
leaq -0x4c(%rbp), %rdx
callq 0x422520
testb $0x1, %al
jne 0x40c12a
movb $0x0, -0x1(%rbp)
jmp 0x40c447
movl $0x1, -0x50(%rbp)
movslq -0x50(%rbp), %rax
imulq $0x2c, %rax, %rdi
callq 0x452d20
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movss 0xd87fa(%rip), %xmm0    # 0x4e4948
movss %xmm0, (%rax)
movq -0x40(%rbp), %rax
movss 0xd87e6(%rip), %xmm0    # 0x4e4944
movss %xmm0, 0x4(%rax)
movq -0x40(%rbp), %rax
movss 0xd87c9(%rip), %xmm0    # 0x4e4938
movss %xmm0, 0x8(%rax)
movq -0x40(%rbp), %rax
movss 0xd87c0(%rip), %xmm0    # 0x4e4940
movss %xmm0, 0xc(%rax)
movq -0x40(%rbp), %rax
movss 0xd87ab(%rip), %xmm0    # 0x4e493c
movss %xmm0, 0x10(%rax)
movq -0x40(%rbp), %rax
movss 0xd8796(%rip), %xmm0    # 0x4e4938
movss %xmm0, 0x14(%rax)
movq -0x40(%rbp), %rax
movss 0xd8781(%rip), %xmm0    # 0x4e4934
movss %xmm0, 0x18(%rax)
movq -0x40(%rbp), %rax
movss 0xd8748(%rip), %xmm0    # 0x4e490c
movss %xmm0, 0x1c(%rax)
movq -0x40(%rbp), %rax
movss 0xd875b(%rip), %xmm0    # 0x4e4930
movss %xmm0, 0x20(%rax)
movq -0x40(%rbp), %rax
movss 0xd8746(%rip), %xmm0    # 0x4e492c
movss %xmm0, 0x24(%rax)
movq -0x40(%rbp), %rax
movss 0xd8715(%rip), %xmm0    # 0x4e490c
movss %xmm0, 0x28(%rax)
movl -0x4c(%rbp), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
jne 0x40c214
movb $0x0, -0x1(%rbp)
jmp 0x40c447
movslq -0x64(%rbp), %rax
imulq $0x18, %rax, %rdi
callq 0x452d20
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rdi
movl -0x4c(%rbp), %esi
movq -0x40(%rbp), %rdx
movl -0x50(%rbp), %ecx
leaq -0x24(%rbp), %r8
leaq -0x30(%rbp), %r9
movq -0x60(%rbp), %rax
movq %rax, (%rsp)
callq 0x422930
movl -0x64(%rbp), %edi
callq 0x40a420
movl %eax, -0x68(%rbp)
movq -0x60(%rbp), %rdi
movl -0x64(%rbp), %esi
leaq -0x24(%rbp), %rdx
leaq -0x30(%rbp), %rcx
movl -0x68(%rbp), %r8d
callq 0x40a490
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x40c27f
movb $0x0, -0x1(%rbp)
jmp 0x40c447
movl $0x2, -0x54(%rbp)
movslq -0x54(%rbp), %rax
imulq $0x24, %rax, %rdi
callq 0x452d20
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movss 0xd71e1(%rip), %xmm0    # 0x4e3484
movss %xmm0, (%rax)
movq -0x48(%rbp), %rax
movss 0xd71d1(%rip), %xmm0    # 0x4e3484
movss %xmm0, 0x4(%rax)
movq -0x48(%rbp), %rax
movss 0xd71c0(%rip), %xmm0    # 0x4e3484
movss %xmm0, 0x8(%rax)
movq -0x48(%rbp), %rax
movss 0xd8687(%rip), %xmm0    # 0x4e495c
movss %xmm0, 0xc(%rax)
movq -0x48(%rbp), %rax
movss 0xd8672(%rip), %xmm0    # 0x4e4958
movss %xmm0, 0x10(%rax)
movq -0x48(%rbp), %rax
movss 0xd8669(%rip), %xmm0    # 0x4e4960
movss %xmm0, 0x14(%rax)
movq -0x48(%rbp), %rax
movss 0xd8648(%rip), %xmm0    # 0x4e4950
movss %xmm0, 0x18(%rax)
movq -0x48(%rbp), %rax
movss 0xd8623(%rip), %xmm0    # 0x4e493c
movss %xmm0, 0x1c(%rax)
movq -0x48(%rbp), %rax
movss 0xd8622(%rip), %xmm0    # 0x4e494c
movss %xmm0, 0x20(%rax)
movq -0x48(%rbp), %rax
movss 0xd7149(%rip), %xmm0    # 0x4e3484
movss %xmm0, 0x24(%rax)
movq -0x48(%rbp), %rax
movss 0xd7138(%rip), %xmm0    # 0x4e3484
movss %xmm0, 0x28(%rax)
movq -0x48(%rbp), %rax
movss 0xd7127(%rip), %xmm0    # 0x4e3484
movss %xmm0, 0x2c(%rax)
movq -0x48(%rbp), %rax
movss 0xd85ee(%rip), %xmm0    # 0x4e495c
movss %xmm0, 0x30(%rax)
movq -0x48(%rbp), %rax
movss 0xd85d9(%rip), %xmm0    # 0x4e4958
movss %xmm0, 0x34(%rax)
movq -0x48(%rbp), %rax
movss 0xd85c4(%rip), %xmm0    # 0x4e4954
movss %xmm0, 0x38(%rax)
movq -0x48(%rbp), %rax
movss 0xd85af(%rip), %xmm0    # 0x4e4950
movss %xmm0, 0x3c(%rax)
movq -0x48(%rbp), %rax
movss 0xd858a(%rip), %xmm0    # 0x4e493c
movss %xmm0, 0x40(%rax)
movq -0x48(%rbp), %rax
movss 0xd8589(%rip), %xmm0    # 0x4e494c
movss %xmm0, 0x44(%rax)
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x48(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x4c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x18(%rax)
movl -0x50(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl -0x54(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movl -0x68(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x10(%rbp), %rax
movq -0x24(%rbp), %rcx
movq %rcx, 0x34(%rax)
movl -0x1c(%rbp), %ecx
movl %ecx, 0x3c(%rax)
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, 0x40(%rax)
movl -0x28(%rbp), %ecx
movl %ecx, 0x48(%rax)
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)