// File: /workspace/github_c_makefile_star2_O3/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, %r13d
movl %ecx, %ebp
movq %rsi, %r15
movq %rdi, %rax
leaq 0x78(%rsp), %rbx
movq $0x0, (%rbx)
movq %rdx, 0x98(%rsp)
movq %rdx, %rdi
movq %rbx, %rsi
movq %rax, 0x70(%rsp)
movq %rax, %rdx
callq 0x9f94e
movq (%rbx), %rdi
movl %ebp, 0x3c(%rsp)
movl %ebp, %esi
callq 0x114f9
movl %eax, 0x60(%rsp)
movq (%rbx), %rdi
callq 0x30309
movl %eax, 0x38(%rsp)
leaq 0xc840c(%rip), %rax     # 0xd5870
movq (%rax), %rax
cmpl $0x0, 0x1bc(%rax)
jle 0xd8c1
movl 0x60(%rsp), %ecx
notl %ecx
movl %ecx, 0x84(%rsp)
xorl %ebp, %ebp
movl %r13d, 0x64(%rsp)
imulq $0x340, %rbp, %rcx      # imm = 0x340
movq %rcx, 0x48(%rsp)
movl 0x30f08(%rax,%rcx), %ecx
cmpl $0x2, %ecx
je 0xd4ad
cmpl $0x1, %ecx
je 0xd4f0
testl %ecx, %ecx
jne 0xd8a4
movq 0x78(%rsp), %rdi
movl %ebp, %esi
leaq 0x38(%rsp), %rdx
callq 0xa0055
movq %rax, %rdi
leaq 0xc83a8(%rip), %rax     # 0xd5870
movq (%rax), %rax
movq 0x48(%rsp), %rcx
cmpl $0x0, 0x30f08(%rax,%rcx)
movq (%rdi), %rax
movq %rbp, 0x50(%rsp)
je 0xd661
movsd (%rax,%rbp,8), %xmm0
jmp 0xd669
movl %r13d, %ebx
movq 0x48(%rsp), %r13
addq %r13, %rax
addq $0x30f08, %rax          # imm = 0x30F08
movslq 0x18(%rax), %rdi
movl $0x4, %esi
leaq 0x98b14(%rip), %r12     # 0xa6025
movq %r12, %rdx
movl $0x5e, %ecx
callq 0x3a1fc
movq %rax, %r14
leaq 0xc8348(%rip), %rax     # 0xd5870
movq (%rax), %rax
movslq 0x30f20(%rax,%r13), %rdi
movl $0x4, %esi
movq %r12, %rdx
movl $0x5f, %ecx
callq 0x3a1fc
movq %rax, %r12
movq 0x78(%rsp), %r13
testq %r13, %r13
je 0xd57e
movq (%r13), %rax
movslq (%rax,%rbp,8), %rax
incl (%r14,%rax,4)
movq %r13, %rdi
callq 0x2f33a
cmpl 0x3c(%rsp), %eax
jne 0xd578
movq (%r13), %rax
movslq (%rax,%rbp,8), %rax
incl (%r12,%rax,4)
movq 0x10(%r13), %r13
jmp 0xd54d
leaq 0xc82eb(%rip), %rax     # 0xd5870
movq (%rax), %rax
movq 0x48(%rsp), %rcx
cmpl $0x0, 0x30f20(%rax,%rcx)
movl %ebx, %r13d
jle 0xd64c
xorl %ebx, %ebx
movl (%r14,%rbx,4), %esi
cmpl 0x38(%rsp), %esi
je 0xd629
movl %esi, %edi
subl (%r12,%rbx,4), %edi
callq 0x7cbf1
cmpl %r13d, 0x10(%r15)
jl 0xd5f8
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 0x7cc0e
ucomisd 0x58(%rsp), %xmm0
jbe 0xd629
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
movl (%r14,%rbx,4), %ecx
movl (%r12,%rbx,4), %r8d
subl %r8d, %ecx
movq 0x70(%rsp), %rdi
movl %ebp, %esi
movl $0x3d, %edx
callq 0xd217
movq %rax, %rdi
movq %r15, %rsi
movl %r13d, %edx
callq 0xd282
incq %rbx
leaq 0xc823d(%rip), %rax     # 0xd5870
movq (%rax), %rax
movq 0x48(%rsp), %rcx
movslq 0x30f20(%rax,%rcx), %rax
cmpq %rax, %rbx
jl 0xd5a0
movq %r14, %rdi
callq 0x3a180
movq %r12, %rdi
callq 0x3a180
jmp 0xd8a4
xorps %xmm0, %xmm0
cvtsi2sdl (%rax,%rbp,8), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %rdi, 0x88(%rsp)
callq 0x2f33a
cmpl $0x2, 0x38(%rsp)
movsd 0x40(%rsp), %xmm0
jl 0xd892
xorl %ebp, %ebp
cmpl 0x3c(%rsp), %eax
sete %bpl
movq 0x88(%rsp), %r12
addq $0x30, %r12
movl $0x1, %r14d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x58(%rsp)
movl 0x84(%rsp), %eax
movl %eax, %ebx
leaq 0xc81ad(%rip), %rax     # 0xd5870
movq (%rax), %rax
movq 0x48(%rsp), %rcx
cmpl $0x0, 0x30f08(%rax,%rcx)
movq (%r12), %rax
je 0xd6e5
movq 0x50(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm1
jmp 0xd6f2
movq 0x50(%rsp), %rcx
xorps %xmm1, %xmm1
cvtsi2sdl (%rax,%rcx,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0xd6fe
jnp 0xd84a
movq %rbx, 0xa0(%rsp)
movsd %xmm1, 0x90(%rsp)
addsd %xmm1, %xmm0
mulsd 0x985fd(%rip), %xmm0    # 0xa5d18
movsd %xmm0, 0x40(%rsp)
movl %r13d, %ebx
movl %ebp, %r13d
negl %r13d
addq %r14, %r13
movl %r13d, %edi
movl %r14d, %esi
callq 0x7cbf1
cmpl %ebx, 0x10(%r15)
jl 0xd77b
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 0x7cc0e
ucomisd 0x68(%rsp), %xmm0
jbe 0xd7aa
movq 0x70(%rsp), %rdi
movq 0x50(%rsp), %rsi
movl $0x3c, %edx
movsd 0x40(%rsp), %xmm0
movl %r13d, %ecx
movl %ebp, %r8d
callq 0xd217
movq %rax, %rdi
movq %r15, %rsi
movl 0x64(%rsp), %edx
callq 0xd282
movl 0x38(%rsp), %eax
movq 0x58(%rsp), %rcx
leal (%rcx,%rax), %esi
movq 0xa0(%rsp), %rbx
leal (%rbx,%rbp), %edi
addl %eax, %edi
callq 0x7cbf1
movl 0x64(%rsp), %r13d
cmpl %r13d, 0x10(%r15)
jl 0xd810
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 0x7cc0e
ucomisd 0x68(%rsp), %xmm0
jbe 0xd853
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 0xd217
movq %rax, %rdi
movq %r15, %rsi
movl %r13d, %edx
callq 0xd282
jmp 0xd853
movsd %xmm0, 0x90(%rsp)
movq %r12, %rdi
callq 0x2f33a
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, %r12
movsd 0x90(%rsp), %xmm0
cmpq %rax, %r14
jl 0xd6bc
movq 0x88(%rsp), %rdi
callq 0x3a180
movq 0x50(%rsp), %rbp
incq %rbp
leaq 0xc7fc2(%rip), %rax     # 0xd5870
movq (%rax), %rax
movslq 0x1bc(%rax), %rcx
cmpq %rcx, %rbp
jl 0xd488
movq 0x78(%rsp), %rsi
movq 0x98(%rsp), %rdi
callq 0x30648
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq