// File: /workspace/github_c_makefile_star2_O1/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 0x2fa14
movq %r14, 0x8(%rsp)
movl %eax, (%r14)
cltq
shlq $0x4, %rax
leaq (%rax,%rax,2), %rdi
leaq 0x12347(%rip), %rsi     # 0xaf3ce
movl $0x4, %edx
callq 0x390f5
movq %rax, %rbp
xorl %eax, %eax
testq %r13, %r13
je 0x9d17c
movslq %ebx, %r15
movl $0x1, %r14d
imulq $0x340, %r15, %rax      # imm = 0x340
movq %rax, 0x18(%rsp)
movq %rbp, 0x10(%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 0x9d15b
leaq 0x311ebc(%rip), %rax    # 0x3aefa4
cmpl $0x0, (%rax)
je 0x9d116
leaq -0x30(%rbp), %rdi
movl %ebx, %esi
callq 0x2e4b6
movsd %xmm0, 0x20(%rsp)
movq %rbp, %rdi
movl %ebx, %esi
callq 0x2e4b6
movsd 0x20(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x9d145
jmp 0x9d15b
leaq 0x35753(%rip), %rax     # 0xd2870
movq (%rax), %rax
movq 0x18(%rsp), %rcx
cmpl $0x0, 0x30f08(%rax,%rcx)
movq -0x30(%rbp), %rcx
movq (%rbp), %rax
je 0x9d14a
movsd (%rcx,%r15,8), %xmm0
ucomisd (%rax,%r15,8), %xmm0
jbe 0x9d15b
xorl %r14d, %r14d
jmp 0x9d15b
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 0x9d0bc
notl %r12d
testl %r14d, %r14d
sete %al
movq 0x10(%rsp), %rbp
jmp 0x9d182
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
testb %al, %al
je 0x9d1e7
leaq 0x311e17(%rip), %rax    # 0x3aefa4
cmpl $0x0, (%rax)
jne 0x9d1d8
leaq 0x356d7(%rip), %rax     # 0xd2870
movq (%rax), %rax
movslq %ebx, %rcx
imulq $0x340, %rcx, %rcx      # imm = 0x340
cmpl $0x0, 0x30f08(%rax,%rcx)
jne 0x9d1d8
addq %rcx, %rax
addq $0x30f08, %rax          # imm = 0x30F08
movl 0x10(%rax), %ecx
subl 0x8(%rax), %ecx
movq 0x8(%rsp), %rax
movl (%rax), %esi
cmpl %esi, %ecx
jge 0x9d1d8
movq %rbp, %rdi
movl %ebx, %edx
callq 0x9cd53
testl %eax, %eax
jne 0x9d1e7
movq %rbp, %rdi
xorl %esi, %esi
movl %r12d, %edx
movl %ebx, %ecx
callq 0x9d1f9
movq %rbp, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq