// File: /workspace/github_c_makefile_star2_O1/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, %r14d
movq %rsi, %r12
movq %rdi, 0x50(%rsp)
leaq 0xa0(%rsp), %rax
movslq 0x10(%rax), %rbp
movl %ebp, %r13d
shlq $0x2, %rbp
leaq 0x6fc50(%rip), %rsi     # 0xa6765
movq %rbp, %rdi
movl $0x4, %edx
callq 0x390f5
movq %rax, %r15
movq %rbp, 0x58(%rsp)
movq %rbp, %rdi
leaq 0x6fc31(%rip), %rsi     # 0xa6765
movl $0x5, %edx
callq 0x390f5
movq %rax, 0x38(%rsp)
movl %ebx, 0x34(%rsp)
testl %ebx, %ebx
jle 0x36cbd
movl $0x7fffffff, 0x2c(%rsp) # imm = 0x7FFFFFFF
xorl %ebx, %ebx
movq %r13, 0x48(%rsp)
movq %r12, 0x40(%rsp)
movl %r14d, 0x30(%rsp)
movq %rbx, 0x60(%rsp)
testl %r13d, %r13d
jle 0x36ba2
xorl %ebx, %ebx
xorpd %xmm0, %xmm0
movsd 0x6b9a0(%rip), %xmm1    # 0xa2520
callq 0x39f62
xorl %eax, %eax
movsd 0x6c189(%rip), %xmm1    # 0xa2d18
ucomisd %xmm0, %xmm1
seta %al
movl %eax, (%r15,%rbx,4)
incq %rbx
cmpq %rbx, %r13
jne 0x36b74
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 %r12, %rsi
movl %r14d, %edx
callq 0x3698a
movl %eax, %ebp
testl %r13d, %r13d
jle 0x36c71
xorl %r13d, %r13d
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %ebx, %ebx
leaq 0xa0(%rsp), %r14
movl $0x1, %eax
subl (%r15,%r13,4), %eax
movl %eax, (%r15,%r13,4)
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 0x40(%rsp), %rsi
movl 0x30(%rsp), %edx
callq 0x3698a
movl $0x1, %ecx
cmpl %ebp, %eax
cmovll %eax, %ebp
cmovll %ecx, %ebx
cmovll %r13d, %r12d
movl $0x1, %eax
subl (%r15,%r13,4), %eax
movl %eax, (%r15,%r13,4)
incq %r13
cmpq %r13, 0x48(%rsp)
jne 0x36bf3
testl %ebx, %ebx
sete %cl
movslq %r12d, %rax
movq 0x48(%rsp), %r13
movl 0x30(%rsp), %r14d
movq 0x40(%rsp), %r12
jmp 0x36c7a
movq $-0x1, %rax
movb $0x1, %cl
testb %cl, %cl
jne 0x36c90
movl $0x1, %ecx
subl (%r15,%rax,4), %ecx
movl %ecx, (%r15,%rax,4)
jmp 0x36bd7
cmpl 0x2c(%rsp), %ebp
movq 0x60(%rsp), %rbx
jge 0x36cb1
movq 0x38(%rsp), %rdi
movq %r15, %rsi
movq 0x58(%rsp), %rdx
callq 0x4310
movl %ebp, 0x2c(%rsp)
incl %ebx
cmpl 0x34(%rsp), %ebx
jne 0x36b68
movq 0x50(%rsp), %r12
movq %r12, %rdi
callq 0x7aa63
testl %r13d, %r13d
leaq 0xa0(%rsp), %r14
movq 0x38(%rsp), %rbp
jle 0x36d07
xorl %ebx, %ebx
movq (%r14), %r14
cmpl $0x0, (%rbp,%rbx,4)
je 0x36cfb
movq %r14, %rdi
callq 0x7a54a
movq %r12, %rdi
movq %rax, %rsi
callq 0x7b0fb
addq $0x30, %r14
incq %rbx
cmpq %rbx, %r13
jne 0x36cde
movq %r15, %rdi
callq 0x39194
movq %rbp, %rdi
callq 0x39194
movq %r12, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq