// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/multivariatetree.c
// Function: find_best_multi_ldt_split
int find_best_multi_ldt_split(Instanceptr* instances, matrix* bestw, double *bestw0, MULTIVARIATE_TYPE multivariate_type, double variance_explained)
{
 /*!Last Changed 22.09.2004*/
 int improved, j, bestdim, dim;
 Partition initial,current,best;
 double bestgain, gain, w0;
 matrix w;
 initial = get_initial_partition(*instances);
 if (initial.count <= 2)
   bestgain = find_gain_for_partition_multivariate(instances, initial, bestw, bestw0, multivariate_type, &bestdim, variance_explained);
 else
  {
   current = create_copy(initial);
   bestgain = find_gain_for_partition_multivariate(instances, current, bestw, bestw0, multivariate_type, &bestdim, variance_explained);
   best = create_copy(current);
   improved = 1;
   while (improved)
    {
     improved = 0;
     for (j = 0; j < current.count; j++)
      {
       current.assignments[j] = 1 - current.assignments[j];
       gain = find_gain_for_partition_multivariate(instances, current, &w, &w0, multivariate_type, &dim, variance_explained);
       if (dless(gain, bestgain))
        {
         bestdim = dim;
         bestgain = gain;
         free_partition(best);
         best = create_copy(current);
         *bestw0 = w0;
         matrix_free(*bestw);
         *bestw = matrix_copy(w);
         matrix_free(w);
         improved = 1;
        }
       else
         matrix_free(w);
       current.assignments[j] = 1 - current.assignments[j];
      }
     if (improved)
      {
       free_partition(current);
       current = create_copy(best);
      }
    }
   free_partition(best);
   free_partition(current);
  }
 free_partition(initial);
 if (bestgain == ISELL)
   return 0;
 return bestdim;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movsd %xmm0, 0x30(%rsp)
movl %ecx, %ebx
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %r12
movq (%rdi), %rsi
leaq 0x90(%rsp), %r14
movq %r14, %rdi
callq 0x1bbad
cmpl $0x2, 0x10(%r14)
jg 0x46e99
movq 0xa0(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x90(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x5c(%rsp), %r14
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
movl %ebx, %ecx
movq %r14, %r8
movsd 0x30(%rsp), %xmm0
callq 0x46d02
movsd %xmm0, 0x20(%rsp)
movl (%r14), %ebx
jmp 0x47154
movq 0xa0(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x90(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0x4dcb2
movq 0x10(%r14), %rax
movq %rax, 0x10(%rsp)
movups (%r14), %xmm0
movups %xmm0, (%rsp)
movl %ebx, 0x2c(%rsp)
movq %r13, %rdx
leaq 0x5c(%rsp), %r13
movq %r12, %rdi
movq %r15, %rsi
movq %rdx, 0xa8(%rsp)
movl 0x2c(%rsp), %ecx
movq %r13, %r8
movsd 0x30(%rsp), %xmm0
callq 0x46d02
movsd %xmm0, 0x20(%rsp)
movq 0x10(%r14), %rax
movq %rax, 0x10(%rsp)
movups (%r14), %xmm0
movups %xmm0, (%rsp)
leaq 0x60(%rsp), %rdi
callq 0x4dcb2
movsd 0x20(%rsp), %xmm1
xorl %ebx, %ebx
movl (%r13), %eax
movl %eax, 0x3c(%rsp)
movl 0x2c(%rsp), %r13d
pushq $0x1
popq %r14
movsd 0x30(%rsp), %xmm0
testb $0x1, %bl
jne 0x4711a
xorl %ebx, %ebx
xorl %ebp, %ebp
movslq 0x50(%rsp), %rax
cmpq %rax, %rbx
movsd %xmm1, 0x20(%rsp)
jge 0x470ac
movq 0x48(%rsp), %rax
movl %r14d, %ecx
subl (%rax,%rbx,4), %ecx
movl %ecx, (%rax,%rbx,4)
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x40(%rsp), %xmm1
movups %xmm1, (%rsp)
movq %r12, %rdi
leaq 0x80(%rsp), %rsi
leaq 0xd0(%rsp), %rdx
movl %r13d, %ecx
leaq 0x58(%rsp), %r8
callq 0x46d02
movsd %xmm0, 0xb0(%rsp)
movsd 0x20(%rsp), %xmm1
callq 0x34c76
testl %eax, %eax
je 0x47075
movl 0x58(%rsp), %eax
movl %eax, 0x3c(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x60(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x4dd42
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x40(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x4dcb2
movq 0xc8(%rsp), %rax
movq %rax, 0x70(%rsp)
movups 0xb8(%rsp), %xmm0
movaps %xmm0, 0x60(%rsp)
movsd 0xd0(%rsp), %xmm0
movq 0xa8(%rsp), %rax
movsd %xmm0, (%rax)
movq (%r15), %rdi
movq 0x8(%r15), %rsi
callq 0x3929f
movq 0x80(%rsp), %r13
movq 0x88(%rsp), %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0x383f4
movq %rax, (%r15)
movq %rdx, 0x8(%r15)
movq %r13, %rdi
movl 0x2c(%rsp), %r13d
movq %rbp, %rsi
callq 0x3929f
movsd 0xb0(%rsp), %xmm1
movl %r14d, %ebp
jmp 0x47090
movq 0x80(%rsp), %rdi
movq 0x88(%rsp), %rsi
callq 0x3929f
movsd 0x20(%rsp), %xmm1
movq 0x48(%rsp), %rax
movl %r14d, %ecx
subl (%rax,%rbx,4), %ecx
movl %ecx, (%rax,%rbx,4)
incq %rbx
movsd 0x30(%rsp), %xmm0
jmp 0x46f49
testl %ebp, %ebp
sete %bl
je 0x46f3c
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x40(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x4dd42
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x60(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x4dcb2
movsd 0x30(%rsp), %xmm0
movq 0xc8(%rsp), %rax
movq %rax, 0x50(%rsp)
movups 0xb8(%rsp), %xmm1
movaps %xmm1, 0x40(%rsp)
movsd 0x20(%rsp), %xmm1
jmp 0x46f3c
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x60(%rsp), %xmm0
movups %xmm0, (%rsp)
movsd %xmm1, 0x20(%rsp)
callq 0x4dd42
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x40(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x4dd42
movl 0x3c(%rsp), %ebx
movq 0xa0(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x90(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x4dd42
xorl %eax, %eax
movsd 0x20(%rsp), %xmm0
ucomisd 0x4eb76(%rip), %xmm0    # 0x95cf8
cmovnel %ebx, %eax
cmovpl %ebx, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq