// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/svmsimplex.c
// Function: solve_svm_regression
Svm_regression_modelptr solve_svm_regression(Instanceptr data, Svm_simplex_parameterptr parameters)
{
 Quadraticprogramptr program;
 Convexsolutionptr solution;
 Svm_regression_modelptr model;
 int i, j, k, correct, size;
 double sum, lower_bound = +INT_MAX, upper_bound = -INT_MAX;
 Instanceptr tmp;
 size = data_size(data);
 model = safemalloc(sizeof(Svm_regression_model), "solve_svm_regression", 4);
 program = prepare_qp_for_epsilon_svm(data, parameters);
 solution = solve_qp_wolfe_method(program);
 model->support_vector_count = 0;
 for (i = 0; i < size; i++)
   if (solution->variables[i] - solution->variables[i + size] > DBL_DELTA)
     model->support_vector_count++;
 model->alpha = safemalloc(model->support_vector_count * sizeof(double), "solve_svm_regression", 10);
 model->support_vectors = safemalloc(model->support_vector_count * sizeof(Instanceptr), "solve_svm_regression", 11);
 j = 0;
 model->b = 0;
 correct = 0;
 for (i = 0, tmp = data; i < size; i++, tmp = tmp->next)
  {
   if (solution->variables[i] - solution->variables[i + size] > DBL_DELTA)
    {
     model->alpha[j] = solution->variables[i] - solution->variables[i + size];
     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];
   if (solution->variables[i] > DBL_DELTA && solution->variables[i] < parameters->C - DBL_DELTA)
    {
     model->b += sum;
     correct++;
    }
   else
     if (solution->variables[i] < DBL_DELTA && sum < lower_bound)
       lower_bound = sum;
     else
       if (solution->variables[i] > parameters->C - DBL_DELTA && sum > upper_bound)
         upper_bound = sum;
   sum = program->c[i + size];
   for (k = 0; k < solution->variablecount; k++)
     sum += program->Q.values[i + size][k] * solution->variables[k];
   sum *= -1;
   if (solution->variables[i + size] > DBL_DELTA && solution->variables[i + size] < parameters->C - DBL_DELTA)
    {
     model->b += sum;
     correct++;
    }
   else
     if (solution->variables[i] < DBL_DELTA && sum > upper_bound)
       upper_bound = sum;
     else
       if (solution->variables[i] > parameters->C - DBL_DELTA && 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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r12
movq %rdi, %r13
callq 0x2fa14
movl %eax, %ebp
leaq 0x1c258(%rip), %rsi     # 0xaeb94
movl $0x20, %edi
movl $0x4, %edx
callq 0x390f5
movq %rax, %rbx
movq %r13, %rdi
movq %r12, %rsi
callq 0x92556
movq %rax, %r14
movq %rax, %rdi
callq 0xfedb
movq %rax, %r15
movl $0x0, (%rbx)
movl %ebp, %eax
movl %ebp, %ebp
movl %eax, 0x4(%rsp)
testl %eax, %eax
jle 0x929a5
movq 0x10(%r15), %rax
leaq (%rax,%rbp,8), %rcx
xorl %edx, %edx
movsd 0x1044d(%rip), %xmm0    # 0xa2dd8
movsd (%rax,%rdx,8), %xmm1
subsd (%rcx,%rdx,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x9299d
incl (%rbx)
incq %rdx
cmpq %rdx, %rbp
jne 0x9298b
movslq (%rbx), %rdi
shlq $0x3, %rdi
leaq 0x1c1e1(%rip), %rsi     # 0xaeb94
movl $0xa, %edx
callq 0x390f5
movq %rax, 0x10(%rbx)
movslq (%rbx), %rdi
shlq $0x3, %rdi
leaq 0x1c1c5(%rip), %rsi     # 0xaeb94
movl $0xb, %edx
callq 0x390f5
movq %rax, 0x8(%rbx)
movq $0x0, 0x18(%rbx)
cmpl $0x0, 0x4(%rsp)
jle 0x92b89
movl 0x18(%r15), %eax
xorl %edx, %edx
movsd 0xfb1a(%rip), %xmm0     # 0xa2518
movsd 0xfb0a(%rip), %xmm1     # 0xa2510
movsd 0x103ca(%rip), %xmm2    # 0xa2dd8
movsd 0x13f7a(%rip), %xmm3    # 0xa6990
movapd 0x107b2(%rip), %xmm4    # 0xa31d0
xorl %ecx, %ecx
xorl %esi, %esi
movq 0x10(%r15), %r8
movsd (%r8,%rdx,8), %xmm5
leaq (%rdx,%rbp), %rdi
subsd (%r8,%rdi,8), %xmm5
ucomisd %xmm2, %xmm5
jbe 0x92a53
movq 0x10(%rbx), %r8
movslq %esi, %rsi
movsd %xmm5, (%r8,%rsi,8)
movq 0x8(%rbx), %r8
movq %r13, (%r8,%rsi,8)
incl %esi
movq 0x30(%r14), %r9
movsd (%r9,%rdx,8), %xmm5
testl %eax, %eax
jle 0x92a88
movq 0x28(%r14), %r8
movq (%r8,%rdx,8), %r8
movq 0x10(%r15), %r10
xorl %r11d, %r11d
movsd (%r8,%r11,8), %xmm6
mulsd (%r10,%r11,8), %xmm6
addsd %xmm6, %xmm5
incq %r11
cmpq %r11, %rax
jne 0x92a70
movq 0x10(%r15), %r8
movsd (%r8,%rdx,8), %xmm6
ucomisd %xmm2, %xmm6
jbe 0x92ab7
movsd 0x20(%r12), %xmm7
addsd %xmm3, %xmm7
ucomisd %xmm6, %xmm7
jbe 0x92ab7
addsd 0x18(%rbx), %xmm5
movsd %xmm5, 0x18(%rbx)
incl %ecx
jmp 0x92ae4
ucomisd %xmm6, %xmm2
jbe 0x92ac9
ucomisd %xmm5, %xmm0
jbe 0x92ac9
movapd %xmm5, %xmm0
jmp 0x92ae4
movsd 0x20(%r12), %xmm7
addsd %xmm3, %xmm7
ucomisd %xmm7, %xmm6
jbe 0x92ae4
ucomisd %xmm1, %xmm5
jbe 0x92ae4
movapd %xmm5, %xmm1
movsd (%r9,%rdi,8), %xmm5
testl %eax, %eax
jle 0x92b11
movq 0x28(%r14), %r9
movq (%r9,%rdi,8), %r9
xorl %r10d, %r10d
movsd (%r9,%r10,8), %xmm6
mulsd (%r8,%r10,8), %xmm6
addsd %xmm6, %xmm5
incq %r10
cmpq %r10, %rax
jne 0x92af9
movsd (%r8,%rdi,8), %xmm6
ucomisd %xmm2, %xmm6
jbe 0x92b40
movsd 0x20(%r12), %xmm7
addsd %xmm3, %xmm7
ucomisd %xmm6, %xmm7
jbe 0x92b40
movsd 0x18(%rbx), %xmm6
subsd %xmm5, %xmm6
movsd %xmm6, 0x18(%rbx)
incl %ecx
jmp 0x92b77
xorpd %xmm4, %xmm5
movsd (%r8,%rdx,8), %xmm6
ucomisd %xmm6, %xmm2
jbe 0x92b5c
ucomisd %xmm1, %xmm5
jbe 0x92b5c
movapd %xmm5, %xmm1
jmp 0x92b77
movsd 0x20(%r12), %xmm7
addsd %xmm3, %xmm7
ucomisd %xmm7, %xmm6
jbe 0x92b77
ucomisd %xmm5, %xmm0
jbe 0x92b77
movapd %xmm5, %xmm0
incq %rdx
movq 0x10(%r13), %r13
cmpq %rbp, %rdx
jne 0x92a22
jmp 0x92b9b
movsd 0xf97f(%rip), %xmm1     # 0xa2510
movsd 0xf97f(%rip), %xmm0     # 0xa2518
xorl %ecx, %ecx
testl %ecx, %ecx
jle 0x92bb1
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
movsd 0x18(%rbx), %xmm0
divsd %xmm1, %xmm0
jmp 0x92bbd
addsd %xmm1, %xmm0
mulsd 0x1015b(%rip), %xmm0    # 0xa2d18
xorpd 0x1060b(%rip), %xmm0    # 0xa31d0
movlpd %xmm0, 0x18(%rbx)
movq %r15, %rdi
callq 0xf3c8
movq %r14, %rdi
callq 0xf392
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq