// File: /workspace/github_c_makefile_star2_O3/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, 0x8(%rsp)
leaq 0x1eb91(%rip), %r8      # 0xb1aa6
movl $0x8, %edi
movl $0x8, %esi
movl %ebx, %edx
movl %ebx, %ecx
movl $0x4, %r9d
callq 0x3a3ac
movq %rax, %r15
movslq %ebx, %rbp
leaq (,%rbp,8), %rdi
leaq 0x1eb7a(%rip), %rsi     # 0xb1abd
movl $0x5, %edx
callq 0x3a0e1
movsd 0x8(%rsp), %xmm3
movq %rax, %r12
movl %ebx, 0x4(%rsp)
movl %ebx, %eax
movq %rbp, 0x10(%rsp)
testl %ebp, %ebp
jle 0x93040
movsd 0x125af(%rip), %xmm0    # 0xa5520
divsd %xmm3, %xmm0
xorl %ecx, %ecx
movapd 0x13251(%rip), %xmm1    # 0xa61d0
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 0x92fd8
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 0x92fa5
leaq 0x1(%rdi), %r9
cmpq 0x10(%rsp), %r9
jge 0x9302c
leaq (%r8,%rcx), %r10
movq (%r13,%rdi,8), %r11
addq %rcx, %r11
movl $0x1, %ebx
movq (%rsi,%rbx,8), %rbp
movsd (%rbp,%rdi,8), %xmm2
mulsd %xmm2, %xmm2
addsd (%r8,%rdi,8), %xmm2
movsd %xmm2, (%r8,%rdi,8)
movsd (%rbp,%rdi,8), %xmm2
xorpd %xmm1, %xmm2
mulsd (%r11,%rbx,8), %xmm2
movsd %xmm2, (%r10,%rbx,8)
incq %rbx
cmpq %rbx, %rdx
jne 0x92ff4
addq $0x8, %rcx
addq $0x8, %rsi
decq %rdx
cmpq %rax, %r9
jne 0x92f88
movsd 0x14d10(%rip), %xmm6    # 0xa7d58
divsd %xmm3, %xmm6
xorl %ecx, %ecx
movapd 0x1318a(%rip), %xmm0    # 0xa61e0
movsd 0x124c2(%rip), %xmm1    # 0xa5520
movl 0x4(%rsp), %esi
xorpd %xmm2, %xmm2
testl %esi, %esi
jle 0x930d8
xorl %edx, %edx
movq $0x0, (%r12,%rdx,8)
movq (%r15,%rdx,8), %r8
xorl %edi, %edi
xorpd %xmm3, %xmm3
movsd (%r8,%rdi,8), %xmm4
mulsd (%r14,%rdi,8), %xmm4
addsd %xmm4, %xmm3
movsd %xmm3, (%r12,%rdx,8)
incq %rdi
cmpq %rdi, %rax
jne 0x9307e
mulsd (%r14,%rdx,8), %xmm3
addsd %xmm3, %xmm2
incq %rdx
cmpq %rax, %rdx
jne 0x9306c
testl %esi, %esi
jle 0x930d8
xorpd %xmm3, %xmm3
xorl %edx, %edx
movapd %xmm3, %xmm4
movsd (%r12,%rdx,8), %xmm3
subsd %xmm2, %xmm3
andpd %xmm0, %xmm3
maxsd %xmm4, %xmm3
incq %rdx
cmpq %rdx, %rax
jne 0x930b8
jmp 0x930dc
xorpd %xmm3, %xmm3
ucomisd %xmm3, %xmm6
ja 0x93193
testl %esi, %esi
jle 0x93188
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 0x93142
divsd %xmm2, %xmm4
incq %rdx
movapd %xmm4, %xmm2
cmpq %rax, %rdx
jne 0x930f0
incl %ecx
cmpl $0x64, %ecx
jne 0x93062
movq %r15, %rdi
callq 0x3a14b
movq %r12, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3a180