// File: /workspace/github_c_makefile_star2_O3/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, 0x28(%rsp)
movl %ecx, %r9d
movq %rdx, %rbx
testl %edi, %edi
movq %rdx, 0x30(%rsp)
jle 0x8ff13
movabsq $-0x100000000, %r10     # imm = 0xFFFFFFFF00000000
addq %rdi, %r10
cvtsi2sd %r9d, %xmm0
sarq $0x20, %r10
movl %r8d, 0x4(%rsp)
cvtsi2sd %r8d, %xmm1
movl %edi, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
xorl %r15d, %r15d
xorl %ebp, %ebp
movq (%rsi,%rcx,8), %rdx
movsd (%rdx,%r10,8), %xmm2
movapd %xmm0, %xmm3
cmpeqsd %xmm2, %xmm3
movq %xmm3, %rdx
subl %edx, %ebp
cmpeqsd %xmm1, %xmm2
movq %xmm2, %rdx
subl %edx, %r15d
incq %rcx
cmpq %rcx, %rax
jne 0x8fd6a
movq %r10, 0x18(%rsp)
movl $0x0, (%rbx)
movq %rdi, %r14
movq %rsi, 0x20(%rsp)
movl %r9d, %edx
movl $0x1, %ecx
movl %r9d, %r12d
callq 0x3fdd0
movq %r14, %r10
testl %r10d, %r10d
jle 0x8ff2b
movslq %r12d, %r11
andl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
xorl %r13d, %r13d
movsd 0x15733(%rip), %xmm3    # 0xa5510
xorl %edi, %edi
xorl %r14d, %r14d
movl %r12d, %r8d
xorl %r12d, %r12d
movq 0x20(%rsp), %rdx
movl 0x4(%rsp), %esi
movq 0x18(%rsp), %r9
movl %r8d, 0x10(%rsp)
movq %r10, 0x40(%rsp)
movq %r11, 0x38(%rsp)
movq (%rdx,%r13,8), %rax
cvttsd2si (%rax,%r9,8), %ecx
movsd (%rax,%r11,8), %xmm0
ucomisd %xmm3, %xmm0
jne 0x8fe21
jnp 0x8fef0
movslq (%rbx), %rdx
leaq 0x8(,%rdx,8), %rax
incq %rdx
leaq (%rax,%rax,2), %rsi
movapd %xmm3, 0x60(%rsp)
movl %ecx, 0x14(%rsp)
callq 0x3a0b4
movq %r12, 0x8(%rsp)
movq %rax, %r12
movslq (%rbx), %rax
leaq (%rax,%rax,2), %rbx
movl %r15d, %ecx
subl 0x8(%rsp), %ecx
movl %ebp, %r8d
subl %r14d, %r8d
leaq 0x48(%rsp), %rdi
movl %r14d, %esi
movq 0x8(%rsp), %rdx
callq *0x28(%rsp)
movq 0x38(%rsp), %r11
movq 0x18(%rsp), %r9
movq 0x40(%rsp), %r10
movl 0x4(%rsp), %esi
movq 0x20(%rsp), %rdx
movl 0x10(%rsp), %r8d
movq 0x58(%rsp), %rax
movq %rax, 0x10(%r12,%rbx,8)
movups 0x48(%rsp), %xmm0
movups %xmm0, (%r12,%rbx,8)
movq 0x30(%rsp), %rbx
movq (%rdx,%r13,8), %rax
movsd (%rax,%r11,8), %xmm0
movsd 0x15e61(%rip), %xmm2    # 0xa5d18
movapd %xmm2, %xmm1
cmpltpd 0x60(%rsp), %xmm1
movapd %xmm0, %xmm3
cmplepd %xmm2, %xmm0
andpd %xmm1, %xmm0
movd %xmm0, %eax
andl $0x1, %eax
movslq (%rbx), %rcx
leaq (%rcx,%rcx,2), %rcx
movl %eax, 0x10(%r12,%rcx,8)
movl 0x14(%rsp), %ecx
movq %r12, %rdi
movq 0x8(%rsp), %r12
incl (%rbx)
xorl %eax, %eax
cmpl %r8d, %ecx
sete %al
addl %eax, %r14d
xorl %eax, %eax
cmpl %esi, %ecx
sete %al
addl %eax, %r12d
incq %r13
cmpq %r13, %r10
jne 0x8fe05
jmp 0x8ff33
movl $0x0, (%rbx)
movl %r9d, %edx
movl $0x1, %ecx
callq 0x3fdd0
xorl %r15d, %r15d
xorl %ebp, %ebp
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %edi, %edi
movslq (%rbx), %rdx
leaq 0x8(,%rdx,8), %rax
incq %rdx
leaq (%rax,%rax,2), %rsi
callq 0x3a0b4
movq %rbx, %rcx
movq %rax, %rbx
movslq (%rcx), %rax
leaq (%rax,%rax,2), %r13
subl %r12d, %r15d
subl %r14d, %ebp
leaq 0x48(%rsp), %rdi
movl %r14d, %esi
movl %r12d, %edx
movl %r15d, %ecx
movl %ebp, %r8d
callq *0x28(%rsp)
leaq 0x48(%rsp), %rcx
movq 0x10(%rcx), %rax
movq %rax, 0x10(%rbx,%r13,8)
movups (%rcx), %xmm0
movups %xmm0, (%rbx,%r13,8)
movq 0x30(%rsp), %rax
incl (%rax)
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq