// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/softtree.c
// Function: find_best_soft_tree_split
BOOLEAN find_best_soft_tree_split(Decisionnodeptr rootnode, Decisionnodeptr node, Instanceptr cvdata, Softregtree_parameterptr param)
{
 int i, j, datasize, performancebefore, performancebest, performancenow;
 double tmp, eta, lambda;
 BOOLEAN result = BOOLEAN_TRUE;
 Decisionnodeptr bestnode;
 matrix tmpw; 
 if (param->leaftype != CONSTANTLEAF)
   tmpw = matrix_copy(node->w);
 else
   tmp = node->w0;
 performancebefore = error_of_soft_tree(rootnode, cvdata);
 performancebest = performancebefore;
 datasize = data_size(rootnode->instances);
 node->left = createnewnode(node, 1);
 node->left->leaftype = param->leaftype;
 node->right = createnewnode(node, 1);
 node->right->leaftype = param->leaftype;
 node->featureno = SOFTLIN;
 bestnode = createnewnode(node, 1);
 bestnode->left = createnewnode(node, 1);
 bestnode->right = createnewnode(node, 1);
 if (param->regularization == NO_REGULARIZATION)
  {
   for (i = 0; i <= 10; i++)
    {
     eta = 10.0 / pow(2, i);
     gradient_descent_soft_tree(rootnode, node, param, eta, 0.0);
     performancenow = error_of_soft_tree(rootnode, cvdata);
     if (performancenow < performancebest)
      {    
       if (performancebest != performancebefore)
         free_soft_tree_ws(bestnode);
       performancebest = performancenow;
       copy_soft_tree_ws(bestnode, node);
      }
     free_soft_tree_ws(node);
    }
  }
 else
  {
   for (i = 0; i <= 10; i++)
    {
     eta = 10.0 / pow(2, i);
     for (j = 1; j <= 10; j++)
      {
       lambda = 1.0 / pow(2, j);
       gradient_descent_soft_tree(rootnode, node, param, eta, lambda);
       performancenow = error_of_soft_tree(rootnode, cvdata);
       if (performancenow < performancebest)
        {    
         if (performancebest != performancebefore)
           free_soft_tree_ws(bestnode);
         performancebest = performancenow;
         copy_soft_tree_ws(bestnode, node);
        }
       free_soft_tree_ws(node);
      }
    }
  }
 if (performancebefore <= performancebest)
  {
   result = BOOLEAN_FALSE;
   deallocate_tree_rule(node->left);
   deallocate_tree_rule(node->right);
   safe_free(node->left);
   safe_free(node->right);
   make_leaf_node(node);
   if (param->leaftype != CONSTANTLEAF)
     node->w = tmpw;
   else
     node->w0 = tmp;
  }
 else
  {
   if (param->leaftype != CONSTANTLEAF)
     matrix_free(tmpw);
   copy_soft_tree_ws(node, bestnode);
   if (param->regularization != NO_REGULARIZATION)
     for (j = 0; j < current_dataset->multifeaturecount; j++)
       if (fabs(node->w.values[j][0]) < 1 / (1000.0 * current_dataset->multifeaturecount))
         node->w.values[j][0] = 0.0;
  }
 if (performancebest != performancebefore)
   free_soft_tree_ws(bestnode);
 deallocate_tree_rule(bestnode->left);
 deallocate_tree_rule(bestnode->right);
 deallocate_tree_rule(bestnode);
 safe_free(bestnode->left);
 safe_free(bestnode->right);
 safe_free(bestnode);
 return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %r13
movq %rcx, 0x18(%rsp)
cmpl $0x0, (%rcx)
je 0x8c37b
movq 0x38(%r14), %rdi
movq 0x40(%r14), %rsi
callq 0x3dae3
movq %rax, 0x30(%rsp)
movq %rdx, 0x38(%rsp)
jmp 0x8c387
movsd 0x48(%r14), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %r13, %rdi
movq %r12, %rsi
callq 0x8b5fe
movl %eax, %r15d
movq 0x20(%r13), %rdi
callq 0x30309
movq %r14, %rdi
movl $0x1, %esi
callq 0x1d107
movq %rax, (%r14)
movq 0x18(%rsp), %rbp
movl (%rbp), %ecx
movl %ecx, 0x60(%rax)
movq %r14, %rdi
movl $0x1, %esi
callq 0x1d107
movq %rax, 0x8(%r14)
movl (%rbp), %ecx
movl %ecx, 0x60(%rax)
movl $0xfffffffa, 0x30(%r14) # imm = 0xFFFFFFFA
movq %r14, %rdi
movl $0x1, %esi
callq 0x1d107
movq %rax, %rbx
movq %r14, %rdi
movl $0x1, %esi
callq 0x1d107
movq %rax, (%rbx)
movq %r14, %rdi
movl $0x1, %esi
callq 0x1d107
movq %rbx, 0x8(%rsp)
movq %rax, 0x8(%rbx)
cmpl $0x0, 0x20(%rbp)
movl %r15d, 0x14(%rsp)
je 0x8c4f3
xorl %eax, %eax
xorpd %xmm0, %xmm0
movl %r15d, %ebx
movl %eax, 0x2c(%rsp)
movsd %xmm0, 0x48(%rsp)
callq 0x4210
movsd 0x1b97b(%rip), %xmm2    # 0xa7db8
movsd 0x190db(%rip), %xmm1    # 0xa5520
divsd %xmm0, %xmm2
movsd %xmm2, 0x50(%rsp)
movl $0xa, %r15d
movapd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
callq 0x4210
movsd 0x190b4(%rip), %xmm1    # 0xa5520
divsd %xmm0, %xmm1
movq %r13, %rdi
movq %r14, %rsi
movq 0x18(%rsp), %rdx
movsd 0x50(%rsp), %xmm0
callq 0x8bae4
movq %r13, %rdi
movq %r12, %rsi
callq 0x8b5fe
cmpl %ebx, %eax
jge 0x8c4b6
movl %eax, %ebp
cmpl 0x14(%rsp), %ebx
je 0x8c4a7
movq 0x8(%rsp), %rdi
callq 0x8bf09
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x8bfa5
movl %ebp, %ebx
movq %r14, %rdi
callq 0x8bf09
movsd 0x1905a(%rip), %xmm1    # 0xa5520
movsd 0x20(%rsp), %xmm0
addsd %xmm1, %xmm0
decl %r15d
jne 0x8c459
movsd 0x48(%rsp), %xmm0
addsd %xmm1, %xmm0
movl 0x2c(%rsp), %eax
incl %eax
cmpl $0xb, %eax
jne 0x8c426
jmp 0x8c57a
xorpd %xmm0, %xmm0
movl $0xb, %ebp
movl %r15d, %ebx
movsd %xmm0, 0x20(%rsp)
callq 0x4210
movsd 0x1b8a6(%rip), %xmm2    # 0xa7db8
divsd %xmm0, %xmm2
xorpd %xmm1, %xmm1
movq %r13, %rdi
movq %r14, %rsi
movq 0x18(%rsp), %rdx
movapd %xmm2, %xmm0
callq 0x8bae4
movq %r13, %rdi
movq %r12, %rsi
callq 0x8b5fe
cmpl %ebx, %eax
jge 0x8c560
movl %eax, %r15d
cmpl 0x14(%rsp), %ebx
je 0x8c550
movq 0x8(%rsp), %rdi
callq 0x8bf09
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x8bfa5
movl %r15d, %ebx
movq %r14, %rdi
callq 0x8bf09
movsd 0x20(%rsp), %xmm0
addsd 0x18faa(%rip), %xmm0    # 0xa5520
decl %ebp
jne 0x8c4ff
movl 0x14(%rsp), %ebp
cmpl %ebx, %ebp
jle 0x8c627
movq 0x18(%rsp), %rax
cmpl $0x0, (%rax)
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdi
je 0x8c59f
callq 0x3ed51
movq %r14, %rdi
movq 0x8(%rsp), %rsi
callq 0x8bfa5
movl $0x1, %r12d
movq 0x18(%rsp), %rax
cmpl $0x0, 0x20(%rax)
je 0x8c67e
leaq 0x492a8(%rip), %rax     # 0xd5870
movq (%rax), %rax
movslq 0x1c0(%rax), %rax
testq %rax, %rax
jle 0x8c67e
movq 0x40(%r14), %rcx
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd 0x1e7a2(%rip), %xmm1    # 0xaad90
movsd 0x18f2a(%rip), %xmm0    # 0xa5520
divsd %xmm1, %xmm0
xorl %edx, %edx
movapd 0x19bdc(%rip), %xmm1    # 0xa61e0
movq (%rcx,%rdx,8), %rsi
movsd (%rsi), %xmm2
andpd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jbe 0x8c61d
movq $0x0, (%rsi)
incq %rdx
cmpq %rdx, %rax
jne 0x8c604
jmp 0x8c67e
movq (%r14), %rdi
callq 0x1d64e
movq 0x8(%r14), %rdi
callq 0x1d64e
movq (%r14), %rdi
callq 0x3a180
movq 0x8(%r14), %rdi
callq 0x3a180
movq %r14, %rdi
callq 0x1cab0
movq 0x18(%rsp), %rax
cmpl $0x0, (%rax)
je 0x8c66f
movq 0x30(%rsp), %rax
movq %rax, 0x38(%r14)
movq 0x38(%rsp), %rax
movq %rax, 0x40(%r14)
jmp 0x8c67b
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x48(%r14)
xorl %r12d, %r12d
cmpl %ebp, %ebx
je 0x8c68c
movq 0x8(%rsp), %rdi
callq 0x8bf09
movq 0x8(%rsp), %rbx
movq (%rbx), %rdi
callq 0x1d64e
movq 0x8(%rbx), %rdi
callq 0x1d64e
movq %rbx, %rdi
callq 0x1d64e
movq (%rbx), %rdi
callq 0x3a180
movq 0x8(%rbx), %rdi
callq 0x3a180
movq %rbx, %rdi
callq 0x3a180
movl %r12d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq