// File: /workspace/github_cpp_makefile_star2_O2/GenisGE[P]evalAdmix/evalAdmix.cpp
// Function: evalAdmix(double*, int, int, float**, float*, unsigned short**, int, double**, double**, int, int, int, int**, int, int*)
void evalAdmix(double *cor, int ind1u, int ind1, float **r, float *mean_r, unsigned short int **G, int K, double **Q, double **F, int nInd, int nSites,int nIts, int **isMissing, int nIndUse, int *useInd){

  float **rAdapted=allocFloat2(nIndUse, nSites);
  float *mean_rAdapted = new float[nIndUse];
  double **fAdapted=allocDouble2(nSites,K);



  for(int j=0; j<nSites;j++){ // initial values for adapted F are normal F
    for(int k=0; k<K;k++){
      fAdapted[j][k] = F[j][k];
    }
  }

    
  // Estimate new f and calculate new residuals
  adaptF(fAdapted, G, K, Q, nInd, nSites, ind1, nIts,isMissing);
  calcRes(rAdapted, mean_rAdapted, G, Q, fAdapted, K, nSites, nInd, nIndUse, isMissing, useInd);

  for(int ind2=(ind1u+1); ind2<nIndUse; ind2++){
    cor[ind2] =  correlateRes(nSites, r[ind1u], rAdapted[ind2], mean_r[ind1u], mean_rAdapted[ind2], isMissing, ind1, ind2);
  }
  
  // Clean

  for(int j = 0; j < nSites; j++){ 
    delete[] fAdapted[j];

  }

  for(int i = 0; i < nIndUse; i++){
    delete[] rAdapted[i];

  }

 
  delete[] fAdapted;
  delete[] rAdapted;
  delete[] mean_rAdapted;


}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r9, 0x58(%rsp)
movq %r8, 0x80(%rsp)
movq %rcx, 0x78(%rsp)
movq %rdx, 0x40(%rsp)
movl %esi, 0x8(%rsp)
movq %rdi, 0x68(%rsp)
movslq 0xf8(%rsp), %r15
movq 0x100(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x38(%rsp)
movl 0xe8(%rsp), %eax
movq %rax, 0x50(%rsp)
movl 0xe0(%rsp), %r13d
movl 0xd8(%rsp), %eax
movq %rax, (%rsp)
movq 0xd0(%rsp), %r14
movq 0xc8(%rsp), %rax
movq %rax, 0x48(%rsp)
movl 0xc0(%rsp), %ebp
movslq %r13d, %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x9fb4
movq %rax, 0x30(%rsp)
leaq (,%r15,4), %rax
movq %r15, 0x18(%rsp)
testq %r15, %r15
pushq $-0x1
popq %rdi
cmovnsq %rax, %rdi
callq 0x2030
movq %rax, 0x28(%rsp)
movslq %ebp, %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x9f40
movq %rax, %r12
xorl %eax, %eax
testl %r15d, %r15d
movl $0x0, %ecx
movl %ebp, %r8d
cmovgl %ebp, %ecx
testl %ebx, %ebx
movl $0x0, %edi
movq %r13, 0x10(%rsp)
cmovgl %r13d, %edi
cmpq %rdi, %rax
je 0xa563
xorl %edx, %edx
cmpq %rdx, %rcx
je 0xa55e
movq (%r14,%rax,8), %rsi
movsd (%rsi,%rdx,8), %xmm0
movq (%r12,%rax,8), %rsi
movsd %xmm0, (%rsi,%rdx,8)
incq %rdx
jmp 0xa542
incq %rax
jmp 0xa53b
movq %rdi, 0x70(%rsp)
subq $0x8, %rsp
movq %r12, %rdi
movq 0x60(%rsp), %rbp
movq %rbp, %rsi
movl %r8d, %edx
movl %r8d, 0x2c(%rsp)
movq 0x50(%rsp), %r13
movq %r13, %rcx
movq 0x8(%rsp), %r8
movq 0x18(%rsp), %r9
movq 0x40(%rsp), %r14
pushq %r14
pushq 0x60(%rsp)
pushq 0x58(%rsp)
callq 0xa028
addq $0x18, %rsp
movq 0x38(%rsp), %r15
movq %r15, %rdi
movq 0x30(%rsp), %rbx
movq %rbx, %rsi
movq %rbp, %rdx
movq %r13, %rcx
movq %r12, %r8
movl 0x2c(%rsp), %r9d
pushq 0x68(%rsp)
pushq %r14
pushq 0x30(%rsp)
pushq 0x20(%rsp)
pushq 0x38(%rsp)
callq 0xa217
addq $0x30, %rsp
movslq 0x8(%rsp), %r14
leaq 0x1(%r14), %rax
movq %rax, (%rsp)
leal 0x1(%r14), %eax
movq %rax, 0x8(%rsp)
leaq 0x8(%r15,%r14,8), %r13
leaq (%rbx,%r14,4), %rbp
addq $0x4, %rbp
movq 0x68(%rsp), %rax
leaq (%rax,%r14,8), %r15
addq $0x8, %r15
xorl %ebx, %ebx
movq (%rsp), %rax
addq %rbx, %rax
cmpq 0x18(%rsp), %rax
jge 0xa66c
movq 0x78(%rsp), %rax
movq (%rax,%r14,8), %rsi
movq 0x80(%rsp), %rax
cvtss2sd (%rax,%r14,4), %xmm0
movq (%r13,%rbx,8), %rdx
cvtss2sd (%rbp,%rbx,4), %xmm1
movq 0x8(%rsp), %rax
leal (%rax,%rbx), %r9d
movq 0x10(%rsp), %rdi
movq 0x38(%rsp), %rcx
movq 0x40(%rsp), %r8
callq 0xa378
movsd %xmm0, (%r15,%rbx,8)
incq %rbx
jmp 0xa614
xorl %ebx, %ebx
movq 0x30(%rsp), %r15
movq 0x70(%rsp), %r14
cmpq %rbx, %r14
je 0xa690
movq (%r12,%rbx,8), %rdi
testq %rdi, %rdi
je 0xa68b
callq 0x22d0
incq %rbx
jmp 0xa678
xorl %ebx, %ebx
movq 0x18(%rsp), %rax
testl %eax, %eax
movl $0x0, %r14d
cmovgl %eax, %r14d
cmpq %rbx, %r14
je 0xa6bb
movq (%r15,%rbx,8), %rdi
testq %rdi, %rdi
je 0xa6b6
callq 0x22d0
incq %rbx
jmp 0xa6a3
movq %r12, %rdi
callq 0x22d0
movq %r15, %rdi
callq 0x22d0
movq 0x28(%rsp), %rdi
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22d0
nop