// File: /workspace/github_c_makefile_star2_O3/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 $0x18, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
leaq 0xc1849(%rip), %rsi     # 0x4d7a77
callq 0x42f2a0
movq %rax, %rbx
testq %rax, %rax
je 0x4163ea
movq %r15, 0x8(%rsp)
movq %r14, 0x10(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x433520
movq %rbx, %rdi
callq 0x42f4a0
movq %rax, %r12
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x433520
movslq %r12d, %rbp
movq %rbp, %rdi
callq 0x4458c0
movq %rax, %r13
movl $0x1, %esi
movq %rax, %rdi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0x42f3a0
movq %rbx, %rdi
callq 0x42eb70
imulq $-0x4de9bd37, %rbp, %r14 # imm = 0xB21642C9
shrq $0x20, %r14
addl %ebp, %r14d
movl %r14d, %eax
shrl $0x1f, %eax
sarl $0x6, %r14d
addl %eax, %r14d
movslq %r14d, %rax
imulq $0x74, %rax, %rdi
callq 0x4458c0
movq %rax, (%rsp)
cmpl $0x5c, %ebp
jl 0x4163b9
movl %r14d, %r15d
movq (%rsp), %rbp
addq $0x34, %rbp
movq %r13, %r12
leaq -0x18(%rbp), %rdi
movsd 0x4(%r12), %xmm0
movsd 0x10(%r12), %xmm1
leaq -0xc(%rbp), %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, -0x18(%rbp)
movsd 0x28(%r12), %xmm2
movsd 0x1c(%r12), %xmm3
movhps 0x30(%r12), %xmm3       # xmm3 = xmm3[0,1],mem[0,1]
movss 0x24(%r12), %xmm4
movups %xmm3, -0x8(%rbp)
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, 0x8(%rbp)
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, 0x18(%rbp)
movsd 0x40(%r12), %xmm0
movsd %xmm0, 0x28(%rbp)
leaq 0x30(%rbp), %r8
movq %rbp, %rdx
movl $0x1, %ecx
callq 0x408d50
movsd 0x48(%r12), %xmm0
movsd %xmm0, -0x34(%rbp)
movss 0x50(%r12), %xmm0
movss %xmm0, -0x2c(%rbp)
movl $0x3f000000, -0x28(%rbp) # imm = 0x3F000000
movsd 0x54(%r12), %xmm0
movsd %xmm0, -0x24(%rbp)
movl $0x3d8f5c29, -0x1c(%rbp) # imm = 0x3D8F5C29
addq $0x74, %rbp
addq $0x5c, %r12
decq %r15
jne 0x4162da
movq %r13, %rdi
callq 0x445c00
movq 0x8(%rsp), %rax
movq (%rsp), %rcx
movq %rcx, (%rax)
movq 0x10(%rsp), %rax
movl %r14d, (%rax)
testq %rbx, %rbx
setne %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq $0x519848, %rax         # imm = 0x519848
movq (%rax), %rdi
leaq 0xc3135(%rip), %rsi     # 0x4d9530
movq %r12, %rdx
xorl %eax, %eax
callq 0x428270
jmp 0x4163d5