// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/rise.c
// Function: learn_ruleset_rise
Model_riseptr learn_ruleset_rise(Instanceptr instances)
{
 int i, classno, maxcount, ruleexists;
 int ***feature_counts;
 int improvement = YES, bestaccuracy, accuracy;
 Model_riseptr m;
 Decisionruleptr newrule, generalizedrule, rule, rulebefore, nextrule;
 Decisionruleptr* nearestrule;
 Instanceptr tmp;
 m = safemalloc(sizeof(Model_rise), "learn_ruleset_rise", 4);
 m->counts = find_class_counts(instances);
 m->svdm = safemalloc(current_dataset->featurecount * sizeof(matrix), "learn_ruleset_rise", 6);
 nearestrule = safemalloc(data_size(instances) * sizeof(Decisionruleptr), "learn_ruleset_rise", 6);
 feature_counts = find_feature_counts(instances);
 for (i = 0; i < current_dataset->featurecount; i++)
   if (current_dataset->features[i].type == STRING)
     m->svdm[i] = distance_between_discrete_values_of_feature(feature_counts, i);
 free_feature_counts(feature_counts);     
 empty_ruleset(&(m->rules));
 m->rules.defaultclass = find_max_in_list(m->counts, current_dataset->classno);
 classno = all_in_one_class(instances, &maxcount);
 if (!(classno % 10))
   return m;
 tmp = instances;
 while (tmp)
  {
   newrule = create_rule_from_instance(tmp);
   add_rule(&(m->rules), newrule);
   tmp = tmp->next;
  }
 rule = m->rules.start;
 while (rule)
  {
   update_counts(rule, instances, YES);
   rule = rule->next;
  }
 i = 0;
 tmp = instances;
 while (tmp)
  {
   nearestrule[i] = nearest_rule(m, tmp, YES);
   i++;
   tmp = tmp->next;
  }
 bestaccuracy = accuracy_of_ruleset(nearestrule, instances);
 while (improvement)
  {
   improvement = NO;
   rule = m->rules.start;
   rulebefore = NULL;
   while (rule)
    {
     nextrule = rule->next;
     tmp = nearest_example_not_covered(m, rule, instances);
     if (tmp)
      {
       generalizedrule = most_specific_generalization(rule, tmp);
       update_counts(generalizedrule, instances, YES);
       if (rule_exists(m->rules, generalizedrule))
         ruleexists = YES;
       else
         ruleexists = NO;
       remove_rule_after(&(m->rules), rulebefore, rule);
       update_nearest_rule(m, nearestrule, instances, 0, rule);
       add_rule_after(&(m->rules), rulebefore, generalizedrule);
       update_nearest_rule(m, nearestrule, instances, 1, generalizedrule);
       accuracy = accuracy_of_ruleset(nearestrule, instances);
       if (accuracy >= bestaccuracy)
        {
         bestaccuracy = accuracy;
         improvement = YES;
         free_rule(*rule);
         safe_free(rule);
         if (ruleexists)
          {
           remove_rule_after(&(m->rules), rulebefore, generalizedrule);
           update_nearest_rule(m, nearestrule, instances, 0, generalizedrule);
           bestaccuracy = accuracy_of_ruleset(nearestrule, instances);
           free_rule(*generalizedrule);
           safe_free(generalizedrule);
          }
         else
           rulebefore = generalizedrule;
        }
       else
        {
         remove_rule_after(&(m->rules), rulebefore, generalizedrule);
         update_nearest_rule(m, nearestrule, instances, 0, generalizedrule);
         add_rule_after(&(m->rules), rulebefore, rule);
         update_nearest_rule(m, nearestrule, instances, 1, rule);
         rulebefore = rule;
         free_rule(*generalizedrule);
         safe_free(generalizedrule);
        }
      }
     else
       rulebefore = rule;
     rule = nextrule;
    }
  }
 safe_free(nearestrule);
 return m; 
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
leaq 0x2f9d6(%rip), %r15     # 0x9fc5c
pushq $0x38
popq %rdi
pushq $0x4
popq %rdx
movq %r15, %rsi
callq 0x34f59
movq %rax, %r14
movq %rbx, %rdi
callq 0x108c8
movq %rax, 0x30(%r14)
leaq 0x5d5c6(%rip), %r12     # 0xcd870
movq (%r12), %rax
movslq 0x1bc(%rax), %rdi
shlq $0x4, %rdi
pushq $0x6
popq %rbp
movq %r15, %rsi
movl %ebp, %edx
callq 0x34f59
movq %rax, 0x28(%r14)
movq %rbx, %rdi
callq 0x2c3cc
movslq %eax, %rdi
shlq $0x3, %rdi
movq %r15, %rsi
movl %ebp, %edx
callq 0x34f59
movq %rax, 0x48(%rsp)
movq %rbx, %rdi
callq 0x10b48
movq %rax, 0x38(%rsp)
movq (%r12), %rax
pushq $0x8
popq %rbp
movl $0x30f08, %r13d         # imm = 0x30F08
xorl %r12d, %r12d
movslq 0x1bc(%rax), %rcx
cmpq %rcx, %r12
jge 0x7034c
cmpl $0x1, (%rax,%r13)
jne 0x7033c
movq 0x28(%r14), %r15
movq 0x38(%rsp), %rdi
movl %r12d, %esi
callq 0x6febd
movq %rax, -0x8(%r15,%rbp)
movq %rdx, (%r15,%rbp)
leaq 0x5d537(%rip), %rax     # 0xcd870
movq (%rax), %rax
incq %r12
addq $0x10, %rbp
addq $0x340, %r13            # imm = 0x340
jmp 0x70305
movq 0x38(%rsp), %rdi
callq 0x10ad2
movq %r14, %rdi
callq 0x71c9d
movq 0x30(%r14), %rdi
leaq 0x5d507(%rip), %rax     # 0xcd870
movq (%rax), %rax
movl 0x10(%rax), %esi
callq 0x336b5
movl %eax, 0x14(%r14)
leaq 0x54(%rsp), %rsi
movq %rbx, %rdi
callq 0x10916
pushq $0xa
popq %rcx
cltd
idivl %ecx
testl %edx, %edx
je 0x70623
movq %rbx, %r15
movq 0x48(%rsp), %r13
testq %r15, %r15
je 0x703b9
movq %r15, %rdi
callq 0x6fde9
movq %r14, %rdi
movq %rax, %rsi
callq 0x7228a
movq 0x10(%r15), %r15
jmp 0x7039b
pushq $0x1
popq %rbp
movq %r14, %r15
movq (%r15), %r15
testq %r15, %r15
je 0x703da
movq %r15, %rdi
movq %rbx, %rsi
movl %ebp, %edx
callq 0x722ae
addq $0x30, %r15
jmp 0x703bf
pushq $0x1
popq %rbp
movq %r13, %r12
movq %rbx, %r15
testq %r15, %r15
je 0x70403
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %edx
callq 0x6fc90
movq %rax, (%r12)
movq 0x10(%r15), %r15
addq $0x8, %r12
jmp 0x703e3
movq %r13, %rdi
movq %rbx, %rsi
callq 0x70229
movl %eax, 0x40(%rsp)
testl %ebp, %ebp
je 0x7061b
movq (%r14), %r15
xorl %ebp, %ebp
movl $0x0, 0x44(%rsp)
movq %rbp, %r13
testq %r15, %r15
je 0x7060d
movq %r13, %r12
movq %r15, %r13
movq 0x30(%r15), %r15
movq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x6fa9f
testq %rax, %rax
je 0x7042a
movq %r13, %rdi
movq %rax, %rsi
callq 0x6f9c0
movq %rax, %rbp
movq %rax, %rdi
movq %rax, 0x38(%rsp)
movq %rbx, %rsi
pushq $0x1
popq %rdx
callq 0x722ae
movq 0x20(%r14), %rax
movq %rax, 0x20(%rsp)
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbp, %rdi
callq 0x9072b
movl %eax, 0x50(%rsp)
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x721ae
movq %r14, %rdi
movq 0x48(%rsp), %rbp
movq %rbp, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
movq %r13, %r8
callq 0x70056
movq %r14, %rdi
movq %r12, %rsi
movq 0x38(%rsp), %rdx
callq 0x7217f
movq %r14, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
pushq $0x1
popq %rcx
movq 0x38(%rsp), %r8
callq 0x70056
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x70229
cmpl 0x40(%rsp), %eax
jge 0x70549
movq %r14, %rdi
movq %r12, %rsi
movq 0x38(%rsp), %rbp
movq %rbp, %rdx
callq 0x721ae
movq %r14, %rdi
movq 0x48(%rsp), %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
movq %rbp, %r8
callq 0x70056
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x7217f
movq %r14, %rdi
movq 0x48(%rsp), %rsi
movq %rbx, %rdx
pushq $0x1
popq %rcx
movq %r13, %r8
callq 0x70056
movq %r13, %r12
jmp 0x705d5
movl %eax, %ebp
movq 0x30(%r13), %rax
movq %rax, 0x30(%rsp)
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups 0x20(%r13), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x71be8
movq %r13, %rdi
callq 0x34ff7
movl %ebp, 0x40(%rsp)
pushq $0x1
popq %rax
movl %eax, 0x44(%rsp)
cmpl $0x0, 0x50(%rsp)
movq 0x38(%rsp), %rbp
je 0x70427
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x721ae
movq %r14, %rdi
movq 0x48(%rsp), %r13
movq %r13, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
movq %rbp, %r8
callq 0x70056
movq %r13, %rdi
movq %rbx, %rsi
callq 0x70229
movl %eax, 0x40(%rsp)
pushq $0x1
popq %rax
movl %eax, 0x44(%rsp)
movq 0x30(%rbp), %rax
movq %rax, 0x30(%rsp)
movups (%rbp), %xmm0
movups 0x10(%rbp), %xmm1
movups 0x20(%rbp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x71be8
movq %rbp, %rdi
callq 0x34ff7
movq %r12, %rbp
jmp 0x70427
movq 0x48(%rsp), %r13
movl 0x44(%rsp), %ebp
jmp 0x70412
movq %r13, %rdi
callq 0x34ff7
movq %r14, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)