// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xc8, %rsp
movl $0x0, 0xc4(%rsp)
movl %edi, 0xc0(%rsp)
movq %rsi, 0xb8(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x23a0
movq $0x0, 0x40(%rsp)
movq $0x0, 0x38(%rsp)
movq $0x0, 0x30(%rsp)
movsd 0x21bfa(%rip), %xmm0    # 0x24008
movsd %xmm0, 0x28(%rsp)
movl 0xc0(%rsp), %edi
movq 0xb8(%rsp), %rsi
leaq 0x21c37(%rip), %rdx     # 0x24061
callq 0x2220
movl %eax, 0x24(%rsp)
cmpl $-0x1, %eax
je 0x24c5
movl 0x24(%rsp), %eax
addl $-0x63, %eax
movl %eax, %ecx
movq %rcx, 0x8(%rsp)
subl $0x11, %eax
ja 0x24b6
movq 0x8(%rsp), %rax
leaq 0x21bb5(%rip), %rcx     # 0x24010
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x28b6d(%rip), %rax     # 0x2afd8
movq (%rax), %rax
movq %rax, 0x40(%rsp)
jmp 0x24c0
movq 0x28b5c(%rip), %rax     # 0x2afd8
movq (%rax), %rax
movq %rax, 0x38(%rsp)
jmp 0x24c0
movq 0x28b4b(%rip), %rax     # 0x2afd8
movq (%rax), %rax
movq %rax, 0x30(%rsp)
jmp 0x24c0
movq 0x28b3a(%rip), %rax     # 0x2afd8
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x20e0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x28(%rsp)
jmp 0x24c0
movl $0x1, %edi
callq 0x2260
jmp 0x2414
cmpq $0x0, 0x40(%rsp)
je 0x24dd
cmpq $0x0, 0x38(%rsp)
je 0x24dd
cmpq $0x0, 0x30(%rsp)
jne 0x24ff
movq 0x28b14(%rip), %rax     # 0x2aff8
movq (%rax), %rdi
leaq 0x21b7c(%rip), %rsi     # 0x2406a
movb $0x0, %al
callq 0x2130
movl $0x1, %edi
callq 0x2260
leaq 0x21ba8(%rip), %rdi     # 0x240ae
movb $0x0, %al
callq 0x20c0
movq 0x40(%rsp), %rdi
callq 0x36f0
movq %rax, 0xb0(%rsp)
movq 0xb0(%rsp), %rax
movq (%rax), %rsi
movq 0xb0(%rsp), %rax
movq 0x8(%rax), %rdx
leaq 0x21b81(%rip), %rdi     # 0x240be
movb $0x0, %al
callq 0x20c0
leaq 0x21b89(%rip), %rdi     # 0x240d4
movb $0x0, %al
callq 0x20c0
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x56f0
movq %rax, 0xa8(%rsp)
movsd 0x28(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x258b
movsd 0x28(%rsp), %xmm0
movq 0xa8(%rsp), %rax
movsd %xmm0, 0x30(%rax)
movq 0xa8(%rsp), %rdi
callq 0x5d00
movq 0xa8(%rsp), %rdi
movq 0xb0(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x4d60
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movsd (%rax), %xmm0
leaq 0x21b2b(%rip), %rdi     # 0x240f2
movb $0x1, %al
callq 0x20c0
movl $0x0, 0x14(%rsp)
movslq 0x14(%rsp), %rax
movq 0xa8(%rsp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x2616
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
movslq 0x14(%rsp), %rcx
movsbl (%rax,%rcx), %esi
leaq 0x21b18(%rip), %rdi     # 0x2411a
movb $0x0, %al
callq 0x20c0
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x25d6
leaq 0x21b01(%rip), %rdi     # 0x2411e
movb $0x0, %al
callq 0x20c0
movq 0x28995(%rip), %rax     # 0x2afc0
movq (%rax), %rdi
callq 0x21a0
movq 0xb0(%rsp), %rdi
callq 0x2fb0
movq 0xa8(%rsp), %rdi
callq 0x5c50
movq 0x18(%rsp), %rdi
callq 0x5e60
leaq 0x21acc(%rip), %rdi     # 0x2412a
movb $0x0, %al
callq 0x20c0
xorl %eax, %eax
addq $0xc8, %rsp
retq
nop