// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/univariatetree.c
// Function: bucketsort_instances
int bucketsort_instances(Instanceptr instances, int size, int fno)
{
 /*!Last Changed 26.11.2005 removed bug counts is deallocated before buckets is deallocated*/
 /*!Last Changed 21.05.2005*/
 int **buckets, *counts, *current, bcount, i, j, k, bucketindex, bottom = current_dataset->features[fno].min.intvalue;
 Instanceptr tmplist;
 bcount = current_dataset->features[fno].max.intvalue - bottom + 1;
 counts = safecalloc(bcount, sizeof(int), "bucketsort_instances", 4);
 buckets = safemalloc(bcount * sizeof(int *), "bucketsort_instances", 5);
 tmplist = safemalloc(size * sizeof(Instance), "bucketsort_instances", 6);
 for (i = 0; i < size; i++)
  {
   bucketindex = instances[i].values[fno].intvalue - bottom;
   if (bucketindex >= bcount || bucketindex < 0)
    {
     printf(m1267, fno, instances[i].values[fno].intvalue, bucketindex, current_dataset->features[fno].min.intvalue, current_dataset->features[fno].max.intvalue);
     safe_free(counts);
     safe_free(buckets);
     safe_free(tmplist);
     return 0;
    }
   (counts[bucketindex])++;
  }
 for (i = 0; i < bcount; i++)
   if (counts[i] > 0)
     buckets[i] = safemalloc(counts[i] * sizeof(int), "bucketsort_instances", 14);
   else
     buckets[i] = NULL;
 current = safecalloc(bcount, sizeof(int), "bucketsort_instances", 17);
 for (i = 0; i < size; i++)
  {
   bucketindex = instances[i].values[fno].intvalue - bottom;
   buckets[bucketindex][current[bucketindex]] = i;
   (current[bucketindex])++;
  }
 k = 0;
 for (i = 0; i < bcount; i++)
   for (j = 0; j < counts[i]; j++)
    {
     tmplist[k] = instances[buckets[i][j]];
     k++;
    }
 for (k = 0; k < size; k++)
   instances[k] = tmplist[k];
 safe_free(current);
 safe_free(tmplist);
 for (i = 0; i < bcount; i++)
    if (counts[i] > 0)
      safe_free(buckets[i]);
 safe_free(counts);
 safe_free(buckets);
 return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, (%rsp)
movq %rdi, %r12
leaq 0x3ced7(%rip), %rax     # 0xcd870
movq (%rax), %rax
movl %edx, 0x10(%rsp)
movslq %edx, %r13
imulq $0x340, %r13, %rcx      # imm = 0x340
movslq 0x30f10(%rax,%rcx), %r15
movq %rcx, 0x8(%rsp)
movslq 0x30f18(%rax,%rcx), %rbp
movq %rbp, %r14
subq %r15, %r14
leaq 0x1(%r14), %rdi
leaq 0x119d8(%rip), %rdx     # 0xa23a8
pushq $0x4
popq %rsi
pushq $0x4
popq %rcx
movq %rdi, 0x20(%rsp)
callq 0x35067
movq %rax, %rbx
movq %r14, 0x18(%rsp)
leaq 0x8(,%r14,8), %rdi
pushq $0x5
popq %rdx
leaq 0x119ae(%rip), %rsi     # 0xa23a8
callq 0x34f59
movq %rax, %r14
movslq (%rsp), %rax
movq %rax, (%rsp)
imulq $0x30, %rax, %rdi
pushq $0x6
popq %rdx
leaq 0x11990(%rip), %rsi     # 0xa23a8
callq 0x34f59
movq %r15, %rdi
movq %rax, %r15
xorl %eax, %eax
movq (%rsp), %rcx
testl %ecx, %ecx
cmovlel %eax, %ecx
movq %rcx, (%rsp)
imulq $0x30, %rcx, %rsi
cmpq %rax, %rsi
je 0x90a62
movq (%r12,%rax), %rcx
movl (%rcx,%r13,8), %edx
movl %edx, %ecx
subl %edi, %ecx
cmpl %ebp, %edx
jg 0x90bb9
testl %ecx, %ecx
js 0x90bb9
movl %ecx, %ecx
incl (%rbx,%rcx,4)
addq $0x30, %rax
jmp 0x90a36
movq %r13, 0x8(%rsp)
movq %rsi, 0x10(%rsp)
movslq 0x18(%rsp), %rbp
xorl %r13d, %r13d
movq %rdi, 0x18(%rsp)
cmpq %rbp, %r13
jg 0x90aa7
movslq (%rbx,%r13,4), %rdi
testq %rdi, %rdi
jle 0x90a9c
shlq $0x2, %rdi
leaq 0x11916(%rip), %rsi     # 0xa23a8
pushq $0xe
popq %rdx
callq 0x34f59
jmp 0x90a9e
xorl %eax, %eax
movq %rax, (%r14,%r13,8)
incq %r13
jmp 0x90a79
leaq 0x118fa(%rip), %rdx     # 0xa23a8
pushq $0x4
popq %rsi
pushq $0x11
popq %rcx
movq 0x20(%rsp), %rdi
callq 0x35067
movq 0x18(%rsp), %r11
xorl %ecx, %ecx
movq %r12, %rdx
movq 0x10(%rsp), %r9
movq 0x8(%rsp), %r10
movq (%rsp), %r13
cmpq %rcx, %r13
je 0x90afd
movq (%rdx), %rsi
movslq (%rsi,%r10,8), %rsi
subq %r11, %rsi
movq (%r14,%rsi,8), %rdi
movslq (%rax,%rsi,4), %r8
movl %ecx, (%rdi,%r8,4)
incl (%rax,%rsi,4)
incq %rcx
addq $0x30, %rdx
jmp 0x90ad6
xorl %ecx, %ecx
xorl %edx, %edx
cmpq %rbp, %rcx
jg 0x90b54
movslq %edx, %rdx
imulq $0x30, %rdx, %rsi
addq %r15, %rsi
xorl %edi, %edi
movslq (%rbx,%rcx,4), %r8
cmpq %r8, %rdi
jge 0x90b4c
movq (%r14,%rcx,8), %r8
movslq (%r8,%rdi,4), %r8
imulq $0x30, %r8, %r8
movups (%r12,%r8), %xmm0
movups 0x10(%r12,%r8), %xmm1
movups 0x20(%r12,%r8), %xmm2
movups %xmm2, 0x20(%rsi)
movups %xmm1, 0x10(%rsi)
movups %xmm0, (%rsi)
incq %rdi
addq $0x30, %rsi
jmp 0x90b12
incq %rcx
addq %rdi, %rdx
jmp 0x90b01
xorl %ecx, %ecx
cmpq %rcx, %r9
je 0x90b83
movups (%r15,%rcx), %xmm0
movups 0x10(%r15,%rcx), %xmm1
movups 0x20(%r15,%rcx), %xmm2
movups %xmm2, 0x20(%r12,%rcx)
movups %xmm1, 0x10(%r12,%rcx)
movups %xmm0, (%r12,%rcx)
addq $0x30, %rcx
jmp 0x90b56
movq %rax, %rdi
callq 0x34ff7
movq %r15, %rdi
callq 0x34ff7
xorl %r15d, %r15d
pushq $0x1
popq %r12
cmpq %rbp, %r15
jg 0x90bb4
cmpl $0x0, (%rbx,%r15,4)
jle 0x90baf
movq (%r14,%r15,8), %rdi
callq 0x34ff7
incq %r15
jmp 0x90b9a
movq %r14, %r15
jmp 0x90bf8
leaq 0x3ccb0(%rip), %rax     # 0xcd870
movq (%rax), %rax
movq 0x8(%rsp), %rsi
movl 0x30f10(%rax,%rsi), %r8d
movl 0x30f18(%rax,%rsi), %r9d
leaq 0x117de(%rip), %rdi     # 0xa23bd
xorl %r12d, %r12d
movl 0x10(%rsp), %esi
xorl %eax, %eax
callq 0x4030
movq %rbx, %rdi
callq 0x34ff7
movq %r14, %rbx
movq %rbx, %rdi
callq 0x34ff7
movq %r15, %rdi
callq 0x34ff7
movl %r12d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq