// File: /workspace/github_c_makefile_star2_O1/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 0x89bcd
movq 0x38(%r14), %rdi
movq 0x40(%r14), %rsi
callq 0x3ca3c
movq %rax, 0x30(%rsp)
movq %rdx, 0x38(%rsp)
jmp 0x89bd9
movsd 0x48(%r14), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %r13, %rdi
movq %r12, %rsi
callq 0x88e16
movl %eax, %r15d
movq 0x20(%r13), %rdi
callq 0x2fa14
movq %r14, %rdi
movl $0x1, %esi
callq 0x1c996
movq %rax, (%r14)
movq 0x18(%rsp), %rbp
movl (%rbp), %ecx
movl %ecx, 0x60(%rax)
movq %r14, %rdi
movl $0x1, %esi
callq 0x1c996
movq %rax, 0x8(%r14)
movl (%rbp), %ecx
movl %ecx, 0x60(%rax)
movl $0xfffffffa, 0x30(%r14) # imm = 0xFFFFFFFA
movq %r14, %rdi
movl $0x1, %esi
callq 0x1c996
movq %rax, %rbx
movq %r14, %rdi
movl $0x1, %esi
callq 0x1c996
movq %rax, (%rbx)
movq %r14, %rdi
movl $0x1, %esi
callq 0x1c996
movq %rbx, 0x8(%rsp)
movq %rax, 0x8(%rbx)
cmpl $0x0, 0x20(%rbp)
movl %r15d, 0x14(%rsp)
je 0x89d45
xorl %eax, %eax
xorpd %xmm0, %xmm0
movl %r15d, %ebx
movl %eax, 0x2c(%rsp)
movsd %xmm0, 0x48(%rsp)
callq 0x4210
movsd 0x1b0a1(%rip), %xmm2    # 0xa4d30
movsd 0x18889(%rip), %xmm1    # 0xa2520
divsd %xmm0, %xmm2
movsd %xmm2, 0x50(%rsp)
movl $0xa, %r15d
movapd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
callq 0x4210
movsd 0x18862(%rip), %xmm1    # 0xa2520
divsd %xmm0, %xmm1
movq %r13, %rdi
movq %r14, %rsi
movq 0x18(%rsp), %rdx
movsd 0x50(%rsp), %xmm0
callq 0x89304
movq %r13, %rdi
movq %r12, %rsi
callq 0x88e16
cmpl %ebx, %eax
jge 0x89d08
movl %eax, %ebp
cmpl 0x14(%rsp), %ebx
je 0x89cf9
movq 0x8(%rsp), %rdi
callq 0x8975b
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x897f7
movl %ebp, %ebx
movq %r14, %rdi
callq 0x8975b
movsd 0x18808(%rip), %xmm1    # 0xa2520
movsd 0x20(%rsp), %xmm0
addsd %xmm1, %xmm0
decl %r15d
jne 0x89cab
movsd 0x48(%rsp), %xmm0
addsd %xmm1, %xmm0
movl 0x2c(%rsp), %eax
incl %eax
cmpl $0xb, %eax
jne 0x89c78
jmp 0x89dcc
xorpd %xmm0, %xmm0
movl $0xb, %ebp
movl %r15d, %ebx
movsd %xmm0, 0x20(%rsp)
callq 0x4210
movsd 0x1afcc(%rip), %xmm2    # 0xa4d30
divsd %xmm0, %xmm2
xorpd %xmm1, %xmm1
movq %r13, %rdi
movq %r14, %rsi
movq 0x18(%rsp), %rdx
movapd %xmm2, %xmm0
callq 0x89304
movq %r13, %rdi
movq %r12, %rsi
callq 0x88e16
cmpl %ebx, %eax
jge 0x89db2
movl %eax, %r15d
cmpl 0x14(%rsp), %ebx
je 0x89da2
movq 0x8(%rsp), %rdi
callq 0x8975b
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x897f7
movl %r15d, %ebx
movq %r14, %rdi
callq 0x8975b
movsd 0x20(%rsp), %xmm0
addsd 0x18758(%rip), %xmm0    # 0xa2520
decl %ebp
jne 0x89d51
movl 0x14(%rsp), %ebp
cmpl %ebx, %ebp
jle 0x89e79
movq 0x18(%rsp), %rax
cmpl $0x0, (%rax)
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdi
je 0x89df1
callq 0x3dbad
movq %r14, %rdi
movq 0x8(%rsp), %rsi
callq 0x897f7
movl $0x1, %r12d
movq 0x18(%rsp), %rax
cmpl $0x0, 0x20(%rax)
je 0x89ed0
leaq 0x48a56(%rip), %rax     # 0xd2870
movq (%rax), %rax
movslq 0x1c0(%rax), %rax
testq %rax, %rax
jle 0x89ed0
movq 0x40(%r14), %rcx
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd 0x1dea0(%rip), %xmm1    # 0xa7ce0
movsd 0x186d8(%rip), %xmm0    # 0xa2520
divsd %xmm1, %xmm0
xorl %edx, %edx
movapd 0x1938a(%rip), %xmm1    # 0xa31e0
movq (%rcx,%rdx,8), %rsi
movsd (%rsi), %xmm2
andpd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jbe 0x89e6f
movq $0x0, (%rsi)
incq %rdx
cmpq %rdx, %rax
jne 0x89e56
jmp 0x89ed0
movq (%r14), %rdi
callq 0x1ced4
movq 0x8(%r14), %rdi
callq 0x1ced4
movq (%r14), %rdi
callq 0x39194
movq 0x8(%r14), %rdi
callq 0x39194
movq %r14, %rdi
callq 0x1c39c
movq 0x18(%rsp), %rax
cmpl $0x0, (%rax)
je 0x89ec1
movq 0x30(%rsp), %rax
movq %rax, 0x38(%r14)
movq 0x38(%rsp), %rax
movq %rax, 0x40(%r14)
jmp 0x89ecd
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x48(%r14)
xorl %r12d, %r12d
cmpl %ebp, %ebx
je 0x89ede
movq 0x8(%rsp), %rdi
callq 0x8975b
movq 0x8(%rsp), %rbx
movq (%rbx), %rdi
callq 0x1ced4
movq 0x8(%rbx), %rdi
callq 0x1ced4
movq %rbx, %rdi
callq 0x1ced4
movq (%rbx), %rdi
callq 0x39194
movq 0x8(%rbx), %rdi
callq 0x39194
movq %rbx, %rdi
callq 0x39194
movl %r12d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq