// File: /workspace/github_cpp_makefile_star2_O2/biotomas[P]ipasir/app/icnf/icnf.c
// Function: main
int main (int argc, char ** argv) {
  int res = 0, i, ch, lit, max_var = 0, assumption;
  char *line = NULL, *line_content;
  size_t len = 0, parsed, solves = 0, parsed_assumptions = 0, core_size = 0;
  ssize_t read;
  char * sig;
  double pre_time, post_time;
  int * current_assumptions = NULL;

  for (i = 1; i < argc; i++) {
    if (!strcmp (argv[i], "-h")) usage ();
    else if (argv[i][0] == '-') die ("invalid '%s' (try '-h')", argv[i]);
    else if (name) die ("multiple files '%s' and '%s'", name, argv[i]);
    else name = argv[i];
  }

  solver = ipasir_init ();

  sig = strdup (ipasir_signature (solver));
  msg ("icnf generic IPASIR Solver");
  msg ("initialized '%s'", sig);

  if (name) {
    closefile = 2;
    if (hasuffix (name, ".bz2")) file = pipeit (name, "bzcat %s");
    else if (hasuffix (name, ".gz")) file = pipeit (name, "gunzip -c %s");
    else file = fopen (name, "r"), closefile = 1;
    if (!file) die ("can not read '%s'", name);
  } else name = "<stdin>", file = stdin;

  msg ("reading '%s'", name);

  while (NEXT () == 'c') {
    while (NEXT () != '\n')
      if (ch == EOF)
    perr ("unexpected end-of-file in comment");
  }
  if (ch != 'p') perr ("expected 'p' or 'c'");
  if (fscanf (file, " inccnf") != 0)
    perr ("invalid header");

  msg ("found 'p inccnf' header at line %d", lineno);
  lit = 0;

  while ((read = getline(&line, &len, file)) != -1) {
    lineno ++;
    /* skip line breaks */
    if( line[0] == '\n') continue;

    /* skip short lines */
    if( read < 1 ) die ("found an empty line in the file");

    /* skip comments */
    if( line[0] == 'c' ) continue;

    line_content = line;
    parsed = 0;
    assumption = 0;

    if( line[0] == 'a' ) {
      if(read < 2) die("expected assumption vector to solve in '%s' (line %d)", line, lineno);
      parsed = 2;
      line_content = &(line[parsed]);
      assumption = 1;
      parsed_assumptions = 0;
    }

    while ( (i = sscanf (line_content, "%d", &lit)) == 1) {

      /* track highest variable */
      if (lit < 0) max_var = max_var > -lit ? max_var : -lit;
      else max_var = max_var > lit ? max_var : lit;

      /* in case we're on the assumption line, assume the literals and solver */
      if (!assumption) {
        ipasir_add (solver, lit);
      }
      else if (lit)
      {
        ipasir_assume(solver, lit);
        /* track variables to be assumed */
        if (current_assumptions == NULL || parsed_assumptions >= max_var)
          current_assumptions = realloc(current_assumptions, sizeof(int) * (max_var > parsed_assumptions ? max_var : parsed_assumptions));
        current_assumptions[parsed_assumptions] = lit;
        parsed_assumptions ++;
      }

      /* stop at the end of the clause, do not read the rest of the line */
      if (!lit) break;
      while (parsed < read && line[parsed] != ' ') ++parsed;
      /* actually skip space */
       ++parsed;
      if (parsed >= read) break;
      line_content = &(line[parsed]);
    }

    if (i != 1) die ("expected literals or a clause delimiter on line %s (line %d), but did not find any\n", lineno);

    if(assumption) {
      core_size = 0;
      solves ++;
      msg ("solved assumptions %lu (%d assumptions) on line %d ...", solves, parsed_assumptions, lineno);
      pre_time = getime ();
      res = ipasir_solve(solver);
      post_time = getime ();

      /* print model, or unsat core */
      if (res == 10)
      {
        if (max_var) {
          fflush (stdout);
          printf ("s SATISFIABLE\n");
          fputc ('v', stdout);
          for (i = 1; i <= max_var; i++) {
          if (!(i % 8)) fputs ("\nv", stdout);
            printf (" %d", ipasir_val (solver, i));
          }
          fputc ('\n', stdout);
        }
        printf ("v 0\n");
      } else if (res == 20) {
        core_size = 0;
        fflush (stdout);
        printf ("s UNSATISFIABLE\n");
        fputc ('v', stdout);
        for( i=0; i < parsed_assumptions; ++i )
        {
          if (ipasir_failed(solver, current_assumptions[i] < 0 ? -current_assumptions[i] : current_assumptions[i]))
          {
            core_size ++;
            printf (" %d", current_assumptions[i]);
          }
        }
        fputc ('\n', stdout);
        printf ("v 0\n");
      }

      msg ("solved assumptions %lu with results %d and unsat core of %u in %.2f seconds", solves, res, core_size, post_time - pre_time);
    }
  }

  if (!feof (file)) perr ("end of file is not reached yet");
  if (current_assumptions) free(current_assumptions);
  if (closefile == 2) pclose (file);
  if (closefile == 1) fclose (file);

  /* cleanup */
  fflush (stdout);
  ipasir_release (solver);
  msg ("released '%s' after %.2f seconds", sig, getime ());
  msg ("exit %d", res);
  free (sig);
  return res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
andq $0x0, 0x38(%rsp)
andq $0x0, 0x50(%rsp)
movq 0xba73(%rip), %rax      # 0xe1c0
movslq %edi, %rcx
pushq $0x1
popq %rdi
cmpq %rcx, %rdi
jge 0x277d
movq (%rsi,%rdi,8), %rdx
cmpb $0x2d, (%rdx)
je 0x2d2c
testq %rax, %rax
jne 0x2d4b
movq %rdx, 0xba4b(%rip)      # 0xe1c0
incq %rdi
movq %rdx, %rax
jmp 0x2753
xorl %eax, %eax
callq 0x314c
movq %rax, 0xba3d(%rip)      # 0xe1c8
movq %rax, %rdi
xorl %eax, %eax
callq 0x3144
movq %rax, %rdi
callq 0x2300
movq %rax, %r15
leaq 0x689e(%rip), %rdi      # 0x9045
xorl %eax, %eax
callq 0x2e92
leaq 0x68ab(%rip), %rdi      # 0x9060
movq %r15, %rsi
xorl %eax, %eax
callq 0x2e92
movq 0xb9fa(%rip), %rbx      # 0xe1c0
testq %rbx, %rbx
je 0x27f1
movl $0x2, 0xb9fb(%rip)      # 0xe1d0
leaq 0x6895(%rip), %rsi      # 0x9071
movq %rbx, %rdi
callq 0x2f5d
testl %eax, %eax
je 0x2812
leaq 0x6887(%rip), %rsi      # 0x9076
jmp 0x2830
leaq 0x68aa(%rip), %rsi      # 0x90a2
movq %rsi, 0xb9c1(%rip)      # 0xe1c0
movq 0xb7d2(%rip), %rax      # 0xdfd8
movq (%rax), %rax
movq %rax, 0xb9c8(%rip)      # 0xe1d8
jmp 0x284f
leaq 0x6866(%rip), %rsi      # 0x907f
movq %rbx, %rdi
callq 0x2f5d
testl %eax, %eax
je 0x2d07
leaq 0x6853(%rip), %rsi      # 0x9083
movq %rbx, %rdi
callq 0x2fa2
movq %rax, 0xb999(%rip)      # 0xe1d8
movq 0xb97a(%rip), %rsi      # 0xe1c0
testq %rax, %rax
je 0x2db3
leaq 0x6854(%rip), %rdi      # 0x90aa
xorl %eax, %eax
callq 0x2e92
movq 0xb974(%rip), %rdi      # 0xe1d8
callq 0x3000
cmpl $0x63, %eax
jne 0x2892
movq 0xb963(%rip), %rdi      # 0xe1d8
callq 0x3000
cmpl $0xa, %eax
je 0x285d
cmpl $-0x1, %eax
jne 0x286e
leaq 0x682c(%rip), %rdi      # 0x90b7
xorl %eax, %eax
callq 0x3013
cmpl $0x70, %eax
jne 0x2d5c
movq 0xb936(%rip), %rdi      # 0xe1d8
leaq 0x6844(%rip), %rsi      # 0x90ed
xorl %eax, %eax
callq 0x2310
testl %eax, %eax
jne 0x2d9b
movl 0xb8ea(%rip), %esi      # 0xe1a8
leaq 0x683f(%rip), %rdi      # 0x9104
xorl %eax, %eax
callq 0x2e92
leaq 0x10(%rsp), %rax
andl $0x0, (%rax)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x18(%rsp)
xorl %ebx, %ebx
movl $0x0, 0xc(%rsp)
movq $0x0, 0x20(%rsp)
leaq 0x38(%rsp), %r12
leaq 0x50(%rsp), %r13
movq 0xb8ce(%rip), %rdx      # 0xe1d8
movq %r12, %rdi
movq %r13, %rsi
callq 0x21e0
cmpq $-0x1, %rax
je 0x2c5d
movl 0xb883(%rip), %edx      # 0xe1a8
incl %edx
movl %edx, 0xb87b(%rip)      # 0xe1a8
movq 0x38(%rsp), %rsi
movb (%rsi), %bpl
cmpb $0xa, %bpl
je 0x2903
movq %rax, %r14
testq %rax, %rax
jle 0x2d79
cmpb $0x63, %bpl
je 0x2903
cmpb $0x61, %bpl
movq %r15, 0x48(%rsp)
jne 0x2975
cmpq $0x1, %r14
je 0x2dbc
addq $0x2, %rsi
pushq $0x2
popq %r15
movq $0x0, 0x18(%rsp)
jmp 0x2978
xorl %r15d, %r15d
movl %ebx, 0x14(%rsp)
movq %rsi, %rdi
leaq 0x679e(%rip), %rsi      # 0x9124
leaq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x2120
cmpl $0x1, %eax
jne 0x2d87
movl 0x10(%rsp), %r13d
movl %r13d, %r12d
negl %r12d
movl %r13d, %ebx
cmovnsl %r12d, %ebx
movl 0x14(%rsp), %eax
cmpl %ebx, %eax
cmovgl %eax, %ebx
cmpb $0x61, %bpl
jne 0x29f6
testl %r13d, %r13d
je 0x2a83
movq 0xb7fc(%rip), %rdi      # 0xe1c8
movl %r13d, %esi
callq 0x31a5
movl %ebx, 0x28(%rsp)
movl %ebx, %esi
cmpq $0x0, 0x20(%rsp)
movq 0x18(%rsp), %rax
je 0x2a0b
cmpq %rsi, %rax
jae 0x2a0b
movq %rax, %rbx
movq 0x20(%rsp), %rax
jmp 0x2a23
movq 0xb7cb(%rip), %rdi      # 0xe1c8
movl %r13d, %esi
callq 0x31a0
movl 0x10(%rsp), %ecx
jmp 0x2a3b
cmpq %rsi, %rax
cmovaq %rax, %rsi
shlq $0x2, %rsi
movq 0x20(%rsp), %rdi
movq %rax, %rbx
callq 0x22a0
movl 0x10(%rsp), %ecx
movq %rax, 0x20(%rsp)
movl %ecx, (%rax,%rbx,4)
incq %rbx
movq %rbx, 0x18(%rsp)
movl 0x28(%rsp), %ebx
testl %ecx, %ecx
je 0x2a72
movq 0x38(%rsp), %rsi
cmpq %r15, %r14
movq %r15, %rax
cmovaq %r14, %rax
cmpq %r15, %rax
je 0x2a5f
cmpb $0x20, (%rsi,%r15)
je 0x2a62
incq %r15
jmp 0x2a4e
movq %rax, %r15
incq %r15
cmpq %r14, %r15
jae 0x2a72
addq %r15, %rsi
jmp 0x2978
cmpb $0x61, %bpl
movq 0x48(%rsp), %r15
jne 0x28f9
jmp 0x2a88
movq 0x48(%rsp), %r15
movq 0x30(%rsp), %rsi
incq %rsi
movl 0xb712(%rip), %ecx      # 0xe1a8
leaq 0x6734(%rip), %rdi      # 0x91d1
movq %rsi, 0x30(%rsp)
movq 0x18(%rsp), %rdx
xorl %eax, %eax
callq 0x2e92
callq 0x30e8
movsd %xmm0, 0x28(%rsp)
movq 0xb708(%rip), %rdi      # 0xe1c8
callq 0x319b
movl %eax, %ebp
callq 0x30e8
cmpl $0x14, %ebp
movl %ebp, 0xc(%rsp)
je 0x2b7d
cmpl $0xa, %ebp
movq 0xb4dd(%rip), %rbp      # 0xdfc0
jne 0x2bff
movsd %xmm0, 0x40(%rsp)
testl %ebx, %ebx
je 0x2c58
movq (%rbp), %rdi
callq 0x2180
leaq 0x67f1(%rip), %rdi      # 0x92f8
callq 0x2270
movq (%rbp), %rsi
pushq $0x76
popq %rdi
callq 0x21d0
movl 0x14(%rsp), %eax
cmpl %r13d, %eax
cmovgl %eax, %r13d
cmpl %r12d, %r13d
cmovlel %r12d, %r13d
negl %r13d
pushq $0x1
popq %rax
movl %eax, %r14d
leaq 0x66ce(%rip), %r12      # 0x9208
leal (%r14,%r13), %eax
cmpl $0x1, %eax
je 0x2c0e
testb $0x7, %r14b
jne 0x2b59
movq (%rbp), %rsi
movq %r12, %rdi
callq 0x2170
movq 0xb668(%rip), %rdi      # 0xe1c8
movl %r14d, %esi
callq 0x31aa
leaq 0x65b4(%rip), %rdi      # 0x9123
movl %eax, %esi
xorl %eax, %eax
callq 0x2050
incl %r14d
jmp 0x2b3a
movsd %xmm0, 0x40(%rsp)
movq %r15, %r12
movq 0xb433(%rip), %rbp      # 0xdfc0
movq (%rbp), %rdi
callq 0x2180
leaq 0x674b(%rip), %rdi      # 0x92e8
callq 0x2270
movq (%rbp), %rsi
pushq $0x76
popq %rdi
callq 0x21d0
xorl %r15d, %r15d
xorl %r14d, %r14d
movq 0x20(%rsp), %r13
movq 0x18(%rsp), %rax
cmpq %r15, %rax
je 0x2bfa
movq 0xb5fe(%rip), %rdi      # 0xe1c8
movl (%r13,%r15,4), %eax
movl %eax, %esi
negl %esi
cmovsl %eax, %esi
callq 0x31af
testl %eax, %eax
je 0x2bf5
incq %r14
movl (%r13,%r15,4), %esi
leaq 0x6535(%rip), %rdi      # 0x9123
xorl %eax, %eax
callq 0x2050
incq %r15
jmp 0x2bb9
movq %r12, %r15
jmp 0x2c11
xorl %r14d, %r14d
movl 0xc(%rsp), %edx
movsd 0x28(%rsp), %xmm1
jmp 0x2c39
xorl %r14d, %r14d
movq (%rbp), %rsi
pushq $0xa
popq %rdi
callq 0x21d0
leaq 0x66e2(%rip), %rdi      # 0x9306
callq 0x2270
movl 0xc(%rsp), %edx
movsd 0x28(%rsp), %xmm1
movsd 0x40(%rsp), %xmm0
subsd %xmm1, %xmm0
leaq 0x65c7(%rip), %rdi      # 0x920b
movq 0x30(%rsp), %rsi
movq %r14, %rcx
movb $0x1, %al
callq 0x2e92
jmp 0x28f9
xorl %r14d, %r14d
jmp 0x2c1d
movq 0xb574(%rip), %rdi      # 0xe1d8
callq 0x2280
testl %eax, %eax
movq 0xb34e(%rip), %rbx      # 0xdfc0
movl 0xc(%rsp), %ebp
je 0x2da7
movq 0x20(%rsp), %rdi
callq 0x21b0
movl 0xb544(%rip), %eax      # 0xe1d0
cmpl $0x2, %eax
jne 0x2ca3
movq 0xb540(%rip), %rdi      # 0xe1d8
callq 0x2240
movl 0xb52d(%rip), %eax      # 0xe1d0
cmpl $0x1, %eax
jne 0x2cb4
movq 0xb529(%rip), %rdi      # 0xe1d8
callq 0x2130
movq (%rbx), %rdi
callq 0x2180
movq 0xb505(%rip), %rdi      # 0xe1c8
callq 0x3188
callq 0x30e8
leaq 0x65a2(%rip), %rdi      # 0x9276
movq %r15, %rsi
movb $0x1, %al
callq 0x2e92
leaq 0x65b2(%rip), %rdi      # 0x9297
movl %ebp, %esi
xorl %eax, %eax
callq 0x2e92
movq %r15, %rdi
callq 0x21b0
movl %ebp, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x63f4(%rip), %rsi      # 0x9102
movq %rbx, %rdi
callq 0x2190
movq %rax, 0xb4bb(%rip)      # 0xe1d8
movl $0x1, 0xb4a9(%rip)      # 0xe1d0
jmp 0x283f
cmpb $0x68, 0x1(%rdx)
jne 0x2d68
cmpb $0x0, 0x2(%rdx)
jne 0x2d68
leaq 0x65cb(%rip), %rdi      # 0x930a
callq 0x2270
xorl %edi, %edi
callq 0x21c0
leaq 0x62d6(%rip), %rdi      # 0x9028
movq %rax, %rsi
xorl %eax, %eax
callq 0x2dca
leaq 0x6376(%rip), %rdi      # 0x90d9
jmp 0x288b
leaq 0x62a1(%rip), %rdi      # 0x9010
movq %rdx, %rsi
xorl %eax, %eax
callq 0x2dca
leaq 0x63a7(%rip), %rdi      # 0x9127
xorl %eax, %eax
callq 0x2dca
movl 0xb41b(%rip), %esi      # 0xe1a8
leaq 0x63e9(%rip), %rdi      # 0x917d
xorl %eax, %eax
callq 0x2dca
leaq 0x6353(%rip), %rdi      # 0x90f5
jmp 0x288b
leaq 0x64a9(%rip), %rdi      # 0x9257
jmp 0x288b
leaq 0x62d6(%rip), %rdi      # 0x9090
jmp 0x2d72
leaq 0x6384(%rip), %rdi      # 0x9147
xorl %eax, %eax
callq 0x2dca