// File: /workspace/github_c_makefile_star2_O2/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, %r13
movq %rsi, %rbx
movq %rdi, %r15
movq %rcx, 0x18(%rsp)
cmpl $0x0, (%rcx)
je 0x7eb6e
movq 0x38(%rbx), %rdi
movq 0x40(%rbx), %rsi
callq 0x383f4
movq %rax, 0x30(%rsp)
movq %rdx, 0x38(%rsp)
jmp 0x7eb79
movsd 0x48(%rbx), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x7de8f
movl %eax, 0xc(%rsp)
movq 0x20(%r15), %rdi
callq 0x2c3cc
pushq $0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x1ac98
movq %rax, (%rbx)
movq 0x18(%rsp), %r12
movl (%r12), %ecx
movl %ecx, 0x60(%rax)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x1ac98
movq %rax, 0x8(%rbx)
movl (%r12), %ecx
movl %ecx, 0x60(%rax)
movl $0xfffffffa, 0x30(%rbx) # imm = 0xFFFFFFFA
movq %rbx, %rdi
movl %ebp, %esi
callq 0x1ac98
movq %rax, %r14
movq %rbx, %rdi
movl %ebp, %esi
callq 0x1ac98
movq %rax, (%r14)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x1ac98
movq %r14, 0x10(%rsp)
movq %rax, 0x8(%r14)
cmpl $0x0, 0x20(%r12)
je 0x7ecda
xorl %eax, %eax
xorpd %xmm0, %xmm0
movl 0xc(%rsp), %r14d
cmpl $0xb, %eax
je 0x7ed66
movl %eax, 0x2c(%rsp)
movsd %xmm0, 0x48(%rsp)
callq 0x4210
movsd 0x1910b(%rip), %xmm1    # 0x97d38
divsd %xmm0, %xmm1
movsd %xmm1, 0x50(%rsp)
pushq $0xa
popq %r12
movsd 0x168dd(%rip), %xmm0    # 0x95520
subl $0x1, %r12d
jb 0x7ecc1
movsd %xmm0, 0x20(%rsp)
callq 0x4210
movsd 0x168c4(%rip), %xmm1    # 0x95520
divsd %xmm0, %xmm1
movq %r15, %rdi
movq %rbx, %rsi
movq 0x18(%rsp), %rdx
movsd 0x50(%rsp), %xmm0
callq 0x7e316
movq %r15, %rdi
movq %r13, %rsi
callq 0x7de8f
cmpl %r14d, %eax
jge 0x7eca9
movl %eax, %ebp
cmpl 0xc(%rsp), %r14d
je 0x7ec99
movq 0x10(%rsp), %rdi
callq 0x7e70c
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x7e7a8
movl %ebp, %r14d
movq %rbx, %rdi
callq 0x7e70c
movsd 0x20(%rsp), %xmm0
addsd 0x16861(%rip), %xmm0    # 0x95520
jmp 0x7ec43
movsd 0x48(%rsp), %xmm0
addsd 0x16851(%rip), %xmm0    # 0x95520
movl 0x2c(%rsp), %eax
incl %eax
jmp 0x7ec0d
xorpd %xmm0, %xmm0
pushq $0xb
popq %rbp
movl 0xc(%rsp), %r14d
subl $0x1, %ebp
jb 0x7ed66
movsd %xmm0, 0x20(%rsp)
callq 0x4210
movsd 0x1903a(%rip), %xmm2    # 0x97d38
divsd %xmm0, %xmm2
xorpd %xmm1, %xmm1
movq %r15, %rdi
movq %rbx, %rsi
movq 0x18(%rsp), %rdx
movapd %xmm2, %xmm0
callq 0x7e316
movq %r15, %rdi
movq %r13, %rsi
callq 0x7de8f
cmpl %r14d, %eax
jge 0x7ed4e
movl %eax, %r12d
cmpl 0xc(%rsp), %r14d
je 0x7ed3e
movq 0x10(%rsp), %rdi
callq 0x7e70c
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x7e7a8
movl %r12d, %r14d
movq %rbx, %rdi
callq 0x7e70c
movsd 0x20(%rsp), %xmm0
addsd 0x167bc(%rip), %xmm0    # 0x95520
jmp 0x7ece6
pushq $0x1
popq %r12
movl 0xc(%rsp), %ebp
cmpl %r14d, %ebp
jle 0x7ee07
movq 0x18(%rsp), %rax
cmpl $0x0, (%rax)
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdi
je 0x7ed90
callq 0x3929f
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0x7e7a8
movq 0x18(%rsp), %rax
cmpl $0x0, 0x20(%rax)
je 0x7ee5d
leaq 0x4eabd(%rip), %rax     # 0xcd870
movq (%rax), %rax
movl 0x1c0(%rax), %eax
cvtsi2sd %eax, %xmm1
mulsd 0x1bef8(%rip), %xmm1    # 0x9acc0
movsd 0x16750(%rip), %xmm0    # 0x95520
divsd %xmm1, %xmm0
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
movapd 0x173fd(%rip), %xmm1    # 0x961e0
cmpq %rcx, %rax
je 0x7ee5d
movq 0x40(%rbx), %rdx
movq (%rdx,%rcx,8), %rdx
movsd (%rdx), %xmm2
andpd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jbe 0x7ee02
andq $0x0, (%rdx)
incq %rcx
jmp 0x7ede3
movq (%rbx), %rdi
callq 0x1b1b9
movq 0x8(%rbx), %rdi
callq 0x1b1b9
movq (%rbx), %rdi
callq 0x34ff7
movq 0x8(%rbx), %rdi
callq 0x34ff7
movq %rbx, %rdi
callq 0x1a6ac
movq 0x18(%rsp), %rax
cmpl $0x0, (%rax)
je 0x7ee4f
movq 0x30(%rsp), %rax
movq %rax, 0x38(%rbx)
movq 0x38(%rsp), %rax
movq %rax, 0x40(%rbx)
jmp 0x7ee5a
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x48(%rbx)
xorl %r12d, %r12d
cmpl %ebp, %r14d
je 0x7ee6c
movq 0x10(%rsp), %rdi
callq 0x7e70c
movq 0x10(%rsp), %rbx
movq (%rbx), %rdi
callq 0x1b1b9
movq 0x8(%rbx), %rdi
callq 0x1b1b9
movq %rbx, %rdi
callq 0x1b1b9
movq (%rbx), %rdi
callq 0x34ff7
movq 0x8(%rbx), %rdi
callq 0x34ff7
movq %rbx, %rdi
callq 0x34ff7
movl %r12d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq