// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/c45rules.c
// Function: rank_classes
void rank_classes(Ruleset* r, Instanceptr traindata)
{
 /*!Last Changed 02.02.2004 added safecalloc*/
 /*!Last Changed 05.11.2003*/
 Decisionruleptr* classstarts = (Decisionruleptr*) safecalloc(current_dataset->classno, sizeof(Decisionruleptr), "rank_classes", 1);
 Decisionruleptr* classends = (Decisionruleptr*) safecalloc(current_dataset->classno, sizeof(Decisionruleptr), "rank_classes", 2);
 int* rulecounts = safecalloc(current_dataset->classno, sizeof(int), "rank_classes", 3);
 int* classdone = safecalloc(current_dataset->classno, sizeof(int), "rank_classes", 4);
 int classcount = 0, classno = -1, i, j, minfpc, minindex, fpc;
 Decisionruleptr tmp;
 Decisionruleptr tmpbefore;
 tmpbefore = NULL;
 tmp = r->start;
 while (tmp)
  {
   classdone[tmp->classno] = 1;
   if (tmp->classno != classno)
    {
     if (classno != -1)
       classends[classno] = tmpbefore;
     classstarts[tmp->classno] = tmp;
     classcount++;
     classno = tmp->classno;
    }
   rulecounts[classno]++;
   tmpbefore = tmp;
   tmp = tmp->next;
  }
 classends[classno] = tmpbefore;
 for (i = 0; i < current_dataset->classno; i++)
   if (classends[i])
     classends[i]->next = NULL;
 safe_free(r->counts);
 empty_ruleset(r);
 for (i = 0; i < classcount; i++)
  {
   minfpc = +INT_MAX;
   minindex = -1;
   tmp = r->end;
   for (j = 0; j < current_dataset->classno; j++)
     if (classdone[j])
      {
       if (r->rulecount == 0)
         r->start = classstarts[j];
       if (r->end)
         r->end->next = classstarts[j];
       r->end = classends[j];
       r->rulecount += rulecounts[j];
       fpc = false_positive_count(*r, traindata);
       if (fpc < minfpc)
        {
         minfpc = fpc;
         minindex = j;
        }
       r->rulecount -= rulecounts[j];
       if (r->rulecount == 0)
         r->start = NULL;
       r->end = tmp;
       if (tmp)
         tmp->next = NULL;
      }
   if (minindex != -1)
    {
     if (r->rulecount == 0)
       r->start = classstarts[minindex];
     if (r->end)
       r->end->next = classstarts[minindex];
     r->end = classends[minindex];
     r->rulecount += rulecounts[minindex];     
     classdone[minindex] = 0;
    }
   else
    {
     printf("Minimum description length larger than INT_MAX\n");
     break;
    }
  }
 safe_free(classstarts);
 safe_free(classends);
 safe_free(rulecounts);
 safe_free(classdone);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, 0x50(%rsp)
movq %rdi, %r14
leaq 0xc5a73(%rip), %rbx     # 0xcd870
movq (%rbx), %rax
movslq 0x10(%rax), %rdi
leaq 0x8df5f(%rip), %r15     # 0x95d6a
pushq $0x8
popq %r12
pushq $0x1
popq %rcx
movq %r12, %rsi
movq %r15, %rdx
callq 0x35067
movq %rax, 0x28(%rsp)
movq (%rbx), %rax
movslq 0x10(%rax), %rdi
pushq $0x2
popq %rcx
movq %r12, %rsi
movq %r15, %rdx
callq 0x35067
movq %rax, 0x30(%rsp)
movq (%rbx), %rax
movslq 0x10(%rax), %rdi
pushq $0x4
popq %rbp
pushq $0x3
popq %rcx
movq %rbp, %rsi
movq %r15, %rdx
callq 0x35067
movq %rax, %r13
movq (%rbx), %rax
movslq 0x10(%rax), %rdi
pushq $0x4
popq %rcx
movq %rbp, %rsi
movq %r15, %rdx
callq 0x35067
movq %rax, 0x38(%rsp)
xorl %ebx, %ebx
pushq $-0x1
popq %rax
movq %r14, %rdx
xorl %esi, %esi
movq 0x38(%rsp), %r8
movq (%rdx), %rcx
testq %rcx, %rcx
je 0x7ec8
movslq %eax, %rdx
movslq (%rcx), %rdi
movl $0x1, (%r8,%rdi,4)
movl (%rcx), %edi
cmpl %edx, %edi
je 0x7eba
cmpl $-0x1, %eax
je 0x7eaa
movq 0x30(%rsp), %rax
movq %rsi, (%rax,%rdx,8)
movslq %edi, %rdx
movq 0x28(%rsp), %rax
movq %rcx, (%rax,%rdx,8)
incl %ebx
movl %edi, %eax
incl (%r13,%rdx,4)
leaq 0x30(%rcx), %rdx
movq %rcx, %rsi
jmp 0x7e80
cltq
movq 0x30(%rsp), %rcx
movq %rsi, (%rcx,%rax,8)
leaq 0xc5996(%rip), %rax     # 0xcd870
movq (%rax), %rax
movl 0x10(%rax), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
cmpq %rcx, %rax
je 0x7f04
movq 0x30(%rsp), %rdx
movq (%rdx,%rcx,8), %rdx
testq %rdx, %rdx
je 0x7eff
andq $0x0, 0x30(%rdx)
incq %rcx
jmp 0x7ee7
movq 0x18(%r14), %rdi
callq 0x34ff7
movq %r14, %rdi
callq 0x71c9d
xorl %eax, %eax
testl %ebx, %ebx
cmovlel %eax, %ebx
movq %rbx, 0x40(%rsp)
cmpl %ebx, %eax
je 0x8067
movq %rax, 0x48(%rsp)
movq 0x8(%r14), %r15
movl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movq %r15, %rax
xorl %ebp, %ebp
pushq $-0x1
popq %rbx
leaq 0xc5929(%rip), %rcx     # 0xcd870
movq (%rcx), %rcx
movslq 0x10(%rcx), %rcx
cmpq %rcx, %rbp
jge 0x7ffd
movq 0x38(%rsp), %rcx
cmpl $0x0, (%rcx,%rbp,4)
je 0x7ff5
movl 0x10(%r14), %ecx
testl %ecx, %ecx
jne 0x7f7a
movq 0x28(%rsp), %rdx
movq (%rdx,%rbp,8), %rdx
movq %rdx, (%r14)
testq %rax, %rax
je 0x7f8c
movq 0x28(%rsp), %rdx
movq (%rdx,%rbp,8), %rdx
movq %rdx, 0x30(%rax)
movq 0x30(%rsp), %rax
movq (%rax,%rbp,8), %rax
movq %rax, 0x8(%r14)
addl (%r13,%rbp,4), %ecx
movl %ecx, 0x10(%r14)
movq 0x20(%r14), %rax
movq %rax, 0x20(%rsp)
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq 0x50(%rsp), %rdi
callq 0x71fda
cmpl %r12d, %eax
cmovll %eax, %r12d
cmovll %ebp, %ebx
movl (%r13,%rbp,4), %eax
subl %eax, 0x10(%r14)
jne 0x7fe0
andq $0x0, (%r14)
movq %r15, 0x8(%r14)
testq %r15, %r15
je 0x7ff3
andq $0x0, 0x30(%r15)
movq %r15, %rax
jmp 0x7ff5
xorl %eax, %eax
incq %rbp
jmp 0x7f40
cmpl $-0x1, %ebx
je 0x805b
movl 0x10(%r14), %ecx
movslq %ebx, %rdx
testl %ecx, %ecx
jne 0x8019
movq 0x28(%rsp), %rsi
movq (%rsi,%rdx,8), %rsi
movq %rsi, (%r14)
testq %rax, %rax
movq 0x40(%rsp), %rbx
je 0x8030
movq 0x28(%rsp), %rsi
movq (%rsi,%rdx,8), %rsi
movq %rsi, 0x30(%rax)
movq 0x30(%rsp), %rax
movq (%rax,%rdx,8), %rax
movq %rax, 0x8(%r14)
addl (%r13,%rdx,4), %ecx
movl %ecx, 0x10(%r14)
movq 0x38(%rsp), %rax
andl $0x0, (%rax,%rdx,4)
movq 0x48(%rsp), %rax
incl %eax
jmp 0x7f21
leaq 0x8dd15(%rip), %rdi     # 0x95d77
callq 0x4090
movq 0x28(%rsp), %rdi
callq 0x34ff7
movq 0x30(%rsp), %rdi
callq 0x34ff7
movq %r13, %rdi
callq 0x34ff7
movq 0x38(%rsp), %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x34ff7