// File: biotomas[P]ipasir/app/genipasat/genipasat.c
// Function: main
int main (int argc, char ** argv) {
  int res = 0, i, ch, c, l, lit;
  char * sig;
  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 ();
  ipasir_set_learn(solver, 0, 2, learncb);
  sig = strdup (ipasir_signature (solver));
  msg ("GenIPASAT 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, " cnf %d %d", &vars, &clauses) != 2)
    perr ("invalid header");
  if (vars < 0) perr ("invalid negative number of variables %d", vars);
  if (clauses < 0) perr ("invalid negative number of clauses %d", clauses);
  msg ("found 'p cnf %d %d' header at line %d", vars, clauses, lineno);
  c = l = lit = 0;
  while (fscanf (file, "%d", &lit) == 1) {
    if (lit == INT_MIN || abs (lit) > vars) perr ("invalid literal %d", lit);
    ipasir_add (solver, lit);
    if (lit) l++; else c++;
  }
  if (!feof (file)) perr ("could not parse literal");
  if (lit) perr ("last literal %d was non zero", lit);
  msg ("parsed %d literals in %d clauses", l, c);
  if (c != clauses) perr ("expected %d clauses but got %d", clauses, c);
  if (closefile == 2) pclose (file);
  if (closefile == 1) fclose (file);
  msg ("calling SAT solver after %.2f seconds", getime ());
  res = ipasir_solve (solver);
  msg ("SAT solver returns %d after %.2f seconds", res, getime ());
  fflush (stderr);
  if (res == 10) {
    printf ("s SATISFIABLE\n");
    if (vars) {
      fflush (stdout);
      fputc ('v', stdout);
      for (i = 1; i <= vars; i++) {
	if (!(i % 8)) fputs ("\nv", stdout);
	printf (" %d", ipasir_val (solver, i));
      }
      if (vars) fputc ('\n', stdout);
    }
    printf ("v 0\n");
  } else if (res == 20) printf ("s UNSATISFIABLE\n");
  else printf ("s UNKNOWN\n");
  fflush (stdout);
  ipasir_release (solver);
  msg ("released '%s' after %.2f seconds", sig, getime ());
  msg ("exit %d", res);
  free (sig);
  return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x1, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x1438
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x18c81(%rip), %rsi     # 0x1a024
callq 0x1100
cmpl $0x0, %eax
jne 0x13b4
callq 0x1e10
jmp 0x1428
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x13e4
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x18c4c(%rip), %rdi     # 0x1a027
movb $0x0, %al
callq 0x1960
jmp 0x1426
cmpq $0x0, 0x1fd3c(%rip)     # 0x21128
je 0x1411
movq 0x1fd33(%rip), %rsi     # 0x21128
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0x18c37(%rip), %rdi     # 0x1a03f
movb $0x0, %al
callq 0x1960
jmp 0x1424
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x1fd04(%rip)     # 0x21128
jmp 0x1426
jmp 0x1428
jmp 0x142a
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1384
movb $0x0, %al
callq 0x1e40
movq %rax, 0x1fcea(%rip)     # 0x21130
movq 0x1fce3(%rip), %rdi     # 0x21130
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
leaq -0x15d(%rip), %rcx      # 0x1300
callq 0x2020
movq 0x1fcc7(%rip), %rdi     # 0x21130
movb $0x0, %al
callq 0x1e30
movq %rax, %rdi
callq 0x11d0
movq %rax, -0x30(%rbp)
leaq 0x18bd9(%rip), %rdi     # 0x1a05c
movb $0x0, %al
callq 0x1a40
movq -0x30(%rbp), %rsi
leaq 0x18be7(%rip), %rdi     # 0x1a07c
movb $0x0, %al
callq 0x1a40
cmpq $0x0, 0x1fc84(%rip)     # 0x21128
je 0x1563
movl $0x2, 0x1fc84(%rip)     # 0x21138
movq 0x1fc6d(%rip), %rdi     # 0x21128
leaq 0x18bcb(%rip), %rsi     # 0x1a08d
callq 0x1b20
cmpl $0x0, %eax
je 0x14e8
movq 0x1fc55(%rip), %rdi     # 0x21128
leaq 0x18bb8(%rip), %rsi     # 0x1a092
callq 0x1bc0
movq %rax, 0x1fc5a(%rip)     # 0x21140
jmp 0x1542
movq 0x1fc39(%rip), %rdi     # 0x21128
leaq 0x18ba5(%rip), %rsi     # 0x1a09b
callq 0x1b20
cmpl $0x0, %eax
je 0x151c
movq 0x1fc21(%rip), %rdi     # 0x21128
leaq 0x18b91(%rip), %rsi     # 0x1a09f
callq 0x1bc0
movq %rax, 0x1fc26(%rip)     # 0x21140
jmp 0x1540
movq 0x1fc05(%rip), %rdi     # 0x21128
leaq 0x1b8de(%rip), %rsi     # 0x1ce08
callq 0x1180
movq %rax, 0x1fc0a(%rip)     # 0x21140
movl $0x1, 0x1fbf8(%rip)     # 0x21138
jmp 0x1542
cmpq $0x0, 0x1fbf6(%rip)     # 0x21140
jne 0x1561
movq 0x1fbd5(%rip), %rsi     # 0x21128
leaq 0x18b52(%rip), %rdi     # 0x1a0ac
movb $0x0, %al
callq 0x1960
jmp 0x1582
leaq 0x18b54(%rip), %rax     # 0x1a0be
movq %rax, 0x1fbb7(%rip)     # 0x21128
movq 0x1fa60(%rip), %rax     # 0x20fd8
movq (%rax), %rax
movq %rax, 0x1fbbe(%rip)     # 0x21140
movq 0x1fb9f(%rip), %rsi     # 0x21128
leaq 0x18b36(%rip), %rdi     # 0x1a0c6
movb $0x0, %al
callq 0x1a40
movq 0x1fba2(%rip), %rdi     # 0x21140
leaq 0x1fb6b(%rip), %rsi     # 0x21110
callq 0x1c40
movl %eax, -0x1c(%rbp)
cmpl $0x63, %eax
jne 0x15e7
jmp 0x15b4
movq 0x1fb85(%rip), %rdi     # 0x21140
leaq 0x1fb4e(%rip), %rsi     # 0x21110
callq 0x1c40
movl %eax, -0x1c(%rbp)
cmpl $0xa, %eax
je 0x15e5
cmpl $-0x1, -0x1c(%rbp)
jne 0x15e3
leaq 0x18af7(%rip), %rdi     # 0x1a0d3
movb $0x0, %al
callq 0x1c80
jmp 0x15b4
jmp 0x1597
cmpl $0x70, -0x1c(%rbp)
je 0x15fb
leaq 0x18b01(%rip), %rdi     # 0x1a0f5
movb $0x0, %al
callq 0x1c80
movq 0x1fb3e(%rip), %rdi     # 0x21140
leaq 0x18b00(%rip), %rsi     # 0x1a109
leaq 0x1fb38(%rip), %rdx     # 0x21148
leaq 0x1fb35(%rip), %rcx     # 0x2114c
movb $0x0, %al
callq 0x1070
cmpl $0x2, %eax
je 0x1631
leaq 0x18aea(%rip), %rdi     # 0x1a114
movb $0x0, %al
callq 0x1c80
cmpl $0x0, 0x1fb10(%rip)     # 0x21148
jge 0x164e
movl 0x1fb08(%rip), %esi     # 0x21148
leaq 0x18adc(%rip), %rdi     # 0x1a123
movb $0x0, %al
callq 0x1c80
cmpl $0x0, 0x1faf7(%rip)     # 0x2114c
jge 0x166b
movl 0x1faef(%rip), %esi     # 0x2114c
leaq 0x18ae7(%rip), %rdi     # 0x1a14b
movb $0x0, %al
callq 0x1c80
movl 0x1fad7(%rip), %esi     # 0x21148
movl 0x1fad5(%rip), %edx     # 0x2114c
movl 0x1fa93(%rip), %ecx     # 0x21110
leaq 0x18aed(%rip), %rdi     # 0x1a171
movb $0x0, %al
callq 0x1a40
movl $0x0, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x20(%rbp)
movq 0x1fa99(%rip), %rdi     # 0x21140
leaq 0x18a63(%rip), %rsi     # 0x1a111
leaq -0x28(%rbp), %rdx
movb $0x0, %al
callq 0x1070
cmpl $0x1, %eax
jne 0x1715
cmpl $0x80000000, -0x28(%rbp) # imm = 0x80000000
je 0x16d9
movl -0x28(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
cmpl 0x1fa71(%rip), %eax     # 0x21148
jle 0x16ea
movl -0x28(%rbp), %esi
leaq 0x18ab4(%rip), %rdi     # 0x1a197
movb $0x0, %al
callq 0x1c80
movq 0x1fa3f(%rip), %rdi     # 0x21130
movl -0x28(%rbp), %esi
callq 0x1ee0
cmpl $0x0, -0x28(%rbp)
je 0x170a
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1713
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x16a0
movq 0x1fa24(%rip), %rdi     # 0x21140
callq 0x1120
cmpl $0x0, %eax
jne 0x1734
leaq 0x18a7d(%rip), %rdi     # 0x1a1aa
movb $0x0, %al
callq 0x1c80
cmpl $0x0, -0x28(%rbp)
je 0x174b
movl -0x28(%rbp), %esi
leaq 0x18a7e(%rip), %rdi     # 0x1a1c2
movb $0x0, %al
callq 0x1c80
movl -0x24(%rbp), %esi
movl -0x20(%rbp), %edx
leaq 0x18a87(%rip), %rdi     # 0x1a1df
movb $0x0, %al
callq 0x1a40
movl -0x20(%rbp), %eax
cmpl 0x1f9e4(%rip), %eax     # 0x2114c
je 0x1781
movl 0x1f9dc(%rip), %esi     # 0x2114c
movl -0x20(%rbp), %edx
leaq 0x18a86(%rip), %rdi     # 0x1a200
movb $0x0, %al
callq 0x1c80
cmpl $0x2, 0x1f9b0(%rip)     # 0x21138
jne 0x1796
movq 0x1f9af(%rip), %rdi     # 0x21140
callq 0x10b0
cmpl $0x1, 0x1f99b(%rip)     # 0x21138
jne 0x17ab
movq 0x1f99a(%rip), %rdi     # 0x21140
callq 0x1080
callq 0x1d70
leaq 0x18a68(%rip), %rdi     # 0x1a21f
movb $0x1, %al
callq 0x1a40
movq 0x1f96b(%rip), %rdi     # 0x21130
callq 0x1f40
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x34(%rbp)
callq 0x1d70
movl -0x34(%rbp), %esi
leaq 0x18a63(%rip), %rdi     # 0x1a245
movb $0x1, %al
callq 0x1a40
movq 0x1f808(%rip), %rax     # 0x20ff8
movq (%rax), %rdi
callq 0x1140
cmpl $0xa, -0x14(%rbp)
jne 0x18d1
leaq 0x18a65(%rip), %rdi     # 0x1a26e
movb $0x0, %al
callq 0x10a0
cmpl $0x0, 0x1f931(%rip)     # 0x21148
je 0x18c1
movq 0x1f7ac(%rip), %rax     # 0x20fd0
movq (%rax), %rdi
callq 0x1140
movq 0x1f79d(%rip), %rax     # 0x20fd0
movq (%rax), %rsi
movl $0x76, %edi
callq 0x10f0
movl $0x1, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl 0x1f8f8(%rip), %eax     # 0x21148
jg 0x18a2
movl -0x18(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x1878
movq 0x1f767(%rip), %rax     # 0x20fd0
movq (%rax), %rsi
leaq 0x18a0a(%rip), %rdi     # 0x1a27d
callq 0x10d0
movq 0x1f8b1(%rip), %rdi     # 0x21130
movl -0x18(%rbp), %esi
callq 0x1f90
movl %eax, %esi
leaq 0x18880(%rip), %rdi     # 0x1a110
movb $0x0, %al
callq 0x10a0
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1847
cmpl $0x0, 0x1f89f(%rip)     # 0x21148
je 0x18bf
movq 0x1f71e(%rip), %rax     # 0x20fd0
movq (%rax), %rsi
movl $0xa, %edi
callq 0x10f0
jmp 0x18c1
leaq 0x189b8(%rip), %rdi     # 0x1a280
movb $0x0, %al
callq 0x10a0
jmp 0x18f7
cmpl $0x14, -0x14(%rbp)
jne 0x18e7
leaq 0x189a7(%rip), %rdi     # 0x1a285
movb $0x0, %al
callq 0x10a0
jmp 0x18f5
leaq 0x189a8(%rip), %rdi     # 0x1a296
movb $0x0, %al
callq 0x10a0
jmp 0x18f7
movq 0x1f6d2(%rip), %rax     # 0x20fd0
movq (%rax), %rdi
callq 0x1140
movq 0x1f823(%rip), %rdi     # 0x21130
callq 0x1eb0
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
callq 0x1d70
movq -0x40(%rbp), %rsi
leaq 0x18977(%rip), %rdi     # 0x1a2a1
movb $0x1, %al
callq 0x1a40
movl -0x14(%rbp), %esi
leaq 0x18987(%rip), %rdi     # 0x1a2c2
movb $0x0, %al
callq 0x1a40
movq -0x30(%rbp), %rdi
callq 0x1040
movl -0x14(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)