// File: /workspace/github_c_makefile_star2_O2/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, %r12
movq %rsi, %rbx
movq %rdi, %r13
cmpl $0x0, (%rcx)
je 0x7d806
movq 0x30(%rbx), %rdi
movq 0x38(%rbx), %rsi
callq 0x383f4
movq %rax, 0x30(%rsp)
movq %rdx, 0x38(%rsp)
jmp 0x7d811
movsd 0x70(%rbx), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %r13, %rdi
movq %r12, %rsi
callq 0x7d2d9
movsd %xmm0, 0x8(%rsp)
movq 0x20(%r13), %rdi
callq 0x2c3cc
movl (%r15), %edx
pushq $0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x6cfdb
movq %rax, (%rbx)
movl (%r15), %edx
movq %rbx, %rdi
movl %ebp, %esi
callq 0x6cfdb
movq %rax, 0x8(%rbx)
movl $0xfffffffa, 0x68(%rbx) # imm = 0xFFFFFFFA
movl (%r15), %edx
movq %rbx, %rdi
movl %ebp, %esi
callq 0x6cfdb
movq %rax, %r14
movl (%r15), %edx
movq %rbx, %rdi
movl %ebp, %esi
callq 0x6cfdb
movq %rax, (%r14)
movl (%r15), %edx
movq %rbx, %rdi
movl %ebp, %esi
callq 0x6cfdb
movsd 0x8(%rsp), %xmm1
movq %rax, 0x8(%r14)
cmpl $0x0, 0x20(%r15)
je 0x7d98d
xorl %eax, %eax
xorpd %xmm0, %xmm0
movsd %xmm1, 0x10(%rsp)
cmpl $0xb, %eax
je 0x7da37
movl %eax, 0x2c(%rsp)
movsd %xmm0, 0x48(%rsp)
callq 0x4210
movsd 0x1a474(%rip), %xmm1    # 0x97d38
divsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
pushq $0xa
popq %rbp
movsd 0x17c47(%rip), %xmm0    # 0x95520
subl $0x1, %ebp
jb 0x7d96e
movsd %xmm0, 0x20(%rsp)
callq 0x4210
movsd 0x17c2b(%rip), %xmm1    # 0x95520
divsd %xmm0, %xmm1
movq %r13, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movsd 0x18(%rsp), %xmm0
callq 0x7d344
movq %r13, %rdi
movq %r12, %rsi
callq 0x7d2d9
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x7d953
movsd %xmm0, 0x50(%rsp)
ucomisd 0x8(%rsp), %xmm1
jne 0x7d934
jnp 0x7d93c
movq %r14, %rdi
callq 0x7d70a
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7d745
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
callq 0x7d70a
movsd 0x20(%rsp), %xmm0
addsd 0x17bb7(%rip), %xmm0    # 0x95520
jmp 0x7d8d9
movsd 0x48(%rsp), %xmm0
addsd 0x17ba4(%rip), %xmm0    # 0x95520
movl 0x2c(%rsp), %eax
incl %eax
movsd 0x8(%rsp), %xmm1
jmp 0x7d8a4
xorpd %xmm0, %xmm0
pushq $0xb
popq %rbp
movsd %xmm1, 0x10(%rsp)
subl $0x1, %ebp
jb 0x7da37
movsd %xmm0, 0x20(%rsp)
callq 0x4210
movsd 0x1a382(%rip), %xmm2    # 0x97d38
divsd %xmm0, %xmm2
xorpd %xmm1, %xmm1
movq %r13, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movapd %xmm2, %xmm0
callq 0x7d344
movq %r13, %rdi
movq %r12, %rsi
callq 0x7d2d9
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x7da16
movsd %xmm0, 0x18(%rsp)
ucomisd 0x8(%rsp), %xmm1
jne 0x7d9f7
jnp 0x7d9ff
movq %r14, %rdi
callq 0x7d70a
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7d745
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
callq 0x7d70a
movsd 0x20(%rsp), %xmm0
addsd 0x17af4(%rip), %xmm0    # 0x95520
movsd 0x8(%rsp), %xmm1
jmp 0x7d99a
movapd %xmm1, %xmm0
subsd 0x10(%rsp), %xmm0
movsd 0x19e5f(%rip), %xmm1    # 0x978a8
ucomisd %xmm0, %xmm1
jae 0x7dad9
cmpl $0x0, (%r15)
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdi
je 0x7da68
callq 0x3929f
movq %rbx, %rdi
movq %r14, %rsi
callq 0x7d745
cmpl $0x0, 0x20(%r15)
je 0x7db0f
leaq 0x4fdeb(%rip), %rax     # 0xcd870
movq (%rax), %rax
movl 0x1c0(%rax), %eax
cvtsi2sd %eax, %xmm1
mulsd 0x1d226(%rip), %xmm1    # 0x9acc0
movsd 0x17a7e(%rip), %xmm0    # 0x95520
divsd %xmm1, %xmm0
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
movapd 0x1872b(%rip), %xmm1    # 0x961e0
cmpq %rcx, %rax
je 0x7db0f
movq 0x38(%rbx), %rdx
movq (%rdx,%rcx,8), %rdx
movsd (%rdx), %xmm2
andpd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jbe 0x7dad4
andq $0x0, (%rdx)
incq %rcx
jmp 0x7dab5
movq (%rbx), %rdi
callq 0x34ff7
movq 0x8(%rbx), %rdi
callq 0x34ff7
movl (%r15), %esi
movq %rbx, %rdi
callq 0x6c64d
cmpl $0x0, (%r15)
je 0x7db1a
movq 0x30(%rsp), %rax
movq %rax, 0x30(%rbx)
movq 0x38(%rsp), %rax
movq %rax, 0x38(%rbx)
jmp 0x7db25
movsd 0x8(%rsp), %xmm0
pushq $0x1
popq %rbx
jmp 0x7db2d
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x70(%rbx)
xorl %ebx, %ebx
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jne 0x7db3b
jnp 0x7db43
movq %r14, %rdi
callq 0x7d70a
movq (%r14), %rdi
callq 0x34ff7
movq 0x8(%r14), %rdi
callq 0x34ff7
movq %r14, %rdi
callq 0x34ff7
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq