// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/cart.c
// Function: find_best_cart_split
int find_best_cart_split(Decisionnodeptr node)
{
 int i;
 Instanceptr inst;
 double w0, v, gamma, bestc, c, delta, impurity, bestimpurity, bestdelta, bestgamma;
 matrix w;
 BOOLEAN improved = BOOLEAN_TRUE;
 node->w = matrix_alloc(1, current_dataset->multifeaturecount - 1);
 w = matrix_alloc(1, current_dataset->multifeaturecount - 1);
 node->w0 = 0;
 for (i = 0; i < current_dataset->multifeaturecount - 1; i++)
   node->w.values[0][i] = 1 / sqrt(current_dataset->multifeaturecount - 1);
 while (improved)
  {
   matrix_identical(&w, node->w);
   w0 = node->w0;
   for (i = 0; i < current_dataset->multifeaturecount - 1; i++)
    {
     bestimpurity = ISELL;
     for (gamma = -0.25; gamma < 0.3; gamma += 0.25)
      {
       inst = node->instances;
       while (inst)
        {
         v = multiply_with_matrix(inst, w);
         if (real_feature(inst, i) + gamma != 0.0)
          {
           delta = (v - w0) / (real_feature(inst, i) + gamma);
           w.values[0][i] -= delta;
           w0 += delta * gamma;
           impurity = information_gain_for_multivariate_split(node->instances, w, w0);
           w.values[0][i] += delta;
           w0 -= delta * gamma;
           if (impurity < bestimpurity)
            {                     
             bestimpurity = impurity;
             bestdelta = delta;
             bestgamma = gamma;
            }
          }
         inst = inst->next;
        }
      }
     if (bestimpurity != ISELL)
      {
       w.values[0][i] -= bestdelta;
       w0 += bestdelta * bestgamma;      
      }
    }
   bestimpurity = ISELL;
   inst = node->instances;
   while (inst)
    {
     c = multiply_with_matrix(inst, w);
     impurity = information_gain_for_multivariate_split(node->instances, w, c);
     if (impurity < bestimpurity)
      {
       bestc = c;
       bestimpurity = impurity;
      }
     inst = inst->next;
    }
   if (bestimpurity != ISELL)
     w0 = bestc;
   if (information_gain_for_multivariate_split(node->instances, w, w0) < information_gain_for_multivariate_split(node->instances, node->w, node->w0))
    {
     matrix_identical(&(node->w), w);
     node->w0 = w0;
     improved = BOOLEAN_TRUE;
    }
   else
     improved = BOOLEAN_FALSE;
  }
 matrix_free(w);
 if (information_gain_for_multivariate_split(node->instances, node->w, node->w0) == ISELL)
   return 0;
 return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %rbx
leaq 0x38(%rdi), %rax
movq %rax, 0x58(%rsp)
leaq 0xc6cec(%rip), %rbp     # 0xcd870
movq (%rbp), %rax
movl 0x1c0(%rax), %esi
decl %esi
pushq $0x1
popq %r15
movl %r15d, %edi
callq 0x380d3
movq %rax, 0x38(%rbx)
movq %rdx, 0x40(%rbx)
movq (%rbp), %rax
movl 0x1c0(%rax), %esi
decl %esi
movl %r15d, %edi
callq 0x380d3
movq %rax, (%rsp)
movq %rdx, 0x8(%rsp)
andq $0x0, 0x48(%rbx)
xorl %r14d, %r14d
xorpd %xmm2, %xmm2
movsd 0x8e94b(%rip), %xmm3    # 0x95520
movq (%rbp), %rax
movslq 0x1c0(%rax), %rax
decq %rax
cmpq %rax, %r14
jge 0x6c23
cvtsi2sd %eax, %xmm0
ucomisd %xmm2, %xmm0
jb 0x6bf8
sqrtsd %xmm0, %xmm0
jmp 0x6c09
callq 0x4300
movsd 0x8e91b(%rip), %xmm3    # 0x95520
xorpd %xmm2, %xmm2
movapd %xmm3, %xmm1
divsd %xmm0, %xmm1
movq 0x40(%rbx), %rax
movq (%rax), %rax
movsd %xmm1, (%rax,%r14,8)
incq %r14
jmp 0x6bd5
leaq 0x20(%rbx), %r14
xorl %r12d, %r12d
movq %rsp, %r15
testb $0x1, %r12b
jne 0x6f38
movq 0x38(%rbx), %rsi
movq 0x40(%rbx), %rdx
movq %r15, %rdi
callq 0x3a763
movsd 0x48(%rbx), %xmm0
movaps %xmm0, 0x10(%rsp)
xorl %r12d, %r12d
movsd 0x30(%rsp), %xmm1
movq (%rbp), %rax
movslq 0x1c0(%rax), %rax
decq %rax
cmpq %rax, %r12
jge 0x6e39
movsd 0x8f087(%rip), %xmm2    # 0x95d00
movsd 0x8f077(%rip), %xmm0    # 0x95cf8
movsd %xmm0, 0x38(%rsp)
movsd 0x8f079(%rip), %xmm0    # 0x95d08
ucomisd %xmm2, %xmm0
jbe 0x6ded
movq %r14, %r13
movsd %xmm2, 0x40(%rsp)
movq (%r13), %r13
testq %r13, %r13
je 0x6de0
movsd %xmm1, 0x30(%rsp)
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r13, %rdi
callq 0x2b0c0
movsd %xmm0, 0x20(%rsp)
movq %r13, %rdi
movl %r12d, %esi
callq 0x2aea2
movsd 0x40(%rsp), %xmm2
addsd %xmm2, %xmm0
ucomisd 0x8f02f(%rip), %xmm0    # 0x95d18
jne 0x6cf1
jnp 0x6dc3
movsd 0x20(%rsp), %xmm0
subsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %r13, %rdi
movl %r12d, %esi
callq 0x2aea2
movsd 0x40(%rsp), %xmm3
addsd %xmm3, %xmm0
movsd 0x20(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
movq 0x8(%rsp), %rax
movq (%rax), %rax
movsd (%rax,%r12,8), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax,%r12,8)
movapd %xmm1, %xmm2
mulsd %xmm3, %xmm2
movsd %xmm2, 0x68(%rsp)
movapd 0x10(%rsp), %xmm0
addsd %xmm2, %xmm0
movapd %xmm0, 0x10(%rsp)
movq (%r14), %rdi
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x46c39
movq 0x8(%rsp), %rax
movq (%rax), %rax
movsd (%rax,%r12,8), %xmm1
movsd 0x20(%rsp), %xmm2
addsd %xmm2, %xmm1
movsd %xmm1, (%rax,%r12,8)
movapd 0x10(%rsp), %xmm1
subsd 0x68(%rsp), %xmm1
movapd %xmm1, 0x10(%rsp)
movsd 0x38(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x6dcb
movapd %xmm2, %xmm1
movsd %xmm0, 0x38(%rsp)
movsd 0x40(%rsp), %xmm2
movsd %xmm2, 0x60(%rsp)
jmp 0x6dd7
movsd 0x30(%rsp), %xmm1
jmp 0x6dd7
movsd 0x30(%rsp), %xmm1
movsd 0x40(%rsp), %xmm2
addq $0x10, %r13
jmp 0x6ca2
addsd 0x8ef28(%rip), %xmm2    # 0x95d10
jmp 0x6c87
movsd 0x38(%rsp), %xmm0
ucomisd 0x8eefd(%rip), %xmm0    # 0x95cf8
jne 0x6dff
jnp 0x6e31
movq 0x8(%rsp), %rax
movq (%rax), %rax
movsd (%rax,%r12,8), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax,%r12,8)
movapd %xmm1, %xmm0
mulsd 0x60(%rsp), %xmm0
movapd 0x10(%rsp), %xmm2
addsd %xmm0, %xmm2
movapd %xmm2, 0x10(%rsp)
incq %r12
jmp 0x6c5a
movsd %xmm1, 0x30(%rsp)
movsd 0x8eeb1(%rip), %xmm0    # 0x95cf8
movq %r14, %r12
movq (%r12), %r12
testq %r12, %r12
je 0x6eb4
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %r12, %rdi
movapd %xmm0, 0x20(%rsp)
callq 0x2b0c0
movapd %xmm0, 0x40(%rsp)
movq (%r14), %rdi
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x46c39
movapd %xmm0, %xmm1
movapd 0x20(%rsp), %xmm2
cmpltsd %xmm2, %xmm1
movapd 0x40(%rsp), %xmm3
andpd %xmm1, %xmm3
andnpd 0x70(%rsp), %xmm1
orpd %xmm3, %xmm1
minsd %xmm2, %xmm0
addq $0x10, %r12
movapd %xmm1, 0x70(%rsp)
jmp 0x6e4a
cmpneqsd 0x8ee3b(%rip), %xmm0    # 0x95cf8
movapd %xmm0, %xmm1
andpd 0x70(%rsp), %xmm1
andnpd 0x10(%rsp), %xmm0
orpd %xmm1, %xmm0
movapd %xmm0, 0x20(%rsp)
movq 0x20(%rbx), %rdi
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x46c39
movsd %xmm0, 0x10(%rsp)
movsd 0x48(%rbx), %xmm0
movq 0x20(%rbx), %rdi
movq 0x38(%rbx), %rsi
movq 0x40(%rbx), %rdx
callq 0x46c39
ucomisd 0x10(%rsp), %xmm0
setbe %r12b
jbe 0x6c2d
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0x58(%rsp), %rdi
callq 0x3a763
movapd 0x20(%rsp), %xmm0
movsd %xmm0, 0x48(%rbx)
jmp 0x6c2d
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x3929f
movsd 0x48(%rbx), %xmm0
movq 0x20(%rbx), %rdi
movq 0x38(%rbx), %rsi
movq 0x40(%rbx), %rdx
callq 0x46c39
cmpneqsd 0x8ed93(%rip), %xmm0    # 0x95cf8
movq %xmm0, %rax
andl $0x1, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq