// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/statistics.c
// Function: find_performance_points
Performance_pointptr find_performance_points(matrix posteriors, int* number_of_points, int posclass, int negclass, Performance_point (*calculate_performance)(int tp, int fp, int tn, int fn))
{
 int i, fp = 0, tp = 0, classno, p = 0, n = 0;
 double fprev = -INT_MAX;
 Performance_pointptr points = NULL;
 for (i = 0; i < posteriors.row; i++)
  {
   if (posteriors.values[i][posteriors.col - 1] == posclass)
     p++;
   if (posteriors.values[i][posteriors.col - 1] == negclass)
     n++;
  }
 (*number_of_points) = 0;
 matrix_sort_by_column(posteriors, posclass, DESCENDING);
 for (i = 0; i < posteriors.row; i++)
  {
   classno = posteriors.values[i][posteriors.col - 1];
   if (posteriors.values[i][posclass] != fprev)
    {
     points = alloc(points, (*number_of_points + 1) * sizeof(Performance_point), *number_of_points + 1);
     points[*number_of_points] = calculate_performance(tp, fp, n - fp, p - tp);
     if (fprev > 0.5 && posteriors.values[i][posclass] <= 0.5)
       points[*number_of_points].equal_loss = YES;
     else 
       points[*number_of_points].equal_loss = NO;
     fprev = posteriors.values[i][posclass];
     (*number_of_points)++;
    }
   if (classno == posclass)
     tp++;
   if (classno == negclass)
     fp++;
  }
 points = alloc(points, (*number_of_points + 1) * sizeof(Performance_point), *number_of_points + 1);
 points[*number_of_points] = calculate_performance(tp, fp, n - fp, p - tp);
 (*number_of_points)++;
 return points;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, 0x20(%rsp)
movq %rdx, 0x10(%rsp)
movq %rsi, %r14
movabsq $-0x100000000, %r12     # imm = 0xFFFFFFFF00000000
addq %rdi, %r12
movl %ecx, 0xc(%rsp)
cvtsi2sd %ecx, %xmm0
movl %r8d, 0x18(%rsp)
cvtsi2sd %r8d, %xmm1
sarq $0x20, %r12
xorl %eax, %eax
testl %edi, %edi
movl $0x0, %ecx
cmovgl %edi, %ecx
movq %rcx, 0x28(%rsp)
xorl %edx, %edx
xorl %esi, %esi
cmpq %rax, 0x28(%rsp)
je 0x821c8
movq (%r14,%rax,8), %rcx
movsd (%rcx,%r12,8), %xmm2
movapd %xmm0, %xmm3
cmpeqsd %xmm2, %xmm3
movq %xmm3, %rcx
subl %ecx, %edx
cmpeqsd %xmm1, %xmm2
movq %xmm2, %rcx
subl %ecx, %esi
incq %rax
jmp 0x82196
movl %esi, 0x4(%rsp)
movl %edx, 0x8(%rsp)
movq 0x10(%rsp), %rax
andl $0x0, (%rax)
pushq $0x1
popq %rcx
movq %r14, %rsi
movl 0xc(%rsp), %ebx
movl %ebx, %edx
callq 0x39f4b
movslq %ebx, %rdx
movsd 0x1331c(%rip), %xmm3    # 0x95510
xorl %ebp, %ebp
xorl %r15d, %r15d
xorl %ebx, %ebx
xorl %edi, %edi
movq %r12, 0x40(%rsp)
movq %rdx, 0x38(%rsp)
movq %r14, 0x30(%rsp)
cmpq %rbp, 0x28(%rsp)
je 0x82304
movq (%r14,%rbp,8), %rax
cvttsd2si (%rax,%r12,8), %ecx
movsd (%rax,%rdx,8), %xmm0
ucomisd %xmm3, %xmm0
jne 0x82232
jnp 0x822e5
movq 0x10(%rsp), %r12
movslq (%r12), %rdx
incq %rdx
imulq $0x18, %rdx, %rsi
movapd %xmm3, 0x60(%rsp)
movl %ecx, 0x1c(%rsp)
callq 0x34f30
movq %rax, %r13
movslq (%r12), %rax
imulq $0x18, %rax, %r14
movl 0x4(%rsp), %ecx
subl %r15d, %ecx
movl 0x8(%rsp), %r8d
subl %ebx, %r8d
leaq 0x48(%rsp), %rdi
movl %ebx, %esi
movl %r15d, %edx
callq *0x20(%rsp)
movq %r13, %rdi
movq 0x38(%rsp), %rdx
movq 0x58(%rsp), %rax
movq %rax, 0x10(%r13,%r14)
movups 0x48(%rsp), %xmm0
movups %xmm0, (%r13,%r14)
movq 0x30(%rsp), %r14
movq (%r14,%rbp,8), %rax
movsd (%rax,%rdx,8), %xmm0
movsd 0x13a74(%rip), %xmm2    # 0x95d20
movapd %xmm2, %xmm1
cmpltpd 0x60(%rsp), %xmm1
movapd %xmm0, %xmm3
cmplepd %xmm2, %xmm0
andpd %xmm1, %xmm0
movd %xmm0, %eax
andl $0x1, %eax
movslq (%r12), %rcx
imulq $0x18, %rcx, %rcx
movl %eax, 0x10(%r13,%rcx)
movl 0x1c(%rsp), %ecx
incl (%r12)
movq 0x40(%rsp), %r12
xorl %eax, %eax
cmpl 0xc(%rsp), %ecx
sete %al
addl %eax, %ebx
xorl %eax, %eax
cmpl 0x18(%rsp), %ecx
sete %al
addl %eax, %r15d
incq %rbp
jmp 0x8220c
movq 0x10(%rsp), %r12
movl %r15d, %ebp
movslq (%r12), %rdx
incq %rdx
movl %ebx, %r13d
imulq $0x18, %rdx, %rsi
callq 0x34f30
movq %rax, %rbx
movslq (%r12), %rax
imulq $0x18, %rax, %r15
movl 0x4(%rsp), %ecx
subl %ebp, %ecx
movl 0x8(%rsp), %r8d
subl %r13d, %r8d
leaq 0x48(%rsp), %r14
movq %r14, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq *0x20(%rsp)
movq 0x10(%r14), %rax
movq %rax, 0x10(%rbx,%r15)
movups (%r14), %xmm0
movups %xmm0, (%rbx,%r15)
incl (%r12)
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq