// File: /workspace/github_c_makefile_star2_O3/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
subq $0x18, %rsp
movq %rsi, %r12
movq %rdi, %r13
callq 0x30309
movl %eax, %ebp
leaq 0x1c791(%rip), %rsi     # 0xb1c0c
movl $0x20, %edi
movl $0x4, %edx
callq 0x3a0e1
movq %rax, %rbx
movq %r13, %rdi
movq %r12, %rsi
callq 0x94fa2
movq %rax, %r14
movq %rax, %rdi
callq 0xfef0
movl $0x0, (%rbx)
xorl %edi, %edi
movl %ebp, %r15d
movl %ebp, 0xc(%rsp)
testl %ebp, %ebp
movq %rax, 0x10(%rsp)
jle 0x954f0
movq 0x10(%rax), %rsi
leaq (%rsi,%r15,8), %rcx
movsd 0x1090d(%rip), %xmm0    # 0xa5dd8
xorl %edx, %edx
movsd (%rsi,%rdx,8), %xmm1
subsd (%rcx,%rdx,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x954e1
incl %edi
movl %edi, (%rbx)
incq %rdx
cmpq %rdx, %r15
jne 0x954cd
movslq %edi, %rdi
shlq $0x3, %rdi
leaq 0x1c715(%rip), %rbp     # 0xb1c0c
movq %rbp, %rsi
movl $0xa, %edx
callq 0x3a0e1
movq %rax, 0x10(%rbx)
movslq (%rbx), %rdi
shlq $0x3, %rdi
movq %rbp, %rsi
movl $0xb, %edx
callq 0x3a0e1
movq %rax, 0x8(%rbx)
movq $0x0, 0x18(%rbx)
cmpl $0x0, 0xc(%rsp)
jle 0x956dc
movq 0x10(%rsp), %rdi
movl 0x18(%rdi), %eax
movq 0x10(%rdi), %rsi
xorl %ecx, %ecx
movsd 0xffcf(%rip), %xmm1     # 0xa5518
movsd 0xffbf(%rip), %xmm0     # 0xa5510
movsd 0x1087f(%rip), %xmm2    # 0xa5dd8
movsd 0x1449f(%rip), %xmm3    # 0xa9a00
movapd 0x10c67(%rip), %xmm4    # 0xa61d0
xorl %edx, %edx
xorl %ebp, %ebp
movsd (%rsi,%rcx,8), %xmm5
leaq (%rcx,%r15), %r8
subsd (%rsi,%r8,8), %xmm5
ucomisd %xmm2, %xmm5
jbe 0x9559c
movq 0x10(%rbx), %rsi
movslq %ebp, %rbp
movsd %xmm5, (%rsi,%rbp,8)
movq 0x8(%rbx), %rsi
movq %r13, (%rsi,%rbp,8)
incl %ebp
movq 0x10(%rdi), %rsi
movq 0x30(%r14), %r9
movsd (%r9,%rcx,8), %xmm5
testl %eax, %eax
jle 0x955cd
movq 0x28(%r14), %r10
movq (%r10,%rcx,8), %r10
xorl %r11d, %r11d
movsd (%r10,%r11,8), %xmm6
mulsd (%rsi,%r11,8), %xmm6
addsd %xmm6, %xmm5
incq %r11
cmpq %r11, %rax
jne 0x955b5
movsd (%rsi,%rcx,8), %xmm6
ucomisd %xmm2, %xmm6
jbe 0x955f7
movsd 0x20(%r12), %xmm7
addsd %xmm3, %xmm7
ucomisd %xmm6, %xmm7
jbe 0x955f7
addsd 0x18(%rbx), %xmm5
movsd %xmm5, 0x18(%rbx)
incl %edx
jmp 0x95624
ucomisd %xmm6, %xmm2
jbe 0x95609
ucomisd %xmm5, %xmm1
jbe 0x95609
movapd %xmm5, %xmm1
jmp 0x95624
movsd 0x20(%r12), %xmm7
addsd %xmm3, %xmm7
ucomisd %xmm7, %xmm6
jbe 0x95624
ucomisd %xmm0, %xmm5
jbe 0x95624
movapd %xmm5, %xmm0
movsd (%r9,%r8,8), %xmm5
testl %eax, %eax
jle 0x95651
movq 0x28(%r14), %r9
movq (%r9,%r8,8), %r9
xorl %r10d, %r10d
movsd (%r9,%r10,8), %xmm6
mulsd (%rsi,%r10,8), %xmm6
addsd %xmm6, %xmm5
incq %r10
cmpq %r10, %rax
jne 0x95639
movsd (%rsi,%r8,8), %xmm6
ucomisd %xmm2, %xmm6
jbe 0x95680
movsd 0x20(%r12), %xmm7
addsd %xmm3, %xmm7
ucomisd %xmm6, %xmm7
jbe 0x95680
movsd 0x18(%rbx), %xmm6
subsd %xmm5, %xmm6
movsd %xmm6, 0x18(%rbx)
incl %edx
jmp 0x956b6
xorpd %xmm4, %xmm5
movsd (%rsi,%rcx,8), %xmm6
ucomisd %xmm6, %xmm2
jbe 0x9569b
ucomisd %xmm0, %xmm5
jbe 0x9569b
movapd %xmm5, %xmm0
jmp 0x956b6
movsd 0x20(%r12), %xmm7
addsd %xmm3, %xmm7
ucomisd %xmm7, %xmm6
jbe 0x956b6
ucomisd %xmm5, %xmm1
jbe 0x956b6
movapd %xmm5, %xmm1
incq %rcx
movq 0x10(%r13), %r13
cmpq %r15, %rcx
jne 0x9556d
testl %edx, %edx
jle 0x956f1
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
movsd 0x18(%rbx), %xmm0
divsd %xmm1, %xmm0
jmp 0x956fd
movsd 0xfe34(%rip), %xmm1     # 0xa5518
movsd 0xfe24(%rip), %xmm0     # 0xa5510
movq 0x10(%rsp), %rdi
addsd %xmm1, %xmm0
mulsd 0x1061b(%rip), %xmm0    # 0xa5d18
xorpd 0x10acb(%rip), %xmm0    # 0xa61d0
movlpd %xmm0, 0x18(%rbx)
callq 0xf3e0
movq %r14, %rdi
callq 0xf3aa
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq