// File: /workspace/github_c_makefile_star2_O1/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 0xc1979(%rip), %rsi     # 0x4d6a37
callq 0x42e3b0
movq %rax, %rbx
testq %rax, %rax
je 0x4152e6
movq %r15, 0x8(%rsp)
movq %r14, 0x10(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x432630
movq %rbx, %rdi
callq 0x42e5b0
movq %rax, %r12
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x432630
movslq %r12d, %rbp
movq %rbp, %rdi
callq 0x4449d0
movq %rax, %r13
movl $0x1, %esi
movq %rax, %rdi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0x42e4b0
movq %rbx, %rdi
callq 0x42dc80
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 0x4449d0
movq %rax, (%rsp)
cmpl $0x5c, %ebp
jl 0x4152b5
movl %r14d, %r15d
movq (%rsp), %rbp
addq $0x34, %rbp
movq %r13, %r12
movss (%r12), %xmm0
leaq -0x18(%rbp), %rdi
movss %xmm0, -0x18(%rbp)
movss 0x4(%r12), %xmm0
movss %xmm0, -0x14(%rbp)
movss 0x8(%r12), %xmm0
movss %xmm0, -0x10(%rbp)
movss 0xc(%r12), %xmm0
movss %xmm0, 0xc(%rbp)
movss 0x10(%r12), %xmm0
movss %xmm0, 0x10(%rbp)
movss 0x14(%r12), %xmm0
movss %xmm0, 0x14(%rbp)
movss 0x18(%r12), %xmm0
leaq -0xc(%rbp), %rsi
movss %xmm0, -0xc(%rbp)
movss 0x1c(%r12), %xmm0
movss %xmm0, -0x8(%rbp)
movss 0x20(%r12), %xmm0
movss %xmm0, -0x4(%rbp)
movss 0x24(%r12), %xmm0
movss %xmm0, 0x18(%rbp)
movss 0x28(%r12), %xmm0
movss %xmm0, 0x1c(%rbp)
movss 0x2c(%r12), %xmm0
movss %xmm0, 0x20(%rbp)
movss 0x30(%r12), %xmm0
movss %xmm0, (%rbp)
movss 0x34(%r12), %xmm0
movss %xmm0, 0x4(%rbp)
movss 0x38(%r12), %xmm0
movss %xmm0, 0x8(%rbp)
movss 0x3c(%r12), %xmm0
movss %xmm0, 0x24(%rbp)
movss 0x40(%r12), %xmm0
movss %xmm0, 0x28(%rbp)
movss 0x44(%r12), %xmm0
movss %xmm0, 0x2c(%rbp)
leaq 0x30(%rbp), %r8
movq %rbp, %rdx
movl $0x1, %ecx
callq 0x4089f1
movss 0x48(%r12), %xmm0
movss %xmm0, -0x34(%rbp)
movss 0x4c(%r12), %xmm0
movss %xmm0, -0x30(%rbp)
movss 0x50(%r12), %xmm0
movss %xmm0, -0x2c(%rbp)
movl $0x3f000000, -0x28(%rbp) # imm = 0x3F000000
movss 0x54(%r12), %xmm0
movss %xmm0, -0x24(%rbp)
movss 0x58(%r12), %xmm0
movss %xmm0, -0x20(%rbp)
movl $0x3d8f5c29, -0x1c(%rbp) # imm = 0x3D8F5C29
addq $0x74, %rbp
addq $0x5c, %r12
decq %r15
jne 0x41516a
movq %r13, %rdi
callq 0x444d10
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 $0x518868, %rax         # imm = 0x518868
movq (%rax), %rdi
leaq 0xc3069(%rip), %rsi     # 0x4d8360
movq %r12, %rdx
xorl %eax, %eax
callq 0x427380
jmp 0x4152d1