// File: /workspace/github_c_makefile_star2_O2/negge[P]xlink/src/paq.c
// Function: xlink_modeler_search
void xlink_modeler_search(xlink_modeler *mod, xlink_list *models) {
  int contains[256];
  double best;
  int add_index;
  int del_index;
  printf("Searching for best context... ");
  fflush(stdout);
  xlink_list_empty(models);
  memset(contains, 0, sizeof(contains));
  best = DBL_MAX;
  do {
    int i;
    xlink_model model;
    add_index = del_index = -1;
    /* Try to add a model to the working set */
    for (i = 0; i < 256; i++) {
      if (!contains[i]) {
        double entropy;
        xlink_model_init(&model, i);
        xlink_list_add(models, &model);
        entropy = xlink_modeler_get_entropy(mod, models);
        xlink_list_remove(models, xlink_list_length(models) - 1);
        if (entropy < best) {
          best = entropy;
          add_index = i;
        }
      }
    }
    if (add_index != -1) {
      xlink_model_init(&model, add_index);
      xlink_list_add(models, &model);
      contains[add_index] = 1;
    }
    /* Try to remove a model from the working set */
    for (i = 0; i < models->length; i++) {
      double entropy;
      xlink_list_swap(models, i, models->length - 1);
      models->length--;
      entropy = xlink_modeler_get_entropy(mod, models);
      models->length++;
      xlink_list_swap(models, models->length - 1, i);
      if (entropy < best) {
        best = entropy;
        del_index = i;
      }
    }
    if (del_index != -1) {
      contains[xlink_list_get_model(models, del_index)->mask] = 0;
      xlink_list_remove(models, del_index);
    }
  }
  while (add_index != -1 || del_index != -1);
  printf("done\n");
  xlink_list_sort(models, model_comp);
  xlink_modeler_print(mod, models);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x428, %rsp            # imm = 0x428
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x2f58(%rip), %rdi      # 0xb055
xorl %eax, %eax
callq 0x20c0
movq 0x7eb5(%rip), %rax      # 0xffc0
movq (%rax), %rdi
callq 0x2160
movq %rbx, %rdi
callq 0x82db
leaq 0x20(%rsp), %rdi
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x20d0
movsd 0x2db4(%rip), %xmm0     # 0xaee8
movsd %xmm0, (%rsp)
pushq $-0x1
popq %rbp
leaq 0x14(%rsp), %r15
xorl %r12d, %r12d
movl %ebp, %r13d
cmpq $0x100, %r12            # imm = 0x100
je 0x81b4
cmpl $0x0, 0x20(%rsp,%r12,4)
jne 0x81af
movzbl %r12b, %esi
movq %r15, %rdi
callq 0x76f0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x838e
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7e39
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
callq 0x82d7
leal -0x1(%rax), %esi
movq %rbx, %rdi
callq 0x84d1
movsd (%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
ucomisd %xmm1, %xmm0
cmoval %r12d, %r13d
minsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
incq %r12
jmp 0x8147
cmpl $-0x1, %r13d
je 0x81dc
movzbl %r13b, %esi
movq %r15, %rdi
callq 0x76f0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x838e
movslq %r13d, %rax
movl $0x1, 0x20(%rsp,%rax,4)
xorl %r12d, %r12d
movl 0x10(%rbx), %edx
cmpl %edx, %r12d
jge 0x823d
decl %edx
movq %rbx, %rdi
movl %r12d, %esi
callq 0x8544
decl 0x10(%rbx)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7e39
movsd %xmm0, 0x8(%rsp)
movl 0x10(%rbx), %esi
leal 0x1(%rsi), %eax
movl %eax, 0x10(%rbx)
movq %rbx, %rdi
movl %r12d, %edx
callq 0x8544
movsd (%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
ucomisd %xmm1, %xmm0
cmoval %r12d, %ebp
minsd %xmm0, %xmm1
incl %r12d
movsd %xmm1, (%rsp)
jmp 0x81df
cmpl $-0x1, %ebp
je 0x825e
movq %rbx, %rdi
movl %ebp, %esi
callq 0x831b
movzbl (%rax), %eax
andl $0x0, 0x20(%rsp,%rax,4)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x84d1
andl %r13d, %ebp
cmpl $-0x1, %ebp
pushq $-0x1
popq %rbp
jne 0x8141
leaq 0x2e12(%rip), %rdi      # 0xb086
callq 0x2060
leaq -0xa90(%rip), %rsi      # 0x77f0
movq %rbx, %rdi
callq 0x861f
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7fe9
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)