// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd 0x254da(%rip), %xmm0    # 0xedfe0
movsd %xmm0, -0x40(%rbp)
movsd 0x1bd65(%rip), %xmm0    # 0xe4878
movsd %xmm0, -0x48(%rbp)
movsd 0x1df08(%rip), %xmm0    # 0xe6a28
movsd %xmm0, -0x50(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x100(%rbp)
movl $0x64, -0x108(%rbp)
movl $0x0, -0x104(%rbp)
movl -0x104(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0xc8ba1
movq -0x18(%rbp), %rax
movslq -0x104(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xc8b7c
movsd 0x194a8(%rip), %xmm0    # 0xe2018
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0xc8b8e
movsd 0x19494(%rip), %xmm0    # 0xe2018
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0xc8b90
movl -0x104(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x104(%rbp)
jmp 0xc8b44
movsd 0x1946f(%rip), %xmm0    # 0xe2018
addsd -0x30(%rbp), %xmm0
movsd 0x1a0ea(%rip), %xmm1    # 0xe2ca0
addsd -0x30(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd 0x1a0d4(%rip), %xmm1    # 0xe2ca0
addsd -0x38(%rbp), %xmm1
movsd 0x1943f(%rip), %xmm0    # 0xe2018
divsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movslq -0x4(%rbp), %rdi
shlq $0x3, %rdi
leaq 0x254c7(%rip), %rsi     # 0xee0b8
movl $0xa, %edx
callq 0x52d70
movq %rax, -0x68(%rbp)
movq -0x20(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movsd 0x19406(%rip), %xmm0    # 0xe2018
addsd -0x38(%rbp), %xmm0
movsd 0x193f9(%rip), %xmm1    # 0xe2018
addsd -0x30(%rbp), %xmm1
divsd %xmm1, %xmm0
callq 0x4120
movq -0x28(%rbp), %rax
movsd %xmm0, (%rax)
movl $0x0, -0x104(%rbp)
movl -0x104(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0xc8de9
movq -0x18(%rbp), %rax
movslq -0x104(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xc8c7e
movsd -0x58(%rbp), %xmm0
movq -0x68(%rbp), %rax
movslq -0x104(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0xc8c93
movsd -0x60(%rbp), %xmm0
movq -0x68(%rbp), %rax
movslq -0x104(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movslq -0x104(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x20(%rbp), %rax
movsd (%rax), %xmm2
movq -0x28(%rbp), %rax
movsd (%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x70(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xc8d59
movq -0x68(%rbp), %rax
movslq -0x104(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x118(%rbp)
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x120(%rbp)
movsd -0x70(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
callq 0x4060
movaps %xmm0, %xmm1
movsd 0x192f5(%rip), %xmm0    # 0xe2018
addsd %xmm1, %xmm0
callq 0x4120
movsd -0x120(%rbp), %xmm2
movaps %xmm0, %xmm1
movsd -0x118(%rbp), %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
addsd -0x100(%rbp), %xmm0
movsd %xmm0, -0x100(%rbp)
jmp 0xc8dd3
movq -0x68(%rbp), %rax
movslq -0x104(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd 0x192a7(%rip), %xmm1    # 0xe2018
subsd %xmm1, %xmm0
movsd %xmm0, -0x128(%rbp)
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x130(%rbp)
movsd -0x70(%rbp), %xmm0
callq 0x4060
movaps %xmm0, %xmm1
movsd 0x19279(%rip), %xmm0    # 0xe2018
addsd %xmm1, %xmm0
callq 0x4120
movsd -0x130(%rbp), %xmm2
movaps %xmm0, %xmm1
movsd -0x128(%rbp), %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
addsd -0x100(%rbp), %xmm0
movsd %xmm0, -0x100(%rbp)
jmp 0xc8dd5
movl -0x104(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x104(%rbp)
jmp 0xc8c3f
movl $0x0, -0x10c(%rbp)
movl -0x10c(%rbp), %eax
cmpl -0x108(%rbp), %eax
jge 0xc94dd
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x98(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xa0(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xa8(%rbp)
movl $0x0, -0x104(%rbp)
movl -0x104(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0xc90b8
movq -0x10(%rbp), %rax
movslq -0x104(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x20(%rbp), %rax
movsd (%rax), %xmm2
movq -0x28(%rbp), %rax
movsd (%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x70(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xc8f42
movsd -0x70(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
callq 0x4060
movsd %xmm0, -0x138(%rbp)
movsd -0x70(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
callq 0x4060
movaps %xmm0, %xmm2
movsd -0x138(%rbp), %xmm0
movsd 0x19123(%rip), %xmm1    # 0xe2018
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x70(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
callq 0x4060
movsd 0x190ed(%rip), %xmm1    # 0xe2018
addsd %xmm0, %xmm1
movsd 0x190e1(%rip), %xmm0    # 0xe2018
divsd %xmm1, %xmm0
movsd %xmm0, -0x80(%rbp)
jmp 0xc8fa5
movsd -0x70(%rbp), %xmm0
callq 0x4060
movsd 0x190c4(%rip), %xmm1    # 0xe2018
addsd %xmm0, %xmm1
movsd 0x190b8(%rip), %xmm0    # 0xe2018
divsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x70(%rbp), %xmm0
callq 0x4060
movsd %xmm0, -0x140(%rbp)
movsd -0x70(%rbp), %xmm0
callq 0x4060
movaps %xmm0, %xmm2
movsd -0x140(%rbp), %xmm0
movsd 0x19080(%rip), %xmm1    # 0xe2018
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x78(%rbp), %xmm0
mulsd -0x80(%rbp), %xmm0
movsd %xmm0, -0xf8(%rbp)
movq -0x10(%rbp), %rax
movslq -0x104(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movslq -0x104(%rbp), %rcx
mulsd (%rax,%rcx,8), %xmm0
movsd -0xf8(%rbp), %xmm2
movsd -0x88(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0xf8(%rbp), %xmm0
addsd -0x90(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
movq -0x10(%rbp), %rax
movslq -0x104(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd -0xf8(%rbp), %xmm2
movsd -0x98(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x98(%rbp)
movq -0x68(%rbp), %rax
movslq -0x104(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
subsd -0x78(%rbp), %xmm0
movsd %xmm0, -0xf0(%rbp)
movq -0x10(%rbp), %rax
movslq -0x104(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd -0xf0(%rbp), %xmm2
movsd -0xa0(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0xf0(%rbp), %xmm0
addsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movl -0x104(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x104(%rbp)
jmp 0xc8e4a
movsd -0xa0(%rbp), %xmm1
movaps 0x19d99(%rip), %xmm0    # 0xe2e60
pand %xmm0, %xmm1
movsd -0x50(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xc90f9
movsd -0xa8(%rbp), %xmm1
movaps 0x19d7b(%rip), %xmm0    # 0xe2e60
pand %xmm0, %xmm1
movsd -0x50(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xc90f9
jmp 0xc94dd
movsd -0x88(%rbp), %xmm0
movsd -0x90(%rbp), %xmm2
movsd -0x98(%rbp), %xmm1
mulsd -0x98(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0x90(%rbp), %xmm0
movsd -0xa0(%rbp), %xmm2
movsd -0x98(%rbp), %xmm1
mulsd -0xa8(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
divsd -0xb0(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd -0x98(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd -0xa0(%rbp), %xmm2
movsd -0x88(%rbp), %xmm1
mulsd -0xa8(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
divsd -0xb0(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
movsd -0xa0(%rbp), %xmm0
movsd -0xb8(%rbp), %xmm2
movsd -0xa8(%rbp), %xmm1
mulsd -0xc0(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd 0x18dd4(%rip), %xmm0    # 0xe2018
movsd %xmm0, -0xd0(%rbp)
movsd -0xd0(%rbp), %xmm0
ucomisd -0x40(%rbp), %xmm0
jb 0xc94b2
movq -0x20(%rbp), %rax
movsd (%rax), %xmm1
movsd -0xd0(%rbp), %xmm0
movsd -0xb8(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xd8(%rbp)
movq -0x28(%rbp), %rax
movsd (%rax), %xmm1
movsd -0xd0(%rbp), %xmm0
movsd -0xc0(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xe0(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xe8(%rbp)
movl $0x0, -0x104(%rbp)
movl -0x104(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0xc9429
movq -0x10(%rbp), %rax
movslq -0x104(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd -0xd8(%rbp), %xmm2
movsd -0xe0(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x70(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xc9399
movq -0x68(%rbp), %rax
movslq -0x104(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x148(%rbp)
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x150(%rbp)
movsd -0x70(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
callq 0x4060
movaps %xmm0, %xmm1
movsd 0x18cb5(%rip), %xmm0    # 0xe2018
addsd %xmm1, %xmm0
callq 0x4120
movsd -0x150(%rbp), %xmm2
movaps %xmm0, %xmm1
movsd -0x148(%rbp), %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
addsd -0xe8(%rbp), %xmm0
movsd %xmm0, -0xe8(%rbp)
jmp 0xc9413
movq -0x68(%rbp), %rax
movslq -0x104(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd 0x18c67(%rip), %xmm1    # 0xe2018
subsd %xmm1, %xmm0
movsd %xmm0, -0x158(%rbp)
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x160(%rbp)
movsd -0x70(%rbp), %xmm0
callq 0x4060
movaps %xmm0, %xmm1
movsd 0x18c39(%rip), %xmm0    # 0xe2018
addsd %xmm1, %xmm0
callq 0x4120
movsd -0x160(%rbp), %xmm2
movaps %xmm0, %xmm1
movsd -0x158(%rbp), %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
addsd -0xe8(%rbp), %xmm0
movsd %xmm0, -0xe8(%rbp)
jmp 0xc9415
movl -0x104(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x104(%rbp)
jmp 0xc92c4
movsd -0xe8(%rbp), %xmm1
movsd -0x100(%rbp), %xmm2
movsd 0x1b0b7(%rip), %xmm0    # 0xe44f8
mulsd -0xd0(%rbp), %xmm0
movsd -0xc8(%rbp), %xmm3
mulsd %xmm3, %xmm0
addsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0xc9491
movsd -0xd8(%rbp), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0xe0(%rbp), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0xe8(%rbp), %xmm0
movsd %xmm0, -0x100(%rbp)
jmp 0xc94b2
movsd -0xd0(%rbp), %xmm0
movsd 0x197ff(%rip), %xmm1    # 0xe2ca0
divsd %xmm1, %xmm0
movsd %xmm0, -0xd0(%rbp)
jmp 0xc924c
movsd -0xd0(%rbp), %xmm1
movsd -0x40(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xc94c7
jmp 0xc94dd
jmp 0xc94c9
movl -0x10c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10c(%rbp)
jmp 0xc8df3
movq -0x68(%rbp), %rdi
callq 0x52e80
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
nop