// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/svm.c
// Function: sigmoid_train
void sigmoid_train(int l, double *dec_values, double *labels, double* A, double* B)
{
 double prior1 = 0, prior0 = 0, min_step = 1e-10, sigma = 1e-3, eps = 1e-5, hiTarget, loTarget, *t;
 double fApB, p, q, h11, h22, h21, g1, g2, det, dA, dB, gd, stepsize, newA, newB, newf, d1, d2, fval = 0.0;
 int i, max_iter = 100, iter;
 for (i = 0; i < l; i++)
   if (labels[i] > 0) 
     prior1 += 1;
   else 
     prior0 += 1;
 hiTarget = (prior1 + 1.0) / (prior1 + 2.0);
 loTarget = 1 / (prior0 + 2.0);
 t = safemalloc(l * sizeof(double), "sigmoid_train", 10);
 /* Initial Point and Initial Fun Value*/
 *A = 0.0; 
 *B = log((prior0 + 1.0) / (prior1 + 1.0));
 for (i = 0; i < l; i++)
  {
   if (labels[i] > 0) 
     t[i] = hiTarget;
   else 
     t[i] = loTarget;
   fApB = dec_values[i] * (*A) + (*B);
   if (fApB >= 0)
     fval += t[i] * fApB + log(1 + exp(-fApB));
   else
     fval += (t[i] - 1) * fApB + log(1 + exp(fApB));
  }
 for (iter = 0; iter < max_iter; iter++)
  {
   h11 = sigma; 
   h22 = sigma;
   h21 = 0.0;
   g1 = 0.0;
   g2 = 0.0;
   for (i = 0; i < l; i++)
    {
     fApB = dec_values[i] * (*A) + (*B);
     if (fApB >= 0)
      {
       p = exp(-fApB) / (1.0 + exp(-fApB));
       q = 1.0 / (1.0 + exp(-fApB));
      }
     else
      {
       p = 1.0 / (1.0 + exp(fApB));
       q = exp(fApB) / (1.0 + exp(fApB));
      }
     d2 = p * q;
     h11 += dec_values[i] * dec_values[i] * d2;
     h22 += d2;
     h21 += dec_values[i] * d2;
     d1 = t[i] - p;
     g1 += dec_values[i] * d1;
     g2 += d1;
    }
   if (fabs(g1) < eps && fabs(g2) < eps)
     break;
   /* Finding Newton direction: -inv(H') * g*/
   det = h11 * h22 - h21 * h21;
   dA = -(h22 * g1 - h21 * g2) / det;
   dB = -(-h21 * g1 + h11 * g2) / det;
   gd = g1 * dA + g2 * dB;
   stepsize = 1;   /* Line Search*/
   while (stepsize >= min_step)
    {
     newA = (*A) + stepsize * dA;
     newB = (*B) + stepsize * dB;
     /* New function value*/
     newf = 0.0;
     for (i = 0; i < l; i++)
      {
       fApB = dec_values[i] * newA + newB;
       if (fApB >= 0)
         newf += t[i] * fApB + log(1 + exp(-fApB));
       else
         newf += (t[i] - 1)*fApB + log(1 + exp(fApB));
      }
     /* Check sufficient decrease*/
     if (newf < fval + 0.0001 * stepsize * gd)
      {
       *A = newA;
       *B = newB;
       fval = newf;
       break;
      }
     else
       stepsize = stepsize / 2.0;
    }
   if (stepsize < min_step)
     break;
 }
 safe_free(t);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %r8, %rbx
movq %rcx, %r14
movq %rdx, 0x40(%rsp)
movq %rsi, %r15
xorpd %xmm0, %xmm0
movsd %xmm0, 0x28(%rsp)
movl %edi, %r13d
xorpd %xmm5, %xmm5
xorpd %xmm6, %xmm6
movl %edi, 0xc(%rsp)
testl %edi, %edi
jle 0x92937
xorl %eax, %eax
movsd 0x12c2a(%rip), %xmm1    # 0xa5520
xorpd %xmm2, %xmm2
movq 0x40(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm3
ucomisd %xmm0, %xmm3
ja 0x9290e
addsd %xmm1, %xmm5
movapd %xmm2, %xmm4
addsd %xmm1, %xmm4
xorpd %xmm6, %xmm6
cmpltsd %xmm3, %xmm6
andpd %xmm6, %xmm4
andnpd %xmm2, %xmm6
orpd %xmm4, %xmm6
incq %rax
movapd %xmm6, %xmm2
cmpq %rax, %r13
jne 0x928ff
movsd %xmm5, 0x10(%rsp)
movapd %xmm6, 0x50(%rsp)
addsd 0x12bd5(%rip), %xmm6    # 0xa5520
movapd %xmm6, 0x30(%rsp)
movl 0xc(%rsp), %ebp
movslq %ebp, %rdi
shlq $0x3, %rdi
leaq 0x1f135(%rip), %rsi     # 0xb1a98
movl $0xa, %edx
callq 0x3a0e1
movq %rax, %r12
movq $0x0, (%r14)
movsd 0x10(%rsp), %xmm0
addsd 0x12b9b(%rip), %xmm0    # 0xa5520
divsd 0x30(%rsp), %xmm0
callq 0x4160
movsd %xmm0, (%rbx)
testl %ebp, %ebp
jle 0x92a9f
movsd 0x1369c(%rip), %xmm0    # 0xa6040
movapd 0x50(%rsp), %xmm2
addsd %xmm0, %xmm2
movapd 0x30(%rsp), %xmm1
divsd %xmm2, %xmm1
movapd %xmm1, 0x30(%rsp)
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd 0x12b50(%rip), %xmm0    # 0xa5520
divsd %xmm1, %xmm0
movapd %xmm0, 0x70(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x28(%rsp)
xorl %ebp, %ebp
xorpd %xmm1, %xmm1
movq 0x40(%rsp), %rax
cmpltsd (%rax,%rbp,8), %xmm1
movapd %xmm1, %xmm0
andpd 0x30(%rsp), %xmm0
andnpd 0x70(%rsp), %xmm1
orpd %xmm0, %xmm1
movlpd %xmm1, (%r12,%rbp,8)
movsd (%r15,%rbp,8), %xmm3
mulsd (%r14), %xmm3
addsd (%rbx), %xmm3
movapd %xmm3, %xmm4
xorpd 0x137a6(%rip), %xmm4    # 0xa61d0
ucomisd %xmm4, %xmm3
movapd %xmm1, %xmm2
addsd 0x1336e(%rip), %xmm2    # 0xa5da8
movapd %xmm3, %xmm0
jb 0x92a44
movapd %xmm4, %xmm0
cmpnlesd %xmm3, %xmm4
andpd %xmm4, %xmm2
andnpd %xmm1, %xmm4
orpd %xmm2, %xmm4
movapd %xmm4, 0x50(%rsp)
movapd %xmm3, 0x10(%rsp)
callq 0x4060
addsd 0x12ab2(%rip), %xmm0    # 0xa5520
callq 0x4160
movapd 0x50(%rsp), %xmm1
mulsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd 0x28(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
incq %rbp
cmpq %rbp, %r13
jne 0x929e6
xorl %eax, %eax
movsd 0x12a77(%rip), %xmm1    # 0xa5520
movq %rax, 0x88(%rsp)
cmpl $0x0, 0xc(%rsp)
jle 0x92c17
xorpd %xmm4, %xmm4
xorpd %xmm3, %xmm3
xorl %ebp, %ebp
movsd 0x1525a(%rip), %xmm0    # 0xa7d28
movaps %xmm0, %xmm5
movaps %xmm0, 0x60(%rsp)
movsd %xmm5, 0x70(%rsp)
movapd %xmm4, 0x30(%rsp)
movapd %xmm3, 0x50(%rsp)
movsd (%r15,%rbp,8), %xmm0
mulsd (%r14), %xmm0
addsd (%rbx), %xmm0
ucomisd 0x13209(%rip), %xmm0    # 0xa5d08
jae 0x92b38
movapd %xmm0, 0x40(%rsp)
callq 0x4060
movsd 0x12a0c(%rip), %xmm1    # 0xa5520
addsd %xmm1, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movapd 0x40(%rsp), %xmm0
callq 0x4060
movapd %xmm0, 0x90(%rsp)
jmp 0x92b81
xorpd 0x13690(%rip), %xmm0    # 0xa61d0
movapd %xmm0, 0x40(%rsp)
callq 0x4060
movsd %xmm0, 0x10(%rsp)
movapd 0x40(%rsp), %xmm0
callq 0x4060
movsd 0x129bc(%rip), %xmm1    # 0xa5520
addsd %xmm1, %xmm0
movsd 0x10(%rsp), %xmm2
divsd %xmm0, %xmm2
movsd %xmm2, 0x10(%rsp)
movapd %xmm1, 0x90(%rsp)
movapd 0x40(%rsp), %xmm0
callq 0x4060
movsd 0x1298c(%rip), %xmm2    # 0xa5520
addsd %xmm2, %xmm0
movapd 0x90(%rsp), %xmm6
divsd %xmm0, %xmm6
movsd 0x10(%rsp), %xmm3
mulsd %xmm3, %xmm6
movsd (%r15,%rbp,8), %xmm0
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
mulsd %xmm6, %xmm1
movsd 0x70(%rsp), %xmm5
addsd %xmm1, %xmm5
movapd 0x60(%rsp), %xmm1
addsd %xmm6, %xmm1
movapd %xmm1, 0x60(%rsp)
movsd (%r12,%rbp,8), %xmm1
subsd %xmm3, %xmm1
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
unpcklpd %xmm1, %xmm6            # xmm6 = xmm6[0],xmm1[0]
mulpd %xmm0, %xmm6
movapd 0x30(%rsp), %xmm4
addpd %xmm6, %xmm4
movapd 0x50(%rsp), %xmm3
addsd %xmm1, %xmm3
incq %rbp
cmpq %rbp, %r13
movapd %xmm2, %xmm1
jne 0x92ad6
jmp 0x92c31
xorpd %xmm4, %xmm4
xorpd %xmm3, %xmm3
movsd 0x15101(%rip), %xmm0    # 0xa7d28
movapd %xmm0, 0x60(%rsp)
movapd %xmm0, %xmm5
movapd %xmm4, %xmm0
unpckhpd %xmm4, %xmm0            # xmm0 = xmm0[1],xmm4[1]
movapd %xmm0, %xmm6
andpd 0x1359b(%rip), %xmm0    # 0xa61e0
movsd 0x17293(%rip), %xmm2    # 0xa9ee0
ucomisd %xmm0, %xmm2
jbe 0x92c71
movapd %xmm3, %xmm0
andpd 0x13581(%rip), %xmm0    # 0xa61e0
movsd 0x17279(%rip), %xmm2    # 0xa9ee0
ucomisd %xmm0, %xmm2
ja 0x92e6a
movapd %xmm4, %xmm0
mulsd %xmm4, %xmm0
movapd %xmm3, %xmm7
mulsd %xmm5, %xmm7
movapd 0x60(%rsp), %xmm2
mulsd %xmm2, %xmm5
subsd %xmm0, %xmm5
movapd %xmm3, %xmm0
mulsd %xmm4, %xmm0
mulsd %xmm6, %xmm2
subsd %xmm0, %xmm2
movapd 0x13529(%rip), %xmm0    # 0xa61d0
xorpd %xmm0, %xmm2
divsd %xmm5, %xmm2
mulsd %xmm6, %xmm4
subsd %xmm4, %xmm7
xorpd %xmm0, %xmm7
divsd %xmm5, %xmm7
movapd %xmm7, 0xa0(%rsp)
mulsd %xmm7, %xmm3
movapd %xmm2, 0x60(%rsp)
mulsd %xmm2, %xmm6
addsd %xmm3, %xmm6
movapd %xmm6, 0xb0(%rsp)
movapd %xmm1, %xmm2
movapd %xmm2, %xmm0
mulsd 0x60(%rsp), %xmm0
addsd (%r14), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd %xmm2, 0x90(%rsp)
mulsd 0xa0(%rsp), %xmm2
addsd (%rbx), %xmm2
movsd %xmm2, 0x70(%rsp)
cmpl $0x0, 0xc(%rsp)
jle 0x92dd0
xorpd %xmm1, %xmm1
xorl %ebp, %ebp
movsd %xmm1, 0x40(%rsp)
movsd (%r15,%rbp,8), %xmm2
mulsd 0x30(%rsp), %xmm2
addsd 0x70(%rsp), %xmm2
movapd %xmm2, %xmm1
xorpd 0x13483(%rip), %xmm1    # 0xa61d0
ucomisd %xmm1, %xmm2
movsd (%r12,%rbp,8), %xmm0
movapd %xmm0, %xmm3
addsd 0x13045(%rip), %xmm3    # 0xa5da8
jb 0x92d69
movapd %xmm0, %xmm3
movsd %xmm3, 0x50(%rsp)
movapd %xmm1, %xmm0
cmpnlesd %xmm2, %xmm0
movapd %xmm2, %xmm4
movapd %xmm2, 0x10(%rsp)
movapd %xmm0, %xmm2
andpd %xmm4, %xmm2
andnpd %xmm1, %xmm0
orpd %xmm2, %xmm0
callq 0x4060
addsd 0x12781(%rip), %xmm0    # 0xa5520
callq 0x4160
movsd 0x50(%rsp), %xmm1
mulsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
movsd 0x40(%rsp), %xmm1
addsd %xmm0, %xmm1
incq %rbp
cmpq %rbp, %r13
jne 0x92d29
jmp 0x92dd4
xorpd %xmm1, %xmm1
movsd 0x90(%rsp), %xmm2
movapd %xmm2, %xmm0
mulsd 0x14b3f(%rip), %xmm0    # 0xa7928
mulsd 0xb0(%rsp), %xmm0
addsd 0x28(%rsp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x92e26
mulsd 0x12f12(%rip), %xmm2    # 0xa5d18
ucomisd 0x1ebb2(%rip), %xmm2    # 0xb19c0
movsd 0x1270a(%rip), %xmm1    # 0xa5520
movq 0x88(%rsp), %rax
jae 0x92ce7
jmp 0x92e51
movsd 0x30(%rsp), %xmm0
movsd %xmm0, (%r14)
movsd 0x70(%rsp), %xmm0
movsd %xmm0, (%rbx)
movsd %xmm1, 0x28(%rsp)
movsd 0x126d7(%rip), %xmm1    # 0xa5520
movq 0x88(%rsp), %rax
movsd 0x1eb67(%rip), %xmm0    # 0xb19c0
ucomisd %xmm2, %xmm0
ja 0x92e6a
incl %eax
cmpl $0x64, %eax
jne 0x92aa9
movq %r12, %rdi
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3a180