// File: /workspace/github_c_makefile_star2_O1/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 $0x78, %rsp
movq %rdi, %rbx
leaq 0xcbb38(%rip), %rbp     # 0xd2870
movq (%rbp), %rax
movl 0x1c0(%rax), %esi
decl %esi
movl $0x1, %edi
callq 0x3c6e5
movq %rax, 0x38(%rbx)
movq %rdx, 0x40(%rbx)
movq (%rbp), %rax
movl 0x1c0(%rax), %esi
decl %esi
movl $0x1, %edi
callq 0x3c6e5
movq %rax, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
movq $0x0, 0x48(%rbx)
movq (%rbp), %rax
movl 0x1c0(%rax), %eax
cmpl $0x2, %eax
jl 0x6ded
decl %eax
xorl %r14d, %r14d
xorpd %xmm2, %xmm2
movsd 0x9b782(%rip), %xmm3    # 0xa2520
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
ucomisd %xmm2, %xmm0
jb 0x6db1
sqrtsd %xmm0, %xmm0
jmp 0x6dc2
callq 0x4300
movsd 0x9b762(%rip), %xmm3    # 0xa2520
xorpd %xmm2, %xmm2
movapd %xmm3, %xmm1
divsd %xmm0, %xmm1
movq 0x40(%rbx), %rax
movq (%rax), %rax
movsd %xmm1, (%rax,%r14,8)
incq %r14
movq (%rbp), %rax
movslq 0x1c0(%rax), %rax
decq %rax
cmpq %rax, %r14
jl 0x6d9e
leaq 0x38(%rbx), %r14
leaq 0x10(%rsp), %r15
movq 0x38(%rbx), %rsi
movq 0x40(%rbx), %rdx
movq %r15, %rdi
callq 0x3f37d
movsd 0x48(%rbx), %xmm0
movapd %xmm0, 0x20(%rsp)
movq (%rbp), %rax
cmpl $0x2, 0x1c0(%rax)
jl 0x7009
xorl %r12d, %r12d
movapd 0x30(%rsp), %xmm2
movsd 0x8(%rsp), %xmm1
movsd 0x9beb7(%rip), %xmm0    # 0xa2cf0
movsd %xmm0, 0x48(%rsp)
movsd 0x9bea1(%rip), %xmm3    # 0xa2ce8
movsd %xmm3, (%rsp)
movq 0x20(%rbx), %r13
testq %r13, %r13
je 0x6f8a
movapd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r13, %rdi
callq 0x2e700
movsd %xmm0, 0x8(%rsp)
movq %r13, %rdi
movl %r12d, %esi
callq 0x2e4b6
addsd (%rsp), %xmm0
ucomisd 0x9be75(%rip), %xmm0    # 0xa2d08
jne 0x6e9b
jnp 0x6f6d
movsd 0x8(%rsp), %xmm0
subsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r13, %rdi
movl %r12d, %esi
callq 0x2e4b6
movsd (%rsp), %xmm1
addsd %xmm1, %xmm0
movsd 0x8(%rsp), %xmm2
divsd %xmm0, %xmm2
movsd %xmm2, 0x8(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rax
movsd (%rax,%r12,8), %xmm0
subsd %xmm2, %xmm0
movsd %xmm0, (%rax,%r12,8)
movapd %xmm2, %xmm3
mulsd %xmm1, %xmm3
movsd %xmm3, 0x70(%rsp)
movapd 0x20(%rsp), %xmm0
addsd %xmm3, %xmm0
movapd %xmm0, 0x20(%rsp)
movq 0x20(%rbx), %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x4c9f5
movq 0x18(%rsp), %rax
movq (%rax), %rax
movsd (%rax,%r12,8), %xmm1
movsd 0x8(%rsp), %xmm2
addsd %xmm2, %xmm1
movsd %xmm1, (%rax,%r12,8)
movapd 0x20(%rsp), %xmm1
subsd 0x70(%rsp), %xmm1
movapd %xmm1, 0x20(%rsp)
movsd 0x48(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x6f6d
movapd %xmm2, %xmm1
movsd %xmm0, 0x48(%rsp)
movsd (%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
jmp 0x6f73
movsd 0x50(%rsp), %xmm1
movapd 0x30(%rsp), %xmm2
movq 0x10(%r13), %r13
movapd %xmm1, %xmm0
testq %r13, %r13
jne 0x6e5d
movsd (%rsp), %xmm3
addsd 0x9bd61(%rip), %xmm3    # 0xa2cf8
movsd 0x9bd61(%rip), %xmm0    # 0xa2d00
ucomisd %xmm3, %xmm0
ja 0x6e47
movsd 0x48(%rsp), %xmm0
ucomisd 0x9bd39(%rip), %xmm0    # 0xa2cf0
jne 0x6fbb
jnp 0x6fed
movq 0x18(%rsp), %rax
movq (%rax), %rax
movsd (%rax,%r12,8), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax,%r12,8)
movapd %xmm1, %xmm0
mulsd 0x68(%rsp), %xmm0
movapd 0x20(%rsp), %xmm3
addsd %xmm0, %xmm3
movapd %xmm3, 0x20(%rsp)
incq %r12
movq (%rbp), %rax
movslq 0x1c0(%rax), %rax
decq %rax
cmpq %rax, %r12
jl 0x6e31
jmp 0x7015
movapd 0x30(%rsp), %xmm2
movsd 0x8(%rsp), %xmm1
movsd %xmm1, 0x8(%rsp)
movq 0x20(%rbx), %r12
testq %r12, %r12
je 0x70bd
movsd 0x9bcc0(%rip), %xmm0    # 0xa2cf0
movapd %xmm2, 0x30(%rsp)
movsd %xmm0, (%rsp)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r12, %rdi
callq 0x2e700
movapd %xmm0, 0x50(%rsp)
movq 0x20(%rbx), %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x4c9f5
movapd %xmm0, %xmm1
movsd (%rsp), %xmm3
cmpltsd %xmm3, %xmm1
movapd 0x50(%rsp), %xmm2
andpd %xmm1, %xmm2
andnpd 0x30(%rsp), %xmm1
orpd %xmm2, %xmm1
movapd %xmm1, %xmm2
minsd %xmm3, %xmm0
movq 0x10(%r12), %r12
testq %r12, %r12
jne 0x7030
cmpneqsd 0x9bc4d(%rip), %xmm0    # 0xa2cf0
movapd %xmm0, %xmm1
movapd %xmm2, 0x30(%rsp)
andpd %xmm2, %xmm1
andnpd 0x20(%rsp), %xmm0
orpd %xmm1, %xmm0
jmp 0x70c3
movapd 0x20(%rsp), %xmm0
movapd %xmm0, 0x20(%rsp)
movq 0x20(%rbx), %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x4c9f5
movsd %xmm0, (%rsp)
movsd 0x48(%rbx), %xmm0
movq 0x20(%rbx), %rdi
movq 0x38(%rbx), %rsi
movq 0x40(%rbx), %rdx
callq 0x4c9f5
ucomisd (%rsp), %xmm0
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
jbe 0x7120
movq %r14, %rdi
callq 0x3f37d
movapd 0x20(%rsp), %xmm0
movsd %xmm0, 0x48(%rbx)
jmp 0x6df6
movq %rsi, %rdi
movq %rdx, %rsi
callq 0x3dbad
movsd 0x48(%rbx), %xmm0
movq 0x20(%rbx), %rdi
movq 0x38(%rbx), %rsi
movq 0x40(%rbx), %rdx
callq 0x4c9f5
cmpneqsd 0x9bba6(%rip), %xmm0    # 0xa2cf0
movq %xmm0, %rax
andl $0x1, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq