// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/univariatetree.c
// Function: sort_instances
Instanceptr sort_instances(Instanceptr instances,int fno,int* size)
{
 /*!Last Changed 21.05.2005*/
 /*!Last Changed 02.02.2004*/
 /*!Last Changed 26.01.2003*/
 Instanceptr result, tmp = instances;
 int i, sorted = 1;
 (*size) = data_size(instances);
 result = (Instanceptr)safemalloc((*size)*sizeof(Instance), "sort_instances", 4);
 i = 0;
 while (tmp)
  {
   result[i] = (*tmp);
   if (i > 0)
    {
     if (!mustrealize)
      {
       if (current_dataset->features[fno].type == INTEGER)
        {
         if (result[i - 1].values[fno].intvalue > result[i].values[fno].intvalue)
           sorted = 0;
        }
       else
        {
         if (result[i - 1].values[fno].floatvalue > result[i].values[fno].floatvalue)
           sorted = 0;
        }
      }
     else
      {
       if (real_feature(&(result[i - 1]), fno) > real_feature(&(result[i]), fno))
         sorted = 0;
      }
    }
   i++;   
   tmp = tmp->next;
  }
 if (!sorted)
  {
   if (!mustrealize && current_dataset->features[fno].type == INTEGER && (current_dataset->features[fno].max.intvalue - current_dataset->features[fno].min.intvalue < (*size)))
    {
     if (!bucketsort_instances(result, *size, fno))
       quicksort_instances(result, 0, i - 1, fno);
    }
   else
     quicksort_instances(result, 0, i - 1, fno);  
  }
 return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r14
movl %esi, %ebx
movq %rdi, %r13
callq 0x30309
movq %r14, 0x10(%rsp)
movl %eax, (%r14)
cltq
shlq $0x4, %rax
leaq (%rax,%rax,2), %rdi
leaq 0x123c5(%rip), %rsi     # 0xb244e
movl $0x4, %edx
callq 0x3a0e1
movq %rax, %rbp
testq %r13, %r13
je 0xa01da
movslq %ebx, %r15
movl $0x1, %r14d
imulq $0x340, %r15, %rax      # imm = 0x340
movq %rax, 0x8(%rsp)
movq %rbp, 0x18(%rsp)
xorl %r12d, %r12d
movupd (%r13), %xmm0
movupd 0x10(%r13), %xmm1
movups 0x20(%r13), %xmm2
movups %xmm2, 0x20(%rbp)
movupd %xmm1, 0x10(%rbp)
movupd %xmm0, (%rbp)
subq $0x1, %r12
jb 0xa015b
leaq 0x311ebc(%rip), %rax    # 0x3b1fa4
cmpl $0x0, (%rax)
je 0xa0116
leaq -0x30(%rbp), %rdi
movl %ebx, %esi
callq 0x2ed6a
movsd %xmm0, 0x20(%rsp)
movq %rbp, %rdi
movl %ebx, %esi
callq 0x2ed6a
movsd 0x20(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0xa0145
jmp 0xa015b
leaq 0x35753(%rip), %rax     # 0xd5870
movq (%rax), %rax
movq 0x8(%rsp), %rcx
cmpl $0x0, 0x30f08(%rax,%rcx)
movq -0x30(%rbp), %rcx
movq (%rbp), %rax
je 0xa014a
movsd (%rcx,%r15,8), %xmm0
ucomisd (%rax,%r15,8), %xmm0
jbe 0xa015b
xorl %r14d, %r14d
jmp 0xa015b
movl (%rcx,%r15,8), %ecx
cmpl (%rax,%r15,8), %ecx
movl $0x0, %eax
cmovgl %eax, %r14d
movq 0x10(%r13), %r13
addq $0x30, %rbp
testq %r13, %r13
jne 0xa00bc
testl %r14d, %r14d
movq 0x18(%rsp), %rbp
jne 0xa01da
leaq 0x311e27(%rip), %rax    # 0x3b1fa4
cmpl $0x0, (%rax)
jne 0xa01c8
leaq 0x356e7(%rip), %rax     # 0xd5870
movq (%rax), %rax
movq 0x8(%rsp), %rcx
cmpl $0x0, 0x30f08(%rax,%rcx)
jne 0xa01c8
movq 0x8(%rsp), %rcx
addq %rcx, %rax
addq $0x30f08, %rax          # imm = 0x30F08
movl 0x10(%rax), %ecx
subl 0x8(%rax), %ecx
movq 0x10(%rsp), %rax
movl (%rax), %esi
cmpl %esi, %ecx
jge 0xa01c8
movq %rbp, %rdi
movl %ebx, %edx
callq 0x9fd55
testl %eax, %eax
jne 0xa01da
notq %r12
movq %rbp, %rdi
xorl %esi, %esi
movl %r12d, %edx
movl %ebx, %ecx
callq 0xa01ec
movq %rbp, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq