// File: /workspace/github_c_makefile_star2_O2/archer1357[P]Offline-Raytracer/utils.c
// Function: loadMesh_old
bool loadMesh_old(const char *fn,
              struct Triangle **trianglesOut,
              int *trianglesNumOut) {
  FILE *file;
  int dataLen;
  char *data;

  file = fopen(fn, "rb");

  if(!file) {
    fprintf(stderr,"loadMesh read file error : %s\n",fn);
    return false;
  }

  fseek(file,0L,SEEK_END);
  dataLen = ftell(file);
  fseek(file,0L,SEEK_SET);
  data=(char*)malloc(dataLen);
  fread(data,1,dataLen,file);
  fclose(file);

  //
  struct Triangle *triangles;
  int trianglesNum,i;
  trianglesNum=dataLen/((9+9+3+2)*4);

  //
  triangles=(struct Triangle*)malloc(sizeof(struct Triangle)*trianglesNum);

  float *data2=(float*)data;

  for(i=0;i<trianglesNum;i++) {
    struct Triangle *triangle=&triangles[i];

    triangle->pt0[0]=*(data2++);
    triangle->pt0[1]=*(data2++);
    triangle->pt0[2]=*(data2++);

    triangle->nor0[0]=*(data2++);
    triangle->nor0[1]=*(data2++);
    triangle->nor0[2]=*(data2++);

    triangle->pt1[0]=*(data2++);
    triangle->pt1[1]=*(data2++);
    triangle->pt1[2]=*(data2++);

    triangle->nor1[0]=*(data2++);
    triangle->nor1[1]=*(data2++);
    triangle->nor1[2]=*(data2++);

    triangle->pt2[0]=*(data2++);
    triangle->pt2[1]=*(data2++);
    triangle->pt2[2]=*(data2++);

    triangle->nor2[0]=*(data2++);
    triangle->nor2[1]=*(data2++);
    triangle->nor2[2]=*(data2++);
    // printf("p %g %g %g, %g %g %g, %g %g %g\n",
    //   triangle->pt0[0],triangle->pt0[1],triangle->pt0[2],
    //   triangle->pt1[0],triangle->pt1[1],triangle->pt1[2],
    //   triangle->pt2[0],triangle->pt2[1],triangle->pt2[2]
    //   );
    // printf("n %g %g %g, %g %g %g, %g %g %g\n",
    //   triangle->nor0[0],triangle->nor0[1],triangle->nor0[2],
    //   triangle->nor1[0],triangle->nor1[1],triangle->nor1[2],
    //   triangle->nor2[0],triangle->nor2[1],triangle->nor2[2]
    //   );

    planeFromTriangle(triangle->pt0,
                      triangle->pt1,
                      triangle->pt2,
                      true,
                      triangle->plane);


    //float E0[3],E1[3],N[3];
    //vec3_sub(E0,triangle->pt1,triangle->pt0);
    // vec3_sub(E1,triangle->pt2,triangle->pt0);
    // vec3_cross(N,E0,E1);
    // // vec3_normal(N,N);

    //
    // planeFromPointNormal(triangle->pt0,N,false,plane);

    //
    triangle->material.col[0]=*(data2++);
    triangle->material.col[1]=*(data2++);
    triangle->material.col[2]=*(data2++);
    triangle->material.reflectAmount=0.5f;

    triangle->material.shininess=*(data2++);
    triangle->material.intensity=*(data2++);


    triangle->material.diffuseRefl=(float)0.07f;

    // triangle->material.shininess=1.0f;
    // triangle->material.intensity=1.0f;
  }

  free(data);

  //
  *trianglesOut=triangles;
  *trianglesNumOut=trianglesNum;

  //
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
leaq 0xc0f30(%rip), %rsi     # 0x4d3a27
callq 0x42bb40
movq %rax, %rbx
testq %rax, %rax
je 0x412cc8
movq %r12, 0x18(%rsp)
movq %r15, 0x20(%rsp)
xorl %r15d, %r15d
pushq $0x2
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x42fdc0
movq %rbx, %rdi
callq 0x42bd40
movq %rax, %r14
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x42fdc0
movslq %r14d, %r14
movq %r14, %rdi
callq 0x442160
movq %rax, %r12
pushq $0x1
popq %rsi
movq %rax, %rdi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x42bc40
movq %rbx, %rdi
callq 0x42b410
pushq $0x5c
popq %rcx
movl %r14d, %eax
cltd
idivl %ecx
movl %eax, 0xc(%rsp)
movslq %eax, %r14
imulq $0x74, %r14, %rdi
callq 0x442160
testl %r14d, %r14d
movl $0x0, %ecx
cmovgl %r14d, %ecx
movq %rax, %r13
imulq $0x74, %rcx, %rbp
pushq $0x1
popq %r14
movq %r12, 0x10(%rsp)
cmpq %r15, %rbp
je 0x412c96
leaq (%r15,%r13), %rdi
addq $0x1c, %rdi
movsd 0x4(%r12), %xmm0
movsd 0x10(%r12), %xmm1
leaq 0x28(%r13,%r15), %rsi
movss (%r12), %xmm2
movlhps %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
movss 0x18(%r12), %xmm3
shufps $0xd4, %xmm0, %xmm3     # xmm3 = xmm3[0,1],xmm0[1,3]
shufps $0x28, %xmm3, %xmm2     # xmm2 = xmm2[0,2],xmm3[2,0]
movss 0xc(%r12), %xmm0
movups %xmm2, 0x1c(%r13,%r15)
movsd 0x28(%r12), %xmm2
leaq 0x34(%r13,%r15), %rdx
movsd 0x1c(%r12), %xmm3
movhps 0x30(%r12), %xmm3       # xmm3 = xmm3[0,1],mem[0,1]
movss 0x24(%r12), %xmm4
movups %xmm3, 0x2c(%r13,%r15)
movss 0x38(%r12), %xmm3
unpcklps %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0],xmm3[1],xmm0[1]
movlhps %xmm1, %xmm3            # xmm3 = xmm3[0],xmm1[0]
movups %xmm3, 0x3c(%r13,%r15)
movlhps %xmm2, %xmm4            # xmm4 = xmm4[0],xmm2[0]
movss 0x3c(%r12), %xmm0
shufps $0xd4, %xmm2, %xmm0     # xmm0 = xmm0[0,1],xmm2[1,3]
shufps $0x28, %xmm0, %xmm4     # xmm4 = xmm4[0,2],xmm0[2,0]
movups %xmm4, 0x4c(%r13,%r15)
movsd 0x40(%r12), %xmm0
movsd %xmm0, 0x5c(%r13,%r15)
leaq (%r15,%r13), %r8
addq $0x64, %r8
movl %r14d, %ecx
callq 0x4080da
movsd 0x48(%r12), %xmm0
movsd %xmm0, (%r13,%r15)
movss 0x50(%r12), %xmm0
movss %xmm0, 0x8(%r13,%r15)
movl $0x3f000000, 0xc(%r13,%r15) # imm = 0x3F000000
movsd 0x54(%r12), %xmm0
movsd %xmm0, 0x10(%r13,%r15)
movl $0x3d8f5c29, 0x18(%r13,%r15) # imm = 0x3D8F5C29
addq $0x74, %r15
addq $0x5c, %r12
jmp 0x412b95
movq 0x10(%rsp), %rdi
callq 0x4424a0
movq 0x18(%rsp), %rax
movq %r13, (%rax)
movq 0x20(%rsp), %rax
movl 0xc(%rsp), %ecx
movl %ecx, (%rax)
testq %rbx, %rbx
setne %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq $0x516868, %rax         # imm = 0x516868
movq (%rax), %rdi
leaq 0xc26c7(%rip), %rsi     # 0x4d53a0
movq %r14, %rdx
xorl %eax, %eax
callq 0x424b10
jmp 0x412cb3