// File: /workspace/github_c_makefile_star2_O2/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 0x2c3cc
movq %r14, 0x10(%rsp)
movl %eax, (%r14)
cltq
imulq $0x30, %rax, %rdi
leaq 0x11764(%rip), %rsi     # 0xa23ae
pushq $0x4
popq %rdx
callq 0x34f59
movq %rax, %rbp
movslq %ebx, %r15
pushq $0x1
popq %r14
imulq $0x340, %r15, %rcx      # imm = 0x340
movq %rcx, 0x8(%rsp)
movq %rax, 0x18(%rsp)
xorl %r12d, %r12d
testq %r13, %r13
je 0x90d25
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 0x90d18
leaq 0x3192ff(%rip), %rax    # 0x3a9fa4
cmpl $0x0, (%rax)
je 0x90cd3
leaq -0x30(%rbp), %rdi
movl %ebx, %esi
callq 0x2aea2
movsd %xmm0, 0x20(%rsp)
movq %rbp, %rdi
movl %ebx, %esi
callq 0x2aea2
movsd 0x20(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x90d02
jmp 0x90d18
leaq 0x3cb96(%rip), %rax     # 0xcd870
movq (%rax), %rax
movq 0x8(%rsp), %rcx
cmpl $0x0, 0x30f08(%rax,%rcx)
movq -0x30(%rbp), %rcx
movq (%rbp), %rax
je 0x90d07
movsd (%rcx,%r15,8), %xmm0
ucomisd (%rax,%r15,8), %xmm0
jbe 0x90d18
xorl %r14d, %r14d
jmp 0x90d18
movl (%rcx,%r15,8), %ecx
cmpl (%rax,%r15,8), %ecx
movl $0x0, %eax
cmovgl %eax, %r14d
movq 0x10(%r13), %r13
addq $0x30, %rbp
jmp 0x90c70
testl %r14d, %r14d
movq 0x18(%rsp), %r14
jne 0x90d93
leaq 0x31926e(%rip), %rax    # 0x3a9fa4
cmpl $0x0, (%rax)
jne 0x90d81
leaq 0x3cb2e(%rip), %rax     # 0xcd870
movq (%rax), %rax
movq 0x8(%rsp), %rcx
cmpl $0x0, 0x30f08(%rax,%rcx)
jne 0x90d81
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 0x90d81
movq %r14, %rdi
movl %ebx, %edx
callq 0x9097e
testl %eax, %eax
jne 0x90d93
notl %r12d
movq %r14, %rdi
xorl %esi, %esi
movl %r12d, %edx
movl %ebx, %ecx
callq 0x90da5
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq