// File: /workspace/github_c_makefile_star2_O1/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 $0x68, %rsp
movq %r9, 0x28(%rsp)
movl %r8d, 0x14(%rsp)
movl %ecx, %r8d
movq %rdx, %rbx
movabsq $-0x100000000, %r13     # imm = 0xFFFFFFFF00000000
xorl %r12d, %r12d
movl $0x0, %r10d
movl $0x0, %r11d
testl %edi, %edi
jle 0x8d5e8
leaq (%rdi,%r13), %rax
cvtsi2sd %r8d, %xmm0
sarq $0x20, %rax
cvtsi2sdl 0x14(%rsp), %xmm1
movl %edi, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
xorl %r11d, %r11d
xorl %r10d, %r10d
movq (%rsi,%rdx,8), %r9
movsd (%r9,%rax,8), %xmm2
movapd %xmm0, %xmm3
cmpeqsd %xmm2, %xmm3
movq %xmm3, %r9
subl %r9d, %r10d
cmpeqsd %xmm1, %xmm2
movq %xmm2, %r9
subl %r9d, %r11d
incq %rdx
cmpq %rdx, %rcx
jne 0x8d5b8
movl %r11d, 0xc(%rsp)
movl %r10d, 0x10(%rsp)
movl $0x0, (%rbx)
movq %rsi, 0x20(%rsp)
movl %r8d, %edx
movl $0x1, %ecx
movl %r8d, %ebp
movq %rdi, %r14
callq 0x3ea75
movq %r14, %rsi
testl %esi, %esi
jle 0x8d75d
addq %rsi, %r13
sarq $0x20, %r13
movq %r13, 0x40(%rsp)
movslq %ebp, %r8
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
xorl %r13d, %r13d
movsd 0x14ed5(%rip), %xmm1    # 0xa2510
xorl %r15d, %r15d
xorl %r14d, %r14d
xorl %r12d, %r12d
movl %ebp, %ecx
movq 0x20(%rsp), %rdx
movq %rbx, 0x38(%rsp)
movl %ebp, 0x18(%rsp)
movq %rsi, 0x30(%rsp)
movq (%rdx,%r13,8), %rax
movq 0x40(%rsp), %rdi
cvttsd2si (%rax,%rdi,8), %edi
movsd (%rax,%r8,8), %xmm0
ucomisd %xmm1, %xmm0
jne 0x8d679
jnp 0x8d739
movl %edi, 0x1c(%rsp)
movslq (%rbx), %rdx
leaq 0x8(,%rdx,8), %rax
incq %rdx
leaq (%rax,%rax,2), %rsi
movq %r15, %rdi
movq %r8, %rbp
movsd %xmm1, 0x48(%rsp)
callq 0x390c8
movq %rax, %r15
movslq (%rbx), %rax
leaq (%rax,%rax,2), %rbx
movl 0xc(%rsp), %ecx
subl %r12d, %ecx
movl 0x10(%rsp), %r8d
subl %r14d, %r8d
leaq 0x50(%rsp), %rdi
movl %r14d, %esi
movl %r12d, %edx
callq *0x28(%rsp)
movq %rbp, %r8
movq 0x20(%rsp), %rdx
movq 0x60(%rsp), %rax
movq %rax, 0x10(%r15,%rbx,8)
movups 0x50(%rsp), %xmm0
movups %xmm0, (%r15,%rbx,8)
movsd 0x48(%rsp), %xmm0
ucomisd 0x15626(%rip), %xmm0    # 0xa2d18
jbe 0x8d70d
movq (%rdx,%r13,8), %rcx
movl $0x1, %eax
movsd 0x15613(%rip), %xmm0    # 0xa2d18
ucomisd (%rcx,%r8,8), %xmm0
jae 0x8d70f
xorl %eax, %eax
movq 0x38(%rsp), %rbx
movslq (%rbx), %rcx
leaq (%rcx,%rcx,2), %rcx
movl %eax, 0x10(%r15,%rcx,8)
movq (%rdx,%r13,8), %rax
movsd (%rax,%r8,8), %xmm1
incl (%rbx)
movl 0x18(%rsp), %ecx
movq 0x30(%rsp), %rsi
movl 0x1c(%rsp), %edi
xorl %eax, %eax
cmpl %ecx, %edi
sete %al
addl %eax, %r14d
xorl %eax, %eax
cmpl 0x14(%rsp), %edi
sete %al
addl %eax, %r12d
incq %r13
cmpq %r13, %rsi
jne 0x8d659
jmp 0x8d763
xorl %r14d, %r14d
xorl %r15d, %r15d
movslq (%rbx), %rdx
leaq 0x8(,%rdx,8), %rax
incq %rdx
leaq (%rax,%rax,2), %rsi
movq %r15, %rdi
callq 0x390c8
movq %rbx, %r15
movq %rax, %rbx
movslq (%r15), %rax
leaq (%rax,%rax,2), %r13
movl 0xc(%rsp), %ecx
subl %r12d, %ecx
movl 0x10(%rsp), %r8d
subl %r14d, %r8d
leaq 0x50(%rsp), %rbp
movq %rbp, %rdi
movl %r14d, %esi
movl %r12d, %edx
callq *0x28(%rsp)
movq 0x10(%rbp), %rax
movq %rax, 0x10(%rbx,%r13,8)
movups (%rbp), %xmm0
movups %xmm0, (%rbx,%r13,8)
incl (%r15)
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq