// File: /workspace/github_c_makefile_star2_O3/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 0xceb40(%rip), %rbp     # 0xd5870
movq (%rbp), %rax
movl 0x1c0(%rax), %esi
decl %esi
movl $0x1, %edi
callq 0x3d79d
movq %rax, 0x38(%rbx)
movq %rdx, 0x40(%rbx)
movq (%rbp), %rax
movl 0x1c0(%rax), %esi
decl %esi
movl $0x1, %edi
callq 0x3d79d
movq %rax, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
movq $0x0, 0x48(%rbx)
movq (%rbp), %rax
movl 0x1c0(%rax), %eax
cmpl $0x2, %eax
jl 0x6de5
decl %eax
xorl %r14d, %r14d
xorpd %xmm2, %xmm2
movsd 0x9e78a(%rip), %xmm3    # 0xa5520
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
ucomisd %xmm2, %xmm0
jb 0x6da9
sqrtsd %xmm0, %xmm0
jmp 0x6dba
callq 0x4300
movsd 0x9e76a(%rip), %xmm3    # 0xa5520
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 0x6d96
leaq 0x38(%rbx), %r14
leaq 0x10(%rsp), %r15
movq 0x38(%rbx), %rsi
movq 0x40(%rbx), %rdx
movq %r15, %rdi
callq 0x406d5
movsd 0x48(%rbx), %xmm0
movapd %xmm0, 0x20(%rsp)
movq (%rbp), %rax
cmpl $0x2, 0x1c0(%rax)
jl 0x7001
xorl %r12d, %r12d
movapd 0x30(%rsp), %xmm2
movsd 0x8(%rsp), %xmm1
movsd 0x9eebf(%rip), %xmm0    # 0xa5cf0
movsd %xmm0, 0x48(%rsp)
movsd 0x9eea9(%rip), %xmm3    # 0xa5ce8
movsd %xmm3, (%rsp)
movq 0x20(%rbx), %r13
testq %r13, %r13
je 0x6f82
movapd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r13, %rdi
callq 0x2efa4
movsd %xmm0, 0x8(%rsp)
movq %r13, %rdi
movl %r12d, %esi
callq 0x2ed6a
addsd (%rsp), %xmm0
ucomisd 0x9ee7d(%rip), %xmm0    # 0xa5d08
jne 0x6e93
jnp 0x6f65
movsd 0x8(%rsp), %xmm0
subsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r13, %rdi
movl %r12d, %esi
callq 0x2ed6a
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 0x4de90
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 0x6f65
movapd %xmm2, %xmm1
movsd %xmm0, 0x48(%rsp)
movsd (%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
jmp 0x6f6b
movsd 0x50(%rsp), %xmm1
movapd 0x30(%rsp), %xmm2
movq 0x10(%r13), %r13
movapd %xmm1, %xmm0
testq %r13, %r13
jne 0x6e55
movsd (%rsp), %xmm3
addsd 0x9ed69(%rip), %xmm3    # 0xa5cf8
movsd 0x9ed69(%rip), %xmm0    # 0xa5d00
ucomisd %xmm3, %xmm0
ja 0x6e3f
movsd 0x48(%rsp), %xmm0
ucomisd 0x9ed41(%rip), %xmm0    # 0xa5cf0
jne 0x6fb3
jnp 0x6fe5
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 0x6e29
jmp 0x700d
movapd 0x30(%rsp), %xmm2
movsd 0x8(%rsp), %xmm1
movsd %xmm1, 0x8(%rsp)
movq 0x20(%rbx), %r12
testq %r12, %r12
je 0x70b9
movsd 0x9ecc8(%rip), %xmm0    # 0xa5cf0
movapd %xmm2, 0x30(%rsp)
movsd %xmm0, (%rsp)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r12, %rdi
callq 0x2efa4
movapd %xmm0, 0x50(%rsp)
movq 0x20(%rbx), %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x4de90
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 0x7028
movq 0x20(%rbx), %rdi
cmpneqsd 0x9ec51(%rip), %xmm0    # 0xa5cf0
movapd %xmm0, %xmm1
movapd %xmm2, 0x30(%rsp)
andpd %xmm2, %xmm1
andnpd 0x20(%rsp), %xmm0
orpd %xmm1, %xmm0
jmp 0x70c1
xorl %edi, %edi
movapd 0x20(%rsp), %xmm0
movapd %xmm0, 0x20(%rsp)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x4de90
movsd %xmm0, (%rsp)
movsd 0x48(%rbx), %xmm0
movq 0x20(%rbx), %rdi
movq 0x38(%rbx), %rsi
movq 0x40(%rbx), %rdx
callq 0x4de90
ucomisd (%rsp), %xmm0
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
jbe 0x711a
movq %r14, %rdi
callq 0x406d5
movapd 0x20(%rsp), %xmm0
movsd %xmm0, 0x48(%rbx)
jmp 0x6dee
movq %rsi, %rdi
movq %rdx, %rsi
callq 0x3ed51
movsd 0x48(%rbx), %xmm0
movq 0x20(%rbx), %rdi
movq 0x38(%rbx), %rsi
movq 0x40(%rbx), %rdx
callq 0x4de90
cmpneqsd 0x9ebac(%rip), %xmm0    # 0xa5cf0
movq %xmm0, %rax
andl $0x1, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq