// File: /workspace/github_c_makefile_star2_O3/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 $0xc8, %rsp
movsd %xmm0, 0x20(%rsp)
movl %ecx, %ebx
movq %rdx, %rbp
movq %rsi, %r15
movq %rdi, %r12
movq (%rdi), %rsi
leaq 0x80(%rsp), %r14
movq %r14, %rdi
callq 0x1e10a
cmpl $0x2, 0x10(%r14)
jg 0x4e10a
movq 0x90(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x80(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x4c(%rsp), %r14
movq %r12, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movl %ebx, %ecx
movq %r14, %r8
movsd 0x20(%rsp), %xmm0
callq 0x4df59
movsd %xmm0, 0x28(%rsp)
movl (%r14), %ebx
jmp 0x4e385
movq 0x90(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x80(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x559be
movq 0x10(%r14), %rax
movq %rax, 0x10(%rsp)
movups (%r14), %xmm0
movups %xmm0, (%rsp)
leaq 0x4c(%rsp), %r13
movq %r12, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movl %ebx, %ecx
movq %r13, %r8
movsd 0x20(%rsp), %xmm0
callq 0x4df59
movsd %xmm0, 0x28(%rsp)
movq 0x10(%r14), %rax
movq %rax, 0x10(%rsp)
movups (%r14), %xmm0
movups %xmm0, (%rsp)
leaq 0x50(%rsp), %rdi
callq 0x559be
movl (%r13), %eax
movl %eax, 0x1c(%rsp)
cmpl $0x0, 0x10(%r14)
jle 0x4e351
movq %rbp, 0x98(%rsp)
xorl %r14d, %r14d
movq 0x38(%rsp), %rax
xorl %ebp, %ebp
movsd 0x20(%rsp), %xmm0
movl $0x1, %ecx
subl (%rax,%r14,4), %ecx
movl %ecx, (%rax,%r14,4)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x30(%rsp), %xmm1
movups %xmm1, (%rsp)
movq %r12, %rdi
leaq 0x70(%rsp), %rsi
leaq 0xc0(%rsp), %rdx
movl %ebx, %ecx
leaq 0x48(%rsp), %r8
callq 0x4df59
movsd %xmm0, 0xa0(%rsp)
movsd 0x28(%rsp), %xmm1
callq 0x39aee
testl %eax, %eax
je 0x4e2bb
movl 0x48(%rsp), %eax
movl %eax, 0x1c(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x50(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x55a69
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x559be
movq 0xb8(%rsp), %rax
movq %rax, 0x60(%rsp)
movups 0xa8(%rsp), %xmm0
movaps %xmm0, 0x50(%rsp)
movsd 0xc0(%rsp), %xmm0
movq 0x98(%rsp), %rax
movsd %xmm0, (%rax)
movq (%r15), %rdi
movq 0x8(%r15), %rsi
callq 0x3ed51
movq 0x70(%rsp), %r13
movq 0x78(%rsp), %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0x3dae3
movq %rax, (%r15)
movq %rdx, 0x8(%r15)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x3ed51
movl $0x1, %ebp
movsd 0xa0(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
jmp 0x4e2ca
movq 0x70(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0x3ed51
movq 0x38(%rsp), %rax
movl $0x1, %ecx
subl (%rax,%r14,4), %ecx
movl %ecx, (%rax,%r14,4)
incq %r14
movslq 0x40(%rsp), %rcx
cmpq %rcx, %r14
movsd 0x20(%rsp), %xmm0
jl 0x4e1ab
testl %ebp, %ebp
je 0x4e351
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x55a69
movq 0x60(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x50(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x559be
movq 0xb8(%rsp), %rax
movq %rax, 0x40(%rsp)
movups 0xa8(%rsp), %xmm0
movaps %xmm0, 0x30(%rsp)
testl %eax, %eax
jg 0x4e19b
movq 0x60(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x50(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x55a69
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x55a69
movl 0x1c(%rsp), %ebx
movq 0x90(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x80(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x55a69
xorl %eax, %eax
movsd 0x28(%rsp), %xmm0
ucomisd 0x5793d(%rip), %xmm0    # 0xa5cf0
cmovnel %ebx, %eax
cmovpl %ebx, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq