// File: /workspace/github_c_makefile_star2_O1/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 $0x4e98, %rsp           # imm = 0x4E98
movq %rcx, %rbx
movl %esi, %r14d
movq %rdi, %r13
leaq 0x8(%rsp), %rax
movq $0x0, (%rax)
movl %edx, 0x14(%rsp)
movslq %edx, %r15
leaq -0x1(%r15), %rbp
leaq -0x8(,%r15,8), %rdi
leaq 0x8dda0(%rip), %rsi     # 0xa38b7
movl $0x4, %edx
callq 0x390f5
movq %rax, 0x28(%rsp)
leaq 0x6c(%rsp), %r12
movq %r13, 0x38(%rsp)
movq %r13, %rdi
movl %r14d, %esi
movq %rbx, %rdx
movq %r12, %rcx
leaq 0x8(%rsp), %r8
callq 0x158bc
movq %rax, %r14
movl (%r12), %r13d
movslq %r13d, %rsi
cmpl %r15d, %esi
jge 0x15ba3
testl %esi, %esi
movq 0x28(%rsp), %rbx
jle 0x15b77
movq 0x8(%rsp), %rax
xorl %ecx, %ecx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rbx,%rcx,8)
incq %rcx
cmpq %rcx, %r13
jne 0x15b65
cmpl %ebp, %r13d
jge 0x15dba
movq 0x8(%rsp), %rax
movslq %ebp, %rcx
movq %rsi, %rdx
movsd -0x8(%rax,%rsi,8), %xmm0
movsd %xmm0, (%rbx,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x15b8b
jmp 0x15dba
movq %rsi, 0x48(%rsp)
leaq (,%rbp,4), %rdi
leaq 0x8dd00(%rip), %rsi     # 0xa38b7
movl $0x5, %edx
callq 0x390f5
movq %rax, 0x30(%rsp)
movl %ebp, %edi
callq 0x3857b
movq %rax, %r12
leaq 0x70(%rsp), %rbx
movl $0x4e20, %edx           # imm = 0x4E20
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4050
movq %r13, 0x40(%rsp)
leal -0x1(%r13), %eax
movl %eax, 0x24(%rsp)
movl %r15d, %eax
movl %ebp, %r13d
imulq $0xc8, %rax, %rax
movq %rax, 0x60(%rsp)
imulq $0xc8, %r15, %rax
addq %rax, %rbx
addq $-0xc8, %rbx
movsd 0x8d0d4(%rip), %xmm0    # 0xa2cf0
movl 0x14(%rsp), %r15d
movq %rbp, 0x58(%rsp)
movq %rbx, 0x50(%rsp)
movsd %xmm0, 0x18(%rsp)
testl %r15d, %r15d
jle 0x15c6c
movq 0x38(%rsp), %rax
movl 0x10(%rax), %ebx
movq %rbx, %rbp
shlq $0x2, %rbp
xorl %r15d, %r15d
testl %ebx, %ebx
jle 0x15c5e
leaq (%rsp,%r15), %rdi
addq $0x70, %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x4050
addq $0xc8, %r15
cmpq %r15, 0x60(%rsp)
jne 0x15c48
movq 0x38(%rsp), %rax
movl 0x10(%rax), %eax
testl %eax, %eax
jle 0x15c91
xorl %ecx, %ecx
movslq (%r12), %rdx
movq (%r14,%rdx,8), %rdx
movl (%rdx,%rcx,4), %edx
movl %edx, 0x70(%rsp,%rcx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x15c7a
movl $0x1, %ecx
movl 0x14(%rsp), %r15d
cmpl $0x3, %r15d
movq 0x50(%rsp), %r9
jl 0x15ce8
leaq 0x138(%rsp), %rdx
testl %eax, %eax
jle 0x15cd7
xorl %esi, %esi
movslq (%r12,%rcx,4), %rdi
movq (%r14,%rdi,8), %rdi
movl (%rdi,%rsi,4), %edi
movslq -0x4(%r12,%rcx,4), %r8
movq (%r14,%r8,8), %r8
subl (%r8,%rsi,4), %edi
movl %edi, (%rdx,%rsi,4)
incq %rsi
cmpq %rsi, %rax
jne 0x15cb4
incq %rcx
addq $0xc8, %rdx
cmpq %r13, %rcx
jne 0x15cae
movl %ecx, %ecx
testl %eax, %eax
movq 0x58(%rsp), %rbp
jle 0x15d19
movq 0x48(%rsp), %rdx
movq -0x8(%r14,%rdx,8), %rdx
xorl %esi, %esi
movl (%rdx,%rsi,4), %edi
movslq -0x4(%r12,%rcx,4), %r8
movq (%r14,%r8,8), %r8
subl (%r8,%rsi,4), %edi
movl %edi, (%r9,%rsi,4)
incq %rsi
cmpq %rsi, %rax
jne 0x15cfd
cmpl $0x2, %r15d
setl %bl
leaq 0x70(%rsp), %rdi
callq 0x1d4c4
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
setbe %al
orb %bl, %al
je 0x15d41
minsd %xmm1, %xmm0
jmp 0x15d57
xorl %eax, %eax
movq 0x30(%rsp), %rdx
movl (%r12,%rax,4), %ecx
movl %ecx, (%rdx,%rax,4)
incq %rax
cmpq %rax, %r13
jne 0x15d48
movsd %xmm0, 0x18(%rsp)
movq %r12, %rdi
movl %ebp, %esi
movl 0x24(%rsp), %edx
callq 0x38aaf
movsd 0x18(%rsp), %xmm0
testl %eax, %eax
jne 0x15c2b
cmpl $0x2, %r15d
movq 0x28(%rsp), %rbx
movq 0x30(%rsp), %rdi
jl 0x15da8
movq 0x8(%rsp), %rax
movl %ebp, %ecx
xorl %edx, %edx
movslq (%rdi,%rdx,4), %rsi
movsd (%rax,%rsi,8), %xmm0
movsd %xmm0, (%rbx,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x15d92
callq 0x39194
movq %r12, %rdi
callq 0x39194
movq 0x40(%rsp), %r13
movq 0x8(%rsp), %rdi
callq 0x39194
movq %r14, %rdi
movl %r13d, %esi
callq 0x3915f
movq %rbx, %rax
addq $0x4e98, %rsp           # imm = 0x4E98
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq