// File: /workspace/github_c_makefile_star2_O1/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 0xca7d1(%rip), %rbx     # 0xd2870
movq (%rbx), %rax
movslq 0x10(%rax), %rdi
leaq 0x9acb5(%rip), %rbp     # 0xa2d62
movl $0x8, %esi
movq %rbp, %rdx
movl $0x1, %ecx
callq 0x39210
movq %rax, 0x28(%rsp)
movq (%rbx), %rax
movslq 0x10(%rax), %rdi
movl $0x8, %esi
movq %rbp, %rdx
movl $0x2, %ecx
callq 0x39210
movq %rax, 0x30(%rsp)
movq (%rbx), %rax
movslq 0x10(%rax), %rdi
movl $0x4, %esi
movq %rbp, %rdx
movl $0x3, %ecx
callq 0x39210
movq %rax, %r13
movq (%rbx), %rax
movslq 0x10(%rax), %rdi
movl $0x4, %esi
movq %rbp, %rdx
movl $0x4, %ecx
callq 0x39210
movq %rax, 0x38(%rsp)
movq (%r14), %rdi
testq %rdi, %rdi
je 0x8180
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %edx, %edx
xorl %ebx, %ebx
movq %rdi, %rax
movslq (%rdi), %rsi
movq 0x38(%rsp), %rdi
movl $0x1, (%rdi,%rsi,4)
movl (%rax), %esi
cmpl %ecx, %esi
jne 0x8149
movl %ecx, %esi
jmp 0x816a
cmpl $-0x1, %ecx
je 0x815a
movslq %ecx, %rcx
movq 0x30(%rsp), %rdi
movq %rdx, (%rdi,%rcx,8)
movslq %esi, %rcx
movq 0x28(%rsp), %rdx
movq %rax, (%rdx,%rcx,8)
incl %ebx
movl %esi, %ecx
movslq %esi, %rsi
incl (%r13,%rsi,4)
movq 0x30(%rax), %rdi
movq %rax, %rdx
testq %rdi, %rdi
jne 0x812d
jmp 0x818b
xorl %ebx, %ebx
movq $-0x1, %rsi
xorl %eax, %eax
movq 0x30(%rsp), %rcx
movq %rax, (%rcx,%rsi,8)
leaq 0xca6d5(%rip), %rax     # 0xd2870
movq (%rax), %rax
movslq 0x10(%rax), %rax
testq %rax, %rax
jle 0x81c7
xorl %ecx, %ecx
movq 0x30(%rsp), %rdx
movq (%rdx,%rcx,8), %rdx
testq %rdx, %rdx
je 0x81bf
movq $0x0, 0x30(%rdx)
incq %rcx
cmpq %rcx, %rax
jne 0x81a9
movq 0x18(%r14), %rdi
callq 0x39194
movq %r14, %rdi
callq 0x7aa63
testl %ebx, %ebx
jle 0x8349
xorl %edi, %edi
movq %rbx, 0x40(%rsp)
movq %rdi, 0x48(%rsp)
leaq 0xca67d(%rip), %rax     # 0xd2870
movq (%rax), %rax
cmpl $0x0, 0x10(%rax)
jle 0x82ce
movq 0x8(%r14), %r15
movl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %ebp, %ebp
movq 0x38(%rsp), %rax
cmpl $0x0, (%rax,%rbp,4)
je 0x82b2
movl 0x10(%r14), %eax
testl %eax, %eax
jne 0x8234
movq 0x28(%rsp), %rcx
movq (%rcx,%rbp,8), %rcx
movq %rcx, (%r14)
movq 0x8(%r14), %rcx
testq %rcx, %rcx
je 0x824a
movq 0x28(%rsp), %rdx
movq (%rdx,%rbp,8), %rdx
movq %rdx, 0x30(%rcx)
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 0x7addb
cmpl %r12d, %eax
cmovll %eax, %r12d
cmovll %ebp, %ebx
movl (%r13,%rbp,4), %eax
subl %eax, 0x10(%r14)
jne 0x82a1
movq $0x0, (%r14)
movq %r15, 0x8(%r14)
testq %r15, %r15
je 0x82b2
movq $0x0, 0x30(%r15)
incq %rbp
leaq 0xca5b4(%rip), %rax     # 0xd2870
movq (%rax), %rax
movslq 0x10(%rax), %rax
cmpq %rax, %rbp
jl 0x8211
jmp 0x82d3
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $-0x1, %ebx
je 0x833d
movl 0x10(%r14), %eax
movslq %ebx, %rcx
testl %eax, %eax
jne 0x82ef
movq 0x28(%rsp), %rdx
movq (%rdx,%rcx,8), %rdx
movq %rdx, (%r14)
movq 0x8(%r14), %rdx
testq %rdx, %rdx
movq 0x40(%rsp), %rbx
movq 0x48(%rsp), %rdi
je 0x830f
movq 0x28(%rsp), %rsi
movq (%rsi,%rcx,8), %rsi
movq %rsi, 0x30(%rdx)
movq 0x30(%rsp), %rdx
movq (%rdx,%rcx,8), %rdx
movq %rdx, 0x8(%r14)
addl (%r13,%rcx,4), %eax
movl %eax, 0x10(%r14)
movq 0x38(%rsp), %rax
movl $0x0, (%rax,%rcx,4)
incl %edi
cmpl %ebx, %edi
jne 0x81e7
jmp 0x8349
leaq 0x9aa2b(%rip), %rdi     # 0xa2d6f
callq 0x4090
movq 0x28(%rsp), %rdi
callq 0x39194
movq 0x30(%rsp), %rdi
callq 0x39194
movq %r13, %rdi
callq 0x39194
movq 0x38(%rsp), %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x39194