// File: /workspace/github_c_makefile_star2_O1/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 0x9dcbf
cmpq $0x0, 0x20(%rbx)
je 0x9dcbf
leaq 0x34cf2(%rip), %r13     # 0xd2870
movq (%r13), %rsi
imulq $0x340, %rcx, %rcx      # imm = 0x340
movl 0x30f08(%rsi,%rcx), %edx
cmpl $0x2, %edx
je 0x9dbab
movl $0x1, %eax
cmpl $0x1, %edx
je 0x9dcce
testl %edx, %edx
jne 0x9de39
movq %rbx, %rdi
movl $0x1, %esi
callq 0x1c996
movq %rax, %r14
movq %rbx, %rdi
movl $0x1, %esi
callq 0x1c996
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 %r12d, %r12d
movl %r12d, 0x40(%rsi)
movl $0xe, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
callq 0x1c954
movl 0x30(%rbx), %eax
movsd 0x28(%rbx), %xmm0
leaq 0xe8(%rsp), %rsi
movl %eax, (%rsi)
movb $0x3e, 0x4(%rsi)
movsd %xmm0, 0x8(%rsi)
movl %r12d, 0x40(%rsi)
movq 0x8(%rbx), %rax
movl $0xe, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %rax, %rdi
callq 0x1c954
movq 0x20(%rbx), %rax
testq %rax, %rax
je 0x9de0f
movq (%r13), %rcx
movslq 0x30(%rbx), %rdx
imulq $0x340, %rdx, %rsi      # imm = 0x340
movl 0x30f08(%rcx,%rsi), %esi
movsd 0x28(%rbx), %xmm0
xorl %ecx, %ecx
xorl %r12d, %r12d
movq (%rax), %rdi
testl %esi, %esi
je 0x9dc7d
movsd (%rdi,%rdx,8), %xmm1
jmp 0x9dc85
xorps %xmm1, %xmm1
cvtsi2sdl (%rdi,%rdx,8), %xmm1
ucomisd %xmm1, %xmm0
movq %rcx, %rdi
cmovbq %r12, %rdi
movq %r14, %r8
cmovbq %r15, %r8
cmovbq %rax, %r12
cmovaeq %rax, %rcx
addq $0x20, %r8
leaq 0x10(%rdi), %r9
testq %rdi, %rdi
cmoveq %r8, %r9
movq %rax, (%r9)
movq 0x10(%rax), %rax
testq %rax, %rax
jne 0x9dc6f
jmp 0x9de11
movq %rbx, %rdi
callq 0x1c39c
xorl %eax, %eax
jmp 0x9de39
leaq (%rsi,%rcx), %rax
addq $0x30f08, %rax          # imm = 0x30F08
movslq 0x18(%rax), %r14
movq %rbx, %rdi
movl %r14d, %esi
callq 0x1c996
movq %rax, 0x10(%rbx)
leaq (,%r14,8), %rdi
leaq 0x11730(%rip), %rsi     # 0xaf42a
movl $0x38, %edx
callq 0x390f5
movq %rax, %r15
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbx)
testq %r14, %r14
jle 0x9dd81
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 0x1c954
movq %rbp, (%r15,%r12,8)
incq %r12
addq $0x160, %r13            # imm = 0x160
cmpq %r12, %r14
jne 0x9dd1f
movq 0x20(%rbx), %rax
testq %rax, %rax
je 0x9ddc6
movslq 0x30(%rbx), %rcx
movq (%rax), %rdx
movslq (%rdx,%rcx,8), %rdx
movq (%r15,%rdx,8), %rsi
testq %rsi, %rsi
je 0x9dda4
addq $0x10, %rsi
jmp 0x9ddb6
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 0x9dd8e
movq $0x0, 0x20(%rbx)
testl %r14d, %r14d
jle 0x9de05
movl $0x20, %eax
xorl %ecx, %ecx
movq (%r15,%rcx,8), %rdx
testq %rdx, %rdx
je 0x9dde9
addq $0x10, %rdx
jmp 0x9ddf0
movq 0x10(%rbx), %rdx
addq %rax, %rdx
movq $0x0, (%rdx)
incq %rcx
addq $0x160, %rax            # imm = 0x160
cmpq %rcx, %r14
jne 0x9ddda
movq %r15, %rdi
callq 0x39194
jmp 0x9de34
xorl %ecx, %ecx
testq %rcx, %rcx
je 0x9de1e
movq $0x0, 0x10(%rcx)
testq %r12, %r12
je 0x9de2c
movq $0x0, 0x10(%r12)
movq $0x0, 0x20(%rbx)
movl $0x1, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq