// File: /workspace/github_c_makefile_star2_O2/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, %r14
movslq 0x30(%rdi), %rax
cmpq $-0x1, %rax
je 0x917c4
cmpq $0x0, 0x20(%r14)
je 0x917c4
leaq 0x20(%r14), %rbp
leaq 0x3c1e1(%rip), %rcx     # 0xcd870
movq (%rcx), %rcx
imulq $0x340, %rax, %rax      # imm = 0x340
movl 0x30f08(%rcx,%rax), %edx
cmpl $0x2, %edx
je 0x916b9
pushq $0x1
popq %rbx
cmpl $0x1, %edx
je 0x917f1
testl %edx, %edx
jne 0x9192b
pushq $0x1
popq %rbx
movq %r14, %rdi
movl %ebx, %esi
callq 0x1ac98
movq %rax, %r15
movq %r14, %rdi
movl %ebx, %esi
callq 0x1ac98
andq $0x0, 0x10(%r14)
movq %rax, %r12
movq %r15, (%r14)
movq %rax, 0x8(%r14)
movl 0x30(%r14), %eax
movsd 0x28(%r14), %xmm0
leaq 0x78(%rsp), %rsi
movl %eax, (%rsi)
movb $0x3c, 0x4(%rsi)
movsd %xmm0, 0x8(%rsi)
andl $0x0, 0x40(%rsi)
pushq $0xe
popq %r13
movq %r13, %rcx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %r15, %rdi
callq 0x1ac58
movl 0x30(%r14), %eax
movsd 0x28(%r14), %xmm0
leaq 0xe8(%rsp), %rsi
movl %eax, (%rsi)
movb $0x3e, 0x4(%rsi)
movsd %xmm0, 0x8(%rsi)
andl $0x0, 0x40(%rsi)
movq 0x8(%r14), %rax
movq %r13, %rcx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
callq 0x1ac58
movl $0x30f08, %ecx          # imm = 0x30F08
leaq 0x3c119(%rip), %rax     # 0xcd870
addq (%rax), %rcx
xorl %eax, %eax
xorl %edx, %edx
movq %rbp, %rsi
movq (%rsi), %rsi
testq %rsi, %rsi
je 0x917d3
movslq 0x30(%r14), %rdi
imulq $0x340, %rdi, %r8       # imm = 0x340
cmpl $0x0, (%rcx,%r8)
movq (%rsi), %r8
je 0x91786
movsd (%r8,%rdi,8), %xmm0
jmp 0x9178c
cvtsi2sdl (%r8,%rdi,8), %xmm0
movsd 0x28(%r14), %xmm1
ucomisd %xmm0, %xmm1
jb 0x917a3
movq %rdx, %rdi
movq %r15, %r8
movq %rsi, %rdx
jmp 0x917ac
movq %rax, %rdi
movq %r12, %r8
movq %rsi, %rax
addq $0x20, %r8
leaq 0x10(%rdi), %r9
testq %rdi, %rdi
cmoveq %r8, %r9
movq %rsi, (%r9)
addq $0x10, %rsi
jmp 0x91761
movq %r14, %rdi
callq 0x1a6ac
xorl %ebx, %ebx
jmp 0x9192b
testq %rdx, %rdx
je 0x917dd
andq $0x0, 0x10(%rdx)
testq %rax, %rax
je 0x917e7
andq $0x0, 0x10(%rax)
andq $0x0, (%rbp)
jmp 0x9192b
movq %rbp, 0x70(%rsp)
addq %rcx, %rax
addq $0x30f08, %rax          # imm = 0x30F08
movslq 0x18(%rax), %r12
movq %r14, %rdi
movl %r12d, %esi
callq 0x1ac98
movq %rax, 0x10(%r14)
movq %r12, %rdi
shlq $0x3, %rdi
leaq 0x10bea(%rip), %rsi     # 0xa240a
pushq $0x38
popq %rdx
callq 0x34f59
movq %rax, %r15
xorl %ebx, %ebx
testl %r12d, %r12d
movl $0x0, %ebp
cmovgl %r12d, %ebp
xorpd %xmm0, %xmm0
movupd %xmm0, (%r14)
leaq 0x78(%rsp), %r13
xorl %r12d, %r12d
cmpq %r12, %rbp
je 0x918a4
movq 0x10(%r14), %rax
andq $0x0, 0x20(%rax,%rbx)
addq %rbx, %rax
movl 0x30(%r14), %ecx
cvtsi2sd %r12d, %xmm0
movl %ecx, 0x78(%rsp)
movb $0x3d, 0x7c(%rsp)
movsd %xmm0, 0x80(%rsp)
andl $0x0, 0xb8(%rsp)
pushq $0xe
popq %rcx
movq %rsp, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
callq 0x1ac58
andq $0x0, (%r15,%r12,8)
incq %r12
addq $0x160, %rbx            # imm = 0x160
jmp 0x9184a
movq 0x70(%rsp), %rdi
movq %rdi, %rax
pushq $0x1
popq %rbx
movq (%rax), %rax
testq %rax, %rax
je 0x918f0
movq (%rax), %rcx
movslq 0x30(%r14), %rdx
movslq (%rcx,%rdx,8), %rcx
movq (%r15,%rcx,8), %rdx
testq %rdx, %rdx
je 0x918d1
addq $0x10, %rdx
jmp 0x918e3
movq 0x10(%r14), %rdx
imulq $0x160, %rcx, %rsi      # imm = 0x160
addq %rsi, %rdx
addq $0x20, %rdx
movq %rax, (%rdx)
movq %rax, (%r15,%rcx,8)
addq $0x10, %rax
jmp 0x918af
andq $0x0, (%rdi)
pushq $0x20
popq %rax
xorl %ecx, %ecx
cmpq %rcx, %rbp
je 0x91923
movq (%r15,%rcx,8), %rdx
testq %rdx, %rdx
je 0x9190d
addq $0x10, %rdx
jmp 0x91914
movq 0x10(%r14), %rdx
addq %rax, %rdx
andq $0x0, (%rdx)
incq %rcx
addq $0x160, %rax            # imm = 0x160
jmp 0x918f9
movq %r15, %rdi
callq 0x34ff7
movl %ebx, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq