// File: /workspace/github_c_makefile_star2_O1/zpole[P]IICV/src/test_gmm.c
// Function: saveResults
void saveResults(const char * dataFileData, const char * dataFileResults, VlGMM * gmm, void * data, vl_size numData)
{
  char *mode = "w";
  FILE * ofp;

  vl_size d, cIdx;
  vl_uindex i_d;

  vl_size dimension = vl_gmm_get_dimension(gmm) ;
  vl_size numClusters = vl_gmm_get_num_clusters(gmm) ;
  vl_type dataType = vl_gmm_get_data_type(gmm) ;
  double const * sigmas = vl_gmm_get_covariances(gmm) ;
  double const * means = vl_gmm_get_means(gmm) ;
  double const * weights = vl_gmm_get_priors(gmm) ;
  double const * posteriors = vl_gmm_get_posteriors(gmm) ;

  ofp = fopen(dataFileData, mode);
  for(i_d = 0; i_d < numData; i_d++) {
    if(vl_gmm_get_data_type(gmm) == VL_TYPE_DOUBLE) {
      for(d = 0; d < vl_gmm_get_dimension(gmm) ; d++) {
        fprintf(ofp, "%f ", ((double*)data)[i_d * vl_gmm_get_dimension(gmm) + d]);
      }
    } else {
      for(d = 0; d < vl_gmm_get_dimension(gmm); d++) {
        fprintf(ofp, "%f ", ((float*) data)[i_d * vl_gmm_get_dimension(gmm) + d]);
      }
    }
    fprintf(ofp, "\n");
  }
  fclose (ofp);

  ofp = fopen(dataFileResults, mode);
  for(cIdx = 0; cIdx < numClusters; cIdx++) {
    if(dataType == VL_TYPE_DOUBLE) {
      for(d = 0; d < vl_gmm_get_dimension(gmm); d++) {
        fprintf(ofp, "%f ", ((double*)means)[cIdx*dimension+d]);
      }
      for(d = 0; d < dimension; d++) {
        fprintf(ofp, "%f ", ((double*)sigmas)[cIdx*dimension+d]);
      }
      fprintf(ofp, "%f ", ((double*)weights)[cIdx]);
      for(i_d = 0; i_d < numData; i_d++) {
        fprintf(ofp, "%f ", ((double*)posteriors)[cIdx*numData + i_d]);
      }
      fprintf(ofp, "\n");
    } else {
      for(d = 0; d < dimension; d++) {
        fprintf(ofp, "%f ", ((float*)means)[cIdx*dimension+d]);
      }
      for(d = 0; d < dimension; d++) {
        fprintf(ofp, "%f ", ((float*)sigmas)[cIdx*dimension+d]);
      }
      fprintf(ofp, "%f ", ((float*)weights)[cIdx]);
      for(i_d = 0; i_d < numData; i_d++) {
        fprintf(ofp, "%f ", ((float*)posteriors)[cIdx*numData + i_d]);

      }
      fprintf(ofp, "\n");
    }
  }
  fclose (ofp);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r8, %rbx
movq %r8, 0x18(%rsp)
movq %rcx, %rbp
movq %rdx, %r14
movq %rsi, 0x8(%rsp)
movq %rdi, %r12
movq %rdx, %rdi
callq 0x1040
movq %rax, 0x50(%rsp)
movq %r14, %rdi
callq 0x1030
movq %rax, 0x48(%rsp)
movq %r14, %rdi
callq 0x11b0
movl %eax, 0x3c(%rsp)
movq %r14, %rdi
callq 0x1150
movq %rax, 0x28(%rsp)
movq %r14, %rdi
callq 0x1170
movq %rax, 0x20(%rsp)
movq %r14, %rdi
callq 0x1190
movq %rax, 0x40(%rsp)
movq %r14, %rdi
callq 0x10b0
movq %rax, 0x30(%rsp)
leaq 0x9ec(%rip), %rsi       # 0x2020
movq %r12, %rdi
callq 0x11a0
movq %rax, %r13
testq %rbx, %rbx
je 0x1716
xorl %ebx, %ebx
xorl %r12d, %r12d
xorl %eax, %eax
movq %rax, 0x10(%rsp)
movq %r14, %rdi
callq 0x11b0
movl %eax, %r15d
movq %r14, %rdi
callq 0x1040
cmpl $0x2, %r15d
jne 0x16ad
testq %rax, %rax
je 0x16ee
xorl %r15d, %r15d
movq %r14, %rdi
callq 0x1040
imulq %rbx, %rax
addq %rbp, %rax
movsd (%rax,%r15,8), %xmm0
movq %r13, %rdi
leaq 0x98e(%rip), %rsi       # 0x2022
movb $0x1, %al
callq 0x10f0
incq %r15
movq %r14, %rdi
callq 0x1040
cmpq %rax, %r15
jb 0x1675
jmp 0x16ee
testq %rax, %rax
je 0x16ee
xorl %r15d, %r15d
movq %r14, %rdi
callq 0x1040
imulq %r12, %rax
addq %rbp, %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax,%r15,4), %xmm0
movq %r13, %rdi
leaq 0x94b(%rip), %rsi       # 0x2022
movb $0x1, %al
callq 0x10f0
incq %r15
movq %r14, %rdi
callq 0x1040
cmpq %rax, %r15
jb 0x16b5
movl $0xa, %edi
movq %r13, %rsi
callq 0x10d0
movq 0x10(%rsp), %rax
incq %rax
addq $0x4, %r12
addq $0x8, %rbx
cmpq 0x18(%rsp), %rax
jne 0x164f
movq %r13, %rdi
callq 0x1070
leaq 0x8fb(%rip), %rsi       # 0x2020
movq 0x8(%rsp), %rdi
callq 0x11a0
movq %rax, %r13
cmpq $0x0, 0x48(%rsp)
movq 0x50(%rsp), %rbx
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %r12
je 0x198a
leaq (,%rbx,4), %rax
movq %rax, 0x80(%rsp)
movq 0x18(%rsp), %rax
leaq (,%rax,4), %rdx
movq %rdx, 0x78(%rsp)
leaq (,%rbx,8), %rdx
movq %rdx, 0x70(%rsp)
leaq (,%rax,8), %rax
movq %rax, 0x68(%rsp)
movq $0x0, 0x8(%rsp)
leaq 0x889(%rip), %rbp       # 0x2022
movq 0x30(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %rcx, %rsi
movq %r12, %rdi
movq %rdi, 0x58(%rsp)
movq %rsi, 0x60(%rsp)
movq %rcx, 0x28(%rsp)
cmpl $0x2, 0x3c(%rsp)
movq %r12, 0x20(%rsp)
jne 0x187a
movq %r14, %rdi
callq 0x1040
testq %rax, %rax
je 0x17fb
xorl %r15d, %r15d
movsd (%r12,%r15,8), %xmm0
movq %r13, %rdi
movq %rbp, %rsi
movb $0x1, %al
callq 0x10f0
incq %r15
movq %r14, %rdi
callq 0x1040
cmpq %rax, %r15
jb 0x17d8
testq %rbx, %rbx
movq 0x28(%rsp), %r12
je 0x1823
xorl %r15d, %r15d
movsd (%r12,%r15,8), %xmm0
movq %r13, %rdi
movq %rbp, %rsi
movb $0x1, %al
callq 0x10f0
incq %r15
cmpq %r15, %rbx
jne 0x1808
movq 0x40(%rsp), %rax
movq 0x8(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq %r13, %rdi
movq %rbp, %rsi
movb $0x1, %al
callq 0x10f0
movq 0x18(%rsp), %rbx
testq %rbx, %rbx
movq 0x20(%rsp), %r12
je 0x191f
xorl %r15d, %r15d
movq 0x30(%rsp), %rax
movsd (%rax,%r15,8), %xmm0
movq %r13, %rdi
movq %rbp, %rsi
movb $0x1, %al
callq 0x10f0
incq %r15
cmpq %r15, %rbx
jne 0x1855
jmp 0x191f
testq %rbx, %rbx
je 0x18cb
xorl %r15d, %r15d
movq 0x58(%rsp), %r12
xorps %xmm0, %xmm0
cvtss2sd (%r12,%r15,4), %xmm0
movq %r13, %rdi
movq %rbp, %rsi
movb $0x1, %al
callq 0x10f0
incq %r15
cmpq %r15, %rbx
jne 0x1887
xorl %r15d, %r15d
movq 0x60(%rsp), %r12
xorps %xmm0, %xmm0
cvtss2sd (%r12,%r15,4), %xmm0
movq %r13, %rdi
movq %rbp, %rsi
movb $0x1, %al
callq 0x10f0
incq %r15
cmpq %r15, %rbx
jne 0x18ad
movq 0x40(%rsp), %rax
movq 0x8(%rsp), %rcx
xorps %xmm0, %xmm0
cvtss2sd (%rax,%rcx,4), %xmm0
movq %r13, %rdi
movq %rbp, %rsi
movb $0x1, %al
callq 0x10f0
movq 0x18(%rsp), %rbx
testq %rbx, %rbx
movq 0x20(%rsp), %r12
je 0x191f
xorl %r15d, %r15d
movq 0x10(%rsp), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax,%r15,4), %xmm0
movq %r13, %rdi
movq %rbp, %rsi
movb $0x1, %al
callq 0x10f0
incq %r15
cmpq %r15, %rbx
jne 0x18fc
movl $0xa, %edi
movq %r13, %rsi
callq 0x10d0
movq 0x8(%rsp), %rdx
incq %rdx
movq 0x80(%rsp), %rax
movq 0x58(%rsp), %rdi
addq %rax, %rdi
movq 0x60(%rsp), %rsi
addq %rax, %rsi
movq 0x10(%rsp), %rax
addq 0x78(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x70(%rsp), %rax
addq %rax, %r12
movq 0x28(%rsp), %rcx
addq %rax, %rcx
movq 0x68(%rsp), %rax
addq %rax, 0x30(%rsp)
movq %rdx, 0x8(%rsp)
cmpq 0x48(%rsp), %rdx
movq 0x50(%rsp), %rbx
jne 0x17a9
movq %r13, %rdi
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1070