// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/svm.c
// Function: multiclass_probability
void multiclass_probability(int k, double **r, double *p)
{
 int t, j;
 int iter = 0, max_iter = 100;
 double **Q, *Qp, pQp, eps=0.005 / k, max_error, error, diff;
 Q = (double**)safemalloc_2d(sizeof(double*), sizeof(double), k, k, "multiclass_probability", 4);
 Qp = safemalloc(k * sizeof(double), "multiclass_proability", 5);
 for (t = 0; t < k; t++)
  {
   p[t] = 1.0 / k;  /* Valid if k = 1*/
   Q[t][t] = 0;
   for (j = 0; j < t; j++)
    {
     Q[t][t] += r[j][t] * r[j][t];
     Q[t][j] = Q[j][t];
    }
   for (j = t + 1; j < k; j++)
    {
     Q[t][t] += r[j][t] * r[j][t];
     Q[t][j] = -r[j][t] * r[t][j];
    }
  }
 for (iter = 0; iter < max_iter; iter++)
  {
   /* stopping condition, recalculate QP,pQP for numerical accuracy*/
   pQp = 0;
   for (t = 0; t < k; t++)
    {
     Qp[t] = 0;
     for (j = 0; j < k; j++)
       Qp[t] += Q[t][j] * p[j];
     pQp += p[t] * Qp[t];
    }
   max_error = 0;
   for (t = 0; t < k; t++)
    {
     error = fabs(Qp[t] - pQp);
     if (error > max_error)
       max_error = error;
    }
   if (max_error < eps) 
     break;
   for (t = 0; t < k; t++)
    {
     diff = (-Qp[t] + pQp) / Q[t][t];
     p[t] += diff;
     pQp = (pQp + diff * (diff * Q[t][t] + 2 * Qp[t])) / (1 + diff) / (1 + diff);
     for (j = 0; j < k; j++)
      {
       Qp[j] = (Qp[j] + diff * Q[t][j]) / (1 + diff);
       p[j] /= (1 + diff);
      }
    }
  }
 free_2d((void**)Q, k);
 safe_free(Qp);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rsi, %r13
movl %edi, %ebx
cvtsi2sd %edi, %xmm0
movsd %xmm0, (%rsp)
leaq 0x1ccc5(%rip), %r8      # 0xa1a06
pushq $0x8
popq %rdi
pushq $0x4
popq %r9
movq %rdi, %rsi
movl %ebx, %edx
movl %ebx, %ecx
callq 0x351c3
movq %rax, %r15
movslq %ebx, %rbp
leaq (,%rbp,8), %rdi
leaq 0x1ccb4(%rip), %rsi     # 0xa1a1d
pushq $0x5
popq %rdx
callq 0x34f59
movsd (%rsp), %xmm4
movq %rax, %r12
movsd 0x1079f(%rip), %xmm0    # 0x95520
movapd %xmm0, %xmm1
divsd %xmm4, %xmm1
xorl %ecx, %ecx
testl %ebp, %ebp
movl $0x0, %eax
cmovgl %ebx, %eax
movapd 0x11433(%rip), %xmm2    # 0x961d0
cmpq %rax, %rcx
je 0x84e30
movsd %xmm1, (%r14,%rcx,8)
movq (%r15,%rcx,8), %rdx
andq $0x0, (%rdx,%rcx,8)
xorl %esi, %esi
cmpq %rsi, %rcx
je 0x84de7
movq (%r13,%rsi,8), %rdi
movsd (%rdi,%rcx,8), %xmm3
mulsd %xmm3, %xmm3
addsd (%rdx,%rcx,8), %xmm3
movsd %xmm3, (%rdx,%rcx,8)
movq (%r15,%rsi,8), %rdi
movsd (%rdi,%rcx,8), %xmm3
movsd %xmm3, (%rdx,%rsi,8)
incq %rsi
jmp 0x84db7
movq %rcx, %rsi
leal 0x1(%rsi), %edi
cmpl %ebx, %edi
jge 0x84e28
movq 0x8(%r13,%rsi,8), %rdi
movsd (%rdi,%rcx,8), %xmm3
mulsd %xmm3, %xmm3
addsd (%rdx,%rcx,8), %xmm3
movsd %xmm3, (%rdx,%rcx,8)
movsd (%rdi,%rcx,8), %xmm3
xorpd %xmm2, %xmm3
movq (%r13,%rcx,8), %rdi
mulsd 0x8(%rdi,%rsi,8), %xmm3
movsd %xmm3, 0x8(%rdx,%rsi,8)
incq %rsi
jmp 0x84dea
incq %rcx
jmp 0x84d9d
movsd 0x12ea0(%rip), %xmm1    # 0x97cd8
divsd %xmm4, %xmm1
movl %ebx, %ecx
xorl %edx, %edx
movapd 0x11398(%rip), %xmm2    # 0x961e0
cmpl $0x64, %edx
je 0x84f71
xorpd %xmm3, %xmm3
xorl %esi, %esi
cmpq %rax, %rsi
je 0x84e9a
andq $0x0, (%r12,%rsi,8)
xorpd %xmm4, %xmm4
xorl %edi, %edi
cmpq %rdi, %rcx
je 0x84e8b
movq (%r15,%rsi,8), %r8
movsd (%r8,%rdi,8), %xmm5
mulsd (%r14,%rdi,8), %xmm5
addsd %xmm5, %xmm4
movsd %xmm4, (%r12,%rsi,8)
incq %rdi
jmp 0x84e67
mulsd (%r14,%rsi,8), %xmm4
addsd %xmm4, %xmm3
incq %rsi
jmp 0x84e57
xorpd %xmm4, %xmm4
xorl %esi, %esi
cmpq %rsi, %rax
je 0x84ec0
movsd (%r12,%rsi,8), %xmm5
subsd %xmm3, %xmm5
andpd %xmm2, %xmm5
maxsd %xmm4, %xmm5
incq %rsi
movapd %xmm5, %xmm4
jmp 0x84ea0
ucomisd %xmm4, %xmm1
ja 0x84f71
xorl %esi, %esi
cmpq %rax, %rsi
je 0x84f6a
movapd %xmm3, %xmm4
subsd (%r12,%rsi,8), %xmm4
movq (%r15,%rsi,8), %rdi
divsd (%rdi,%rsi,8), %xmm4
movsd (%r14,%rsi,8), %xmm5
addsd %xmm4, %xmm5
movsd %xmm5, (%r14,%rsi,8)
movsd (%r12,%rsi,8), %xmm6
addsd %xmm6, %xmm6
movsd (%rdi,%rsi,8), %xmm5
mulsd %xmm4, %xmm5
addsd %xmm6, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm3, %xmm5
movapd %xmm4, %xmm3
addsd %xmm0, %xmm3
divsd %xmm3, %xmm5
xorl %r8d, %r8d
cmpq %r8, %rcx
je 0x84f5a
movsd (%rdi,%r8,8), %xmm6
mulsd %xmm4, %xmm6
addsd (%r12,%r8,8), %xmm6
divsd %xmm3, %xmm6
movsd %xmm6, (%r12,%r8,8)
movsd (%r14,%r8,8), %xmm6
divsd %xmm3, %xmm6
movsd %xmm6, (%r14,%r8,8)
incq %r8
jmp 0x84f26
divsd %xmm3, %xmm5
incq %rsi
movapd %xmm5, %xmm3
jmp 0x84ecc
incl %edx
jmp 0x84e48
movq %r15, %rdi
movl %ebx, %esi
callq 0x34fc3
movq %r12, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x34ff7