// File: /workspace/github_c_makefile_star2_O3/UCLA-StarAI[P]TrimBN/src/main.c
// Function: main
int main(int argc, char** argv) {
  Fnf* fnf;
  SearchData* data;
  SddCompilerOptions options = sdd_default_opt(); // default options

  // Read input options
  char *cnf_filename = NULL, *lmap_filename = NULL, *input_filename = NULL;
  SddWmc threshold = -1.0;
  int option;
  while ((option = getopt(argc, argv, "c:l:e:t:")) != -1) {
    switch (option) {
      case 'c':
        cnf_filename = optarg;
        break;
      case 'l':
        lmap_filename = optarg;
        break;
      case 'e':
        input_filename = optarg;
        break;
      case 't':
        threshold = strtof(optarg, NULL);
        break;
      default:
        exit(1);
    }
  }
  if (cnf_filename == NULL || lmap_filename == NULL || input_filename == NULL) {
    fprintf(stderr,
      "Must provide names of CNF, lmap, and feature selection input files\n");
    exit(1);
  }

  printf("\nreading cnf...");
  fnf = read_cnf(cnf_filename);
  printf("vars=%"PRIlitS" clauses=%"PRIsS"\n",fnf->var_count,fnf->litset_count);

  printf("\nreading esdp search data...\n");
  data = read_search_data(lmap_filename, input_filename);

  // Overwrite threshold if explicitly given
  if (threshold > 0) {
    data->threshold = threshold;
  }

  print_search_data(data);
  
  SearchResult* result = search_best_subset(data, fnf, &options);
  
  printf("\nbest ECA: %f\nbest subset of features: ", result->best_score);
  for (int i = 0; i < data->num_features; i++) {
    printf("%d,", result->best_subset[i]);
  }

  printf("\nfreeing..."); fflush(stdout);
  free_fnf(fnf);
  free_search_data(data);
  free_search_result(result);
  printf("done\n"); 

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %r12
movl %edi, %ebp
leaq 0x288f7(%rip), %rsi     # 0x2ad60
leaq 0x18(%rsp), %rdi
movl $0xc, %ecx
rep  movsq (%rsi), %es:(%rdi)
movsd 0x20b8a(%rip), %xmm0    # 0x23008
movq $0x0, 0x8(%rsp)
leaq 0x20b8b(%rip), %r13     # 0x23019
movq 0x28b43(%rip), %rbx     # 0x2afd8
xorl %r14d, %r14d
xorl %r15d, %r15d
movsd %xmm0, 0x10(%rsp)
movl %ebp, %edi
movq %r12, %rsi
movq %r13, %rdx
callq 0x2240
cmpl $0x63, %eax
jne 0x24b8
movq (%rbx), %r15
jmp 0x24a1
cmpl $0x6b, %eax
jle 0x24c7
cmpl $0x6c, %eax
jne 0x24e5
movq (%rbx), %r14
jmp 0x24a1
cmpl $-0x1, %eax
movsd 0x10(%rsp), %xmm0
je 0x24fe
cmpl $0x65, %eax
jne 0x2626
movq (%rbx), %rax
movq %rax, 0x8(%rsp)
jmp 0x249b
cmpl $0x74, %eax
jne 0x2626
movq (%rbx), %rdi
xorl %esi, %esi
callq 0x2100
cvtss2sd %xmm0, %xmm0
jmp 0x249b
testq %r15, %r15
movq 0x8(%rsp), %rbx
je 0x2630
testq %r14, %r14
je 0x2630
testq %rbx, %rbx
je 0x2630
leaq 0x20b41(%rip), %rdi     # 0x23066
xorl %eax, %eax
callq 0x20e0
movq %r15, %rdi
callq 0x30a0
movq %rax, %r15
movq (%rax), %rsi
movq 0x8(%rax), %rdx
leaq 0x20b31(%rip), %rdi     # 0x23076
xorl %eax, %eax
callq 0x20e0
leaq 0x20b71(%rip), %rdi     # 0x230c4
callq 0x2050
movq %r14, %rdi
movq %rbx, %rsi
callq 0x49de
movq %rax, %rbx
xorps %xmm0, %xmm0
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x257a
movsd %xmm1, 0x30(%rbx)
movq %rbx, %rdi
callq 0x4e2e
leaq 0x18(%rsp), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4310
movq %rax, %r14
movsd (%rax), %xmm0
leaq 0x20aec(%rip), %rdi     # 0x2308c
movb $0x1, %al
callq 0x20e0
cmpq $0x0, 0x20(%rbx)
je 0x25d4
leaq 0x20aff(%rip), %r12     # 0x230b4
xorl %r13d, %r13d
movq 0x8(%r14), %rax
movsbl (%rax,%r13), %esi
movq %r12, %rdi
xorl %eax, %eax
callq 0x20e0
incq %r13
cmpq %r13, 0x20(%rbx)
ja 0x25b8
leaq 0x20add(%rip), %rdi     # 0x230b8
xorl %eax, %eax
callq 0x20e0
movq 0x289d7(%rip), %rax     # 0x2afc0
movq (%rax), %rdi
callq 0x21c0
movq %r15, %rdi
callq 0x2c82
movq %rbx, %rdi
callq 0x4dc3
movq %r14, %rdi
callq 0x4f12
leaq 0x20ad1(%rip), %rdi     # 0x230e1
callq 0x2050
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %edi
callq 0x2280
callq 0x22e0
nopl (%rax)