// File: /workspace/github_c_makefile_star2_O3/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 0x8af46
movq 0x30(%rbx), %rdi
movq 0x38(%rbx), %rsi
callq 0x3dae3
movq %rax, 0x30(%rsp)
movq %rdx, 0x38(%rsp)
jmp 0x8af51
movsd 0x70(%rbx), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
callq 0x8a9dd
movsd %xmm0, 0x10(%rsp)
movq 0x20(%r12), %rdi
callq 0x30309
movl (%r15), %edx
movq %rbx, %rdi
movl $0x1, %esi
callq 0x7710e
movq %rax, (%rbx)
movl (%r15), %edx
movq %rbx, %rdi
movl $0x1, %esi
callq 0x7710e
movq %rax, 0x8(%rbx)
movl $0xfffffffa, 0x68(%rbx) # imm = 0xFFFFFFFA
movl (%r15), %edx
movq %rbx, %rdi
movl $0x1, %esi
callq 0x7710e
movq %rax, %r14
movl (%r15), %edx
movq %rbx, %rdi
movl $0x1, %esi
callq 0x7710e
movq %rax, (%r14)
movl (%r15), %edx
movq %rbx, %rdi
movl $0x1, %esi
callq 0x7710e
movq %rax, 0x8(%r14)
cmpl $0x0, 0x20(%r15)
je 0x8b0d6
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 0x1cdb0(%rip), %xmm2    # 0xa7db8
movsd 0x1a510(%rip), %xmm1    # 0xa5520
divsd %xmm0, %xmm2
movsd %xmm2, 0x18(%rsp)
movl $0xa, %r13d
movapd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
callq 0x4210
movsd 0x1a4e9(%rip), %xmm1    # 0xa5520
divsd %xmm0, %xmm1
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movsd 0x18(%rsp), %xmm0
callq 0x8aa58
movq %r12, %rdi
movq %rbp, %rsi
callq 0x8a9dd
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x8b095
movsd %xmm0, 0x50(%rsp)
ucomisd 0x10(%rsp), %xmm1
jne 0x8b076
jnp 0x8b07e
movq %r14, %rdi
callq 0x8ae4a
movq %r14, %rdi
movq %rbx, %rsi
callq 0x8ae85
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
callq 0x8ae4a
movsd 0x1a47b(%rip), %xmm1    # 0xa5520
movsd 0x20(%rsp), %xmm0
addsd %xmm1, %xmm0
decl %r13d
jne 0x8b024
movsd 0x48(%rsp), %xmm0
addsd %xmm1, %xmm0
movl 0x2c(%rsp), %eax
incl %eax
cmpl $0xb, %eax
jne 0x8aff1
jmp 0x8b17e
xorpd %xmm0, %xmm0
movl $0xb, %r13d
movsd 0x10(%rsp), %xmm1
movsd %xmm1, 0x8(%rsp)
movsd %xmm0, 0x20(%rsp)
callq 0x4210
movsd 0x1ccb9(%rip), %xmm2    # 0xa7db8
divsd %xmm0, %xmm2
xorpd %xmm1, %xmm1
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movapd %xmm2, %xmm0
callq 0x8aa58
movq %r12, %rdi
movq %rbp, %rsi
callq 0x8a9dd
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x8b15f
movsd %xmm0, 0x18(%rsp)
ucomisd 0x10(%rsp), %xmm1
jne 0x8b140
jnp 0x8b148
movq %r14, %rdi
callq 0x8ae4a
movq %r14, %rdi
movq %rbx, %rsi
callq 0x8ae85
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
callq 0x8ae4a
movsd 0x20(%rsp), %xmm0
addsd 0x1a3ab(%rip), %xmm0    # 0xa5520
decl %r13d
jne 0x8b0ec
movsd 0x10(%rsp), %xmm0
subsd 0x8(%rsp), %xmm0
movsd 0x1c796(%rip), %xmm1    # 0xa7928
ucomisd %xmm0, %xmm1
jae 0x8b232
cmpl $0x0, (%r15)
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdi
je 0x8b1b1
callq 0x3ed51
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8ae85
movl $0x1, %ebp
cmpl $0x0, 0x20(%r15)
je 0x8b275
leaq 0x4a69d(%rip), %rax     # 0xd5870
movq (%rax), %rax
movslq 0x1c0(%rax), %rax
testq %rax, %rax
jle 0x8b275
movq 0x38(%rbx), %rcx
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd 0x1fb97(%rip), %xmm1    # 0xaad90
movsd 0x1a31f(%rip), %xmm0    # 0xa5520
divsd %xmm1, %xmm0
xorl %edx, %edx
movapd 0x1afd1(%rip), %xmm1    # 0xa61e0
movq (%rcx,%rdx,8), %rsi
movsd (%rsi), %xmm2
andpd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jbe 0x8b228
movq $0x0, (%rsi)
incq %rdx
cmpq %rdx, %rax
jne 0x8b20f
jmp 0x8b275
movq (%rbx), %rdi
callq 0x3a180
movq 0x8(%rbx), %rdi
callq 0x3a180
movl (%r15), %esi
movq %rbx, %rdi
callq 0x766ca
cmpl $0x0, (%r15)
je 0x8b268
movq 0x30(%rsp), %rax
movq %rax, 0x30(%rbx)
movq 0x38(%rsp), %rax
movq %rax, 0x38(%rbx)
jmp 0x8b273
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x70(%rbx)
xorl %ebp, %ebp
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jne 0x8b289
jnp 0x8b291
movq %r14, %rdi
callq 0x8ae4a
movq (%r14), %rdi
callq 0x3a180
movq 0x8(%r14), %rdi
callq 0x3a180
movq %r14, %rdi
callq 0x3a180
movl %ebp, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq