// File: /workspace/github_c_makefile_star2_O3/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, (%rsp)
movq 0x20(%rdi), %rdi
callq 0x30309
cmpl $0x0, 0x14(%rbx)
cvtsi2sd %eax, %xmm0
movl %eax, 0x28(%rsp)
movsd %xmm0, 0x50(%rsp)
je 0x502d1
xorl %r14d, %r14d
jmp 0x50308
movl %eax, %ebp
movq 0x20(%r15), %rdi
callq 0x11561
movl %eax, %r14d
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x50(%rsp), %xmm0
movsd 0x18(%rbx), %xmm1
movsd 0x20(%rbx), %xmm2
movl $0x1, %edi
movl %ebp, %esi
callq 0x4896e
movsd %xmm0, 0x48(%rsp)
movl 0x8(%rbx), %ebp
movl 0xc(%rbx), %ecx
xorl %edx, %edx
cmpl $0x9, %ebp
setne %dl
negl %edx
movq %rsp, %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x50108
movq (%r12), %r15
movq $0x0, 0x20(%rsp)
testq %r15, %r15
je 0x507c6
xorl %eax, %eax
cmpl $0x9, %ebp
sete %al
movq %rax, 0x18(%rsp)
leaq 0x30(%rbx), %rax
movq %rax, 0x38(%rsp)
xorl %ebp, %ebp
movslq %ebp, %rax
leaq (%rax,%rax), %rcx
movq %rcx, 0x8(%rsp)
incl %eax
movq %rax, 0x40(%rsp)
movq %r15, %r12
cmpl (%rbx), %ebp
jge 0x507c1
cmpl $0x0, 0x14(%rbx)
jne 0x50389
movq (%r12), %rax
movq 0x20(%rax), %rdi
callq 0x11561
movl %eax, 0x34(%rsp)
movq (%r12), %r13
movq 0x10(%r12), %r15
movq %r12, %rdi
callq 0x3a180
movl 0x8(%rbx), %eax
addl $-0x5, %eax
cmpl $0x4, %eax
ja 0x50455
leaq 0x5a438(%rip), %rcx     # 0xaa7e8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x0, 0xc(%rbx)
je 0x50466
movq 0x20(%r13), %rdi
leaq 0x28(%r13), %rsi
callq 0xa2571
movl %eax, 0x30(%r13)
xorl %r12d, %r12d
cmpl $-0x1, %eax
setne %r12b
jmp 0x50478
movq 0x8(%rsp), %rax
movsbl 0x30(%rbx,%rax), %esi
movsd 0x28(%rbx), %xmm0
movq %r13, %rdi
callq 0x5409c
jmp 0x50475
movsd 0x28(%rbx), %xmm0
movq %r13, %rdi
movl $0xfffffffd, %esi       # imm = 0xFFFFFFFD
jmp 0x50470
movq %r13, %rdi
callq 0x1e5bb
movl %eax, %r12d
movq 0x38(%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 %r13, %rdi
callq 0x5409c
movl 0x2c(%rsp), %r12d
jmp 0x50478
movsd 0x28(%rbx), %xmm0
movq %r13, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
jmp 0x50470
leaq 0x5a3d2(%rip), %rdi     # 0xaa82e
callq 0x4090
xorl %r12d, %r12d
jmp 0x50478
movsd 0x28(%rbx), %xmm0
movq %r13, %rdi
xorl %esi, %esi
callq 0x534c7
movl %eax, %r12d
cmpl $0x0, 0xc(%rbx)
je 0x50488
movq %r13, %rdi
callq 0xa0b60
jmp 0x50490
movq %r13, %rdi
callq 0x4db5c
testl %r12d, %r12d
movl %r12d, 0x2c(%rsp)
je 0x50586
testl %eax, %eax
je 0x50586
cmpl $0x0, 0x14(%rbx)
jne 0x505a7
cmpl $0x0, 0x10(%rbx)
jne 0x504d4
leaq 0x853b3(%rip), %rax     # 0xd5870
movq (%rax), %rdi
movl 0x8(%rbx), %edx
addl $-0x5, %edx
movq 0x40(%rsp), %rsi
callq 0xa323d
movl %eax, 0x30(%rsp)
movq (%r13), %rax
movq 0x20(%rax), %rdi
callq 0x11561
movl %eax, %r12d
movq 0x8(%r13), %rax
movq 0x20(%rax), %rdi
callq 0x11561
subl 0x34(%rsp), %r14d
addl %r12d, %r14d
addl %eax, %r14d
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
divsd 0x50(%rsp), %xmm0
movsd 0x18(%rbx), %xmm1
movsd 0x20(%rbx), %xmm2
movl 0x30(%rsp), %edi
movl 0x28(%rsp), %esi
callq 0x4896e
movsd 0x48(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x505a1
movq (%r13), %rax
movq 0x8(%r13), %rcx
movq 0x20(%rax), %rax
leaq 0x20(%r13), %rdi
movq %rax, 0x20(%r13)
movq 0x20(%rcx), %rsi
callq 0x30648
movq (%r13), %rax
xorl %ecx, %ecx
movq %rcx, 0x20(%rax)
movq 0x8(%r13), %rax
movq $0x0, 0x20(%rsp)
movq %rcx, 0x20(%rax)
movq %r13, %rdi
callq 0x1d8e3
movq %r13, %rdi
callq 0x1cab0
movq %r15, %r12
testq %r15, %r15
jne 0x5036a
jmp 0x507c6
movq %r15, (%rsp)
movq %r13, %rdi
callq 0x1cab0
cmpl $0x9, 0x8(%rbx)
jne 0x507b6
jmp 0x507e6
movsd %xmm0, 0x48(%rsp)
movq %r15, (%rsp)
cmpl $0x9, 0x8(%rbx)
leaq 0x852ba(%rip), %rbp     # 0xd5870
jne 0x50652
movslq 0x8(%rsp), %rax
movq 0x38(%rsp), %rcx
movzbl 0x1(%rcx,%rax), %eax
cmpl $0x30, %eax
movq 0x18(%rsp), %r15
je 0x5073d
cmpl $0x32, %eax
je 0x506fa
cmpl $0x31, %eax
jne 0x507ab
movq (%r13), %rax
movq 0x20(%rax), %rdi
callq 0x115a6
movq %rax, %r12
movq 0x8(%r13), %rax
movq 0x20(%rax), %rdi
callq 0x115a6
movq %rax, %rbp
movq %r12, %rdi
callq 0x1de84
movsd %xmm0, 0x8(%rsp)
movq %rbp, 0x10(%rsp)
movq %rbp, %rdi
callq 0x1de84
ucomisd 0x8(%rsp), %xmm0
movq %rsp, %rbp
jbe 0x50767
movq 0x8(%r13), %rdi
xorl %esi, %esi
callq 0x1d053
movq 0x8(%r13), %rdi
callq 0x1cab0
movq (%r13), %rdi
jmp 0x5077f
movl 0xc(%rbx), %ecx
testl %ecx, %ecx
je 0x506cd
movq (%rbp), %rax
movslq 0x30(%r13), %rdx
imulq $0x340, %rdx, %rdx      # imm = 0x340
cmpl $0x1, 0x30f08(%rax,%rdx)
jne 0x506cd
addq $0x30f08, %rax          # imm = 0x30F08
cmpl $0x0, 0x18(%rax,%rdx)
jle 0x507ab
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x10(%r13), %rdi
addq %r15, %rdi
movq %rsp, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x1, %ecx
callq 0x50108
incq %r12
movq (%rbp), %rax
movslq 0x30(%r13), %rcx
imulq $0x340, %rcx, %rcx      # imm = 0x340
movslq 0x30f20(%rax,%rcx), %rax
addq $0x160, %r15            # imm = 0x160
cmpq %rax, %r12
jl 0x50689
jmp 0x507ab
movq (%r13), %rdi
movq %rsp, %r15
movq %r15, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x50108
movq 0x8(%r13), %rdi
movl 0xc(%rbx), %ecx
movq %r15, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x50108
jmp 0x507ab
movq (%r13), %rdi
movl 0xc(%rbx), %ecx
movq %rsp, %r12
movq %r12, %rsi
movl %r15d, %edx
callq 0x50108
testl %eax, %eax
je 0x5080f
leal 0x1(%r15), %edx
movq 0x8(%r13), %rdi
movl 0xc(%rbx), %ecx
movq %r12, %rsi
callq 0x50108
testl %eax, %eax
je 0x50830
addl $0x2, %r15d
movq %r15, 0x18(%rsp)
jmp 0x507ab
movq (%r13), %rdi
xorl %esi, %esi
callq 0x1d053
movq (%r13), %rdi
callq 0x1cab0
movq 0x8(%r13), %rdi
xorl %esi, %esi
callq 0x1d053
movq 0x8(%r13), %rdi
callq 0x1cab0
jmp 0x507ab
movq (%r13), %rdi
xorl %esi, %esi
callq 0x1d053
movq (%r13), %rdi
callq 0x1cab0
movq 0x8(%r13), %rdi
movl 0xc(%rbx), %ecx
movq %rbp, %rsi
movl %r15d, %edx
callq 0x50108
testl %eax, %eax
je 0x507f2
incl %r15d
movq %r15, 0x18(%rsp)
movq %r12, %rdi
callq 0x3a180
movq 0x10(%rsp), %rdi
callq 0x3a180
movq (%rsp), %r15
movq 0x40(%rsp), %rax
movl %eax, %ebp
testq %r15, %r15
jne 0x50354
jmp 0x507c6
movq %r12, 0x20(%rsp)
movq 0x20(%rsp), %rdi
callq 0x5015e
movl $0x1, %ebx
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x5015e
xorl %ebx, %ebx
jmp 0x507d5
movq (%rsp), %rdi
callq 0x5015e
movq %r12, %rdi
callq 0x3a180
movq 0x10(%rsp), %rdi
callq 0x3a180
jmp 0x507ee
movq 0x8(%r13), %rdi
xorl %ebx, %ebx
xorl %esi, %esi
callq 0x1d053
movq 0x8(%r13), %rdi
callq 0x1cab0
movq (%rsp), %rdi
callq 0x5015e
jmp 0x507d5
movq (%rsp), %rdi
jmp 0x507e9
nop