// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/metaclassification.c
// Function: ensemble
Classificationresultptr ensemble(matrixptr* posteriors, int learner_count, int fold_count)
{
 int i, j, k, t, class_count, predicted_class, actual_class;
 matrix ensemble_posteriors;
 int* predictions;
 Classificationresultptr results;
 results = safemalloc(fold_count * sizeof(Classificationresult), "ensemble", 5);
 class_count = posteriors[0][0].col - 1;
 predictions = safemalloc(learner_count * sizeof(int), "ensemble", 7);
 ensemble_posteriors = matrix_alloc(learner_count, class_count);
 for (i = 0; i < fold_count; i++)
  {
   results[i].performance = 0;
   results[i].datasize = posteriors[0][i].row;
   results[i].classno = class_count;
   results[i].class_performance = safecalloc(class_count, sizeof(int), "ensemble", 14);
   results[i].class_counts = safecalloc(class_count, sizeof(int), "ensemble", 15);
   results[i].confusion_matrix = (int**) safecalloc_2d(sizeof(int*), sizeof(int), class_count, class_count, "ensemble", 16);
   for (j = 0; j < results[i].datasize; j++)
    {
     for (k = 0; k < learner_count; k++)
      {
       for (t = 0; t < class_count; t++)
         ensemble_posteriors.values[k][t] = posteriors[k][i].values[j][t];
       predictions[k] = find_max_in_list_double(ensemble_posteriors.values[k], class_count);
      }
     predicted_class = combination_algorithms[get_parameter_l("combinationtype")](predictions, ensemble_posteriors);
     actual_class = posteriors[0][i].values[j][class_count];
     (results[i].class_counts[actual_class])++;
     (results[i].confusion_matrix[actual_class][predicted_class])++;
     if (predicted_class == actual_class)
      {
       (results[i].performance)++;
       (results[i].class_performance[actual_class])++;
      }
    }
  }
 matrix_free(ensemble_posteriors);
 safe_free(predictions);
 return results;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %esi, %ebp
movq %rdi, %r14
movl %edx, 0x10(%rsp)
movslq %edx, %r15
imulq $0x58, %r15, %rdi
leaq 0x67018(%rip), %rbx     # 0xaa322
movq %rbx, %rsi
movl $0x5, %edx
callq 0x3a0e1
movq %rax, 0x18(%rsp)
movq %r14, 0x30(%rsp)
movq (%r14), %rax
movl 0x4(%rax), %eax
movq %rax, 0x60(%rsp)
leal -0x1(%rax), %r13d
movl %ebp, 0xc(%rsp)
movslq %ebp, %r14
leaq (,%r14,4), %rdi
movq %rbx, %rsi
movl $0x7, %edx
callq 0x3a0e1
movq %rax, 0x38(%rsp)
movl %r14d, %edi
movl %r13d, %r12d
movl %r13d, %esi
callq 0x3d79d
movq %rax, 0x48(%rsp)
movq %rdx, %r14
testl %r15d, %r15d
jle 0x4353d
movslq %r12d, %rcx
movq %rcx, 0x20(%rsp)
movl 0x10(%rsp), %ecx
movq %rcx, 0x50(%rsp)
movl 0xc(%rsp), %ebx
movl %r12d, %r15d
xorl %ecx, %ecx
movl %r12d, 0x44(%rsp)
imulq $0x58, %rcx, %rdx
movq %rdx, 0x28(%rsp)
movq 0x18(%rsp), %r13
movl $0x0, (%r13,%rdx)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq %rcx, 0x58(%rsp)
shlq $0x4, %rcx
movq %rcx, 0x10(%rsp)
movl (%rax,%rcx), %eax
movl %eax, 0x30(%r13,%rdx)
movl %r12d, 0x20(%r13,%rdx)
movl $0x4, %esi
movq 0x20(%rsp), %rdi
leaq 0x66f48(%rip), %rdx     # 0xaa322
movl $0xe, %ecx
callq 0x3a1fc
movq 0x28(%rsp), %rbp
movq %rax, 0x8(%r13,%rbp)
movl $0x4, %esi
movq 0x20(%rsp), %rdi
leaq 0x66f23(%rip), %rdx     # 0xaa322
movl $0xf, %ecx
callq 0x3a1fc
movq %rax, 0x10(%r13,%rbp)
movl $0x8, %edi
movl $0x4, %esi
movl 0x44(%rsp), %ecx
movl %ecx, %edx
leaq 0x66efd(%rip), %r8      # 0xaa322
movl $0x10, %r9d
callq 0x3a231
movq %rax, 0x18(%r13,%rbp)
cmpl $0x0, 0x30(%r13,%rbp)
jle 0x4352a
addq 0x18(%rsp), %rbp
xorl %r13d, %r13d
movq %rbp, 0x28(%rsp)
cmpl $0x0, 0xc(%rsp)
jle 0x434ab
xorl %ebp, %ebp
cmpl $0x1, 0x60(%rsp)
jle 0x4348f
movq 0x30(%rsp), %rax
movq (%rax,%rbp,8), %rax
movq 0x10(%rsp), %rcx
movq 0x8(%rax,%rcx), %rax
movq (%rax,%r13,8), %rax
movq (%r14,%rbp,8), %rdi
xorl %ecx, %ecx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rdi,%rcx,8)
incq %rcx
cmpq %rcx, %r15
jne 0x4347b
jmp 0x43493
movq (%r14,%rbp,8), %rdi
movl %r12d, %esi
callq 0x38031
movq 0x38(%rsp), %rcx
movl %eax, (%rcx,%rbp,4)
incq %rbp
cmpq %rbx, %rbp
jne 0x43457
leaq 0x66e60(%rip), %rdi     # 0xaa312
callq 0x54afc
cltq
movq 0x38(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq %r14, %rdx
leaq 0x91ab3(%rip), %rcx     # 0xd4f80
callq *(%rcx,%rax,8)
movq 0x30(%rsp), %rcx
movq (%rcx), %rcx
movq 0x10(%rsp), %rdx
movq 0x8(%rcx,%rdx), %rcx
movq (%rcx,%r13,8), %rcx
movq 0x20(%rsp), %rdx
cvttsd2si (%rcx,%rdx,8), %ecx
movq 0x28(%rsp), %rbp
movq 0x10(%rbp), %rdx
movslq %ecx, %rcx
incl (%rdx,%rcx,4)
movq 0x18(%rbp), %rdx
movq (%rdx,%rcx,8), %rdx
cltq
incl (%rdx,%rax,4)
cmpl %ecx, %eax
jne 0x4351a
incl (%rbp)
movq 0x8(%rbp), %rax
incl (%rax,%rcx,4)
incq %r13
movslq 0x30(%rbp), %rax
cmpq %rax, %r13
jl 0x4344e
movq 0x58(%rsp), %rcx
incq %rcx
cmpq 0x50(%rsp), %rcx
jne 0x4338f
movq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0x3ed51
movq 0x38(%rsp), %rdi
callq 0x3a180
movq 0x18(%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq