// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
leaq 0xc249c(%rip), %rsi     # 0x4e49db
callq 0x43c8a0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x422574
movq $0x526c68, %rax         # imm = 0x526C68
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0xc39d0(%rip), %rsi     # 0x4e5f34
movb $0x0, %al
callq 0x435870
movb $0x0, -0x1(%rbp)
jmp 0x422918
movq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x440980
movq -0x28(%rbp), %rdi
callq 0x43caa0
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x440980
movslq -0x2c(%rbp), %rdi
callq 0x452d20
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movslq -0x2c(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl $0x1, %esi
callq 0x43c9a0
movq -0x28(%rbp), %rdi
callq 0x43c170
movl -0x2c(%rbp), %eax
movl $0x5c, %ecx
cltd
idivl %ecx
movl %eax, -0x44(%rbp)
movslq -0x44(%rbp), %rax
imulq $0x74, %rax, %rdi
callq 0x452d20
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x4228f7
movq -0x40(%rbp), %rax
movslq -0x48(%rbp), %rcx
imulq $0x74, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x50(%rbp)
movss (%rax), %xmm0
movq -0x58(%rbp), %rax
movss %xmm0, 0x1c(%rax)
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x50(%rbp)
movss (%rax), %xmm0
movq -0x58(%rbp), %rax
movss %xmm0, 0x20(%rax)
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x50(%rbp)
movss (%rax), %xmm0
movq -0x58(%rbp), %rax
movss %xmm0, 0x24(%rax)
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x50(%rbp)
movss (%rax), %xmm0
movq -0x58(%rbp), %rax
movss %xmm0, 0x40(%rax)
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x50(%rbp)
movss (%rax), %xmm0
movq -0x58(%rbp), %rax
movss %xmm0, 0x44(%rax)
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x50(%rbp)
movss (%rax), %xmm0
movq -0x58(%rbp), %rax
movss %xmm0, 0x48(%rax)
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x50(%rbp)
movss (%rax), %xmm0
movq -0x58(%rbp), %rax
movss %xmm0, 0x28(%rax)
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x50(%rbp)
movss (%rax), %xmm0
movq -0x58(%rbp), %rax
movss %xmm0, 0x2c(%rax)
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x50(%rbp)
movss (%rax), %xmm0
movq -0x58(%rbp), %rax
movss %xmm0, 0x30(%rax)
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x50(%rbp)
movss (%rax), %xmm0
movq -0x58(%rbp), %rax
movss %xmm0, 0x4c(%rax)
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x50(%rbp)
movss (%rax), %xmm0
movq -0x58(%rbp), %rax
movss %xmm0, 0x50(%rax)
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x50(%rbp)
movss (%rax), %xmm0
movq -0x58(%rbp), %rax
movss %xmm0, 0x54(%rax)
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x50(%rbp)
movss (%rax), %xmm0
movq -0x58(%rbp), %rax
movss %xmm0, 0x34(%rax)
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x50(%rbp)
movss (%rax), %xmm0
movq -0x58(%rbp), %rax
movss %xmm0, 0x38(%rax)
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x50(%rbp)
movss (%rax), %xmm0
movq -0x58(%rbp), %rax
movss %xmm0, 0x3c(%rax)
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x50(%rbp)
movss (%rax), %xmm0
movq -0x58(%rbp), %rax
movss %xmm0, 0x58(%rax)
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x50(%rbp)
movss (%rax), %xmm0
movq -0x58(%rbp), %rax
movss %xmm0, 0x5c(%rax)
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x50(%rbp)
movss (%rax), %xmm0
movq -0x58(%rbp), %rax
movss %xmm0, 0x60(%rax)
movq -0x58(%rbp), %rdi
addq $0x1c, %rdi
movq -0x58(%rbp), %rsi
addq $0x28, %rsi
movq -0x58(%rbp), %rdx
addq $0x34, %rdx
movq -0x58(%rbp), %r8
addq $0x64, %r8
movl $0x1, %ecx
callq 0x40e9e0
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x50(%rbp)
movss (%rax), %xmm0
movq -0x58(%rbp), %rax
movss %xmm0, (%rax)
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x50(%rbp)
movss (%rax), %xmm0
movq -0x58(%rbp), %rax
movss %xmm0, 0x4(%rax)
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x50(%rbp)
movss (%rax), %xmm0
movq -0x58(%rbp), %rax
movss %xmm0, 0x8(%rax)
movq -0x58(%rbp), %rax
movss 0xc0bc9(%rip), %xmm0    # 0x4e3464
movss %xmm0, 0xc(%rax)
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x50(%rbp)
movss (%rax), %xmm0
movq -0x58(%rbp), %rax
movss %xmm0, 0x10(%rax)
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x50(%rbp)
movss (%rax), %xmm0
movq -0x58(%rbp), %rax
movss %xmm0, 0x14(%rax)
movq -0x58(%rbp), %rax
movss 0xc3630(%rip), %xmm0    # 0x4e5f14
movss %xmm0, 0x18(%rax)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x4225fb
movq -0x38(%rbp), %rdi
callq 0x453060
movq -0x40(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movl -0x44(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)