// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x68(%rbp)
movq %rdi, -0x60(%rbp)
leaq 0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
movq %rsi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
movl %ecx, -0x10(%rbp)
movl 0x10(%rax), %eax
movl %eax, -0x1c(%rbp)
movl $0x7fffffff, -0x24(%rbp) # imm = 0x7FFFFFFF
movslq -0x1c(%rbp), %rdi
shlq $0x2, %rdi
leaq 0x9701b(%rip), %rsi     # 0xe633c
movl $0x4, %edx
callq 0x52d70
movq %rax, -0x38(%rbp)
movslq -0x1c(%rbp), %rdi
shlq $0x2, %rdi
leaq 0x96ffe(%rip), %rsi     # 0xe633c
movl $0x5, %edx
callq 0x52d70
movq %rax, -0x40(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x4f509
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x4f3bf
xorps %xmm0, %xmm0
movsd 0x92c9f(%rip), %xmm1    # 0xe2018
callq 0x545a0
movsd %xmm0, -0x48(%rbp)
movsd 0x9362d(%rip), %xmm0    # 0xe29b8
ucomisd -0x48(%rbp), %xmm0
jbe 0x4f3a3
movq -0x38(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl $0x1, (%rax,%rcx,4)
jmp 0x4f3b2
movq -0x38(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
jmp 0x4f3b4
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x4f366
movq -0x58(%rbp), %rcx
movq -0x38(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl -0xc(%rbp), %edx
movq 0x20(%rcx), %r8
movq %rsp, %rax
movq %r8, 0x20(%rax)
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x4f150
movl %eax, -0x28(%rbp)
movl $0x1, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
je 0x4f4d6
movl $0x0, -0x30(%rbp)
movl $0xffffffff, -0x20(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x4f4b0
movq -0x58(%rbp), %rcx
movq -0x38(%rbp), %rax
movslq -0x18(%rbp), %rdx
movl $0x1, %esi
subl (%rax,%rdx,4), %esi
movq -0x38(%rbp), %rax
movslq -0x18(%rbp), %rdx
movl %esi, (%rax,%rdx,4)
movq -0x38(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl -0xc(%rbp), %edx
movq 0x20(%rcx), %r8
movq %rsp, %rax
movq %r8, 0x20(%rax)
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x4f150
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x4f487
movl -0x2c(%rbp), %eax
movl %eax, -0x28(%rbp)
movl $0x1, -0x30(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x38(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl $0x1, %edx
subl (%rax,%rcx,4), %edx
movq -0x38(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x4f415
cmpl $0x0, -0x30(%rbp)
je 0x4f4d1
movq -0x38(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl $0x1, %edx
subl (%rax,%rcx,4), %edx
movq -0x38(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x4f3f6
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x4f4f9
movl -0x28(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movslq -0x1c(%rbp), %rdx
shlq $0x2, %rdx
callq 0x42b0
jmp 0x4f4fb
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x4f353
movq -0x68(%rbp), %rdi
callq 0xade30
movq -0x58(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x4f568
movq -0x40(%rbp), %rax
movslq -0x14(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x4f54f
movq -0x50(%rbp), %rdi
callq 0xad610
movq -0x68(%rbp), %rdi
movq %rax, %rsi
callq 0xaea30
jmp 0x4f551
movq -0x50(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x50(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x4f524
movq -0x38(%rbp), %rdi
callq 0x52e80
movq -0x40(%rbp), %rdi
callq 0x52e80
movq -0x60(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)