// File: /workspace/github_c_makefile_star2_O2/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 $0xb8, %rsp
movl %r8d, 0x48(%rsp)
movl %ecx, %ebp
movq %rsi, %r13
movq %rdi, %rax
leaq 0x88(%rsp), %r14
andq $0x0, (%r14)
movq %rdx, 0xa8(%rsp)
movq %rdx, %rdi
movq %r14, %rsi
movq %rax, 0x78(%rsp)
movq %rax, %rdx
callq 0x90582
movq (%r14), %rdi
movl %ebp, 0x4c(%rsp)
movl %ebp, %esi
callq 0x10827
movl %eax, %ebp
movq (%r14), %rdi
callq 0x2c3cc
leaq 0x44(%rsp), %rcx
movl %eax, (%rcx)
movl %ebp, 0x94(%rsp)
notl %ebp
movl %ebp, 0x90(%rsp)
xorl %r15d, %r15d
movq %r13, 0x98(%rsp)
leaq 0xc0d6e(%rip), %rax     # 0xcd870
movq (%rax), %rax
movslq 0x1bc(%rax), %rcx
cmpq %rcx, %r15
jge 0xcf39
imulq $0x340, %r15, %rcx      # imm = 0x340
movq %rcx, 0x68(%rsp)
movl 0x30f08(%rax,%rcx), %ecx
cmpl $0x2, %ecx
movq %r15, 0x58(%rsp)
je 0xcb3f
cmpl $0x1, %ecx
je 0xcb83
testl %ecx, %ecx
jne 0xcf31
movq 0x88(%rsp), %rdi
movl %r15d, %esi
leaq 0x44(%rsp), %rdx
callq 0x90c1a
movq %rax, %r12
leaq 0xc0d12(%rip), %rax     # 0xcd870
movq (%rax), %rax
movq 0x68(%rsp), %rcx
cmpl $0x0, 0x30f08(%rax,%rcx)
movq (%r12), %rax
je 0xcce9
movsd (%rax,%r15,8), %xmm0
jmp 0xccef
movl 0x48(%rsp), %ebp
movq 0x68(%rsp), %rcx
addq %rcx, %rax
addq $0x30f08, %rax          # imm = 0x30F08
movslq 0x18(%rax), %rdi
pushq $0x4
popq %r12
movq %r12, %rsi
leaq 0x89486(%rip), %r14     # 0x9602d
movq %r14, %rdx
pushq $0x5e
popq %rcx
callq 0x35067
movq %rax, %rbx
leaq 0xc0cb4(%rip), %rax     # 0xcd870
movq (%rax), %rax
movq 0x68(%rsp), %rcx
movslq 0x30f20(%rax,%rcx), %rdi
movq %r12, %rsi
movq %r14, %rdx
pushq $0x5f
popq %rcx
callq 0x35067
movq %rax, %r14
leaq 0x88(%rsp), %r12
movq (%r12), %r12
testq %r12, %r12
je 0xcc19
movq (%r12), %rax
movslq (%rax,%r15,8), %rax
incl (%rbx,%rax,4)
movq %r12, %rdi
callq 0x2b47e
cmpl 0x4c(%rsp), %eax
jne 0xcc13
movq (%r12), %rax
movslq (%rax,%r15,8), %rax
incl (%r14,%rax,4)
addq $0x10, %r12
jmp 0xcbe5
xorl %r15d, %r15d
pushq $0x3d
popq %r12
leaq 0xc0c49(%rip), %rax     # 0xcd870
movq (%rax), %rax
movq 0x68(%rsp), %rcx
movslq 0x30f20(%rax,%rcx), %rax
cmpq %rax, %r15
jge 0xcccf
movl (%rbx,%r15,4), %esi
cmpl 0x44(%rsp), %esi
je 0xccc7
movl %esi, %edi
subl (%r14,%r15,4), %edi
callq 0x724a0
cmpl %ebp, 0x10(%r13)
jl 0xcc98
movq 0x8(%r13), %rax
movq 0x30(%rax), %rcx
movq %rcx, 0x30(%rsp)
movsd %xmm0, 0x50(%rsp)
movupd (%rax), %xmm0
movupd 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movups %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
callq 0x724bd
ucomisd 0x50(%rsp), %xmm0
jbe 0xccc7
cvtsi2sd %r15d, %xmm0
movl (%rbx,%r15,4), %ecx
movl (%r14,%r15,4), %r8d
subl %r8d, %ecx
movq 0x78(%rsp), %rdi
movq 0x58(%rsp), %rsi
movl %r12d, %edx
callq 0xc907
movq %rax, %rdi
movq %r13, %rsi
movl %ebp, %edx
callq 0xc972
incq %r15
jmp 0xcc20
movq %rbx, %rdi
callq 0x34ff7
movq %r14, %rdi
callq 0x34ff7
movq 0x58(%rsp), %r15
jmp 0xcf31
cvtsi2sdl (%rax,%r15,8), %xmm0
movsd %xmm0, 0x60(%rsp)
movq %r12, %rdi
callq 0x2b47e
xorl %ebp, %ebp
cmpl 0x4c(%rsp), %eax
sete %bpl
movq %r12, 0xb0(%rsp)
addq $0x30, %r12
pushq $-0x1
popq %rax
movl %eax, %r13d
movl 0x90(%rsp), %eax
movl %eax, %ebx
pushq $0x1
popq %r14
movsd 0x60(%rsp), %xmm0
movslq 0x44(%rsp), %rax
cmpq %rax, %r14
jge 0xcf1c
movq %rbx, 0x50(%rsp)
leaq 0xc0b2a(%rip), %rax     # 0xcd870
movq (%rax), %rax
movq 0x68(%rsp), %rcx
cmpl $0x0, 0x30f08(%rax,%rcx)
movq (%r12), %rax
je 0xcd64
movsd (%rax,%r15,8), %xmm1
jmp 0xcd6a
cvtsi2sdl (%rax,%r15,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0xcd76
jnp 0xcee1
movq %r13, 0x80(%rsp)
movsd %xmm1, 0xa0(%rsp)
addsd %xmm1, %xmm0
mulsd 0x88f8d(%rip), %xmm0    # 0x95d20
movsd %xmm0, 0x60(%rsp)
movl 0x48(%rsp), %r15d
movl %ebp, %ebx
negl %ebx
addq %r14, %rbx
movl %ebx, %edi
movl %r14d, %esi
callq 0x724a0
movq 0x98(%rsp), %r13
cmpl %r15d, 0x10(%r13)
jl 0xcdfa
movq 0x8(%r13), %rax
movq 0x30(%rax), %rcx
movq %rcx, 0x30(%rsp)
movsd %xmm0, 0x70(%rsp)
movupd (%rax), %xmm0
movupd 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movups %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
callq 0x724bd
ucomisd 0x70(%rsp), %xmm0
jbe 0xce25
movq 0x78(%rsp), %rdi
movq 0x58(%rsp), %rsi
pushq $0x3c
popq %rdx
movsd 0x60(%rsp), %xmm0
movl %ebx, %ecx
movl %ebp, %r8d
callq 0xc907
movq %rax, %rdi
movq %r13, %rsi
movl %r15d, %edx
callq 0xc972
movl 0x44(%rsp), %eax
movq 0x80(%rsp), %rcx
leal (%rcx,%rax), %esi
movq 0x50(%rsp), %rcx
leal (%rcx,%rbp), %edi
addl %eax, %edi
callq 0x724a0
cmpl %r15d, 0x10(%r13)
jl 0xce95
movq 0x8(%r13), %rax
movq 0x30(%rax), %rcx
movq %rcx, 0x30(%rsp)
movsd %xmm0, 0x70(%rsp)
movupd (%rax), %xmm0
movupd 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movups %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
callq 0x724bd
ucomisd 0x70(%rsp), %xmm0
ja 0xce95
movq 0x58(%rsp), %r15
movq 0x80(%rsp), %r13
jmp 0xceea
movl 0x44(%rsp), %ecx
addl %ebp, %ecx
movq 0x50(%rsp), %rbx
addl %ebx, %ecx
movl 0x94(%rsp), %r8d
subl %ebp, %r8d
movq 0x78(%rsp), %rdi
movq 0x58(%rsp), %r15
movl %r15d, %esi
pushq $0x3e
popq %rdx
movsd 0x60(%rsp), %xmm0
callq 0xc907
movq %rax, %rdi
movq %r13, %rsi
movl 0x48(%rsp), %edx
callq 0xc972
movq 0x80(%rsp), %r13
jmp 0xceef
movsd %xmm0, 0xa0(%rsp)
movq 0x50(%rsp), %rbx
movq %r12, %rdi
callq 0x2b47e
xorl %ecx, %ecx
cmpl 0x4c(%rsp), %eax
sete %cl
addl %ecx, %ebp
incq %r14
addq $0x30, %r12
decl %ebx
decl %r13d
movsd 0xa0(%rsp), %xmm0
jmp 0xcd2c
movq 0xb0(%rsp), %rdi
callq 0x34ff7
movq 0x98(%rsp), %r13
incq %r15
jmp 0xcafb
movq 0x88(%rsp), %rsi
movq 0xa8(%rsp), %rdi
callq 0x2c6e4
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq