// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/lerils.c
// Function: optimal_subset_of_rule_pool
Ruleset optimal_subset_of_rule_pool(Ruleset rule_pool, Instanceptr instances, int positive, int restarts)
{
 int i, j, M = rule_pool.rulecount, bestflip;
 int best_description_length = +INT_MAX, current_best_description_length, description_length, improved; 
 int *current_ruleset, *best_ruleset;
 double p;
 Decisionruleptr current_rule;
 Ruleset result;
 current_ruleset = safemalloc(M * sizeof(int), "optimal_subset_of_rule_pool", 4);
 best_ruleset = safemalloc(M * sizeof(int), "optimal_subset_of_rule_pool", 5);
 for (i = 0; i < restarts; i++)
  {
   /*Initialize ruleset*/
   for (j = 0; j < M; j++)
    {
     p = produce_random_value(0.0, 1.0);
     if (p < 0.5)
       current_ruleset[j] = YES;
     else 
       current_ruleset[j] = NO;
    }
   /*Greedy search*/
   current_best_description_length = description_length_of_ruleset_lerils(rule_pool, current_ruleset, instances, positive);
   improved = YES;
   while (improved)
    {
     improved = NO;
     bestflip = -1;
     for (j = 0; j < M; j++)
      {
       /*flip rules, 1 becomes 0, 0 becomes 1*/;
       current_ruleset[j] = 1 - current_ruleset[j]; 
       description_length = description_length_of_ruleset_lerils(rule_pool, current_ruleset, instances, positive);
       if (description_length < current_best_description_length)
        {
         current_best_description_length = description_length;
         improved = YES;
         bestflip = j;
        }
       current_ruleset[j] = 1 - current_ruleset[j];
      }
     if (improved)
       current_ruleset[bestflip] = 1 - current_ruleset[bestflip];
    }
   if (current_best_description_length < best_description_length)
    {
     best_description_length = current_best_description_length;
     memcpy(best_ruleset, current_ruleset, M * sizeof(int));
    }
  }
 empty_ruleset(&result);
 for (current_rule = rule_pool.start, i = 0; i < M; current_rule = current_rule->next, i++)
   if (best_ruleset[i])
     add_rule(&result, create_copy_of_rule(current_rule));
 safe_free(current_ruleset);
 safe_free(best_ruleset);
 return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %ecx, %ebp
movl %edx, 0x2c(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdi, 0x50(%rsp)
leaq 0xa0(%rsp), %rax
movslq 0x10(%rax), %rbx
movq %rbx, %r13
shlq $0x2, %r13
leaq 0x669c7(%rip), %r12     # 0x99703
pushq $0x4
popq %rdx
movq %r13, %rdi
movq %r12, %rsi
callq 0x34f59
movq %rax, %r15
pushq $0x5
popq %rdx
movq %r13, 0x58(%rsp)
movq %r13, %rdi
movq %r12, %rsi
callq 0x34f59
movq %rax, 0x30(%rsp)
xorl %ecx, %ecx
testl %ebx, %ebx
movl $0x0, %eax
cmovgl %ebx, %eax
movq %rax, 0x38(%rsp)
testl %ebp, %ebp
cmovlel %ecx, %ebp
movl %ebp, 0x44(%rsp)
movl $0x7fffffff, 0x28(%rsp) # imm = 0x7FFFFFFF
cmpl 0x44(%rsp), %ecx
je 0x32ec0
movq %rcx, 0x60(%rsp)
xorl %ebx, %ebx
leaq 0xa0(%rsp), %r14
cmpq %rbx, 0x38(%rsp)
je 0x32dd2
xorpd %xmm0, %xmm0
movsd 0x6276d(%rip), %xmm1    # 0x95520
callq 0x35cae
xorl %eax, %eax
movsd 0x62f5e(%rip), %xmm1    # 0x95d20
ucomisd %xmm0, %xmm1
seta %al
movl %eax, (%r15,%rbx,4)
incq %rbx
jmp 0x32da0
movq 0x20(%r14), %rax
movq %rax, 0x20(%rsp)
movupd (%r14), %xmm0
movupd 0x10(%r14), %xmm1
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq %r15, %rdi
movq 0x48(%rsp), %rsi
movl 0x2c(%rsp), %edx
callq 0x32bfd
movl %eax, %ebp
xorl %eax, %eax
testb $0x1, %al
jne 0x32e98
xorl %r12d, %r12d
xorl %r13d, %r13d
pushq $-0x1
popq %rbx
cmpq %r12, 0x38(%rsp)
je 0x32e7d
pushq $0x1
popq %r14
movl %r14d, %eax
subl (%r15,%r12,4), %eax
movl %eax, (%r15,%r12,4)
leaq 0xa0(%rsp), %rcx
movq 0x20(%rcx), %rax
movq %rax, 0x20(%rsp)
movupd (%rcx), %xmm0
movupd 0x10(%rcx), %xmm1
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq %r15, %rdi
movq 0x48(%rsp), %rsi
movl 0x2c(%rsp), %edx
callq 0x32bfd
cmpl %ebp, %eax
cmovll %eax, %ebp
cmovll %r14d, %r13d
cmovll %r12d, %ebx
subl (%r15,%r12,4), %r14d
movl %r14d, (%r15,%r12,4)
incq %r12
jmp 0x32e17
testl %r13d, %r13d
sete %al
je 0x32e06
movslq %ebx, %rcx
pushq $0x1
popq %rdx
subl (%r15,%rcx,4), %edx
movl %edx, (%r15,%rcx,4)
jmp 0x32e06
cmpl 0x28(%rsp), %ebp
jge 0x32eb4
movq 0x30(%rsp), %rdi
movq %r15, %rsi
movq 0x58(%rsp), %rdx
callq 0x4310
movl %ebp, 0x28(%rsp)
movq 0x60(%rsp), %rcx
incl %ecx
jmp 0x32d87
movq 0x50(%rsp), %r12
movq %r12, %rdi
callq 0x71c9d
xorl %ebx, %ebx
leaq 0xa0(%rsp), %r14
cmpq %rbx, 0x38(%rsp)
je 0x32f08
movq (%r14), %r14
movq 0x30(%rsp), %rax
cmpl $0x0, (%rax,%rbx,4)
je 0x32eff
movq %r14, %rdi
callq 0x717f9
movq %r12, %rdi
movq %rax, %rsi
callq 0x7228a
addq $0x30, %r14
incq %rbx
jmp 0x32ed7
movq %r15, %rdi
callq 0x34ff7
movq 0x30(%rsp), %rdi
callq 0x34ff7
movq %r12, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq