// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/softregtree.c
// Function: find_best_soft_regtree_split
BOOLEAN find_best_soft_regtree_split(Regressionnodeptr rootnode, Regressionnodeptr node, Instanceptr cvdata, Softregtree_parameterptr param)
{
 int i, j, datasize;
 double performancebefore, performancenow, performancebest, tmp, eta, lambda;
 BOOLEAN result = BOOLEAN_TRUE;
 matrix tmpw;
 Regressionnodeptr bestnode;
 if (param->leaftype != CONSTANTLEAF)
   tmpw = matrix_copy(node->w);
 else
   tmp = node->regressionvalue;
 performancebefore = mse_error_of_soft_regression_tree(rootnode, cvdata);
 performancebest = performancebefore;
 datasize = data_size(rootnode->instances);
 node->left = createnewregnode(node, 1, param->leaftype);
 node->right = createnewregnode(node, 1, param->leaftype);
 node->featureno = SOFTLIN;
 bestnode = createnewregnode(node, 1, param->leaftype);
 bestnode->left = createnewregnode(node, 1, param->leaftype);
 bestnode->right = createnewregnode(node, 1, param->leaftype);
 if (param->regularization == NO_REGULARIZATION)
  {
   for (i = 0; i <= 10; i++)
    {
     eta = 10.0 / (pow(2, i));
     gradient_descent_soft_regtree(rootnode, node, param, eta, 0.0);
     performancenow = mse_error_of_soft_regression_tree(rootnode, cvdata);
     if (performancenow < performancebest)
      {    
       if (performancebest != performancebefore)
         free_soft_regtree_ws(bestnode);
       performancebest = performancenow;
       copy_soft_regtree_ws(bestnode, node);
      }
     free_soft_regtree_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_regtree(rootnode, node, param, eta, lambda);
       performancenow = mse_error_of_soft_regression_tree(rootnode, cvdata);
       if (performancenow < performancebest)
        {    
         if (performancebest != performancebefore)
           free_soft_regtree_ws(bestnode);
         performancebest = performancenow;
         copy_soft_regtree_ws(bestnode, node);
        }
       free_soft_regtree_ws(node);
      }
    }
  }
 if (performancebefore - performancebest <= 0.0001)
  {
   result = BOOLEAN_FALSE;
   safe_free(node->left);
   safe_free(node->right);
   make_leaf_regression_node(node, param->leaftype);
   if (param->leaftype != CONSTANTLEAF)
     node->w = tmpw;
   else
     node->regressionvalue = tmp;
  }
 else
  {
   if (param->leaftype != CONSTANTLEAF)
     matrix_free(tmpw);
   copy_soft_regtree_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_regtree_ws(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 %rcx, %r15
movq %rdx, %rbp
movq %rsi, %rbx
movq %rdi, %r12
cmpl $0x0, (%rcx)
je 0x88740
movq 0x30(%rbx), %rdi
movq 0x38(%rbx), %rsi
callq 0x3ca3c
movq %rax, 0x30(%rsp)
movq %rdx, 0x38(%rsp)
jmp 0x8874b
movsd 0x70(%rbx), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
callq 0x881a5
movsd %xmm0, 0x10(%rsp)
movq 0x20(%r12), %rdi
callq 0x2fa14
movl (%r15), %edx
movq %rbx, %rdi
movl $0x1, %esi
callq 0x7580b
movq %rax, (%rbx)
movl (%r15), %edx
movq %rbx, %rdi
movl $0x1, %esi
callq 0x7580b
movq %rax, 0x8(%rbx)
movl $0xfffffffa, 0x68(%rbx) # imm = 0xFFFFFFFA
movl (%r15), %edx
movq %rbx, %rdi
movl $0x1, %esi
callq 0x7580b
movq %rax, %r14
movl (%r15), %edx
movq %rbx, %rdi
movl $0x1, %esi
callq 0x7580b
movq %rax, (%r14)
movl (%r15), %edx
movq %rbx, %rdi
movl $0x1, %esi
callq 0x7580b
movq %rax, 0x8(%r14)
cmpl $0x0, 0x20(%r15)
je 0x888d0
xorl %eax, %eax
xorpd %xmm0, %xmm0
movsd 0x10(%rsp), %xmm1
movsd %xmm1, 0x8(%rsp)
movl %eax, 0x2c(%rsp)
movsd %xmm0, 0x48(%rsp)
callq 0x4210
movsd 0x1c52e(%rip), %xmm2    # 0xa4d30
movsd 0x19d16(%rip), %xmm1    # 0xa2520
divsd %xmm0, %xmm2
movsd %xmm2, 0x18(%rsp)
movl $0xa, %r13d
movapd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
callq 0x4210
movsd 0x19cef(%rip), %xmm1    # 0xa2520
divsd %xmm0, %xmm1
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movsd 0x18(%rsp), %xmm0
callq 0x88220
movq %r12, %rdi
movq %rbp, %rsi
callq 0x881a5
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x8888f
movsd %xmm0, 0x50(%rsp)
ucomisd 0x10(%rsp), %xmm1
jne 0x88870
jnp 0x88878
movq %r14, %rdi
callq 0x88644
movq %r14, %rdi
movq %rbx, %rsi
callq 0x8867f
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
callq 0x88644
movsd 0x19c81(%rip), %xmm1    # 0xa2520
movsd 0x20(%rsp), %xmm0
addsd %xmm1, %xmm0
decl %r13d
jne 0x8881e
movsd 0x48(%rsp), %xmm0
addsd %xmm1, %xmm0
movl 0x2c(%rsp), %eax
incl %eax
cmpl $0xb, %eax
jne 0x887eb
jmp 0x88978
xorpd %xmm0, %xmm0
movl $0xb, %r13d
movsd 0x10(%rsp), %xmm1
movsd %xmm1, 0x8(%rsp)
movsd %xmm0, 0x20(%rsp)
callq 0x4210
movsd 0x1c437(%rip), %xmm2    # 0xa4d30
divsd %xmm0, %xmm2
xorpd %xmm1, %xmm1
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movapd %xmm2, %xmm0
callq 0x88220
movq %r12, %rdi
movq %rbp, %rsi
callq 0x881a5
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x88959
movsd %xmm0, 0x18(%rsp)
ucomisd 0x10(%rsp), %xmm1
jne 0x8893a
jnp 0x88942
movq %r14, %rdi
callq 0x88644
movq %r14, %rdi
movq %rbx, %rsi
callq 0x8867f
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
callq 0x88644
movsd 0x20(%rsp), %xmm0
addsd 0x19bb1(%rip), %xmm0    # 0xa2520
decl %r13d
jne 0x888e6
movsd 0x10(%rsp), %xmm0
subsd 0x8(%rsp), %xmm0
movsd 0x1bf5c(%rip), %xmm1    # 0xa48e8
ucomisd %xmm0, %xmm1
jae 0x88a2c
cmpl $0x0, (%r15)
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdi
je 0x889ab
callq 0x3dbad
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8867f
movl $0x1, %ebp
cmpl $0x0, 0x20(%r15)
je 0x88a6f
leaq 0x49ea3(%rip), %rax     # 0xd2870
movq (%rax), %rax
movslq 0x1c0(%rax), %rax
testq %rax, %rax
jle 0x88a6f
movq 0x38(%rbx), %rcx
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd 0x1f2ed(%rip), %xmm1    # 0xa7ce0
movsd 0x19b25(%rip), %xmm0    # 0xa2520
divsd %xmm1, %xmm0
xorl %edx, %edx
movapd 0x1a7d7(%rip), %xmm1    # 0xa31e0
movq (%rcx,%rdx,8), %rsi
movsd (%rsi), %xmm2
andpd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jbe 0x88a22
movq $0x0, (%rsi)
incq %rdx
cmpq %rdx, %rax
jne 0x88a09
jmp 0x88a6f
movq (%rbx), %rdi
callq 0x39194
movq 0x8(%rbx), %rdi
callq 0x39194
movl (%r15), %esi
movq %rbx, %rdi
callq 0x74df3
cmpl $0x0, (%r15)
je 0x88a62
movq 0x30(%rsp), %rax
movq %rax, 0x30(%rbx)
movq 0x38(%rsp), %rax
movq %rax, 0x38(%rbx)
jmp 0x88a6d
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x70(%rbx)
xorl %ebp, %ebp
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jne 0x88a83
jnp 0x88a8b
movq %r14, %rdi
callq 0x88644
movq (%r14), %rdi
callq 0x39194
movq 0x8(%r14), %rdi
callq 0x39194
movq %r14, %rdi
callq 0x39194
movl %ebp, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq