// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/cn2.c
// Function: specialize_complex
void specialize_complex(Decisionruleptr current, Ruleset* newstar, Instanceptr* instances, int positive, int maxstar)
{
 int i, j, size, *featurecounts, *positivecounts, poscount, totalpositive;
 double split, prevvalue, value;
 Decisionruleptr candidate;
 Instanceptr covered = NULL, instancelist, tmp;
 remove_covered(instances, &covered, current);
 totalpositive = find_class_count(covered, positive);
 size = data_size(covered);
 for (i = 0; i < current_dataset->featurecount; i++)
   switch (current_dataset->features[i].type)
    { 
     case INTEGER:
     case    REAL:instancelist = sort_instances(covered, i, &size);
                  if (current_dataset->features[i].type == INTEGER)
                    prevvalue = instancelist[0].values[i].intvalue;
                  else
                    prevvalue = instancelist[0].values[i].floatvalue;
                  if (give_classno(&(instancelist[0])) == positive)
                    poscount = 1;
                  else
                    poscount = 0;
                  for (j = 1; j < size; j++)
                   {
                    if (current_dataset->features[i].type == INTEGER)
                      value = instancelist[j].values[i].intvalue;
                    else
                      value = instancelist[j].values[i].floatvalue;
                    if (value != prevvalue)
                     {
                      split = (value + prevvalue) / 2;
                      if (is_better_candidate(*newstar, maxstar, laplace_estimate(j - poscount, j)))
                       {
                        candidate = generate_candidate_for_newstar(current, i, '<', split, j - poscount, poscount);
                        add_candidate_to_newstar(candidate, newstar, maxstar);
                       }
                      if (is_better_candidate(*newstar, maxstar, laplace_estimate(size - j - totalpositive + poscount, size - j)))
                       {
                        candidate = generate_candidate_for_newstar(current, i, '>', split, size - j - totalpositive + poscount, totalpositive - poscount);
                        add_candidate_to_newstar(candidate, newstar, maxstar);
                       }
                      prevvalue = value;
                     }
                    if (give_classno(&(instancelist[j])) == positive)
                      poscount++;
                   }
                  safe_free(instancelist);
                  break;
     case  STRING:featurecounts = safecalloc(current_dataset->features[i].valuecount, sizeof(int), "find_best_condition", 94);
                  positivecounts = safecalloc(current_dataset->features[i].valuecount,sizeof(int), "find_best_condition", 95); 
                  tmp = covered;
                  while (tmp)
                   {
                    featurecounts[tmp->values[i].stringindex]++;
                    if (give_classno(tmp) == positive)
                      positivecounts[tmp->values[i].stringindex]++;
                    tmp = tmp->next;
                   }
                  for (j = 0; j < current_dataset->features[i].valuecount; j++)
                    if (featurecounts[j] != size && is_better_candidate(*newstar, maxstar, laplace_estimate(featurecounts[j] - positivecounts[j], featurecounts[j])))
                     {
                      candidate = generate_candidate_for_newstar(current, i, '=', j, featurecounts[j] - positivecounts[j], positivecounts[j]);
                      add_candidate_to_newstar(candidate, newstar, maxstar);
                     }
                  safe_free(featurecounts);
                  safe_free(positivecounts);
                  break;
    }
 merge_instancelist(instances, covered); 
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %r8d, %r12d
movl %ecx, %ebp
movq %rsi, %r15
movq %rdi, %rax
leaq 0x78(%rsp), %rbx
movq $0x0, (%rbx)
movq %rdx, 0x90(%rsp)
movq %rdx, %rdi
movq %rbx, %rsi
movq %rax, 0x70(%rsp)
movq %rax, %rdx
callq 0x9c951
movq (%rbx), %rdi
movl %ebp, 0x3c(%rsp)
movl %ebp, %esi
callq 0x11534
movl %eax, 0x60(%rsp)
movq (%rbx), %rdi
callq 0x2fa14
movl %eax, 0x38(%rsp)
leaq 0xc54a4(%rip), %rax     # 0xd2870
movq (%rax), %rax
cmpl $0x0, 0x1bc(%rax)
jle 0xd83b
movl 0x60(%rsp), %ecx
notl %ecx
movl %ecx, 0x84(%rsp)
xorl %r13d, %r13d
leaq 0x38(%rsp), %rbx
movl %r12d, 0x64(%rsp)
imulq $0x340, %r13, %rcx      # imm = 0x340
movq %rcx, 0x48(%rsp)
movl 0x30f08(%rax,%rcx), %ecx
cmpl $0x2, %ecx
je 0xd41b
cmpl $0x1, %ecx
je 0xd45a
testl %ecx, %ecx
jne 0xd81e
movq 0x78(%rsp), %rdi
movl %r13d, %esi
movq %rbx, %rdx
callq 0x9d053
movq %rax, %rbp
leaq 0xc543b(%rip), %rax     # 0xd2870
movq (%rax), %rax
movq 0x48(%rsp), %rcx
cmpl $0x0, 0x30f08(%rax,%rcx)
movq (%rbp), %rax
je 0xd5cf
movsd (%rax,%r13,8), %xmm0
jmp 0xd5d8
movl %r12d, %ebx
movq 0x48(%rsp), %rbp
addq %rbp, %rax
addq $0x30f08, %rax          # imm = 0x30F08
movslq 0x18(%rax), %rdi
movl $0x4, %esi
leaq 0x95baa(%rip), %r12     # 0xa3025
movq %r12, %rdx
movl $0x5e, %ecx
callq 0x39210
movq %rax, %r14
leaq 0xc53de(%rip), %rax     # 0xd2870
movq (%rax), %rax
movslq 0x30f20(%rax,%rbp), %rdi
movl $0x4, %esi
movq %r12, %rdx
movl $0x5f, %ecx
callq 0x39210
movq %rax, %rbp
movq 0x78(%rsp), %r12
testq %r12, %r12
je 0xd4e9
movq (%r12), %rax
movslq (%rax,%r13,8), %rax
incl (%r14,%rax,4)
movq %r12, %rdi
callq 0x2eaca
cmpl 0x3c(%rsp), %eax
jne 0xd4e2
movq (%r12), %rax
movslq (%rax,%r13,8), %rax
incl (%rbp,%rax,4)
movq 0x10(%r12), %r12
jmp 0xd4b7
leaq 0xc5380(%rip), %rax     # 0xd2870
movq (%rax), %rax
movq 0x48(%rsp), %rcx
cmpl $0x0, 0x30f20(%rax,%rcx)
movl %ebx, %r12d
jle 0xd5bd
xorl %ebx, %ebx
movl (%r14,%rbx,4), %esi
cmpl 0x38(%rsp), %esi
je 0xd59a
movl %esi, %edi
subl (%rbp,%rbx,4), %edi
callq 0x7b322
cmpl %r12d, 0x10(%r15)
jl 0xd567
movq 0x8(%r15), %rax
movq 0x30(%rax), %rcx
movq %rcx, 0x30(%rsp)
movsd %xmm0, 0x58(%rsp)
movupd (%rax), %xmm0
movupd 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movups %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
callq 0x7b33f
ucomisd 0x58(%rsp), %xmm0
jbe 0xd59a
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
movl (%r14,%rbx,4), %ecx
movl (%rbp,%rbx,4), %r8d
subl %r8d, %ecx
movq 0x70(%rsp), %rdi
movl %r13d, %esi
movl $0x3d, %edx
callq 0xd17f
movq %rax, %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0xd1ea
incq %rbx
leaq 0xc52cc(%rip), %rax     # 0xd2870
movq (%rax), %rax
movq 0x48(%rsp), %rcx
movslq 0x30f20(%rax,%rcx), %rax
cmpq %rax, %rbx
jl 0xd50b
movq %r14, %rdi
callq 0x39194
leaq 0x38(%rsp), %rbx
jmp 0xd816
xorps %xmm0, %xmm0
cvtsi2sdl (%rax,%r13,8), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %rbp, %rdi
callq 0x2eaca
cmpl $0x2, 0x38(%rsp)
jl 0xd816
movq %r13, 0x50(%rsp)
movq %rbp, %r13
xorl %ebp, %ebp
cmpl 0x3c(%rsp), %eax
sete %bpl
movq %r13, 0x98(%rsp)
addq $0x30, %r13
movl $0x1, %r14d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x58(%rsp)
movl 0x84(%rsp), %eax
movl %eax, %ebx
movsd 0x40(%rsp), %xmm0
leaq 0xc523b(%rip), %rax     # 0xd2870
movq (%rax), %rax
movq 0x48(%rsp), %rcx
cmpl $0x0, 0x30f08(%rax,%rcx)
movq (%r13), %rax
je 0xd657
movq 0x50(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm1
jmp 0xd664
movq 0x50(%rsp), %rcx
xorps %xmm1, %xmm1
cvtsi2sdl (%rax,%rcx,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0xd670
jnp 0xd7bc
movq %rbx, 0xa0(%rsp)
movsd %xmm1, 0x88(%rsp)
addsd %xmm1, %xmm0
mulsd 0x9568b(%rip), %xmm0    # 0xa2d18
movsd %xmm0, 0x40(%rsp)
movl %r12d, %ebx
movl %ebp, %r12d
negl %r12d
addq %r14, %r12
movl %r12d, %edi
movl %r14d, %esi
callq 0x7b322
cmpl %ebx, 0x10(%r15)
jl 0xd6ed
movq 0x8(%r15), %rax
movq 0x30(%rax), %rcx
movq %rcx, 0x30(%rsp)
movsd %xmm0, 0x68(%rsp)
movupd (%rax), %xmm0
movupd 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movups %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
callq 0x7b33f
ucomisd 0x68(%rsp), %xmm0
jbe 0xd71c
movq 0x70(%rsp), %rdi
movq 0x50(%rsp), %rsi
movl $0x3c, %edx
movsd 0x40(%rsp), %xmm0
movl %r12d, %ecx
movl %ebp, %r8d
callq 0xd17f
movq %rax, %rdi
movq %r15, %rsi
movl 0x64(%rsp), %edx
callq 0xd1ea
movl 0x38(%rsp), %eax
movq 0x58(%rsp), %rcx
leal (%rcx,%rax), %esi
movq 0xa0(%rsp), %rbx
leal (%rbx,%rbp), %edi
addl %eax, %edi
callq 0x7b322
movl 0x64(%rsp), %r12d
cmpl %r12d, 0x10(%r15)
jl 0xd782
movq 0x8(%r15), %rax
movq 0x30(%rax), %rcx
movq %rcx, 0x30(%rsp)
movsd %xmm0, 0x68(%rsp)
movupd (%rax), %xmm0
movupd 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movups %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
callq 0x7b33f
ucomisd 0x68(%rsp), %xmm0
jbe 0xd7c5
movl 0x38(%rsp), %ecx
addl %ebp, %ecx
addl %ebx, %ecx
movl 0x60(%rsp), %r8d
subl %ebp, %r8d
movq 0x70(%rsp), %rdi
movq 0x50(%rsp), %rsi
movl $0x3e, %edx
movsd 0x40(%rsp), %xmm0
callq 0xd17f
movq %rax, %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0xd1ea
jmp 0xd7c5
movsd %xmm0, 0x88(%rsp)
movq %r13, %rdi
callq 0x2eaca
xorl %ecx, %ecx
cmpl 0x3c(%rsp), %eax
sete %cl
addl %ecx, %ebp
incq %r14
movslq 0x38(%rsp), %rax
decl %ebx
movq 0x58(%rsp), %rcx
decl %ecx
movq %rcx, 0x58(%rsp)
addq $0x30, %r13
movsd 0x88(%rsp), %xmm0
cmpq %rax, %r14
jl 0xd62e
movq 0x50(%rsp), %r13
leaq 0x38(%rsp), %rbx
movq 0x98(%rsp), %rbp
movq %rbp, %rdi
callq 0x39194
incq %r13
leaq 0xc5048(%rip), %rax     # 0xd2870
movq (%rax), %rax
movslq 0x1bc(%rax), %rcx
cmpq %rcx, %r13
jl 0xd3f6
movq 0x78(%rsp), %rsi
movq 0x90(%rsp), %rdi
callq 0x2fd59
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq