// File: /workspace/github_c_makefile_star2_O2/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, %r15
movq %rdi, %r12
callq 0x2c3cc
movl %eax, %ebp
leaq 0x1acd6(%rip), %rsi     # 0xa1b6c
pushq $0x20
popq %rdi
pushq $0x4
popq %rdx
callq 0x34f59
movq %rax, %rbx
movq %r12, %rdi
movq %r15, %rsi
callq 0x86abd
movq %rax, %r14
movq %rax, %rdi
callq 0xf2bf
andl $0x0, (%rbx)
movslq %ebp, %rdx
xorl %ecx, %ecx
testl %edx, %edx
movl $0x0, %ebp
cmovgl %edx, %ebp
movq %rax, %r13
movq %rdx, (%rsp)
leaq (,%rdx,8), %rax
xorl %edx, %edx
cmpq %rdx, %rbp
je 0x86f07
movq 0x10(%r13), %rsi
leaq (%rsi,%rdx,8), %rdi
movsd (%rsi,%rdx,8), %xmm0
subsd (%rax,%rdi), %xmm0
ucomisd 0xeee4(%rip), %xmm0     # 0x95de0
jbe 0x86f02
incl %ecx
movl %ecx, (%rbx)
incq %rdx
jmp 0x86edd
movslq %ecx, %rdi
shlq $0x3, %rdi
leaq 0x1ac57(%rip), %rsi     # 0xa1b6c
pushq $0xa
popq %rdx
callq 0x34f59
movq %rax, 0x10(%rbx)
movslq (%rbx), %rdi
shlq $0x3, %rdi
pushq $0xb
popq %rdx
leaq 0x1ac3a(%rip), %rsi     # 0xa1b6c
callq 0x34f59
movsd 0xeea1(%rip), %xmm7     # 0x95de0
movq %rax, 0x8(%rbx)
andq $0x0, 0x18(%rbx)
movsd 0xe5c0(%rip), %xmm1     # 0x95510
movsd 0xe5c0(%rip), %xmm0     # 0x95518
xorl %eax, %eax
movsd 0x129c6(%rip), %xmm2    # 0x99928
movapd 0xf266(%rip), %xmm3     # 0x961d0
xorl %edx, %edx
xorl %esi, %esi
xorl %ecx, %ecx
cmpq %rbp, %rdx
je 0x870e1
movq 0x10(%r13), %r8
movsd (%r8,%rdx,8), %xmm4
movq (%rsp), %rdi
addq %rdx, %rdi
subsd (%r8,%rdi,8), %xmm4
ucomisd %xmm7, %xmm4
jbe 0x86fad
movq 0x10(%rbx), %r8
movslq %esi, %rsi
movsd %xmm4, (%r8,%rsi,8)
movq 0x8(%rbx), %r8
movq %r12, (%r8,%rsi,8)
incl %esi
movq 0x30(%r14), %r10
movsd (%r10,%rdx,8), %xmm4
movl 0x18(%r13), %r8d
testl %r8d, %r8d
cmovlel %eax, %r8d
xorl %r9d, %r9d
cmpq %r9, %r8
je 0x86feb
movq 0x28(%r14), %r11
movq (%r11,%rdx,8), %r11
movsd (%r11,%r9,8), %xmm5
movq 0x10(%r13), %r11
mulsd (%r11,%r9,8), %xmm5
addsd %xmm5, %xmm4
incq %r9
jmp 0x86fc5
movq 0x10(%r13), %r9
movsd (%r9,%rdx,8), %xmm5
ucomisd %xmm7, %xmm5
jbe 0x87019
movsd 0x20(%r15), %xmm6
addsd %xmm2, %xmm6
ucomisd %xmm5, %xmm6
jbe 0x87019
addsd 0x18(%rbx), %xmm4
movsd %xmm4, 0x18(%rbx)
incl %ecx
jmp 0x87045
ucomisd %xmm5, %xmm7
jbe 0x8702b
ucomisd %xmm4, %xmm0
jbe 0x8702b
movapd %xmm4, %xmm0
jmp 0x87045
movsd 0x20(%r15), %xmm6
addsd %xmm2, %xmm6
ucomisd %xmm6, %xmm5
jbe 0x87045
ucomisd %xmm1, %xmm4
jbe 0x87045
movapd %xmm4, %xmm1
movsd (%r10,%rdi,8), %xmm4
xorl %r10d, %r10d
cmpq %r10, %r8
je 0x87070
movq 0x28(%r14), %r11
movq (%r11,%rdi,8), %r11
movsd (%r11,%r10,8), %xmm5
mulsd (%r9,%r10,8), %xmm5
addsd %xmm5, %xmm4
incq %r10
jmp 0x8704e
movsd (%r9,%rdi,8), %xmm5
ucomisd %xmm7, %xmm5
jbe 0x8709e
movsd 0x20(%r15), %xmm6
addsd %xmm2, %xmm6
ucomisd %xmm5, %xmm6
jbe 0x8709e
movsd 0x18(%rbx), %xmm5
subsd %xmm4, %xmm5
movsd %xmm5, 0x18(%rbx)
incl %ecx
jmp 0x870d4
xorpd %xmm3, %xmm4
movsd (%r9,%rdx,8), %xmm5
ucomisd %xmm5, %xmm7
jbe 0x870ba
ucomisd %xmm1, %xmm4
jbe 0x870ba
movapd %xmm4, %xmm1
jmp 0x870d4
movsd 0x20(%r15), %xmm6
addsd %xmm2, %xmm6
ucomisd %xmm6, %xmm5
jbe 0x870d4
ucomisd %xmm4, %xmm0
jbe 0x870d4
movapd %xmm4, %xmm0
incq %rdx
movq 0x10(%r12), %r12
jmp 0x86f70
testl %ecx, %ecx
jle 0x870f4
cvtsi2sd %ecx, %xmm1
movsd 0x18(%rbx), %xmm0
divsd %xmm1, %xmm0
jmp 0x87100
addsd %xmm1, %xmm0
mulsd 0xec20(%rip), %xmm0     # 0x95d20
xorpd 0xf0c8(%rip), %xmm0     # 0x961d0
movlpd %xmm0, 0x18(%rbx)
movq %r13, %rdi
callq 0xe94d
movq %r14, %rdi
callq 0xe917
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq