// File: /workspace/github_c_makefile_star2_O3/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 0xcd7df(%rip), %rbx     # 0xd5870
movq (%rbx), %rax
movslq 0x10(%rax), %rdi
leaq 0x9dcc3(%rip), %rbp     # 0xa5d62
movl $0x8, %esi
movq %rbp, %rdx
movl $0x1, %ecx
callq 0x3a1fc
movq %rax, 0x28(%rsp)
movq (%rbx), %rax
movslq 0x10(%rax), %rdi
movl $0x8, %esi
movq %rbp, %rdx
movl $0x2, %ecx
callq 0x3a1fc
movq %rax, 0x30(%rsp)
movq (%rbx), %rax
movslq 0x10(%rax), %rdi
movl $0x4, %esi
movq %rbp, %rdx
movl $0x3, %ecx
callq 0x3a1fc
movq %rax, %r13
movq (%rbx), %rax
movslq 0x10(%rax), %rdi
movl $0x4, %esi
movq %rbp, %rdx
movl $0x4, %ecx
callq 0x3a1fc
movq %rax, 0x38(%rsp)
movq (%r14), %rsi
testq %rsi, %rsi
je 0x8175
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %edx, %edx
xorl %r12d, %r12d
movq %rsi, %rax
movslq (%rsi), %rsi
movq 0x38(%rsp), %rdi
movl $0x1, (%rdi,%rsi,4)
movl (%rax), %esi
cmpl %ecx, %esi
jne 0x813d
movslq %ecx, %rdx
jmp 0x815f
cmpl $-0x1, %ecx
je 0x814e
movslq %ecx, %rcx
movq 0x30(%rsp), %rdi
movq %rdx, (%rdi,%rcx,8)
movslq %esi, %rdx
movq 0x28(%rsp), %rcx
movq %rax, (%rcx,%rdx,8)
incl %r12d
movl %esi, %ecx
incl (%r13,%rdx,4)
movq 0x30(%rax), %rsi
movq %rax, %rdx
testq %rsi, %rsi
jne 0x8120
movslq %ecx, %rcx
jmp 0x8181
xorl %r12d, %r12d
movq $-0x1, %rcx
xorl %eax, %eax
movq 0x30(%rsp), %rdx
movq %rax, (%rdx,%rcx,8)
leaq 0xcd6df(%rip), %rax     # 0xd5870
movq (%rax), %rax
movslq 0x10(%rax), %rax
testq %rax, %rax
jle 0x81bd
xorl %ecx, %ecx
movq 0x30(%rsp), %rdx
movq (%rdx,%rcx,8), %rdx
testq %rdx, %rdx
je 0x81b5
movq $0x0, 0x30(%rdx)
incq %rcx
cmpq %rcx, %rax
jne 0x819f
movq 0x18(%r14), %rdi
callq 0x3a180
movq %r14, %rdi
callq 0x7c32b
testl %r12d, %r12d
jle 0x8353
movq 0x8(%r14), %rbx
leaq 0xcd68e(%rip), %rax     # 0xd5870
movq (%rax), %rcx
xorl %r8d, %r8d
movq %r12, 0x40(%rsp)
cmpl $0x0, 0x10(%rcx)
jle 0x8347
movq %r8, 0x48(%rsp)
movl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movq %rbx, %rax
movq %rbx, %rdx
xorl %ebp, %ebp
movq 0x38(%rsp), %rcx
cmpl $0x0, (%rcx,%rbp,4)
je 0x82ba
movl 0x10(%r14), %eax
testl %eax, %eax
jne 0x8233
movq 0x28(%rsp), %rcx
movq (%rcx,%rbp,8), %rcx
movq %rcx, (%r14)
testq %rdx, %rdx
je 0x8245
movq 0x28(%rsp), %rcx
movq (%rcx,%rbp,8), %rcx
movq %rcx, 0x30(%rdx)
movq 0x30(%rsp), %rcx
movq (%rcx,%rbp,8), %rcx
movq %rcx, 0x8(%r14)
addl (%r13,%rbp,4), %eax
movl %eax, 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 0x7c694
cmpl %r12d, %eax
cmovll %eax, %r12d
cmovll %ebp, %r15d
movl (%r13,%rbp,4), %eax
subl %eax, 0x10(%r14)
jne 0x829d
movq $0x0, (%r14)
movq %rbx, 0x8(%r14)
testq %rbx, %rbx
je 0x82b6
movq $0x0, 0x30(%rbx)
movq %rbx, %rax
movq %rbx, %rdx
jmp 0x82ba
xorl %eax, %eax
xorl %edx, %edx
incq %rbp
leaq 0xcd5ac(%rip), %rcx     # 0xd5870
movq (%rcx), %rcx
movslq 0x10(%rcx), %rsi
cmpq %rsi, %rbp
jl 0x8210
cmpl $-0x1, %r15d
movq 0x40(%rsp), %r12
movq 0x48(%rsp), %r8
je 0x8347
movl 0x10(%r14), %edx
movslq %r15d, %rsi
testl %edx, %edx
jne 0x8305
movq 0x28(%rsp), %rcx
movq (%rcx,%rsi,8), %rcx
movq %rcx, (%r14)
leaq 0xcd56e(%rip), %rcx     # 0xd5870
movq (%rcx), %rcx
testq %rax, %rax
je 0x8317
movq 0x28(%rsp), %rdi
movq (%rdi,%rsi,8), %rdi
movq %rdi, 0x30(%rax)
movq 0x30(%rsp), %rax
movq (%rax,%rsi,8), %rbx
movq %rbx, 0x8(%r14)
addl (%r13,%rsi,4), %edx
movl %edx, 0x10(%r14)
movq 0x38(%rsp), %rax
movl $0x0, (%rax,%rsi,4)
incl %r8d
cmpl %r12d, %r8d
jne 0x81ed
jmp 0x8353
leaq 0x9da21(%rip), %rdi     # 0xa5d6f
callq 0x4090
movq 0x28(%rsp), %rdi
callq 0x3a180
movq 0x30(%rsp), %rdi
callq 0x3a180
movq %r13, %rdi
callq 0x3a180
movq 0x38(%rsp), %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3a180