// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movl %esi, %r14d
movq %rdi, %rbx
movslq %edx, %r12
imulq $0x58, %r12, %rdi
leaq 0x5d33c(%rip), %r15     # 0x9a252
pushq $0x5
popq %rdx
movq %r15, %rsi
callq 0x34f59
movq %rax, 0x18(%rsp)
movq (%rbx), %rax
movl 0x4(%rax), %ebp
decl %ebp
movslq %r14d, %r14
leaq (,%r14,4), %rdi
pushq $0x7
popq %rdx
movq %r15, %rsi
callq 0x34f59
movq %rax, 0x8(%rsp)
movl %r14d, %edi
movl %ebp, %esi
callq 0x380d3
movslq %ebp, %rsi
xorl %edi, %edi
movq %rsi, (%rsp)
testl %esi, %esi
movl $0x0, %r15d
movl %ebp, 0x14(%rsp)
cmovgl %ebp, %r15d
testl %r14d, %r14d
cmovlel %edi, %r14d
movq %r14, 0x40(%rsp)
movq %rax, 0x20(%rsp)
testl %r12d, %r12d
cmovlel %edi, %r12d
movq %r12, 0x30(%rsp)
movq %rdx, %r14
cmpq 0x30(%rsp), %rdi
je 0x3d0fb
imulq $0x58, %rdi, %r12
movq 0x18(%rsp), %r13
andl $0x0, (%r13,%r12)
leaq (%r12,%r13), %rax
movq %rax, 0x28(%rsp)
movq (%rbx), %rax
movq %rdi, 0x38(%rsp)
movq %rdi, %rbp
shlq $0x4, %rbp
movl (%rax,%rbp), %eax
movl %eax, 0x30(%r13,%r12)
movq (%rsp), %rdi
movl %edi, 0x20(%r13,%r12)
pushq $0x4
popq %rsi
leaq 0x5d279(%rip), %rdx     # 0x9a252
pushq $0xe
popq %rcx
callq 0x35067
movq %rax, 0x8(%r13,%r12)
movq (%rsp), %rdi
pushq $0x4
popq %rsi
leaq 0x5d25e(%rip), %rdx     # 0x9a252
pushq $0xf
popq %rcx
callq 0x35067
movq %rax, 0x10(%r13,%r12)
pushq $0x8
popq %rdi
pushq $0x4
popq %rsi
movq (%rsp), %rcx
movl %ecx, %edx
leaq 0x5d23e(%rip), %r8      # 0x9a252
pushq $0x10
popq %r9
callq 0x3509c
movq %rax, 0x18(%r13,%r12)
movq 0x28(%rsp), %rsi
xorl %r12d, %r12d
movslq 0x30(%rsi), %rax
cmpq %rax, %r12
jge 0x3d0ee
xorl %r13d, %r13d
cmpq 0x40(%rsp), %r13
je 0x3d083
xorl %eax, %eax
cmpq %rax, %r15
je 0x3d068
movq (%rbx,%r13,8), %rcx
movq 0x8(%rcx,%rbp), %rcx
movq (%rcx,%r12,8), %rcx
movsd (%rcx,%rax,8), %xmm0
movq (%r14,%r13,8), %rcx
movsd %xmm0, (%rcx,%rax,8)
incq %rax
jmp 0x3d043
movq (%r14,%r13,8), %rdi
movl 0x14(%rsp), %esi
callq 0x336dd
movq 0x8(%rsp), %rcx
movl %eax, (%rcx,%r13,4)
incq %r13
jmp 0x3d03a
leaq 0x5d1b8(%rip), %rdi     # 0x9a242
callq 0x4cf11
cltq
movq 0x8(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq %r14, %rdx
leaq 0x8fedb(%rip), %rcx     # 0xccf80
callq *(%rcx,%rax,8)
movq (%rbx), %rcx
movq 0x8(%rcx,%rbp), %rcx
movq (%rcx,%r12,8), %rcx
movq (%rsp), %rdx
cvttsd2si (%rcx,%rdx,8), %ecx
movq 0x28(%rsp), %rsi
movq 0x10(%rsi), %rdx
movslq %ecx, %rcx
incl (%rdx,%rcx,4)
movq 0x18(%rsi), %rdx
movq (%rdx,%rcx,8), %rdx
cltq
incl (%rdx,%rax,4)
cmpl %ecx, %eax
jne 0x3d0e6
incl (%rsi)
movq 0x8(%rsi), %rax
incl (%rax,%rcx,4)
incq %r12
jmp 0x3d02a
movq 0x38(%rsp), %rdi
incq %rdi
jmp 0x3cf8c
movq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x3929f
movq 0x8(%rsp), %rdi
callq 0x34ff7
movq 0x18(%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop