// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x450, %rsp            # imm = 0x450
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq 0x403c(%rip), %rdi      # 0x10376
movb $0x0, %al
callq 0x20a0
movq 0x7c78(%rip), %rax      # 0x13fc0
movq (%rax), %rdi
callq 0x2130
movq -0x10(%rbp), %rdi
callq 0xc6c0
leaq -0x410(%rbp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x20b0
movsd 0x3e84(%rip), %xmm0     # 0x101f8
movsd %xmm0, -0x418(%rbp)
movl $0xffffffff, -0x420(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x41c(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x424(%rbp)
cmpl $0x100, -0x424(%rbp)    # imm = 0x100
jge 0xc468
movslq -0x424(%rbp), %rax
cmpl $0x0, -0x410(%rbp,%rax,4)
jne 0xc452
movl -0x424(%rbp), %eax
leaq -0x430(%rbp), %rdi
movzbl %al, %esi
callq 0xb050
movq -0x10(%rbp), %rdi
leaq -0x430(%rbp), %rsi
callq 0xc950
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xbf90
movsd %xmm0, -0x438(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x448(%rbp)
movq -0x10(%rbp), %rdi
callq 0xc6a0
movq -0x448(%rbp), %rdi
movl %eax, %esi
subl $0x1, %esi
callq 0xcb80
movsd -0x438(%rbp), %xmm1
movsd -0x418(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xc450
movsd -0x438(%rbp), %xmm0
movsd %xmm0, -0x418(%rbp)
movl -0x424(%rbp), %eax
movl %eax, -0x41c(%rbp)
jmp 0xc452
jmp 0xc454
movl -0x424(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x424(%rbp)
jmp 0xc39a
cmpl $-0x1, -0x41c(%rbp)
je 0xc4a8
movl -0x41c(%rbp), %eax
leaq -0x430(%rbp), %rdi
movzbl %al, %esi
callq 0xb050
movq -0x10(%rbp), %rdi
leaq -0x430(%rbp), %rsi
callq 0xc950
movslq -0x41c(%rbp), %rax
movl $0x1, -0x410(%rbp,%rax,4)
movl $0x0, -0x424(%rbp)
movl -0x424(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0xc56e
movq -0x10(%rbp), %rdi
movl -0x424(%rbp), %esi
movq -0x10(%rbp), %rax
movl 0x10(%rax), %edx
subl $0x1, %edx
callq 0xcc30
movq -0x10(%rbp), %rax
movl 0x10(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xbf90
movsd %xmm0, -0x440(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x10(%rax), %esi
subl $0x1, %esi
movl -0x424(%rbp), %edx
callq 0xcc30
movsd -0x440(%rbp), %xmm1
movsd -0x418(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xc558
movsd -0x440(%rbp), %xmm0
movsd %xmm0, -0x418(%rbp)
movl -0x424(%rbp), %eax
movl %eax, -0x420(%rbp)
jmp 0xc55a
movl -0x424(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x424(%rbp)
jmp 0xc4b2
cmpl $-0x1, -0x420(%rbp)
je 0xc5a3
movq -0x10(%rbp), %rdi
movl -0x420(%rbp), %esi
callq 0xc870
movzbl (%rax), %eax
movl $0x0, -0x410(%rbp,%rax,4)
movq -0x10(%rbp), %rdi
movl -0x420(%rbp), %esi
callq 0xcb80
jmp 0xc5a5
movb $0x1, %al
cmpl $-0x1, -0x41c(%rbp)
movb %al, -0x449(%rbp)
jne 0xc5c6
cmpl $-0x1, -0x420(%rbp)
setne %al
movb %al, -0x449(%rbp)
movb -0x449(%rbp), %al
testb $0x1, %al
jne 0xc37c
leaq 0x3ce8(%rip), %rdi      # 0x102c3
movb $0x0, %al
callq 0x20a0
movq -0x10(%rbp), %rdi
leaq -0x138d(%rip), %rsi     # 0xb260
callq 0xcd80
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xc1f0
addq $0x450, %rsp            # imm = 0x450
popq %rbp
retq
nopl (%rax,%rax)