// File: /workspace/github_c_makefile_star2_O2/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 0x28969(%rip), %rsi     # 0x2ad60
pushq $0xc
popq %rcx
leaq 0x18(%rsp), %rdi
rep  movsq (%rsi), %es:(%rdi)
movsd 0x20bfe(%rip), %xmm0    # 0x23008
movq $0x0, 0x8(%rsp)
leaq 0x20bff(%rip), %r13     # 0x23019
movq 0x28bb7(%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 0x2444
movq (%rbx), %r15
jmp 0x242d
cmpl $-0x1, %eax
movsd 0x10(%rsp), %xmm0
je 0x2481
cmpl $0x65, %eax
je 0x2477
cmpl $0x6c, %eax
jne 0x245e
movq (%rbx), %r14
jmp 0x242d
cmpl $0x74, %eax
jne 0x25c0
movq (%rbx), %rdi
xorl %esi, %esi
callq 0x2100
cvtss2sd %xmm0, %xmm0
jmp 0x2427
movq (%rbx), %rax
movq %rax, 0x8(%rsp)
jmp 0x2427
testq %r15, %r15
movq 0x8(%rsp), %rbx
je 0x25a4
testq %r14, %r14
je 0x25a4
testq %rbx, %rbx
je 0x25a4
leaq 0x20bbe(%rip), %rdi     # 0x23066
xorl %eax, %eax
callq 0x20e0
movq %r15, %rdi
callq 0x2e8e
movq %rax, %r15
movq (%rax), %rsi
movq 0x8(%rax), %rdx
leaq 0x20bae(%rip), %rdi     # 0x23076
xorl %eax, %eax
callq 0x20e0
leaq 0x20bee(%rip), %rdi     # 0x230c4
callq 0x2050
movq %r14, %rdi
movq %rbx, %rsi
callq 0x41c3
movq %rax, %rbx
xorps %xmm0, %xmm0
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x24fd
movsd %xmm1, 0x30(%rbx)
movq %rbx, %rdi
callq 0x45ed
leaq 0x18(%rsp), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3b1b
movq %rax, %r14
movsd (%rax), %xmm0
leaq 0x20b69(%rip), %rdi     # 0x2308c
movb $0x1, %al
callq 0x20e0
leaq 0x20b83(%rip), %r12     # 0x230b4
xorl %r13d, %r13d
cmpq %r13, 0x20(%rbx)
jbe 0x2552
movq 0x8(%r14), %rax
movsbl (%rax,%r13), %esi
movq %r12, %rdi
xorl %eax, %eax
callq 0x20e0
incq %r13
jmp 0x2534
leaq 0x20b5f(%rip), %rdi     # 0x230b8
xorl %eax, %eax
callq 0x20e0
movq 0x28a59(%rip), %rax     # 0x2afc0
movq (%rax), %rdi
callq 0x21c0
movq %r15, %rdi
callq 0x2af6
movq %rbx, %rdi
callq 0x458b
movq %r14, %rdi
callq 0x46be
leaq 0x20b53(%rip), %rdi     # 0x230e1
callq 0x2050
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x28a4d(%rip), %rax     # 0x2aff8
movq (%rax), %rcx
leaq 0x20a6d(%rip), %rdi     # 0x23022
pushq $0x43
popq %rsi
pushq $0x1
popq %rdx
callq 0x2290
pushq $0x1
popq %rdi
callq 0x2280