// File: /workspace/github_c_makefile_star2_O0/olcaytaner[P]Isell/svmsimplex.c
// Function: solve_binary_svm
Svm_binary_modelptr solve_binary_svm(Instanceptr data, Svm_simplex_parameterptr parameters, int negative)
{
 int i, j, k, correct;
 Quadraticprogramptr program;
 Convexsolutionptr solution;
 Svm_binary_modelptr model;
 Instanceptr tmp;
 double sum, upper_bound = -INT_MAX, lower_bound = +INT_MAX;
 model = safemalloc(sizeof(Svm_binary_model), "solve_binary_svm", 4);
 program = prepare_qp_for_C_svm(data, parameters, negative);
 solution = solve_qp_wolfe_method(program);
 model->support_vector_count = 0;
 for (i = 0; i < solution->variablecount; i++)
   if (solution->variables[i] > DBL_DELTA)
     model->support_vector_count++;
 model->alpha_y = safemalloc(model->support_vector_count * sizeof(double), "solve_binary_svm", 10);
 model->support_vectors = safemalloc(model->support_vector_count * sizeof(Instanceptr), "solve_binary_svm", 11);
 j = 0;
 model->b = 0;
 correct = 0;
 for (i = 0, tmp = data; i < solution->variablecount; i++, tmp = tmp->next)
  {
   if (solution->variables[i] > DBL_DELTA)
    {
     model->alpha_y[j] = solution->variables[i] * svm_classno(tmp, negative);
     model->support_vectors[j] = tmp;
     j++;
    }
   sum = program->c[i];
   for (k = 0; k < solution->variablecount; k++)
     sum += program->Q.values[i][k] * solution->variables[k];
   sum *= svm_classno(tmp, negative);
   if (solution->variables[i] > DBL_DELTA && solution->variables[i] < (parameters->C - DBL_DELTA))
    {
     model->b += sum;
     correct++;
    }
   else
     if (solution->variables[i] < DBL_DELTA)
      {
       if (svm_classno(tmp, negative) == -1 && sum > upper_bound)
         upper_bound = sum;
       if (svm_classno(tmp, negative) == 1 && sum < lower_bound)
         lower_bound = sum;
      }
     else
       if (solution->variables[i] > (parameters->C - DBL_DELTA))
        {
         if (svm_classno(tmp, negative) == 1 && sum > upper_bound)
           upper_bound = sum;
         if (svm_classno(tmp, negative) == -1 && sum < lower_bound)
           lower_bound = sum;
        }
  }
 if (correct > 0)
   model->b /= correct;
 else
   model->b = (upper_bound + lower_bound) / 2;
 model->b *= -1;
 free_convex_solution(solution);
 free_quadratic_program(program);
 return model;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movsd 0x14fdd(%rip), %xmm0    # 0xe2008
movsd %xmm0, -0x58(%rbp)
movsd 0x14fd8(%rip), %xmm0    # 0xe2010
movsd %xmm0, -0x60(%rbp)
movl $0x20, %edi
leaq 0x211f8(%rip), %rsi     # 0xee241
movl $0x4, %edx
callq 0x52d70
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
callq 0xcc880
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x16000
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0xcd0cc
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd 0x159c2(%rip), %xmm1    # 0xe2a70
ucomisd %xmm1, %xmm0
jbe 0xcd0bf
movq -0x40(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0xcd0c1
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xcd089
movq -0x40(%rbp), %rax
movslq (%rax), %rdi
shlq $0x3, %rdi
leaq 0x21163(%rip), %rsi     # 0xee241
movl $0xa, %edx
callq 0x52d70
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rax
movslq (%rax), %rdi
shlq $0x3, %rdi
leaq 0x2113c(%rip), %rsi     # 0xee241
movl $0xb, %edx
callq 0x52d70
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x8(%rax)
movl $0x0, -0x1c(%rbp)
movq -0x40(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x18(%rax)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x18(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0xcd3d7
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd 0x15904(%rip), %xmm1    # 0xe2a70
ucomisd %xmm1, %xmm0
jbe 0xcd1cf
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x68(%rbp)
movq -0x48(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x444b0
movsd -0x68(%rbp), %xmm0
cvtsi2sd %eax, %xmm1
mulsd %xmm1, %xmm0
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x1c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x48(%rbp), %rdx
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x18(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x50(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0xcd23f
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
movsd -0x50(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xcd1ec
movq -0x48(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x444b0
cvtsi2sd %eax, %xmm0
mulsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd 0x157fe(%rip), %xmm1    # 0xe2a70
ucomisd %xmm1, %xmm0
jbe 0xcd2c5
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x10(%rbp), %rax
movsd 0x20(%rax), %xmm0
movsd 0x157d6(%rip), %xmm2    # 0xe2a70
subsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0xcd2c5
movsd -0x50(%rbp), %xmm0
movq -0x40(%rbp), %rax
addsd 0x18(%rax), %xmm0
movsd %xmm0, 0x18(%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xcd3bb
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
movsd 0x15797(%rip), %xmm0    # 0xe2a70
ucomisd (%rax,%rcx,8), %xmm0
jbe 0xcd337
movq -0x48(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x444b0
cmpl $-0x1, %eax
jne 0xcd307
movsd -0x50(%rbp), %xmm0
ucomisd -0x58(%rbp), %xmm0
jbe 0xcd307
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0x48(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x444b0
cmpl $0x1, %eax
jne 0xcd332
movsd -0x50(%rbp), %xmm1
movsd -0x60(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xcd332
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
jmp 0xcd3b9
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movsd 0x20(%rax), %xmm1
movsd 0x15717(%rip), %xmm2    # 0xe2a70
subsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xcd3b7
movq -0x48(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x444b0
cmpl $0x1, %eax
jne 0xcd38a
movsd -0x50(%rbp), %xmm0
ucomisd -0x58(%rbp), %xmm0
jbe 0xcd38a
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0x48(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x444b0
cmpl $-0x1, %eax
jne 0xcd3b5
movsd -0x50(%rbp), %xmm1
movsd -0x60(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xcd3b5
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
jmp 0xcd3b7
jmp 0xcd3b9
jmp 0xcd3bb
jmp 0xcd3bd
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0xcd143
cmpl $0x0, -0x24(%rbp)
jle 0xcd3f6
cvtsi2sdl -0x24(%rbp), %xmm1
movq -0x40(%rbp), %rax
movsd 0x18(%rax), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rax)
jmp 0xcd415
movsd -0x58(%rbp), %xmm0
addsd -0x60(%rbp), %xmm0
movsd 0x15898(%rip), %xmm1    # 0xe2ca0
divsd %xmm1, %xmm0
movq -0x40(%rbp), %rax
movsd %xmm0, 0x18(%rax)
movq -0x40(%rbp), %rax
movsd 0x15627(%rip), %xmm0    # 0xe2a48
mulsd 0x18(%rax), %xmm0
movsd %xmm0, 0x18(%rax)
movq -0x38(%rbp), %rdi
callq 0x14f00
movq -0x30(%rbp), %rdi
callq 0x14ea0
movq -0x40(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)