// File: /workspace/github_c_makefile_star2_O3/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, %r15
leaq 0x20(%rsp), %rax
movq $0x0, (%rax)
movl %edx, 0xc(%rsp)
movslq %edx, %r13
leaq -0x1(%r13), %rbp
leaq -0x8(,%r13,8), %rdi
leaq 0x90b9e(%rip), %rsi     # 0xa68fb
movl $0x4, %edx
callq 0x3a0e1
movq %rax, 0x18(%rsp)
leaq 0x6c(%rsp), %r12
movq %r15, 0x58(%rsp)
movq %r15, %rdi
movl %r14d, %esi
movq %rbx, %rdx
movq %r12, %rcx
leaq 0x20(%rsp), %r8
callq 0x15b02
movq %rax, %r14
movl (%r12), %ebx
movslq %ebx, %rdx
cmpl %r13d, %edx
jge 0x15e72
movq 0x20(%rsp), %r12
testl %edx, %edx
movq 0x18(%rsp), %rcx
jle 0x15dc2
xorl %eax, %eax
movsd (%r12,%rax,8), %xmm0
movsd %xmm0, (%rcx,%rax,8)
incq %rax
cmpq %rax, %rbx
jne 0x15daf
cmpl %ebp, %ebx
jge 0x16094
movsd -0x8(%r12,%rdx,8), %xmm0
movq %rdx, %rax
notq %rax
addq %r13, %rax
decq %rax
subq %rdx, %r13
andq $-0x2, %r13
movq %rax, %xmm1
pshufd $0x44, %xmm1, %xmm1     # xmm1 = xmm1[0,1,0,1]
leaq (%rcx,%rdx,8), %rax
addq $0x8, %rax
xorl %ecx, %ecx
movdqa 0x90640(%rip), %xmm2    # 0xa6440
movdqa 0x90648(%rip), %xmm3    # 0xa6450
pxor %xmm3, %xmm1
pcmpeqd %xmm4, %xmm4
movq %rcx, %xmm5
pshufd $0x44, %xmm5, %xmm5     # xmm5 = xmm5[0,1,0,1]
por %xmm2, %xmm5
pxor %xmm3, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm1, %xmm6
pcmpeqd %xmm1, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
movd %xmm5, %edx
notl %edx
testb $0x1, %dl
je 0x15e51
movsd %xmm0, -0x8(%rax,%rcx,8)
pxor %xmm4, %xmm5
pextrw $0x4, %xmm5, %edx
testb $0x1, %dl
je 0x15e64
movsd %xmm0, (%rax,%rcx,8)
addq $0x2, %rcx
cmpq %rcx, %r13
jne 0x15e10
jmp 0x16094
movq %rdx, 0x48(%rsp)
leaq (,%rbp,4), %rdi
leaq 0x90a75(%rip), %rsi     # 0xa68fb
movl $0x5, %edx
callq 0x3a0e1
movq %rax, 0x30(%rsp)
movl %ebp, %edi
callq 0x391d6
movq %rbx, %r15
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
movl $0x4e20, %edx           # imm = 0x4E20
xorl %esi, %esi
callq 0x4050
movq %r15, 0x40(%rsp)
leal -0x1(%r15), %eax
movl %eax, 0x2c(%rsp)
movl %r13d, %eax
movl %ebp, %r12d
imulq $0xc8, %rax, %rax
movq %rax, 0x60(%rsp)
imulq $0xc8, %r13, %rax
leaq 0x70(%rsp), %rcx
leaq (%rax,%rcx), %r13
addq $-0xc8, %r13
movsd 0x8fdff(%rip), %xmm0    # 0xa5cf0
movl 0xc(%rsp), %r15d
movq %rbp, 0x38(%rsp)
movq %r13, 0x50(%rsp)
movsd %xmm0, 0x10(%rsp)
movq 0x58(%rsp), %rax
movl 0x10(%rax), %ebp
testl %r15d, %r15d
jle 0x15f42
leaq (,%rbp,4), %r13
xorl %r15d, %r15d
testl %ebp, %ebp
jle 0x15f34
leaq (%rsp,%r15), %rdi
addq $0x70, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x4050
addq $0xc8, %r15
cmpq %r15, 0x60(%rsp)
jne 0x15f1e
testl %ebp, %ebp
jle 0x15f5e
xorl %eax, %eax
movslq (%rbx), %rcx
movq (%r14,%rcx,8), %rcx
movl (%rcx,%rax,4), %ecx
movl %ecx, 0x70(%rsp,%rax,4)
incq %rax
cmpq %rax, %rbp
jne 0x15f48
movl $0x1, %eax
movl 0xc(%rsp), %r15d
cmpl $0x3, %r15d
movq 0x50(%rsp), %r13
jl 0x15fb5
leaq 0x138(%rsp), %rcx
testl %ebp, %ebp
jle 0x15fa3
xorl %edx, %edx
movslq (%rbx,%rax,4), %rsi
movq (%r14,%rsi,8), %rsi
movl (%rsi,%rdx,4), %esi
movslq -0x4(%rbx,%rax,4), %rdi
movq (%r14,%rdi,8), %rdi
subl (%rdi,%rdx,4), %esi
movl %esi, (%rcx,%rdx,4)
incq %rdx
cmpq %rdx, %rbp
jne 0x15f81
incq %rax
addq $0xc8, %rcx
cmpq %r12, %rax
jne 0x15f7b
movq %r12, %rax
testl %ebp, %ebp
jle 0x15fe1
movq 0x48(%rsp), %rcx
movq -0x8(%r14,%rcx,8), %rcx
xorl %edx, %edx
movl (%rcx,%rdx,4), %esi
movslq -0x4(%rbx,%rax,4), %rdi
movq (%r14,%rdi,8), %rdi
subl (%rdi,%rdx,4), %esi
movl %esi, (%r13,%rdx,4)
incq %rdx
cmpq %rdx, %rbp
jne 0x15fc5
cmpl $0x2, %r15d
setl %bpl
leaq 0x70(%rsp), %rdi
callq 0x1dc4b
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
setbe %al
orb %bpl, %al
je 0x16016
minsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x38(%rsp), %rbp
jmp 0x16036
xorl %eax, %eax
movq 0x38(%rsp), %rbp
movq 0x30(%rsp), %rdx
movl (%rbx,%rax,4), %ecx
movl %ecx, (%rdx,%rax,4)
incq %rax
cmpq %rax, %r12
jne 0x16022
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
movl %ebp, %esi
movl 0x2c(%rsp), %edx
callq 0x39814
movsd 0x10(%rsp), %xmm0
testl %eax, %eax
jne 0x15f00
movq 0x20(%rsp), %r12
cmpl $0x2, %r15d
movq 0x18(%rsp), %rsi
movq 0x30(%rsp), %rdi
jl 0x16082
movl %ebp, %eax
xorl %ecx, %ecx
movslq (%rdi,%rcx,4), %rdx
movsd (%r12,%rdx,8), %xmm0
movsd %xmm0, (%rsi,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x1606b
callq 0x3a180
movq %rbx, %rdi
callq 0x3a180
movq 0x40(%rsp), %rbx
movq %r12, %rdi
callq 0x3a180
movq %r14, %rdi
movl %ebx, %esi
callq 0x3a14b
movq 0x18(%rsp), %rax
addq $0x4e98, %rsp           # imm = 0x4E98
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq