// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movl %esi, %r15d
movl %esi, 0xc(%rsp)
movq %rdi, %r12
leaq 0x35afe(%rip), %rax     # 0xd2870
movq (%rax), %rax
movl %edx, 0x10(%rsp)
movslq %edx, %rcx
movq %rcx, 0x28(%rsp)
imulq $0x340, %rcx, %rcx      # imm = 0x340
movslq 0x30f10(%rax,%rcx), %rdx
movq %rdx, (%rsp)
movq %rcx, 0x18(%rsp)
movslq 0x30f18(%rax,%rcx), %rbp
movq %rbp, %r14
subq %rdx, %r14
leaq 0x1(%r14), %rdi
leaq 0x12616(%rip), %r13     # 0xaf3c8
movl $0x4, %esi
movq %rdi, 0x30(%rsp)
movq %r13, %rdx
movl $0x4, %ecx
callq 0x39210
movq %rax, %rbx
movq %r14, 0x20(%rsp)
leaq 0x8(,%r14,8), %rdi
movq %r13, %rsi
movl $0x5, %edx
callq 0x390f5
movq %rax, %r14
movslq %r15d, %r13
movq %r13, %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rdi
leaq 0x125ca(%rip), %rsi     # 0xaf3c8
movl $0x6, %edx
callq 0x390f5
movq %rax, %r15
movl 0xc(%rsp), %r8d
testl %r13d, %r13d
movq 0x28(%rsp), %r9
movq (%rsp), %rdi
jle 0x9ce55
movq %r8, %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rax
xorl %esi, %esi
movq (%r12,%rsi), %rcx
movl (%rcx,%r9,8), %edx
movl %edx, %ecx
subl %edi, %ecx
cmpl %ebp, %edx
jg 0x9cff2
testl %ecx, %ecx
js 0x9cff2
movl %ecx, %ecx
incl (%rbx,%rcx,4)
addq $0x30, %rsi
cmpq %rsi, %rax
jne 0x9ce2b
movq %r8, 0x18(%rsp)
movq %rbp, 0x10(%rsp)
cmpl $0x0, 0x20(%rsp)
js 0x9cea1
movq 0x10(%rsp), %rbp
subl (%rsp), %ebp
incl %ebp
xorl %r13d, %r13d
movslq (%rbx,%r13,4), %rdi
testq %rdi, %rdi
jle 0x9ce93
shlq $0x2, %rdi
leaq 0x12541(%rip), %rsi     # 0xaf3c8
movl $0xe, %edx
callq 0x390f5
jmp 0x9ce95
xorl %eax, %eax
movq %rax, (%r14,%r13,8)
incq %r13
cmpq %r13, %rbp
jne 0x9ce73
leaq 0x12520(%rip), %rdx     # 0xaf3c8
movl $0x4, %esi
movq 0x30(%rsp), %rdi
movl $0x11, %ecx
callq 0x39210
movl 0xc(%rsp), %r10d
testl %r10d, %r10d
movq (%rsp), %r9
movq 0x18(%rsp), %r11
movq 0x28(%rsp), %r13
jle 0x9cefe
xorl %ecx, %ecx
movq %r12, %rdx
movq (%rdx), %rsi
movslq (%rsi,%r13,8), %rsi
subq %r9, %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
cmpq %rcx, %r11
jne 0x9ced9
cmpl $0x0, 0x20(%rsp)
movq 0x10(%rsp), %r13
js 0x9cf74
movl %r13d, %ecx
subl (%rsp), %ecx
incl %ecx
xorl %edx, %edx
xorl %esi, %esi
cmpl $0x0, (%rbx,%rdx,4)
jle 0x9cf6c
movslq %esi, %rdi
leaq (%rdi,%rdi,2), %rdi
shlq $0x4, %rdi
addq %r15, %rdi
xorl %r8d, %r8d
movq (%r14,%rdx,8), %r9
movslq (%r9,%r8,4), %r9
leaq (%r9,%r9,2), %r9
shlq $0x4, %r9
movups (%r12,%r9), %xmm0
movups 0x10(%r12,%r9), %xmm1
movups 0x20(%r12,%r9), %xmm2
movups %xmm2, 0x20(%rdi)
movups %xmm1, 0x10(%rdi)
movups %xmm0, (%rdi)
incq %r8
movslq (%rbx,%rdx,4), %r9
addq $0x30, %rdi
cmpq %r9, %r8
jl 0x9cf2d
addl %r8d, %esi
incq %rdx
cmpq %rcx, %rdx
jne 0x9cf16
testl %r10d, %r10d
jle 0x9cfae
shlq $0x4, %r11
leaq (%r11,%r11,2), %rcx
xorl %edx, %edx
movups (%r15,%rdx), %xmm0
movups 0x10(%r15,%rdx), %xmm1
movups 0x20(%r15,%rdx), %xmm2
movups %xmm2, 0x20(%r12,%rdx)
movups %xmm1, 0x10(%r12,%rdx)
movups %xmm0, (%r12,%rdx)
addq $0x30, %rdx
cmpq %rdx, %rcx
jne 0x9cf83
movq %rax, %rdi
callq 0x39194
movq %r15, %rdi
callq 0x39194
movl $0x1, %r12d
cmpl $0x0, 0x20(%rsp)
js 0x9cfed
subl (%rsp), %r13d
incl %r13d
xorl %r15d, %r15d
cmpl $0x0, (%rbx,%r15,4)
jle 0x9cfe5
movq (%r14,%r15,8), %rdi
callq 0x39194
incq %r15
cmpq %r15, %r13
jne 0x9cfd5
movq %r14, %r15
jmp 0x9d031
leaq 0x35877(%rip), %rax     # 0xd2870
movq (%rax), %rax
movq 0x18(%rsp), %rsi
movl 0x30f10(%rax,%rsi), %r8d
movl 0x30f18(%rax,%rsi), %r9d
leaq 0x123c5(%rip), %rdi     # 0xaf3dd
xorl %r12d, %r12d
movl 0x10(%rsp), %esi
xorl %eax, %eax
callq 0x4030
movq %rbx, %rdi
callq 0x39194
movq %r14, %rbx
movq %rbx, %rdi
callq 0x39194
movq %r15, %rdi
callq 0x39194
movl %r12d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq