// File: /workspace/github_c_makefile_star2_O1/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
subq $0x18, %rsp
movq %rdx, %r14
movq %rsi, %r13
movl %edi, %ebx
cvtsi2sd %edi, %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x1e586(%rip), %r8      # 0xaea2e
movl $0x8, %edi
movl $0x8, %esi
movl %ebx, %edx
movl %ebx, %ecx
movl $0x4, %r9d
callq 0x393b5
movq %rax, %r15
movslq %ebx, %rbp
leaq (,%rbp,8), %rdi
leaq 0x1e56f(%rip), %rsi     # 0xaea45
movl $0x5, %edx
callq 0x390f5
movsd 0x10(%rsp), %xmm3
movq %rax, %r12
movl %ebx, 0xc(%rsp)
movl %ebx, %eax
testl %ebp, %ebp
jle 0x905ca
movsd 0x12021(%rip), %xmm0    # 0xa2520
divsd %xmm3, %xmm0
xorl %ecx, %ecx
movapd 0x12cc3(%rip), %xmm1    # 0xa31d0
movq %rax, %rdx
movq %r13, %rsi
xorl %r9d, %r9d
movq %r9, %rdi
movsd %xmm0, (%r14,%r9,8)
movq (%r15,%r9,8), %r8
movq $0x0, (%r8,%r9,8)
testq %r9, %r9
je 0x90566
xorl %r9d, %r9d
movq (%r13,%r9,8), %r10
movsd (%r10,%rdi,8), %xmm2
mulsd %xmm2, %xmm2
addsd (%r8,%rdi,8), %xmm2
movsd %xmm2, (%r8,%rdi,8)
movq (%r15,%r9,8), %r10
movsd (%r10,%rdi,8), %xmm2
movsd %xmm2, (%r8,%r9,8)
incq %r9
cmpq %r9, %rdi
jne 0x90533
leaq 0x1(%rdi), %r9
cmpq %rax, %r9
jae 0x905b6
leaq (%r8,%rcx), %r10
movq (%r13,%rdi,8), %r11
addq %rcx, %r11
movl $0x1, %ebp
movq (%rsi,%rbp,8), %rbx
movsd (%rbx,%rdi,8), %xmm2
mulsd %xmm2, %xmm2
addsd (%r8,%rdi,8), %xmm2
movsd %xmm2, (%r8,%rdi,8)
movsd (%rbx,%rdi,8), %xmm2
xorpd %xmm1, %xmm2
mulsd (%r11,%rbp,8), %xmm2
movsd %xmm2, (%r10,%rbp,8)
incq %rbp
cmpq %rbp, %rdx
jne 0x90580
addq $0x8, %rcx
addq $0x8, %rsi
decq %rdx
cmpq %rax, %r9
jne 0x90516
movsd 0x146d6(%rip), %xmm6    # 0xa4ca8
divsd %xmm3, %xmm6
xorl %ecx, %ecx
movapd 0x12c00(%rip), %xmm0    # 0xa31e0
movsd 0x11f38(%rip), %xmm1    # 0xa2520
movl 0xc(%rsp), %esi
xorpd %xmm3, %xmm3
xorpd %xmm2, %xmm2
testl %esi, %esi
jle 0x90642
xorl %edx, %edx
movq $0x0, (%r12,%rdx,8)
movq (%r15,%rdx,8), %r8
xorl %edi, %edi
xorpd %xmm4, %xmm4
movsd (%r8,%rdi,8), %xmm5
mulsd (%r14,%rdi,8), %xmm5
addsd %xmm5, %xmm4
movsd %xmm4, (%r12,%rdx,8)
incq %rdi
cmpq %rdi, %rax
jne 0x9060c
movsd (%r14,%rdx,8), %xmm4
mulsd (%r12,%rdx,8), %xmm4
addsd %xmm4, %xmm2
incq %rdx
cmpq %rax, %rdx
jne 0x905fa
testl %esi, %esi
jle 0x9066a
xorpd %xmm4, %xmm4
xorl %edx, %edx
movsd (%r12,%rdx,8), %xmm3
subsd %xmm2, %xmm3
andpd %xmm0, %xmm3
maxsd %xmm4, %xmm3
incq %rdx
movapd %xmm3, %xmm4
cmpq %rdx, %rax
jne 0x9064c
ucomisd %xmm3, %xmm6
ja 0x90721
testl %esi, %esi
jle 0x90716
xorl %edx, %edx
movapd %xmm2, %xmm3
subsd (%r12,%rdx,8), %xmm3
movq (%r15,%rdx,8), %r8
divsd (%r8,%rdx,8), %xmm3
movsd (%r14,%rdx,8), %xmm4
addsd %xmm3, %xmm4
movsd %xmm4, (%r14,%rdx,8)
movsd (%r12,%rdx,8), %xmm5
addsd %xmm5, %xmm5
movsd (%r8,%rdx,8), %xmm4
mulsd %xmm3, %xmm4
addsd %xmm5, %xmm4
mulsd %xmm3, %xmm4
addsd %xmm2, %xmm4
movapd %xmm3, %xmm2
addsd %xmm1, %xmm2
divsd %xmm2, %xmm4
xorl %edi, %edi
movsd (%r8,%rdi,8), %xmm5
mulsd %xmm3, %xmm5
addsd (%r12,%rdi,8), %xmm5
divsd %xmm2, %xmm5
movsd %xmm5, (%r12,%rdi,8)
movsd (%r14,%rdi,8), %xmm5
divsd %xmm2, %xmm5
movsd %xmm5, (%r14,%rdi,8)
incq %rdi
cmpq %rdi, %rax
jne 0x906d0
divsd %xmm2, %xmm4
incq %rdx
movapd %xmm4, %xmm2
cmpq %rax, %rdx
jne 0x9067e
incl %ecx
cmpl $0x64, %ecx
jne 0x905ec
movq %r15, %rdi
callq 0x3915f
movq %r12, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x39194