// File: /workspace/github_c_makefile_star2_O1/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 0x8fea1
xorl %eax, %eax
movsd 0x126c0(%rip), %xmm1    # 0xa2520
xorpd %xmm2, %xmm2
movq 0x40(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm3
ucomisd %xmm0, %xmm3
ja 0x8fe78
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 0x8fe69
movsd %xmm5, 0x10(%rsp)
movapd %xmm6, 0x70(%rsp)
addsd 0x1266b(%rip), %xmm6    # 0xa2520
movapd %xmm6, 0x30(%rsp)
movl 0xc(%rsp), %ebp
movslq %ebp, %rdi
shlq $0x3, %rdi
leaq 0x1eb53(%rip), %rsi     # 0xaea20
movl $0xa, %edx
callq 0x390f5
movq %rax, %r12
movq $0x0, (%r14)
movsd 0x10(%rsp), %xmm0
addsd 0x12631(%rip), %xmm0    # 0xa2520
divsd 0x30(%rsp), %xmm0
callq 0x4160
movsd %xmm0, (%rbx)
testl %ebp, %ebp
jle 0x9000f
movsd 0x13132(%rip), %xmm0    # 0xa3040
movapd 0x70(%rsp), %xmm2
addsd %xmm0, %xmm2
movapd 0x30(%rsp), %xmm1
divsd %xmm2, %xmm1
movapd %xmm1, 0x30(%rsp)
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd 0x125e6(%rip), %xmm0    # 0xa2520
divsd %xmm1, %xmm0
movapd %xmm0, 0x90(%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 0x90(%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 0x13236(%rip), %xmm4    # 0xa31d0
ucomisd %xmm4, %xmm3
movapd %xmm1, %xmm2
addsd 0x12dfe(%rip), %xmm2    # 0xa2da8
movapd %xmm3, %xmm0
jb 0x8ffb4
movapd %xmm4, %xmm0
cmpnlesd %xmm3, %xmm4
andpd %xmm4, %xmm2
andnpd %xmm1, %xmm4
orpd %xmm2, %xmm4
movapd %xmm4, 0x70(%rsp)
movapd %xmm3, 0x10(%rsp)
callq 0x4060
addsd 0x12542(%rip), %xmm0    # 0xa2520
callq 0x4160
movapd 0x70(%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 0x8ff53
xorl %eax, %eax
movsd 0x12507(%rip), %xmm1    # 0xa2520
movq %rax, 0xa8(%rsp)
xorpd %xmm4, %xmm4
xorpd %xmm0, %xmm0
movapd %xmm0, 0x60(%rsp)
xorpd %xmm5, %xmm5
movsd 0x14c3d(%rip), %xmm0    # 0xa4c78
movapd %xmm0, 0x80(%rsp)
movapd %xmm0, %xmm6
cmpl $0x0, 0xc(%rsp)
jle 0x901be
xorl %ebp, %ebp
movsd 0x14c1b(%rip), %xmm0    # 0xa4c78
movaps %xmm0, %xmm6
movaps %xmm0, 0x80(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movsd %xmm6, 0x90(%rsp)
movsd %xmm5, 0x30(%rsp)
movapd %xmm4, 0x70(%rsp)
movsd (%r15,%rbp,8), %xmm0
mulsd (%r14), %xmm0
addsd (%rbx), %xmm0
ucomisd 0x12c6c(%rip), %xmm0    # 0xa2d08
jae 0x900d2
movapd %xmm0, 0x40(%rsp)
callq 0x4060
movsd 0x1246f(%rip), %xmm1    # 0xa2520
addsd %xmm1, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movapd 0x40(%rsp), %xmm0
callq 0x4060
movsd %xmm0, 0x58(%rsp)
jmp 0x90118
xorpd 0x130f6(%rip), %xmm0    # 0xa31d0
movapd %xmm0, 0x40(%rsp)
callq 0x4060
movsd %xmm0, 0x10(%rsp)
movapd 0x40(%rsp), %xmm0
callq 0x4060
movsd 0x12422(%rip), %xmm1    # 0xa2520
addsd %xmm1, %xmm0
movsd 0x10(%rsp), %xmm2
divsd %xmm0, %xmm2
movsd %xmm2, 0x10(%rsp)
movsd %xmm1, 0x58(%rsp)
movapd 0x40(%rsp), %xmm0
callq 0x4060
movsd 0x123f5(%rip), %xmm3    # 0xa2520
addsd %xmm3, %xmm0
movsd 0x58(%rsp), %xmm4
divsd %xmm0, %xmm4
movsd 0x10(%rsp), %xmm2
mulsd %xmm2, %xmm4
movsd (%r15,%rbp,8), %xmm0
movapd %xmm0, %xmm1
mulsd %xmm0, %xmm1
mulsd %xmm4, %xmm1
movsd 0x90(%rsp), %xmm6
addsd %xmm1, %xmm6
movapd 0x80(%rsp), %xmm1
addsd %xmm4, %xmm1
movapd %xmm1, 0x80(%rsp)
mulsd %xmm0, %xmm4
movsd 0x30(%rsp), %xmm5
addsd %xmm4, %xmm5
movsd (%r12,%rbp,8), %xmm1
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movapd 0x60(%rsp), %xmm2
addsd %xmm0, %xmm2
movapd %xmm2, 0x60(%rsp)
movapd 0x70(%rsp), %xmm4
addsd %xmm1, %xmm4
incq %rbp
cmpq %rbp, %r13
movapd %xmm3, %xmm1
jne 0x90070
movapd 0x60(%rsp), %xmm0
andpd 0x13014(%rip), %xmm0    # 0xa31e0
movsd 0x16c9c(%rip), %xmm2    # 0xa6e70
ucomisd %xmm0, %xmm2
jbe 0x901f8
movapd %xmm4, %xmm0
andpd 0x12ffa(%rip), %xmm0    # 0xa31e0
movsd 0x16c82(%rip), %xmm2    # 0xa6e70
ucomisd %xmm0, %xmm2
ja 0x903fd
movapd %xmm5, %xmm0
mulsd %xmm5, %xmm0
movapd %xmm4, %xmm7
mulsd %xmm6, %xmm7
movapd 0x80(%rsp), %xmm3
mulsd %xmm3, %xmm6
subsd %xmm0, %xmm6
movapd %xmm4, %xmm0
mulsd %xmm5, %xmm0
movapd 0x60(%rsp), %xmm2
mulsd %xmm2, %xmm3
subsd %xmm0, %xmm3
movapd 0x12f99(%rip), %xmm0    # 0xa31d0
xorpd %xmm0, %xmm3
divsd %xmm6, %xmm3
mulsd %xmm2, %xmm5
subsd %xmm5, %xmm7
xorpd %xmm0, %xmm7
divsd %xmm6, %xmm7
movapd %xmm7, 0xb0(%rsp)
mulsd %xmm7, %xmm4
movapd %xmm3, 0x80(%rsp)
mulsd %xmm3, %xmm2
addsd %xmm4, %xmm2
movapd %xmm2, 0x60(%rsp)
movapd %xmm1, %xmm2
movapd %xmm2, %xmm0
mulsd 0x80(%rsp), %xmm0
addsd (%r14), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd %xmm2, 0x58(%rsp)
mulsd 0xb0(%rsp), %xmm2
addsd (%rbx), %xmm2
movsd %xmm2, 0x90(%rsp)
cmpl $0x0, 0xc(%rsp)
jle 0x90366
xorpd %xmm1, %xmm1
xorl %ebp, %ebp
movsd %xmm1, 0x40(%rsp)
movsd (%r15,%rbp,8), %xmm2
mulsd 0x30(%rsp), %xmm2
addsd 0x90(%rsp), %xmm2
movapd %xmm2, %xmm1
xorpd 0x12eed(%rip), %xmm1    # 0xa31d0
ucomisd %xmm1, %xmm2
movsd (%r12,%rbp,8), %xmm0
movapd %xmm0, %xmm3
addsd 0x12aaf(%rip), %xmm3    # 0xa2da8
jb 0x902ff
movapd %xmm0, %xmm3
movsd %xmm3, 0x70(%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 0x121eb(%rip), %xmm0    # 0xa2520
callq 0x4160
movsd 0x70(%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 0x902bc
jmp 0x9036a
xorpd %xmm1, %xmm1
movsd 0x58(%rsp), %xmm2
movapd %xmm2, %xmm0
mulsd 0x1456c(%rip), %xmm0    # 0xa48e8
mulsd 0x60(%rsp), %xmm0
addsd 0x28(%rsp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x903b6
mulsd 0x12982(%rip), %xmm2    # 0xa2d18
ucomisd 0x1e592(%rip), %xmm2    # 0xae930
movsd 0x1217a(%rip), %xmm1    # 0xa2520
movq 0xa8(%rsp), %rax
jae 0x90277
jmp 0x903e4
movsd 0x30(%rsp), %xmm0
movsd %xmm0, (%r14)
movsd 0x90(%rsp), %xmm0
movsd %xmm0, (%rbx)
movsd %xmm1, 0x28(%rsp)
movsd 0x12144(%rip), %xmm1    # 0xa2520
movq 0xa8(%rsp), %rax
movsd 0x1e544(%rip), %xmm0    # 0xae930
ucomisd %xmm2, %xmm0
ja 0x903fd
incl %eax
cmpl $0x64, %eax
jne 0x90019
movq %r12, %rdi
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x39194