// File: /workspace/github_c_makefile_star2_O0/archer1357[P]Offline-Raytracer/utils.c
// Function: calcLights
void calcLights(const struct Ray *ray,struct Material *material,
                const float *colPt,const float *nor,
                struct KdTraverseNode *traverseStack,
                const float *minBound,const float *maxBound,
                struct KdNode *rootNode,
                struct Triangle *triangles,int trianglesNum,
                struct Sphere *spheres,int spheresNum,
                struct PointLight *pointLights,int pointLightsNum,
                float *colOut,float *specOut) {
  //
  int q;
  float resultCol[3]={0.0f,0.0f,0.0f};
  float resultSpec[3]={0.0f,0.0f,0.0f};

  //
  for(q=0;q<pointLightsNum;q++) {
    bool blocked=false;
    float col[3],spec;

    //light dir, dist
    float toLightDir[3],lightDist,invLightDist;
    vec3_sub(toLightDir,pointLights[q].pos,colPt);

    lightDist=vec3_length(toLightDir);
    invLightDist=1.0f/lightDist;
    vec3_mulScalar(toLightDir,toLightDir,invLightDist);

    //

#ifndef RUN_TEST
    if(intersectKdtreeP(colPt,toLightDir,lightDist,
    minBound,maxBound,
                        traverseStack,rootNode,
                        triangles,trianglesNum,spheres,spheresNum)) {
      blocked=true;
    }
#endif

    if(blocked) {
      continue;
    }

    calc_pointLight(&pointLights[q],toLightDir,lightDist,
                    ray->vec,
                    material->shininess,material->intensity,
                    nor,
                    col,&spec);

    resultCol[0]+=col[0]+spec;
    resultCol[1]+=col[1]+spec;
    resultCol[2]+=col[2]+spec;
    resultSpec[0]+=pointLights[q].col[0]*spec;
    resultSpec[1]+=pointLights[q].col[1]*spec;
    resultSpec[2]+=pointLights[q].col[2]*spec;
  }

  colOut[0]=resultCol[0];
  colOut[1]=resultCol[1];
  colOut[2]=resultCol[2];
  specOut[0]=resultSpec[0];
  specOut[1]=resultSpec[1];
  specOut[2]=resultSpec[2];

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x98, %rsp
movq 0x58(%rbp), %rax
movq 0x50(%rbp), %rax
movl 0x48(%rbp), %eax
movq 0x40(%rbp), %rax
movl 0x38(%rbp), %eax
movq 0x30(%rbp), %rax
movl 0x28(%rbp), %eax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x4010e0
leaq -0x54(%rbp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x4010e0
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl 0x48(%rbp), %eax
jge 0x423257
movb $0x0, -0x55(%rbp)
leaq -0x74(%rbp), %rdi
movq 0x40(%rbp), %rsi
movslq -0x3c(%rbp), %rax
imulq $0x24, %rax, %rax
addq %rax, %rsi
addq $0xc, %rsi
movq -0x20(%rbp), %rdx
callq 0x40cae0
leaq -0x74(%rbp), %rdi
callq 0x40c9d0
movss %xmm0, -0x78(%rbp)
movss 0xc03ae(%rip), %xmm0    # 0x4e3484
divss -0x78(%rbp), %xmm0
movss %xmm0, -0x7c(%rbp)
leaq -0x74(%rbp), %rdi
leaq -0x74(%rbp), %rsi
movss -0x7c(%rbp), %xmm0
callq 0x40cb40
movq -0x20(%rbp), %rdi
leaq -0x74(%rbp), %rsi
movss -0x78(%rbp), %xmm0
movq -0x38(%rbp), %rdx
movq 0x10(%rbp), %rcx
movq -0x30(%rbp), %r8
movq 0x18(%rbp), %r9
movq 0x20(%rbp), %rbx
movl 0x28(%rbp), %r11d
movq 0x30(%rbp), %r10
movl 0x38(%rbp), %eax
movq %rbx, (%rsp)
movl %r11d, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movl %eax, 0x18(%rsp)
callq 0x4222c0
testb $0x1, %al
jne 0x42313b
jmp 0x42313f
movb $0x1, -0x55(%rbp)
testb $0x1, -0x55(%rbp)
je 0x42314a
jmp 0x423249
movq 0x40(%rbp), %rdi
movslq -0x3c(%rbp), %rax
imulq $0x24, %rax, %rax
addq %rax, %rdi
leaq -0x74(%rbp), %rsi
movss -0x78(%rbp), %xmm0
movq -0x10(%rbp), %rdx
addq $0xc, %rdx
movq -0x18(%rbp), %rax
movss 0x10(%rax), %xmm1
movq -0x18(%rbp), %rax
movss 0x14(%rax), %xmm2
movq -0x28(%rbp), %rcx
leaq -0x64(%rbp), %r8
leaq -0x68(%rbp), %r9
callq 0x422b70
movss -0x64(%rbp), %xmm0
addss -0x68(%rbp), %xmm0
addss -0x48(%rbp), %xmm0
movss %xmm0, -0x48(%rbp)
movss -0x60(%rbp), %xmm0
addss -0x68(%rbp), %xmm0
addss -0x44(%rbp), %xmm0
movss %xmm0, -0x44(%rbp)
movss -0x5c(%rbp), %xmm0
addss -0x68(%rbp), %xmm0
addss -0x40(%rbp), %xmm0
movss %xmm0, -0x40(%rbp)
movq 0x40(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movss (%rax), %xmm0
movss -0x68(%rbp), %xmm2
movss -0x54(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x54(%rbp)
movq 0x40(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movss 0x4(%rax), %xmm0
movss -0x68(%rbp), %xmm2
movss -0x50(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x50(%rbp)
movq 0x40(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movss 0x8(%rax), %xmm0
movss -0x68(%rbp), %xmm2
movss -0x4c(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x4c(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x423090
movss -0x48(%rbp), %xmm0
movq 0x50(%rbp), %rax
movss %xmm0, (%rax)
movss -0x44(%rbp), %xmm0
movq 0x50(%rbp), %rax
movss %xmm0, 0x4(%rax)
movss -0x40(%rbp), %xmm0
movq 0x50(%rbp), %rax
movss %xmm0, 0x8(%rax)
movss -0x54(%rbp), %xmm0
movq 0x58(%rbp), %rax
movss %xmm0, (%rax)
movss -0x50(%rbp), %xmm0
movq 0x58(%rbp), %rax
movss %xmm0, 0x4(%rax)
movss -0x4c(%rbp), %xmm0
movq 0x58(%rbp), %rax
movss %xmm0, 0x8(%rax)
addq $0x98, %rsp
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)