// File: /workspace/github_c_makefile_star2_O1/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, 0x40(%rsp)
movl %ecx, %ebx
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %r12
movq (%rdi), %rsi
leaq 0x88(%rsp), %r14
movq %r14, %rdi
callq 0x1d994
cmpl $0x2, 0x10(%r14)
jg 0x4cc69
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x88(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x18(%rsp), %r8
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
movl %ebx, %ecx
movsd 0x40(%rsp), %xmm0
callq 0x4cabe
movsd %xmm0, 0x48(%rsp)
jmp 0x4cef7
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x88(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0x544be
movq 0x10(%r14), %rax
movq %rax, 0x10(%rsp)
movups (%r14), %xmm0
movups %xmm0, (%rsp)
movq %r13, 0x50(%rsp)
leaq 0x18(%rsp), %r13
movq %r12, %rdi
movq %r15, %rsi
movq 0x50(%rsp), %rdx
movl %ebx, %ecx
movq %r13, %r8
movsd 0x40(%rsp), %xmm0
callq 0x4cabe
movsd %xmm0, 0x48(%rsp)
movq 0x10(%r14), %rax
movq %rax, 0x10(%rsp)
movups (%r14), %xmm0
movups %xmm0, (%rsp)
leaq 0x60(%rsp), %rdi
callq 0x544be
movl (%r13), %eax
movl %eax, 0x1c(%rsp)
movq 0x50(%rsp), %r13
cmpl $0x0, 0x30(%rsp)
movsd 0x40(%rsp), %xmm0
jle 0x4ce62
xorl %r14d, %r14d
xorl %ebp, %ebp
movq 0x28(%rsp), %rax
movl $0x1, %ecx
subl (%rax,%r14,4), %ecx
movl %ecx, (%rax,%r14,4)
movq 0x30(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x20(%rsp), %xmm1
movups %xmm1, (%rsp)
movq %r12, %rdi
leaq 0x78(%rsp), %rsi
leaq 0xc0(%rsp), %rdx
movl %ebx, %ecx
leaq 0x5c(%rsp), %r8
callq 0x4cabe
movsd %xmm0, 0xa0(%rsp)
movsd 0x48(%rsp), %xmm1
callq 0x38d8e
testl %eax, %eax
je 0x4ce20
movl 0x5c(%rsp), %eax
movl %eax, 0x1c(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x60(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x54550
movq 0x30(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x20(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x544be
movq 0xb8(%rsp), %rax
movq %rax, 0x70(%rsp)
movups 0xa8(%rsp), %xmm0
movaps %xmm0, 0x60(%rsp)
movsd 0xc0(%rsp), %xmm0
movsd %xmm0, (%r13)
movq (%r15), %rdi
movq 0x8(%r15), %rsi
callq 0x3dbad
movq 0x78(%rsp), %r13
movq 0x80(%rsp), %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0x3ca3c
movq %rax, (%r15)
movq %rdx, 0x8(%r15)
movq %r13, %rdi
movq 0x50(%rsp), %r13
movq %rbp, %rsi
callq 0x3dbad
movl $0x1, %ebp
movsd 0xa0(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
jmp 0x4ce32
movq 0x78(%rsp), %rdi
movq 0x80(%rsp), %rsi
callq 0x3dbad
movq 0x28(%rsp), %rax
movl $0x1, %ecx
subl (%rax,%r14,4), %ecx
movl %ecx, (%rax,%r14,4)
incq %r14
movslq 0x30(%rsp), %rax
cmpq %rax, %r14
movsd 0x40(%rsp), %xmm0
jl 0x4cd09
testl %ebp, %ebp
sete %al
jmp 0x4ce64
movb $0x1, %al
testb %al, %al
jne 0x4cebf
movq 0x30(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x20(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x54550
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x60(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x544be
movq 0xb8(%rsp), %rax
movq %rax, 0x30(%rsp)
movups 0xa8(%rsp), %xmm0
movaps %xmm0, 0x20(%rsp)
jmp 0x4ccf3
movl 0x1c(%rsp), %eax
movl %eax, 0x18(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x60(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x54550
movq 0x30(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x20(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x54550
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x88(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x54550
xorl %eax, %eax
movsd 0x48(%rsp), %xmm0
ucomisd 0x55dcb(%rip), %xmm0    # 0xa2cf0
movl 0x18(%rsp), %ecx
cmovnel %ecx, %eax
cmovpl %ecx, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq