// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/univariatetree.c
// Function: make_children
int make_children(Decisionnodeptr node)
{
 /*!Last Changed 02.02.2004*/
 /*!Last Changed 08.04.2003*/
 Instanceptr inst,leftbefore=NULL,rightbefore=NULL,*before;
 Decisionnodeptr left,right;
 Decisioncondition ruleleft, ruleright, rule;
 int i,count;
 double value;
 if (node->featureno == LEAF_NODE || node->instances == NULL)
  {
   make_leaf_node(node);
   return 0;
  }
 switch (current_dataset->features[node->featureno].type)
  {
   case INTEGER:
   case REAL   :left = createnewnode(node, 1);
                right = createnewnode(node, 1);
                node->string = NULL;
                node->left = left;
                node->right = right;
                ruleleft = createcondition(node->featureno,'<',node->split);
                ruleleft.conditiontype = UNIVARIATE_CONDITION;
                addcondition(node->left, ruleleft);
                ruleright = createcondition(node->featureno,'>',node->split);
                ruleright.conditiontype = UNIVARIATE_CONDITION;
                addcondition(node->right, ruleright);
                inst=node->instances;
                while (inst)
                 {
                  if (current_dataset->features[node->featureno].type==INTEGER)
                    value=inst->values[node->featureno].intvalue;
                  else
                    value=inst->values[node->featureno].floatvalue;
                  if (value<=node->split)
                   {
                    if (leftbefore)
                      leftbefore->next=inst;
                    else
                      left->instances=inst;
                    leftbefore=inst;
                   }
                  else
                   {
                    if (rightbefore)
                      rightbefore->next=inst;
                    else
                      right->instances=inst;
                    rightbefore=inst;
                   }
                  inst=inst->next;
                 }
                if (leftbefore)
                  leftbefore->next=NULL;
                if (rightbefore)
                  rightbefore->next=NULL;
                node->instances=NULL;
                break;
   case STRING :count=current_dataset->features[node->featureno].valuecount;
                node->string = createnewnode(node, count);                
                before = (Instanceptr*)safemalloc(count*sizeof(Instanceptr), "make_children", 56);
                node->left = NULL;
                node->right = NULL;
                for (i = 0; i < count; i++)
                 {
                  node->string[i].instances = NULL;
                  rule = createcondition(node->featureno, '=', i);
                  rule.conditiontype = UNIVARIATE_CONDITION;
                  addcondition(&(node->string[i]), rule);
                  before[i] = NULL;
                 }
                inst=node->instances;
                while (inst)
                 {
                  i=inst->values[node->featureno].stringindex;
                  if (before[i]==NULL)
                   {
                    node->string[i].instances=inst;
                    before[i]=inst;
                   }
                  else
                   {
                    before[i]->next=inst;
                    before[i]=inst;
                   }
                  inst=inst->next;
                 }
                node->instances=NULL;
                for (i=0;i<count;i++)
                 {
                  if (before[i])
                    before[i]->next=NULL;
                  else
                    node->string[i].instances=NULL;
                 }
                safe_free(before);
                break;
  }
 return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %rdi, %rbx
movslq 0x30(%rdi), %rcx
cmpq $-0x1, %rcx
je 0xa0cf9
cmpq $0x0, 0x20(%rbx)
je 0xa0cf9
leaq 0x34cdc(%rip), %r12     # 0xd5870
movq (%r12), %rax
imulq $0x340, %rcx, %rcx      # imm = 0x340
movl 0x30f08(%rax,%rcx), %edx
cmpl $0x2, %edx
je 0xa0bc2
movl $0x1, %r13d
cmpl $0x1, %edx
je 0xa0d19
testl %edx, %edx
jne 0xa0d04
movl $0x1, %r13d
movq %rbx, %rdi
movl $0x1, %esi
callq 0x1d107
movq %rax, %r14
movq %rbx, %rdi
movl $0x1, %esi
callq 0x1d107
movq %rax, %r15
movq $0x0, 0x10(%rbx)
movq %r14, (%rbx)
movq %rax, 0x8(%rbx)
movl 0x30(%rbx), %eax
movsd 0x28(%rbx), %xmm0
leaq 0x78(%rsp), %rsi
movl %eax, (%rsi)
movb $0x3c, 0x4(%rsi)
movsd %xmm0, 0x8(%rsi)
xorl %ebp, %ebp
movl %ebp, 0x40(%rsi)
movl $0xe, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
callq 0x1d0c5
movl 0x30(%rbx), %eax
movsd 0x28(%rbx), %xmm0
leaq 0xe8(%rsp), %rsi
movl %eax, (%rsi)
movb $0x3e, 0x4(%rsi)
movsd %xmm0, 0x8(%rsi)
movl %ebp, 0x40(%rsi)
movq 0x8(%rbx), %rax
movl $0xe, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
callq 0x1d0c5
movq 0x20(%rbx), %rax
testq %rax, %rax
je 0xa0cef
movq (%r12), %rcx
movslq 0x30(%rbx), %rsi
imulq $0x340, %rsi, %rdx      # imm = 0x340
movl 0x30f08(%rcx,%rdx), %edi
movsd 0x28(%rbx), %xmm0
xorl %edx, %edx
xorl %ecx, %ecx
movq (%rax), %r8
testl %edi, %edi
je 0xa0c97
movsd (%r8,%rsi,8), %xmm1
jmp 0xa0ca0
xorps %xmm1, %xmm1
cvtsi2sdl (%r8,%rsi,8), %xmm1
ucomisd %xmm1, %xmm0
movq %rdx, %r8
cmovbq %rcx, %r8
movq %r14, %r9
cmovbq %r15, %r9
cmovbq %rax, %rcx
cmovaeq %rax, %rdx
addq $0x20, %r9
leaq 0x10(%r8), %r10
testq %r8, %r8
cmoveq %r9, %r10
movq %rax, (%r10)
movq 0x10(%rax), %rax
testq %rax, %rax
jne 0xa0c88
testq %rdx, %rdx
je 0xa0ce2
movq $0x0, 0x10(%rdx)
testq %rcx, %rcx
je 0xa0cef
movq $0x0, 0x10(%rcx)
movq $0x0, 0x20(%rbx)
jmp 0xa0d04
movq %rbx, %rdi
callq 0x1cab0
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq %rcx, %rax
addq $0x30f08, %rax          # imm = 0x30F08
movslq 0x18(%rax), %r14
movq %rbx, %rdi
movl %r14d, %esi
callq 0x1d107
movq %rax, 0x10(%rbx)
leaq (,%r14,8), %rdi
leaq 0x11766(%rip), %rsi     # 0xb24aa
movl $0x38, %edx
callq 0x3a0e1
movq %rax, %r15
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbx)
testq %r14, %r14
jle 0xa0dcb
movl $0x20, %r13d
xorl %ebp, %ebp
xorl %r12d, %r12d
movq 0x10(%rbx), %rax
addq %r13, %rax
addq $-0x20, %rax
movq %rbp, 0x20(%rax)
movl 0x30(%rbx), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
movl %ecx, 0x78(%rsp)
movb $0x3d, 0x7c(%rsp)
movsd %xmm0, 0x80(%rsp)
movl $0x0, 0xb8(%rsp)
movl $0xe, %ecx
movq %rsp, %rdi
leaq 0x78(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
callq 0x1d0c5
movq %rbp, (%r15,%r12,8)
incq %r12
addq $0x160, %r13            # imm = 0x160
cmpq %r12, %r14
jne 0xa0d69
movq 0x20(%rbx), %rax
testq %rax, %rax
je 0xa0e10
movslq 0x30(%rbx), %rcx
movq (%rax), %rdx
movslq (%rdx,%rcx,8), %rdx
movq (%r15,%rdx,8), %rsi
testq %rsi, %rsi
je 0xa0dee
addq $0x10, %rsi
jmp 0xa0e00
movq 0x10(%rbx), %rsi
imulq $0x160, %rdx, %rdi      # imm = 0x160
addq %rdi, %rsi
addq $0x20, %rsi
movq %rax, (%rsi)
movq %rax, (%r15,%rdx,8)
movq 0x10(%rax), %rax
testq %rax, %rax
jne 0xa0dd8
movq $0x0, 0x20(%rbx)
testl %r14d, %r14d
movl $0x1, %r13d
jle 0xa0e55
movl $0x20, %eax
xorl %ecx, %ecx
movq (%r15,%rcx,8), %rdx
testq %rdx, %rdx
je 0xa0e39
addq $0x10, %rdx
jmp 0xa0e40
movq 0x10(%rbx), %rdx
addq %rax, %rdx
movq $0x0, (%rdx)
incq %rcx
addq $0x160, %rax            # imm = 0x160
cmpq %rcx, %r14
jne 0xa0e2a
movq %r15, %rdi
callq 0x3a180
jmp 0xa0d04