// File: /workspace/github_c_makefile_star2_O1/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)
leaq 0x170(%rsp), %r14
movl (%r14), %ebp
movslq %ebp, %rbx
leaq (,%rbx,8), %rdi
leaq 0x1f366(%rip), %rsi     # 0xaea5b
movl $0x3, %edx
callq 0x390f5
movq %rax, %r15
movq %rbx, 0xd8(%rsp)
movl %ebx, %edi
callq 0x39fdc
movq %rax, %rbx
movq 0x8(%r14), %r13
movq 0x10(%r14), %r14
xorl %esi, %esi
movl %ebp, 0x84(%rsp)
movl %esi, %eax
imull %ebp, %eax
movslq %eax, %r12
imulq $0x66666667, %r12, %rcx # imm = 0x66666667
movq %rcx, %rax
shrq $0x3f, %rax
sarq $0x21, %rcx
addl %eax, %ecx
incl %esi
movq %rsi, 0x88(%rsp)
movl %esi, %eax
imull %ebp, %eax
cltq
imulq $0x66666667, %rax, %rdx # imm = 0x66666667
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x21, %rdx
addl %eax, %edx
movq %rcx, 0x78(%rsp)
movl %ecx, %eax
movq %rdx, 0xb0(%rsp)
subl %edx, %eax
addl %ebp, %eax
movl %eax, 0x90(%rsp)
movslq %eax, %rdi
shlq $0x3, %rdi
leaq 0x1f2cd(%rip), %rbp     # 0xaea5b
movq %rbp, %rsi
movl $0xa, %edx
callq 0x390f5
movq %rax, 0xa0(%rsp)
movslq 0x90(%rsp), %rdi
shlq $0x3, %rdi
movq %rbp, %rsi
movl $0xb, %edx
callq 0x390f5
movq %rax, 0x98(%rsp)
movl $0x0, %eax
cmpl $0x5, %r12d
jl 0x8f805
movl 0x78(%rsp), %ecx
xorl %eax, %eax
movslq (%rbx,%rax,4), %rdx
movq (%r14,%rdx,8), %rsi
movq 0xa0(%rsp), %rdi
movq %rsi, (%rdi,%rax,8)
movsd (%r13,%rdx,8), %xmm0
movq 0x98(%rsp), %rdx
movsd %xmm0, (%rdx,%rax,8)
incq %rax
cmpq %rax, %rcx
jne 0x8f7d5
movl 0x84(%rsp), %ebp
movq 0xb0(%rsp), %r11
cmpl %ebp, %r11d
jge 0x8f86e
movslq %r11d, %rcx
movl %eax, %eax
leaq (%rbx,%rcx,4), %rdx
movq 0xd8(%rsp), %rsi
subq %rcx, %rsi
xorl %ecx, %ecx
movq %rax, %rdi
xorpd %xmm1, %xmm1
movslq (%rdx,%rcx,4), %r8
movq (%r14,%r8,8), %r9
movq 0xa0(%rsp), %r10
movq %r9, (%r10,%rdi,8)
movsd (%r13,%r8,8), %xmm0
movq 0x98(%rsp), %r8
movsd %xmm0, (%r8,%rdi,8)
incq %rdi
incq %rcx
cmpq %rcx, %rsi
jne 0x8f836
addl %ecx, %eax
jmp 0x8f872
xorpd %xmm1, %xmm1
testl %eax, %eax
je 0x8f8ad
movq 0x98(%rsp), %rdx
movl %eax, %esi
xorl %edi, %edi
xorl %eax, %eax
xorl %ecx, %ecx
movsd (%rdx,%rdi,8), %xmm0
xorl %r8d, %r8d
xorl %r9d, %r9d
ucomisd %xmm1, %xmm0
setbe %r8b
seta %r9b
addl %r9d, %ecx
addl %r8d, %eax
incq %rdi
cmpq %rdi, %rsi
jne 0x8f886
jmp 0x8f8b1
xorl %ecx, %ecx
xorl %eax, %eax
movl %ecx, %edx
orl %eax, %edx
jne 0x8f8eb
movq 0x78(%rsp), %rax
cmpl %r11d, %eax
movq 0x88(%rsp), %rsi
jge 0x8faa6
cltq
movslq %r11d, %rcx
movslq (%rbx,%rax,4), %rdx
movq $0x0, (%r15,%rdx,8)
incq %rax
cmpq %rax, %rcx
jne 0x8f8d2
jmp 0x8faa6
testl %eax, %eax
sete %dl
testl %ecx, %ecx
setg %sil
andb %dl, %sil
cmpb $0x1, %sil
movabsq $0x3ff0000000000000, %r8 # imm = 0x3FF0000000000000
jne 0x8f939
movq 0x78(%rsp), %rax
cmpl %r11d, %eax
movq 0x88(%rsp), %rsi
jge 0x8faa6
cltq
movslq %r11d, %rcx
movslq (%rbx,%rax,4), %rdx
movq %r8, (%r15,%rdx,8)
incq %rax
cmpq %rax, %rcx
jne 0x8f924
jmp 0x8faa6
testl %ecx, %ecx
sete %cl
testl %eax, %eax
setg %al
andb %cl, %al
cmpb $0x1, %al
jne 0x8f983
movq 0x78(%rsp), %rax
cmpl %r11d, %eax
movq 0x88(%rsp), %rsi
jge 0x8faa6
cltq
movslq %r11d, %rcx
movslq (%rbx,%rax,4), %rdx
movabsq $-0x4010000000000000, %rdi # imm = 0xBFF0000000000000
movq %rdi, (%r15,%rdx,8)
incq %rax
cmpq %rax, %rcx
jne 0x8f964
jmp 0x8faa6
movl $0xb, %ecx
leaq 0xe0(%rsp), %r12
movq %r12, %rdi
leaq 0x190(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r8, 0x110(%rsp)
movl $0x10, %edi
leaq 0x1f0a9(%rip), %rsi     # 0xaea5b
movl $0x28, %edx
callq 0x390f5
movq %rax, 0x118(%rsp)
movsd 0xc8(%rsp), %xmm0
movsd %xmm0, (%rax)
movsd 0xd0(%rsp), %xmm0
movsd %xmm0, 0x8(%rax)
leaq 0x20(%rsp), %rdi
movl $0xb, %ecx
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
movupd 0x90(%rsp), %xmm0
movupd 0xa0(%rsp), %xmm1
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
xorl %edi, %edi
callq 0x8eb29
movq 0xb0(%rsp), %rcx
movq %rax, %r12
movq 0x78(%rsp), %rax
cmpl %ecx, %eax
jge 0x8fa68
movslq %eax, %rbp
movslq %ecx, %rax
movq %rax, 0x78(%rsp)
movslq (%rbx,%rbp,4), %rax
movq (%r14,%rax,8), %rsi
leaq (%r15,%rax,8), %rdx
movq %r12, %rdi
callq 0x8faf6
movslq (%rbx,%rbp,4), %rax
movsd (%r15,%rax,8), %xmm0
xorpd 0x13778(%rip), %xmm0    # 0xa31d0
movlpd %xmm0, (%r15,%rax,8)
incq %rbp
cmpq %rbp, 0x78(%rsp)
jne 0x8fa32
movq %r12, %rdi
callq 0x8ddc0
movq 0x118(%rsp), %rdi
callq 0x39194
movq 0xa0(%rsp), %rdi
callq 0x39194
movq 0x98(%rsp), %rdi
callq 0x39194
movl 0x84(%rsp), %ebp
movq 0x88(%rsp), %rsi
cmpl $0x5, %esi
jne 0x8f725
leaq 0x170(%rsp), %rax
movq 0x8(%rax), %rdx
movl %ebp, %edi
movq %r15, %rsi
movq 0xb8(%rsp), %rcx
movq 0xc0(%rsp), %r8
callq 0x8fe1a
movq %r15, %rdi
callq 0x39194
movq %rbx, %rdi
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x39194