// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/svm.c
// Function: svm_binary_svc_probability
void svm_binary_svc_probability(Svm_problem prob, Svm_parameter param, double Cp, double Cn, double* probA, double* probB)
{
 int i, nr_fold = 5, *perm, begin, end, j, k, p_count, n_count;
 double* dec_values, firstlabel;
 Svm_problem subprob;
 Svm_parameter subparam;
 Svm_modelptr submodel;
 dec_values = safemalloc(prob.l * sizeof(double), "svm_binary_svc_probability", 3);
 perm = random_array(prob.l);
 for (i = 0; i < nr_fold; i++)
  {
   begin = i * prob.l / nr_fold;
   end = (i + 1) * prob.l / nr_fold;
   subprob.l = prob.l - (end - begin);
   subprob.x = safemalloc(subprob.l * sizeof(Svm_nodeptr), "svm_binary_svc_probability", 10);
   subprob.y = safemalloc(subprob.l * sizeof(double), "svm_binary_svc_probability", 11);
   k = 0;
   for (j = 0; j < begin; j++)
    {
     if (k == 0)
       firstlabel = prob.y[perm[j]];
     subprob.x[k] = prob.x[perm[j]];
     subprob.y[k] = prob.y[perm[j]];
     k++;
    }
   for (j = end; j < prob.l; j++)
    {
     if (k == 0)
       firstlabel = prob.y[perm[j]];
     subprob.x[k] = prob.x[perm[j]];
     subprob.y[k] = prob.y[perm[j]];
     k++;
    }
   p_count = 0;
   n_count = 0;
   for (j = 0; j < k; j++)
    {
     if (subprob.y[j] > 0)
       p_count++;
     else
       n_count++;
    }
   if (p_count == 0 && n_count == 0)
     for (j = begin; j < end; j++)
       dec_values[perm[j]] = 0;
   else 
     if (p_count > 0 && n_count == 0)
       for (j = begin; j < end; j++)
         dec_values[perm[j]] = 1;
     else 
       if (p_count == 0 && n_count > 0)
         for (j = begin; j < end; j++)
           dec_values[perm[j]] = -1;
       else
        {
         subparam = param;
         subparam.C = 1.0;
         subparam.cweights = safemalloc(2 * sizeof(double), "svm_binary_svc_probability", 40);
         subparam.cweights[0] = Cp;
         subparam.cweights[1] = Cn;
         submodel = svm_train(subprob, subparam, 0);
         for (j = begin; j < end; j++)
          {
           svm_predict_values(submodel, prob.x[perm[j]], &(dec_values[perm[j]])); 
           dec_values[perm[j]] *= -1;
          }
         free_svm_model(submodel);
         safe_free(subparam.cweights);
         safe_free(subprob.x);
         safe_free(subprob.y);
        }
  }
 sigmoid_train(prob.l, dec_values, prob.y, probA, probB);
 safe_free(dec_values);
 safe_free(perm);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %rsi, 0xc0(%rsp)
movq %rdi, 0xb8(%rsp)
movsd %xmm1, 0xd0(%rsp)
movsd %xmm0, 0xc8(%rsp)
movl 0x170(%rsp), %eax
movl %eax, 0x7c(%rsp)
movslq %eax, %rbx
leaq (,%rbx,8), %rdi
leaq 0x1d905(%rip), %rsi     # 0xa1a33
pushq $0x3
popq %rdx
callq 0x34f59
movq %rax, %r12
movq %rbx, 0xd8(%rsp)
movl %ebx, %edi
callq 0x35cf7
movq %rax, %rbx
movq 0x178(%rsp), %r15
movq 0x180(%rsp), %rbp
xorl %ecx, %ecx
cmpl $0x5, %ecx
je 0x84450
movl %ecx, %eax
movl 0x7c(%rsp), %edi
imull %edi, %eax
cltd
pushq $0x5
popq %rsi
idivl %esi
movl %eax, %r8d
movl %eax, 0x94(%rsp)
incl %ecx
movq %rcx, 0x80(%rsp)
movl %ecx, %eax
imull %edi, %eax
cltd
idivl %esi
movl %eax, 0x88(%rsp)
subl %eax, %r8d
addl %edi, %r8d
movl %r8d, 0x98(%rsp)
movslq %r8d, %r14
shlq $0x3, %r14
movq %r14, %rdi
leaq 0x1d87c(%rip), %r13     # 0xa1a33
movq %r13, %rsi
pushq $0xa
popq %rdx
callq 0x34f59
movq %rax, 0xa8(%rsp)
movq %r14, %rdi
movq %r13, %rsi
pushq $0xb
popq %rdx
callq 0x34f59
movl 0x94(%rsp), %r10d
movq %rax, 0xa0(%rsp)
testl %r10d, %r10d
movl $0x0, %eax
cmovgl %r10d, %eax
xorl %ecx, %ecx
movq 0xd8(%rsp), %r8
cmpq %rcx, %rax
je 0x84230
movslq (%rbx,%rcx,4), %rdx
movq (%rbp,%rdx,8), %rsi
movq 0xa8(%rsp), %rdi
movq %rsi, (%rdi,%rcx,8)
movsd (%r15,%rdx,8), %xmm0
movq 0xa0(%rsp), %rdx
movsd %xmm0, (%rdx,%rcx,8)
incq %rcx
jmp 0x841fe
movslq 0x88(%rsp), %r14
movq %r14, %rcx
xorpd %xmm1, %xmm1
cmpq %r8, %rcx
jge 0x84274
movslq (%rbx,%rcx,4), %rdx
movq (%rbp,%rdx,8), %rsi
movq 0xa8(%rsp), %rdi
movq %rsi, (%rdi,%rax,8)
movsd (%r15,%rdx,8), %xmm0
movq 0xa0(%rsp), %rdx
movsd %xmm0, (%rdx,%rax,8)
incq %rax
incq %rcx
jmp 0x8423f
xorl %esi, %esi
movq 0xa0(%rsp), %rdi
xorl %edx, %edx
xorl %ecx, %ecx
cmpq %rax, %rsi
jae 0x842a9
movsd (%rdi,%rsi,8), %xmm0
xorl %r8d, %r8d
xorl %r9d, %r9d
ucomisd %xmm1, %xmm0
setbe %r8b
seta %r9b
addl %r9d, %edx
addl %r8d, %ecx
incq %rsi
jmp 0x84282
movl %edx, %eax
orl %ecx, %eax
jne 0x842c9
movslq %r10d, %rax
cmpq %r14, %rax
jge 0x84443
movslq (%rbx,%rax,4), %rcx
andq $0x0, (%r12,%rcx,8)
incq %rax
jmp 0x842b2
testl %ecx, %ecx
sete %al
testl %edx, %edx
setne %sil
andb %al, %sil
cmpb $0x1, %sil
jne 0x84300
movslq %r10d, %rax
movabsq $0x3ff0000000000000, %rdx # imm = 0x3FF0000000000000
cmpq %r14, %rax
jge 0x84443
movslq (%rbx,%rax,4), %rcx
movq %rdx, (%r12,%rcx,8)
incq %rax
jmp 0x842ea
testl %edx, %edx
sete %al
testl %ecx, %ecx
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x84334
movslq %r10d, %rax
movabsq $-0x4010000000000000, %rdx # imm = 0xBFF0000000000000
cmpq %r14, %rax
jge 0x84443
movslq (%rbx,%rax,4), %rcx
movq %rdx, (%r12,%rcx,8)
incq %rax
jmp 0x8431e
movslq %r10d, %r13
pushq $0xb
popq %rcx
leaq 0xe0(%rsp), %rdi
leaq 0x190(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x110(%rsp)
pushq $0x10
popq %rdi
leaq 0x1d6ca(%rip), %rsi     # 0xa1a33
pushq $0x28
popq %rdx
callq 0x34f59
movq %rax, 0x118(%rsp)
movsd 0xc8(%rsp), %xmm0
movsd %xmm0, (%rax)
movsd 0xd0(%rsp), %xmm0
movsd %xmm0, 0x8(%rax)
leaq 0x20(%rsp), %rdi
pushq $0xb
popq %rcx
leaq 0xe0(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movupd 0x98(%rsp), %xmm0
movupd 0xa8(%rsp), %xmm1
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
xorl %edi, %edi
callq 0x8362c
movq %rax, 0x88(%rsp)
cmpq %r14, %r13
jge 0x8440f
movslq (%rbx,%r13,4), %rax
movq (%rbp,%rax,8), %rsi
leaq (%r12,%rax,8), %rdx
movq 0x88(%rsp), %rdi
callq 0x84490
movslq (%rbx,%r13,4), %rax
movsd (%r12,%rax,8), %xmm0
xorpd 0x11dcc(%rip), %xmm0    # 0x961d0
movlpd %xmm0, (%r12,%rax,8)
incq %r13
jmp 0x843d3
movq 0x88(%rsp), %rdi
callq 0x8290c
movq 0x118(%rsp), %rdi
callq 0x34ff7
movq 0xa8(%rsp), %rdi
callq 0x34ff7
movq 0xa0(%rsp), %rdi
callq 0x34ff7
movq 0x80(%rsp), %rcx
jmp 0x8415d
movl 0x7c(%rsp), %edi
movq %r12, %rsi
movq %r15, %rdx
movq 0xb8(%rsp), %rcx
movq 0xc0(%rsp), %r8
callq 0x8473e
movq %r12, %rdi
callq 0x34ff7
movq %rbx, %rdi
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x34ff7