// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/nodeboundedtree.c
// Function: create_node_bounded_tree
int create_node_bounded_tree(Decisionnodeptr node, Nodeboundedtree_parameterptr param)
{
 /*!Last Changed 01.10.2006 added second vc calculation type*/
 /*!Last Changed 24.09.2006 discrete type is also added*/
 /*!Last Changed 01.07.2006 added nodeindex with MODEL_SELECTION_FIX*/
 /*!Last Changed 31.05.2006 added a1 and a2 to parameters*/
 /*!Last Changed 24.05.2006 added free_children and continue*/
 /*!Last Changed 19.03.2006*/
 Node_expandedptr header = NULL, nextexpanded;
 BOOLEAN isexpanded;
 int *countsleft, *countsright, expandedcount = 0, numinstances = data_size(node->instances);
 int i, error = 0, h, parenterror, lefterror, righterror, level, len, nodeindex = 0, childrenproduced;
 double bestupperbound, upperbound;
 Decisionnodeptr expanded_node;
 if (param->prunetype == PREPRUNING)
  {
   error = find_error_as_leaf(node->instances);
   bestupperbound = srm_classification((error + 0.0) / numinstances, 1, numinstances, param->a1, param->a2);
  }
 if (param->model != MODEL_SELECTION_FIX)
   add_node_to_expanded_list(node, &header, -1, param->usediscrete);
 else
  {
   add_node_to_expanded_list(node, &header, nodeindex, param->usediscrete);
   nodeindex++;
  }
 while (header && expandedcount < param->nodecount)
  {
   if (param->prunetype == PREPRUNING)     
     parenterror = find_error_as_leaf(header->node->instances);
   nextexpanded = header->next;
   expanded_node = header->node;
   safe_free(header);
   header = nextexpanded;
   switch (param->model)
    {
     case MODEL_SELECTION_UNI:if (param->usediscrete)
                               {
                                expanded_node->featureno = find_best_ldt_feature(expanded_node->instances, &(expanded_node->split));
                                if (expanded_node->featureno == -1)
                                  isexpanded = BOOLEAN_FALSE;
                                else
                                  isexpanded = BOOLEAN_TRUE;
                               }
                              else
                                isexpanded = find_best_hybrid_ldt_split_single_model(expanded_node, UNIVARIATE, param->variance_explained);
                              break;
     case MODEL_SELECTION_LIN:isexpanded = find_best_hybrid_ldt_split_single_model(expanded_node, LINEAR, param->variance_explained);
                              break;
     case MODEL_SELECTION_QUA:isexpanded = find_best_hybrid_ldt_split_single_model(expanded_node, QUADRATIC, param->variance_explained);
                              break;
     case MODEL_SELECTION_LEV:level = level_of_node(expanded_node);
                              len = strlen(param->modelstring);
                              if (level >= len)
                                level = len - 1;
                              find_best_hybrid_ldt_split_according_char(expanded_node, param->modelstring[level], param->variance_explained);
                              break;
     case MODEL_SELECTION_FIX:isexpanded = find_best_hybrid_ldt_split_according_char(expanded_node, param->modelstring[2 * expandedcount], param->variance_explained);
                              break;
     default                 :printf(m1325);
                              isexpanded = BOOLEAN_FALSE;
                              break;
    }
   if (param->usediscrete)
     childrenproduced = make_children(expanded_node);
   else
     childrenproduced = make_multivariate_children(expanded_node);
   if (isexpanded && childrenproduced)
    {     
     if (param->prunetype == PREPRUNING)     
      {
       switch (param->vccalculationtype)
        {
         case VC_GENERAL:h = decisiontree_vc_dimension_wrt_nodetype(current_dataset, expandedcount + 1, param->model - 5);
                         break;
        }
       lefterror = find_error_as_leaf(expanded_node->left->instances);
       righterror = find_error_as_leaf(expanded_node->right->instances);
       error += lefterror + righterror - parenterror;
       upperbound = srm_classification((error + 0.0) / numinstances, h, numinstances, param->a1, param->a2);
       if (upperbound < bestupperbound)
         bestupperbound = upperbound;
       else
        {
         expanded_node->instances = expanded_node->left->instances;
         merge_instancelist(&(expanded_node->instances), expanded_node->right->instances);
         expanded_node->left->instances = NULL;
         expanded_node->right->instances = NULL;
         free_children(expanded_node);
         make_leaf_node(expanded_node);
         continue;
        }
      }
     if (param->model == MODEL_SELECTION_FIX)
      {
       switch (param->modelstring[2 * expandedcount + 1]){
         case '1':countsleft = find_class_counts(expanded_node->left->instances);
                  countsright = find_class_counts(expanded_node->right->instances);
                  if (log_likelihood_for_classification(countsleft) < log_likelihood_for_classification(countsright))
                   {
                    can_be_divided(expanded_node->right, NULL);
                    make_leaf_node(expanded_node->right);
                    if (!add_node_to_expanded_list(expanded_node->left, &header, nodeindex, param->usediscrete))
                     {
                      empty_heap(header);
                      safe_free(countsleft);
                      safe_free(countsright);                      
                      return 0;
                     }
                    nodeindex++;
                   }
                  else
                   {
                    can_be_divided(expanded_node->left, NULL);
                    make_leaf_node(expanded_node->left);
                    if (!add_node_to_expanded_list(expanded_node->right, &header, nodeindex, param->usediscrete))
                     { 
                      empty_heap(header);
                      safe_free(countsleft);
                      safe_free(countsright);                      
                      return 0;
                     }
                    nodeindex++;
                   }
                  safe_free(countsleft);
                  safe_free(countsright);
                  break;
         case '2':if (!add_node_to_expanded_list(expanded_node->left, &header, nodeindex, param->usediscrete))
                   {
                    can_be_divided(expanded_node->right, NULL);
                    make_leaf_node(expanded_node->right);
                    empty_heap(header);
                    return 0;
                   }
                  nodeindex++;
                  if (!add_node_to_expanded_list(expanded_node->right, &header, nodeindex, param->usediscrete))
                   {
                    empty_heap(header);
                    return 0;
                   }
                  nodeindex++;
                  break;
         case '0':can_be_divided(expanded_node->left, NULL);
                  make_leaf_node(expanded_node->left);
                  can_be_divided(expanded_node->right, NULL);
                  make_leaf_node(expanded_node->right);
                  break;
       }
      }
     else
      {
       if (param->usediscrete && current_dataset->features[expanded_node->featureno].type == STRING)
        {
         for (i = 0; i < current_dataset->features[expanded_node->featureno].valuecount; i++)
           add_node_to_expanded_list(&(expanded_node->string[i]), &header, -1, BOOLEAN_TRUE); 
        }
       else
        {
         add_node_to_expanded_list(expanded_node->left, &header, -1, param->usediscrete);
         add_node_to_expanded_list(expanded_node->right, &header, -1, param->usediscrete);
        }
      }
     expandedcount++;      
    }
   else
    {
     make_leaf_node(expanded_node);
     if (param->model == MODEL_SELECTION_FIX)
      {
       empty_heap(header);
       return 0;
      }
    }
  }
 empty_heap(header);
 return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %rbx
movq %rdi, %r15
movq $0x0, 0x8(%rsp)
movq 0x20(%rdi), %rdi
callq 0x2fa14
cmpl $0x0, 0x14(%rbx)
cvtsi2sd %eax, %xmm0
movl %eax, 0x34(%rsp)
movsd %xmm0, 0x48(%rsp)
je 0x4edb4
xorl %r14d, %r14d
jmp 0x4edeb
movl %eax, %ebp
movq 0x20(%r15), %rdi
callq 0x1159c
movl %eax, %r14d
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x48(%rsp), %xmm0
movsd 0x18(%rbx), %xmm1
movsd 0x20(%rbx), %xmm2
movl $0x1, %edi
movl %ebp, %esi
callq 0x475c7
movsd %xmm0, 0x40(%rsp)
movl 0x8(%rbx), %ebp
movl 0xc(%rbx), %ecx
xorl %edx, %edx
cmpl $0x9, %ebp
setne %dl
negl %edx
leaq 0x8(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x4ebea
movq (%r12), %r13
testq %r13, %r13
je 0x4f2c8
xorl %eax, %eax
cmpl $0x9, %ebp
sete %al
movq %rax, 0x18(%rsp)
leaq 0x30(%rbx), %rax
movq %rax, 0x50(%rsp)
movl $0x0, 0x4(%rsp)
movslq 0x4(%rsp), %rcx
movq %rcx, 0x28(%rsp)
leal 0x1(%rcx), %eax
movl %eax, 0x14(%rsp)
movq %r13, %r12
movl 0x4(%rsp), %eax
cmpl (%rbx), %eax
jge 0x4f2c5
cmpl $0x0, 0x14(%rbx)
jne 0x4ee6d
movq (%r12), %rax
movq 0x20(%rax), %rdi
callq 0x1159c
movl %eax, 0x3c(%rsp)
movq (%r12), %rbp
movq 0x10(%r12), %r13
movq %r12, %rdi
callq 0x39194
movl 0x8(%rbx), %eax
addl $-0x5, %eax
cmpl $0x4, %eax
ja 0x4ef36
leaq 0x588b4(%rip), %rcx     # 0xa7748
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x0, 0xc(%rbx)
je 0x4ef47
movq 0x20(%rbp), %rdi
leaq 0x28(%rbp), %rsi
callq 0x9f595
movl %eax, 0x30(%rbp)
xorl %r12d, %r12d
cmpl $-0x1, %eax
setne %r12b
jmp 0x4ef59
movq 0x28(%rsp), %rax
movsbl 0x30(%rbx,%rax,2), %esi
movsd 0x28(%rbx), %xmm0
movq %rbp, %rdi
callq 0x52b85
jmp 0x4ef56
movsd 0x28(%rbx), %xmm0
movq %rbp, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
jmp 0x4ef51
movq %rbp, %rdi
callq 0x1de5c
movl %eax, %r12d
movq 0x50(%rsp), %rdi
callq 0x4190
leal -0x1(%rax), %ecx
cmpl %eax, %r12d
cmovll %r12d, %ecx
movslq %ecx, %rax
movsbl 0x30(%rbx,%rax), %esi
movsd 0x28(%rbx), %xmm0
movq %rbp, %rdi
callq 0x52b85
movl %r15d, %r12d
jmp 0x4ef59
movsd 0x28(%rbx), %xmm0
movq %rbp, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
jmp 0x4ef51
leaq 0x58851(%rip), %rdi     # 0xa778e
callq 0x4090
xorl %r12d, %r12d
jmp 0x4ef59
movsd 0x28(%rbx), %xmm0
movq %rbp, %rdi
xorl %esi, %esi
callq 0x51fd3
movl %eax, %r12d
cmpl $0x0, 0xc(%rbx)
je 0x4ef69
movq %rbp, %rdi
callq 0x9db4a
jmp 0x4ef71
movq %rbp, %rdi
callq 0x4c6b9
testl %r12d, %r12d
je 0x4f05b
testl %eax, %eax
je 0x4f05b
cmpl $0x0, 0x14(%rbx)
jne 0x4f080
movl %r12d, %r15d
cmpl $0x0, 0x10(%rbx)
jne 0x4efb2
leaq 0x838d4(%rip), %rax     # 0xd2870
movq (%rax), %rdi
movl 0x8(%rbx), %edx
addl $-0x5, %edx
movl 0x14(%rsp), %esi
callq 0xa0337
movl %eax, 0x38(%rsp)
movq (%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x1159c
movl %eax, %r12d
movq 0x8(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x1159c
subl 0x3c(%rsp), %r14d
addl %r12d, %r14d
addl %eax, %r14d
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
divsd 0x48(%rsp), %xmm0
movsd 0x18(%rbx), %xmm1
movsd 0x20(%rbx), %xmm2
movl 0x38(%rsp), %edi
movl 0x34(%rsp), %esi
callq 0x475c7
movsd 0x40(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x4f077
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
movq 0x20(%rax), %rax
leaq 0x20(%rbp), %rdi
movq %rax, 0x20(%rbp)
movq 0x20(%rcx), %rsi
callq 0x2fd59
movq (%rbp), %rax
xorl %ecx, %ecx
movq %rcx, 0x20(%rax)
movq 0x8(%rbp), %rax
movq %rcx, 0x20(%rax)
movq %rbp, %rdi
callq 0x1d173
movq %rbp, %rdi
callq 0x1c39c
movq %r13, %r12
testq %r13, %r13
jne 0x4ee4a
jmp 0x4f2c8
movq %r13, 0x8(%rsp)
movq %rbp, %rdi
callq 0x1c39c
cmpl $0x9, 0x8(%rbx)
jne 0x4f2b2
jmp 0x4f2eb
movsd %xmm0, 0x40(%rsp)
movl %r15d, %r12d
movq %r13, 0x8(%rsp)
cmpl $0x9, 0x8(%rbx)
jne 0x4f12a
movl 0x4(%rsp), %eax
addl %eax, %eax
cltq
movzbl 0x31(%rbx,%rax), %eax
cmpl $0x30, %eax
je 0x4f237
cmpl $0x32, %eax
leaq 0x8(%rsp), %r13
je 0x4f1f2
cmpl $0x31, %eax
jne 0x4f2aa
movl %r12d, 0x4(%rsp)
movq (%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x115e1
movq %rax, %r12
movq 0x8(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x115e1
movq %rax, %r15
movq %r12, %rdi
callq 0x1d726
movsd %xmm0, 0x28(%rsp)
movq %r15, 0x20(%rsp)
movq %r15, %rdi
callq 0x1d726
ucomisd 0x28(%rsp), %xmm0
movq 0x18(%rsp), %r15
jbe 0x4f261
movq 0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x1c8e2
movq 0x8(%rbp), %rdi
callq 0x1c39c
movq (%rbp), %rdi
jmp 0x4f279
movl 0xc(%rbx), %ecx
testl %ecx, %ecx
leaq 0x8373a(%rip), %r13     # 0xd2870
je 0x4f1c3
movq (%r13), %rax
movslq 0x30(%rbp), %rdx
imulq $0x340, %rdx, %rdx      # imm = 0x340
cmpl $0x1, 0x30f08(%rax,%rdx)
jne 0x4f1c3
movq (%r13), %rax
movslq 0x30(%rbp), %rcx
imulq $0x340, %rcx, %rcx      # imm = 0x340
cmpl $0x0, 0x30f20(%rax,%rcx)
jle 0x4f2aa
movl %r12d, 0x4(%rsp)
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x10(%rbp), %rdi
addq %r15, %rdi
leaq 0x8(%rsp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x1, %ecx
callq 0x4ebea
incq %r12
movq (%r13), %rax
movslq 0x30(%rbp), %rcx
imulq $0x340, %rcx, %rcx      # imm = 0x340
movslq 0x30f20(%rax,%rcx), %rax
addq $0x160, %r15            # imm = 0x160
cmpq %rax, %r12
jl 0x4f17d
jmp 0x4f2a5
movq (%rbp), %rdi
leaq 0x8(%rsp), %r15
movq %r15, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x4ebea
movq 0x8(%rbp), %rdi
movl 0xc(%rbx), %ecx
movq %r15, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x4ebea
jmp 0x4f2aa
movq (%rbp), %rdi
movl 0xc(%rbx), %ecx
movq %r13, %rsi
movq 0x18(%rsp), %r15
movl %r15d, %edx
callq 0x4ebea
testl %eax, %eax
je 0x4f315
leal 0x1(%r15), %edx
movq 0x8(%rbp), %rdi
movl 0xc(%rbx), %ecx
movq %r13, %rsi
callq 0x4ebea
testl %eax, %eax
je 0x4f337
addl $0x2, %r15d
movq %r15, 0x18(%rsp)
jmp 0x4f2aa
movq (%rbp), %rdi
xorl %esi, %esi
callq 0x1c8e2
movq (%rbp), %rdi
callq 0x1c39c
movq 0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x1c8e2
movq 0x8(%rbp), %rdi
callq 0x1c39c
jmp 0x4f2aa
movq (%rbp), %rdi
xorl %esi, %esi
callq 0x1c8e2
movq (%rbp), %rdi
callq 0x1c39c
movq 0x8(%rbp), %rdi
movl 0xc(%rbx), %ecx
movq %r13, %rsi
movl %r15d, %edx
callq 0x4ebea
testl %eax, %eax
je 0x4f2f7
incl %r15d
movq %r15, 0x18(%rsp)
movq %r12, %rdi
callq 0x39194
movq 0x20(%rsp), %rdi
callq 0x39194
movl 0x4(%rsp), %r12d
movl 0x14(%rsp), %eax
movl %eax, 0x4(%rsp)
movl %r12d, %r15d
movq 0x8(%rsp), %r13
testq %r13, %r13
jne 0x4ee36
jmp 0x4f2c8
movq %r12, %r13
movq %r13, 0x8(%rsp)
movq %r13, %rdi
callq 0x4ec40
movl $0x1, %ebx
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
callq 0x4ec40
xorl %ebx, %ebx
jmp 0x4f2da
movq 0x8(%rsp), %rdi
callq 0x4ec40
movq %r12, %rdi
callq 0x39194
movq 0x20(%rsp), %rdi
callq 0x39194
jmp 0x4f2f3
movq 0x8(%rbp), %rdi
xorl %ebx, %ebx
xorl %esi, %esi
callq 0x1c8e2
movq 0x8(%rbp), %rdi
callq 0x1c39c
movq 0x8(%rsp), %rdi
callq 0x4ec40
jmp 0x4f2da
movq 0x8(%rsp), %rdi
jmp 0x4f2ee
nop