// File: /workspace/github_c_makefile_star2_O3/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, %ebx
movl %edx, 0x2c(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdi, 0x50(%rsp)
leaq 0xa0(%rsp), %r14
movslq 0x10(%r14), %r12
movl %r12d, %r13d
shlq $0x2, %r12
leaq 0x722d1(%rip), %rbp     # 0xa9793
movq %r12, %rdi
movq %rbp, %rsi
movl $0x4, %edx
callq 0x3a0e1
movq %rax, %r15
movq %r12, 0x58(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
movl $0x5, %edx
callq 0x3a0e1
movq %rax, 0x40(%rsp)
movl %ebx, 0x3c(%rsp)
testl %ebx, %ebx
jle 0x3765f
movl $0x7fffffff, 0x28(%rsp) # imm = 0x7FFFFFFF
xorl %ebx, %ebx
movq %r13, 0x30(%rsp)
movq %rbx, 0x60(%rsp)
testl %r13d, %r13d
jle 0x37544
xorl %ebx, %ebx
xorpd %xmm0, %xmm0
movsd 0x6dffe(%rip), %xmm1    # 0xa5520
callq 0x3af6a
xorl %eax, %eax
movsd 0x6e7e7(%rip), %xmm1    # 0xa5d18
ucomisd %xmm0, %xmm1
seta %al
movl %eax, (%r15,%rbx,4)
incq %rbx
cmpq %rbx, %r13
jne 0x37516
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 0x3735e
movl %eax, %ebp
testl %r13d, %r13d
jle 0x37625
xorl %r13d, %r13d
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %r12d, %r12d
movq 0x30(%rsp), %r14
movl $0x1, %eax
subl (%r15,%r13,4), %eax
movl %eax, (%r15,%r13,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 0x3735e
cmpl %ebp, %eax
cmovll %eax, %ebp
movl $0x1, %eax
cmovll %eax, %r12d
cmovll %r13d, %ebx
subl (%r15,%r13,4), %eax
movl %eax, (%r15,%r13,4)
incq %r13
cmpq %r14, %r13
jne 0x3758f
testl %r12d, %r12d
je 0x37625
movslq %ebx, %rax
movl $0x1, %ecx
subl (%r15,%rax,4), %ecx
xorl %r13d, %r13d
movl %ecx, (%r15,%rax,4)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl $0x0, %r12d
movq 0x30(%rsp), %r14
testl %r14d, %r14d
jg 0x3758f
cmpl 0x28(%rsp), %ebp
movq 0x60(%rsp), %rbx
jge 0x37646
movq 0x40(%rsp), %rdi
movq %r15, %rsi
movq 0x58(%rsp), %rdx
callq 0x4310
movl %ebp, 0x28(%rsp)
incl %ebx
cmpl 0x3c(%rsp), %ebx
movq 0x30(%rsp), %r13
leaq 0xa0(%rsp), %r14
jne 0x3750a
movq 0x50(%rsp), %r12
movq %r12, %rdi
callq 0x7c32b
testl %r13d, %r13d
movq 0x40(%rsp), %rbp
jle 0x376a1
xorl %ebx, %ebx
movq (%r14), %r14
cmpl $0x0, (%rbp,%rbx,4)
je 0x37695
movq %r14, %rdi
callq 0x7be1e
movq %r12, %rdi
movq %rax, %rsi
callq 0x7c9c6
addq $0x30, %r14
incq %rbx
cmpq %rbx, %r13
jne 0x37678
movq %r15, %rdi
callq 0x3a180
movq %rbp, %rdi
callq 0x3a180
movq %r12, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq