// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/dataset.c
// Function: discretization_entropy
double* discretization_entropy(Datasetptr original, int fno, int valuecount, Instanceptr data)
{
 int ratio[MAXVALUES][MAXCLASSES];
 double *splits, *values = NULL, bestinfo = ISELL, info;
 int i, j, size, *combination, *best, **counts;
 splits = safemalloc((valuecount - 1) * sizeof(double), "discretization_entropy", 4);
 counts = find_counts_for_all_splits(original, fno, data, &size, &values);
 if (size > valuecount - 1)
  {
   best = safemalloc((valuecount - 1) * sizeof(int), "discretization_entropy", 5);
   combination = first_combination(valuecount - 1);
   for (i = 0; i < MAXVALUES; i++)
     for (j = 0; j < MAXCLASSES; j++)
       ratio[i][j] = 0;
   do{
     for (i = 0; i < valuecount; i++)
       for (j = 0; j < original->classno; j++)
         ratio[i][j] = 0;
     for (j = 0; j < original->classno; j++)
       ratio[0][j] = counts[combination[0]][j];
     for (i = 1; i < valuecount - 1; i++)
       for (j = 0; j < original->classno; j++)
         ratio[i][j] = counts[combination[i]][j] - counts[combination[i - 1]][j];
     for (j = 0; j < original->classno; j++)
       ratio[valuecount - 1][j] = counts[size - 1][j] - counts[combination[i - 1]][j];
     info = information_gain_from_ratios(ratio);
     if (info < bestinfo)
      {
       bestinfo = info;
       for (i = 0; i < valuecount - 1; i++)
         best[i] = combination[i];
      }
   }while (next_combination(combination, valuecount - 1, size - 1));
   for (i = 0; i < valuecount - 1; i++)
     splits[i] = values[best[i]];
   safe_free(best);
   safe_free(combination);   
  }
 else
  {
   for (i = 0; i < size; i++)
     splits[i] = values[i]; 
   for (i = size; i < valuecount - 1; i++)
     splits[i] = values[size - 1];  
  }
 safe_free(values);
 free_2d((void **) counts, size);
 return splits; 
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4e68, %rsp           # imm = 0x4E68
movq %rcx, %r13
movl %esi, %ebp
movq %rsp, %rax
andq $0x0, (%rax)
movq %rdi, %r14
movslq %edx, %rbx
leaq -0x1(%rbx), %r12
leaq -0x8(,%rbx,8), %rdi
leaq 0x81ff1(%rip), %rsi     # 0x9689b
pushq $0x4
popq %rdx
callq 0x34f59
movq %rax, 0x10(%rsp)
leaq 0x3c(%rsp), %r15
movq %r14, 0x30(%rsp)
movq %r14, %rdi
movl %ebp, %esi
movq %r13, %rdx
movq %r15, %rcx
movq %rsp, %r8
callq 0x14697
movq %rax, %r14
movslq (%r15), %r15
cmpl %ebx, %r15d
jge 0x1490b
movq (%rsp), %rbp
xorl %eax, %eax
testl %r15d, %r15d
movl $0x0, %ecx
cmovgl %r15d, %ecx
movq 0x10(%rsp), %rbx
cmpq %rax, %rcx
je 0x1495b
movsd (%rbp,%rax,8), %xmm0
movsd %xmm0, (%rbx,%rax,8)
incq %rax
jmp 0x148f6
leaq (,%r12,4), %rdi
leaq 0x81f81(%rip), %rsi     # 0x9689b
pushq $0x5
popq %rdx
callq 0x34f59
movq %rax, 0x18(%rsp)
movl %r12d, %edi
callq 0x34598
movq %rax, %r13
leaq 0x40(%rsp), %rax
xorl %ecx, %ecx
cmpq $0x64, %rcx
je 0x14978
xorl %edx, %edx
cmpq $0x32, %rdx
je 0x14950
andl $0x0, (%rax,%rdx,4)
incq %rdx
jmp 0x14941
incq %rcx
addq $0xc8, %rax
jmp 0x14939
movq %r15, %rax
cmpq %r12, %rax
jge 0x14b0c
movsd -0x8(%rbp,%r15,8), %xmm0
movsd %xmm0, (%rbx,%rax,8)
incq %rax
jmp 0x1495e
leal -0x1(%r15), %eax
movl %eax, 0xc(%rsp)
testl %ebx, %ebx
movl $0x0, %ebp
cmovgl %ebx, %ebp
testl %r12d, %r12d
movl $0x0, %r9d
cmovgl %r12d, %r9d
imulq $0xc8, %rbx, %rax
leaq 0x40(%rsp), %rdi
leaq (%rax,%rdi), %rbx
addq $-0xc8, %rbx
movsd 0x81342(%rip), %xmm0    # 0x95cf8
movsd %xmm0, 0x20(%rsp)
movq %r9, 0x28(%rsp)
movq 0x30(%rsp), %rax
movl 0x10(%rax), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
movq %rdi, %rcx
xorl %edx, %edx
cmpq %rbp, %rdx
je 0x149f9
xorl %esi, %esi
cmpq %rsi, %rax
je 0x149ed
andl $0x0, (%rcx,%rsi,4)
incq %rsi
jmp 0x149df
incq %rdx
addq $0xc8, %rcx
jmp 0x149d8
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x14a14
movslq (%r13), %rdx
movq (%r14,%rdx,8), %rdx
movl (%rdx,%rcx,4), %edx
movl %edx, 0x40(%rsp,%rcx,4)
incq %rcx
jmp 0x149fb
leaq 0x108(%rsp), %rdx
pushq $0x1
popq %rcx
cmpq %r12, %rcx
jge 0x14a5a
xorl %esi, %esi
cmpq %rsi, %rax
je 0x14a4e
movslq (%r13,%rcx,4), %r8
movq (%r14,%r8,8), %r8
movl (%r8,%rsi,4), %r10d
movslq -0x4(%r13,%rcx,4), %r8
movq (%r14,%r8,8), %r8
subl (%r8,%rsi,4), %r10d
movl %r10d, (%rdx,%rsi,4)
incq %rsi
jmp 0x14a26
incq %rcx
addq $0xc8, %rdx
jmp 0x14a1f
movl %ecx, %ecx
xorl %edx, %edx
cmpq %rdx, %rax
je 0x14a80
movq -0x8(%r14,%r15,8), %rsi
movl (%rsi,%rdx,4), %esi
movslq -0x4(%r13,%rcx,4), %r8
movq (%r14,%r8,8), %r8
subl (%r8,%rdx,4), %esi
movl %esi, (%rbx,%rdx,4)
incq %rdx
jmp 0x14a5e
callq 0x1b73b
movsd 0x20(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x14ab5
xorl %eax, %eax
movq 0x18(%rsp), %rdx
movq 0x28(%rsp), %rsi
cmpq %rax, %rsi
je 0x14aaf
movl (%r13,%rax,4), %ecx
movl %ecx, (%rdx,%rax,4)
incq %rax
jmp 0x14a9d
movsd %xmm0, 0x20(%rsp)
movq %r13, %rdi
movl %r12d, %esi
movl 0xc(%rsp), %edx
callq 0x349ff
testl %eax, %eax
movq 0x28(%rsp), %r9
leaq 0x40(%rsp), %rdi
jne 0x149c1
movq (%rsp), %rbp
xorl %eax, %eax
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %rdi
cmpq %rax, %r9
je 0x14aff
movslq (%rdi,%rax,4), %rcx
movsd (%rbp,%rcx,8), %xmm0
movsd %xmm0, (%rbx,%rax,8)
incq %rax
jmp 0x14ae6
callq 0x34ff7
movq %r13, %rdi
callq 0x34ff7
movq %rbp, %rdi
callq 0x34ff7
movq %r14, %rdi
movl %r15d, %esi
callq 0x34fc3
movq %rbx, %rax
addq $0x4e68, %rsp           # imm = 0x4E68
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq