// File: biotomas[P]ipasir/sat/picosat961/picosat-961/picogcnf.c
// Function: main
int main (int argc, char ** argv) {
  int ch, nvars, sclauses, nclauses, sign, lit, group, res;
  const int * mus, * p;
  FILE * file;
  if (argc != 2) die ("usage: picogcnf <gcnf-file>");
  if (!(file = fopen (argv[1], "r"))) die ("can not read '%s'", argv[1]);
  ps = picosat_init ();
HEADER:
  ch = getc (file);
  if (ch == 'c') {
    while ((ch = getc (file)) != '\n')
      if (ch == EOF) die ("unexpected EOF");
    goto HEADER;
  }
  if (ch != 'p' || 
      getc (file) != ' ' ||
      fscanf (file, "gcnf %d %d %d", &nvars, &sclauses, &ngroups) != 3)
    die ("invalid header");
  nclauses = lit = 0;
  group = INT_MAX;
  LOG ("p gcnf %d %d %d\n", nvars, sclauses, ngroups);
LIT:
  ch = getc (file);
  if (ch == EOF) {
    if (lit) die ("zero missing");
    if (nclauses < sclauses) die ("clauses missing");
    goto DONE;
  }
  if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r') goto LIT;
  if (lit) {
    if (ch == '-') {
      sign = -1;
      ch = getc (file);
    } else sign = 1;
    lit = ch - '0';
    while (isdigit (ch = getc (file)))
      lit = 10 * lit + ch - '0';
    if (lit > nvars) die ("maximum variable exceeded");
    lit *= sign;
    if (lit) {
      LOG ("%d ", lit);
    } else {
      LOG ("0\n");
      group = INT_MAX;
      nclauses++;
    }
    picosat_add (ps, lit);
  } else if (ch == '{') {
    if (nclauses == sclauses) die ("too many clauses");
    if (group < INT_MAX) die ("multiple groups per clause");
GROUP:
    ch = getc (file);
    if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r') goto GROUP;
    if (!isdigit (ch)) die ("group does not start with digit");
    group = ch - '0';
    while (isdigit (ch = getc (file)))
      group = 10 * group + (ch - '0');
    if (group > ngroups) die ("maximal group exceeded");
    while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r')
      ch = getc (file);
    if (ch != '}') die ("expected '}'");
    LOG ("{%d} ", group);
    if (group) picosat_add (ps, -(nvars + group));
    lit = INT_MAX;
  } else die ("expected '{'");
  goto LIT;
DONE:
  fclose (file);
  for (lit = nvars + 1; lit <= nvars + ngroups; lit++) picosat_assume (ps, lit);
  res = picosat_sat (ps, -1);
  msg ("first call to SAT solver returned");
  if (res == 10) printf ("s SATISFIABLE\n");
  else if (res == 20) printf ("s UNSATISFIABLE\n");
  else printf ("s UNKNOWN\n");
  fflush (stdout);
  if (res == 20) {
    mus = picosat_mus_assumptions (ps, 0, callback, 1);
    assert (mus);
    printf ("v");
    for (p = mus; (lit = *p); p++) {
      assert (nvars + 1 <= lit && lit <= nvars + ngroups);
      printf (" %d", lit - nvars);
    }
    printf (" 0\n");
    fflush (stdout);
  }
  msg ("max memory %.1f MB",
       picosat_max_bytes_allocated (ps) / (double)(1<<20));
  picosat_reset (ps);
  msg ("%d reductions", reductions);
  return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
je 0x12da
leaq 0x18d6d(%rip), %rdi     # 0x1a040
movb $0x0, %al
callq 0x1870
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x1ba48(%rip), %rsi     # 0x1cd31
callq 0x1140
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
jne 0x130e
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x18d55(%rip), %rdi     # 0x1a05c
movb $0x0, %al
callq 0x1870
callq 0x1c50
movq %rax, 0x1fdd6(%rip)     # 0x210f0
movq -0x48(%rbp), %rdi
callq 0x1190
movl %eax, -0x14(%rbp)
cmpl $0x63, -0x14(%rbp)
jne 0x1357
jmp 0x132e
movq -0x48(%rbp), %rdi
callq 0x1190
movl %eax, -0x14(%rbp)
cmpl $0xa, %eax
je 0x1355
cmpl $-0x1, -0x14(%rbp)
jne 0x1353
leaq 0x18d22(%rip), %rdi     # 0x1a06e
movb $0x0, %al
callq 0x1870
jmp 0x132e
jmp 0x131a
cmpl $0x70, -0x14(%rbp)
jne 0x1391
movq -0x48(%rbp), %rdi
callq 0x1190
cmpl $0x20, %eax
jne 0x1391
movq -0x48(%rbp), %rdi
leaq 0x18d07(%rip), %rsi     # 0x1a07d
leaq -0x18(%rbp), %rdx
leaq -0x1c(%rbp), %rcx
leaq 0x1fd73(%rip), %r8      # 0x210f8
movb $0x0, %al
callq 0x1070
cmpl $0x3, %eax
je 0x139f
leaq 0x18cf3(%rip), %rdi     # 0x1a08b
movb $0x0, %al
callq 0x1870
movl $0x0, -0x28(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x7fffffff, -0x2c(%rbp) # imm = 0x7FFFFFFF
jmp 0x13b6
jmp 0x13b8
movq -0x48(%rbp), %rdi
callq 0x1190
movl %eax, -0x14(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x13f9
cmpl $0x0, -0x28(%rbp)
je 0x13de
leaq 0x18cc3(%rip), %rdi     # 0x1a09a
movb $0x0, %al
callq 0x1870
movl -0x20(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x13f4
leaq 0x18cba(%rip), %rdi     # 0x1a0a7
movb $0x0, %al
callq 0x1870
jmp 0x1659
cmpl $0x20, -0x14(%rbp)
je 0x1411
cmpl $0x9, -0x14(%rbp)
je 0x1411
cmpl $0xa, -0x14(%rbp)
je 0x1411
cmpl $0xd, -0x14(%rbp)
jne 0x1413
jmp 0x13b8
cmpl $0x0, -0x28(%rbp)
je 0x14da
cmpl $0x2d, -0x14(%rbp)
jne 0x1438
movl $0xffffffff, -0x24(%rbp) # imm = 0xFFFFFFFF
movq -0x48(%rbp), %rdi
callq 0x1190
movl %eax, -0x14(%rbp)
jmp 0x143f
movl $0x1, -0x24(%rbp)
movl -0x14(%rbp), %eax
subl $0x30, %eax
movl %eax, -0x28(%rbp)
callq 0x11a0
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
callq 0x1190
movl %eax, %ecx
movq -0x50(%rbp), %rax
movl %ecx, -0x14(%rbp)
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x1486
imull $0xa, -0x28(%rbp), %eax
addl -0x14(%rbp), %eax
subl $0x30, %eax
movl %eax, -0x28(%rbp)
jmp 0x1448
movl -0x28(%rbp), %eax
cmpl -0x18(%rbp), %eax
jle 0x149c
leaq 0x18c22(%rip), %rdi     # 0x1a0b7
movb $0x0, %al
callq 0x1870
movl -0x24(%rbp), %eax
imull -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0x14b2
jmp 0x14ae
jmp 0x14b0
jmp 0x14c6
jmp 0x14b4
jmp 0x14b6
movl $0x7fffffff, -0x2c(%rbp) # imm = 0x7FFFFFFF
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movq 0x1fc23(%rip), %rdi     # 0x210f0
movl -0x28(%rbp), %esi
callq 0x47a0
jmp 0x1654
cmpl $0x7b, -0x14(%rbp)
jne 0x1644
movl -0x20(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0x14fa
leaq 0x18bde(%rip), %rdi     # 0x1a0d1
movb $0x0, %al
callq 0x1870
cmpl $0x7fffffff, -0x2c(%rbp) # imm = 0x7FFFFFFF
jge 0x1511
leaq 0x18bd8(%rip), %rdi     # 0x1a0e2
movb $0x0, %al
callq 0x1870
jmp 0x1513
movq -0x48(%rbp), %rdi
callq 0x1190
movl %eax, -0x14(%rbp)
cmpl $0x20, -0x14(%rbp)
je 0x1537
cmpl $0x9, -0x14(%rbp)
je 0x1537
cmpl $0xa, -0x14(%rbp)
je 0x1537
cmpl $0xd, -0x14(%rbp)
jne 0x1539
jmp 0x1513
callq 0x11a0
movq (%rax), %rax
movslq -0x14(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
jne 0x1561
leaq 0x18ba3(%rip), %rdi     # 0x1a0fd
movb $0x0, %al
callq 0x1870
movl -0x14(%rbp), %eax
subl $0x30, %eax
movl %eax, -0x2c(%rbp)
callq 0x11a0
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rdi
callq 0x1190
movl %eax, %ecx
movq -0x58(%rbp), %rax
movl %ecx, -0x14(%rbp)
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x15aa
imull $0xa, -0x2c(%rbp), %eax
movl -0x14(%rbp), %ecx
subl $0x30, %ecx
addl %ecx, %eax
movl %eax, -0x2c(%rbp)
jmp 0x156a
movl -0x2c(%rbp), %eax
cmpl 0x1fb45(%rip), %eax     # 0x210f8
jle 0x15c3
leaq 0x18b61(%rip), %rdi     # 0x1a11d
movb $0x0, %al
callq 0x1870
jmp 0x15c5
movb $0x1, %al
cmpl $0x20, -0x14(%rbp)
movb %al, -0x59(%rbp)
je 0x15f0
movb $0x1, %al
cmpl $0x9, -0x14(%rbp)
movb %al, -0x59(%rbp)
je 0x15f0
movb $0x1, %al
cmpl $0xa, -0x14(%rbp)
movb %al, -0x59(%rbp)
je 0x15f0
cmpl $0xd, -0x14(%rbp)
sete %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
testb $0x1, %al
jne 0x15f9
jmp 0x1607
movq -0x48(%rbp), %rdi
callq 0x1190
movl %eax, -0x14(%rbp)
jmp 0x15c5
cmpl $0x7d, -0x14(%rbp)
je 0x161b
leaq 0x18b20(%rip), %rdi     # 0x1a134
movb $0x0, %al
callq 0x1870
jmp 0x161d
jmp 0x161f
cmpl $0x0, -0x2c(%rbp)
je 0x163b
movq 0x1fac4(%rip), %rdi     # 0x210f0
movl -0x18(%rbp), %eax
addl -0x2c(%rbp), %eax
xorl %esi, %esi
subl %eax, %esi
callq 0x47a0
movl $0x7fffffff, -0x28(%rbp) # imm = 0x7FFFFFFF
jmp 0x1652
leaq 0x18af6(%rip), %rdi     # 0x1a141
movb $0x0, %al
callq 0x1870
jmp 0x1654
jmp 0x13b8
movq -0x48(%rbp), %rdi
callq 0x1080
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
movl -0x18(%rbp), %ecx
addl 0x1fa81(%rip), %ecx     # 0x210f8
cmpl %ecx, %eax
jg 0x1695
movq 0x1fa6e(%rip), %rdi     # 0x210f0
movl -0x28(%rbp), %esi
callq 0x5150
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x166b
movq 0x1fa54(%rip), %rdi     # 0x210f0
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5420
movl %eax, -0x30(%rbp)
leaq 0x18a9e(%rip), %rdi     # 0x1a14e
movb $0x0, %al
callq 0x1950
cmpl $0xa, -0x30(%rbp)
jne 0x16cd
leaq 0x18aac(%rip), %rdi     # 0x1a170
movb $0x0, %al
callq 0x10a0
jmp 0x16f3
cmpl $0x14, -0x30(%rbp)
jne 0x16e3
leaq 0x18aa5(%rip), %rdi     # 0x1a17f
movb $0x0, %al
callq 0x10a0
jmp 0x16f1
leaq 0x18aa6(%rip), %rdi     # 0x1a190
movb $0x0, %al
callq 0x10a0
jmp 0x16f3
movq 0x1f8de(%rip), %rax     # 0x20fd8
movq (%rax), %rdi
callq 0x1110
cmpl $0x14, -0x30(%rbp)
jne 0x17f3
movq 0x1f9dd(%rip), %rdi     # 0x210f0
xorl %eax, %eax
movl %eax, %esi
leaq 0x302(%rip), %rdx       # 0x1a20
movl $0x1, %ecx
callq 0x6be0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x1735
jmp 0x1754
leaq 0x194d0(%rip), %rdi     # 0x1ac0c
leaq 0x18a58(%rip), %rsi     # 0x1a19b
movl $0x97, %edx
leaq 0x18a57(%rip), %rcx     # 0x1a1a6
callq 0x10b0
leaq 0x1b59d(%rip), %rdi     # 0x1ccf8
movb $0x0, %al
callq 0x10a0
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, %eax
je 0x17d6
movl -0x18(%rbp), %eax
addl $0x1, %eax
cmpl -0x28(%rbp), %eax
jg 0x1795
movl -0x28(%rbp), %eax
movl -0x18(%rbp), %ecx
addl 0x1f969(%rip), %ecx     # 0x210f8
cmpl %ecx, %eax
jg 0x1795
jmp 0x17b4
leaq 0x18a21(%rip), %rdi     # 0x1a1bd
leaq 0x189f8(%rip), %rsi     # 0x1a19b
movl $0x9a, %edx
leaq 0x189f7(%rip), %rcx     # 0x1a1a6
callq 0x10b0
movl -0x28(%rbp), %esi
subl -0x18(%rbp), %esi
leaq 0x188c6(%rip), %rdi     # 0x1a087
movb $0x0, %al
callq 0x10a0
movq -0x40(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x40(%rbp)
jmp 0x176a
leaq 0x196a4(%rip), %rdi     # 0x1ae81
movb $0x0, %al
callq 0x10a0
movq 0x1f7ed(%rip), %rax     # 0x20fd8
movq (%rax), %rdi
callq 0x1110
movq 0x1f8f6(%rip), %rdi     # 0x210f0
callq 0x8a00
movq %rax, %xmm0
movaps 0x18815(%rip), %xmm1    # 0x1a020
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x18819(%rip), %xmm1    # 0x1a030
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x187da(%rip), %xmm1    # 0x1a008
divsd %xmm1, %xmm0
leaq 0x189af(%rip), %rdi     # 0x1a1e8
movb $0x1, %al
callq 0x1950
movq 0x1f8a9(%rip), %rdi     # 0x210f0
callq 0x3f70
movl 0x1f8aa(%rip), %esi     # 0x210fc
leaq 0x189a2(%rip), %rdi     # 0x1a1fb
movb $0x0, %al
callq 0x1950
movl -0x30(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)