// File: /workspace/github_c_makefile_star2_O3/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 0x35afc(%rip), %rax     # 0xd5870
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 0x12694(%rip), %r13     # 0xb2448
movl $0x4, %esi
movq %rdi, 0x30(%rsp)
movq %r13, %rdx
movl $0x4, %ecx
callq 0x3a1fc
movq %rax, %rbx
movq %r14, 0x20(%rsp)
leaq 0x8(,%r14,8), %rdi
movq %r13, %rsi
movl $0x5, %edx
callq 0x3a0e1
movq %rax, %r14
movslq %r15d, %r13
movq %r13, %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rdi
leaq 0x12648(%rip), %rsi     # 0xb2448
movl $0x6, %edx
callq 0x3a0e1
movq %rax, %r15
movl 0xc(%rsp), %r8d
testl %r13d, %r13d
movq 0x28(%rsp), %r9
movq (%rsp), %rdi
jle 0x9fe57
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 0x9fff4
testl %ecx, %ecx
js 0x9fff4
movl %ecx, %ecx
incl (%rbx,%rcx,4)
addq $0x30, %rsi
cmpq %rsi, %rax
jne 0x9fe2d
movq %r8, 0x18(%rsp)
movq %rbp, 0x10(%rsp)
cmpl $0x0, 0x20(%rsp)
js 0x9fea3
movq 0x10(%rsp), %rbp
subl (%rsp), %ebp
incl %ebp
xorl %r13d, %r13d
movslq (%rbx,%r13,4), %rdi
testq %rdi, %rdi
jle 0x9fe95
shlq $0x2, %rdi
leaq 0x125bf(%rip), %rsi     # 0xb2448
movl $0xe, %edx
callq 0x3a0e1
jmp 0x9fe97
xorl %eax, %eax
movq %rax, (%r14,%r13,8)
incq %r13
cmpq %r13, %rbp
jne 0x9fe75
leaq 0x1259e(%rip), %rdx     # 0xb2448
movl $0x4, %esi
movq 0x30(%rsp), %rdi
movl $0x11, %ecx
callq 0x3a1fc
movl 0xc(%rsp), %r10d
testl %r10d, %r10d
movq (%rsp), %r9
movq 0x18(%rsp), %r11
movq 0x28(%rsp), %r13
jle 0x9ff00
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 0x9fedb
cmpl $0x0, 0x20(%rsp)
movq 0x10(%rsp), %r13
js 0x9ff76
movl %r13d, %ecx
subl (%rsp), %ecx
incl %ecx
xorl %edx, %edx
xorl %esi, %esi
cmpl $0x0, (%rbx,%rdx,4)
jle 0x9ff6e
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 0x9ff2f
addl %r8d, %esi
incq %rdx
cmpq %rcx, %rdx
jne 0x9ff18
testl %r10d, %r10d
jle 0x9ffb0
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 0x9ff85
movq %rax, %rdi
callq 0x3a180
movq %r15, %rdi
callq 0x3a180
movl $0x1, %r12d
cmpl $0x0, 0x20(%rsp)
js 0x9ffef
subl (%rsp), %r13d
incl %r13d
xorl %r15d, %r15d
cmpl $0x0, (%rbx,%r15,4)
jle 0x9ffe7
movq (%r14,%r15,8), %rdi
callq 0x3a180
incq %r15
cmpq %r15, %r13
jne 0x9ffd7
movq %r14, %r15
jmp 0xa0033
leaq 0x35875(%rip), %rax     # 0xd5870
movq (%rax), %rax
movq 0x18(%rsp), %rsi
movl 0x30f10(%rax,%rsi), %r8d
movl 0x30f18(%rax,%rsi), %r9d
leaq 0x12443(%rip), %rdi     # 0xb245d
xorl %r12d, %r12d
movl 0x10(%rsp), %esi
xorl %eax, %eax
callq 0x4030
movq %rbx, %rdi
callq 0x3a180
movq %r14, %rbx
movq %rbx, %rdi
callq 0x3a180
movq %r15, %rdi
callq 0x3a180
movl %r12d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq