// File: /workspace/github_c_makefile_star2_O1/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 0x652e3(%rip), %rbx     # 0xa7282
movq %rbx, %rsi
movl $0x5, %edx
callq 0x390f5
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 0x390f5
movq %rax, 0x38(%rsp)
movl %r14d, %edi
movl %r13d, %r12d
movl %r13d, %esi
callq 0x3c6e5
movq %rax, 0x48(%rsp)
movq %rdx, %r14
testl %r15d, %r15d
jle 0x421d0
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 0x65213(%rip), %rdx     # 0xa7282
movl $0xe, %ecx
callq 0x39210
movq 0x28(%rsp), %rbp
movq %rax, 0x8(%r13,%rbp)
movl $0x4, %esi
movq 0x20(%rsp), %rdi
leaq 0x651ee(%rip), %rdx     # 0xa7282
movl $0xf, %ecx
callq 0x39210
movq %rax, 0x10(%r13,%rbp)
movl $0x8, %edi
movl $0x4, %esi
movl 0x44(%rsp), %ecx
movl %ecx, %edx
leaq 0x651c8(%rip), %r8      # 0xa7282
movl $0x10, %r9d
callq 0x39245
movq %rax, 0x18(%r13,%rbp)
cmpl $0x0, 0x30(%r13,%rbp)
jle 0x421bd
addq 0x18(%rsp), %rbp
xorl %r13d, %r13d
movq %rbp, 0x28(%rsp)
cmpl $0x0, 0xc(%rsp)
jle 0x4213e
xorl %ebp, %ebp
cmpl $0x2, 0x60(%rsp)
jl 0x42122
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), %rcx
xorl %edx, %edx
movsd (%rax,%rdx,8), %xmm0
movsd %xmm0, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %r15
jne 0x42110
movq (%r14,%rbp,8), %rdi
movl %r12d, %esi
callq 0x37533
movq 0x38(%rsp), %rcx
movl %eax, (%rcx,%rbp,4)
incq %rbp
cmpq %rbx, %rbp
jne 0x420ec
leaq 0x6512d(%rip), %rdi     # 0xa7272
callq 0x535f7
cltq
movq 0x38(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq %r14, %rdx
leaq 0x8fe20(%rip), %rcx     # 0xd1f80
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 0x421ad
incl (%rbp)
movq 0x8(%rbp), %rax
incl (%rax,%rcx,4)
incq %r13
movslq 0x30(%rbp), %rax
cmpq %rax, %r13
jl 0x420e3
movq 0x58(%rsp), %rcx
incq %rcx
cmpq 0x50(%rsp), %rcx
jne 0x42024
movq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0x3dbad
movq 0x38(%rsp), %rdi
callq 0x39194
movq 0x18(%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop