// File: biotomas[P]ipasir/sat/picosat961/picosat-961/picosat.c
// Function: next_mss
static const int *
next_mss (PS * ps, int mcs)
{
  int i, *a, size, mssize, mcsize, lit, inmss;
  const int * res, * p;
  Var * v;

  if (ps->mtcls) return 0;

  check_mss_flags_clean (ps);

  if (mcs && ps->mcsass)
    {
      DELETEN (ps->mcsass, ps->szmcsass);
      ps->nmcsass = ps->szmcsass = 0;
      ps->mcsass = 0;
    }

  size = ps->alshead - ps->als;
  NEWN (a, size);

  for (i = 0; i < size; i++)
    a[i] = LIT2INT (ps->als[i]);

  (void) picosat_sat (ps, -1);

  //TODO short cut for 'picosat_res () == 10'?

  if (ps->mtcls)
    {
      assert (picosat_res (ps) == 20);
      res = 0;
      goto DONE;
    }

  res = mss (ps, a, size);

  if (ps->mtcls)
    {
      res = 0;
      goto DONE;
    }

  for (p = res; (lit = *p); p++) 
    {
      v = ps->vars + abs (lit);
      if (lit < 0)
	{
	  assert (!v->msspos);
	  v->mssneg = 1;
	}
      else
	{
	  assert (!v->mssneg);
	  v->msspos = 1;
	}
    }

  mssize = p - res;
  mcsize = INT_MIN;

  for (i = 0; i < size; i++)
    {
      lit = a[i];
      v = ps->vars + abs (lit);
      if (lit > 0 && v->msspos)
	inmss = 1;
      else if (lit < 0 && v->mssneg)
	inmss = 1;
      else 
	inmss = 0;

      if (mssize < mcsize)
	{
	  if (inmss)
	    picosat_add (ps, -lit);
	}
      else
	{
	  if (!inmss)
	    picosat_add (ps, lit);
	}

      if (!inmss && mcs)
	push_mcsass (ps, lit);
    }
  picosat_add (ps, 0);
  if (mcs)
    push_mcsass (ps, 0);

  for (i = 0; i < size; i++)
    {
      lit = a[i];
      v = ps->vars + abs (lit);
      v->msspos = 0;
      v->mssneg = 0;
    }

DONE:

  reassume (ps, a, size);
  DELETEN (a, size);

  return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x248(%rax)
je 0x9f0a
movq $0x0, -0x8(%rbp)
jmp 0xa374
movq -0x10(%rbp), %rdi
callq 0x1b100
cmpl $0x0, -0x14(%rbp)
je 0x9f86
movq -0x10(%rbp), %rax
cmpq $0x0, 0x198(%rax)
je 0x9f86
jmp 0x9f29
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x198(%rax), %rsi
movq -0x10(%rbp), %rax
movslq 0x1a4(%rax), %rdx
shlq $0x2, %rdx
callq 0x97a0
movq -0x10(%rbp), %rax
movq $0x0, 0x198(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x1a4(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x1a0(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x198(%rax)
movq -0x10(%rbp), %rax
movq 0x100(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0xf8(%rcx), %rcx
subq %rcx, %rax
sarq $0x3, %rax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x24(%rbp), %rsi
shlq $0x2, %rsi
callq 0x9900
movq %rax, -0x20(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0xa036
movq -0x10(%rbp), %rax
movq 0xf8(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x10(%rbp), %rcx
movq 0x38(%rcx), %rcx
subq %rcx, %rax
movl %eax, %ecx
andl $0x1, %ecx
movl $0x1, %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x0, %ecx
cmovnel %eax, %edx
movq -0x10(%rbp), %rax
movq 0xf8(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x10(%rbp), %rcx
movq 0x38(%rcx), %rcx
subq %rcx, %rax
shrl %eax
imull %eax, %edx
movq -0x20(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x9fc2
movq -0x10(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x7500
movq -0x10(%rbp), %rax
cmpq $0x0, 0x248(%rax)
je 0xa08e
movq -0x10(%rbp), %rdi
callq 0x7db0
cmpl $0x14, %eax
jne 0xa062
jmp 0xa081
leaq 0x158d7(%rip), %rdi     # 0x1f940
leaq 0x13234(%rip), %rsi     # 0x1d2a4
movl $0x1e11, %edx           # imm = 0x1E11
leaq 0x158db(%rip), %rcx     # 0x1f957
callq 0x10b0
movq $0x0, -0x40(%rbp)
jmp 0xa33f
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0x9bb0
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x248(%rax)
je 0xa0bd
movq $0x0, -0x40(%rbp)
jmp 0xa33f
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, %eax
je 0xa1aa
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x30(%rbp), %ecx
movl %ecx, %edx
negl %edx
cmovnsl %edx, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
cmpl $0x0, -0x30(%rbp)
jge 0xa14b
movq -0x50(%rbp), %rax
movw (%rax), %ax
shrw $0x9, %ax
andw $0x1, %ax
movzwl %ax, %eax
cmpl $0x0, %eax
jne 0xa116
jmp 0xa135
leaq 0x15859(%rip), %rdi     # 0x1f976
leaq 0x13180(%rip), %rsi     # 0x1d2a4
movl $0x1e23, %edx           # imm = 0x1E23
leaq 0x15827(%rip), %rcx     # 0x1f957
callq 0x10b0
movq -0x50(%rbp), %rax
movw (%rax), %cx
andw $0xfbff, %cx            # imm = 0xFBFF
orw $0x400, %cx             # imm = 0x400
movw %cx, (%rax)
jmp 0xa197
movq -0x50(%rbp), %rax
movw (%rax), %ax
shrw $0xa, %ax
andw $0x1, %ax
movzwl %ax, %eax
cmpl $0x0, %eax
jne 0xa164
jmp 0xa183
leaq 0x15816(%rip), %rdi     # 0x1f981
leaq 0x13132(%rip), %rsi     # 0x1d2a4
movl $0x1e28, %edx           # imm = 0x1E28
leaq 0x157d9(%rip), %rcx     # 0x1f957
callq 0x10b0
movq -0x50(%rbp), %rax
movw (%rax), %cx
andw $0xfdff, %cx            # imm = 0xFDFF
orw $0x200, %cx             # imm = 0x200
movw %cx, (%rax)
jmp 0xa199
movq -0x48(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x48(%rbp)
jmp 0xa0c5
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
subq %rcx, %rax
sarq $0x2, %rax
movl %eax, -0x28(%rbp)
movl $0x80000000, -0x2c(%rbp) # imm = 0x80000000
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0xa2b3
movq -0x20(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x30(%rbp), %ecx
movl %ecx, %edx
negl %edx
cmovnsl %edx, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
cmpl $0x0, -0x30(%rbp)
jle 0xa22a
movq -0x50(%rbp), %rax
movw (%rax), %ax
shrw $0x9, %ax
andw $0x1, %ax
movzwl %ax, %eax
cmpl $0x0, %eax
je 0xa22a
movl $0x1, -0x34(%rbp)
jmp 0xa259
cmpl $0x0, -0x30(%rbp)
jge 0xa250
movq -0x50(%rbp), %rax
movw (%rax), %ax
shrw $0xa, %ax
andw $0x1, %ax
movzwl %ax, %eax
cmpl $0x0, %eax
je 0xa250
movl $0x1, -0x34(%rbp)
jmp 0xa257
movl $0x0, -0x34(%rbp)
jmp 0xa259
movl -0x28(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0xa277
cmpl $0x0, -0x34(%rbp)
je 0xa275
movq -0x10(%rbp), %rdi
xorl %esi, %esi
subl -0x30(%rbp), %esi
callq 0x6880
jmp 0xa28b
cmpl $0x0, -0x34(%rbp)
jne 0xa289
movq -0x10(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0x6880
jmp 0xa28b
cmpl $0x0, -0x34(%rbp)
jne 0xa2a3
cmpl $0x0, -0x14(%rbp)
je 0xa2a3
movq -0x10(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0x1b1d0
jmp 0xa2a5
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xa1ca
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x6880
cmpl $0x0, -0x14(%rbp)
je 0xa2cf
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x1b1d0
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0xa33d
movq -0x20(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x30(%rbp), %ecx
movl %ecx, %edx
negl %edx
cmovnsl %edx, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movw (%rax), %cx
andw $0xfdff, %cx            # imm = 0xFDFF
orw $0x0, %cx
movw %cx, (%rax)
movq -0x50(%rbp), %rax
movw (%rax), %cx
andw $0xfbff, %cx            # imm = 0xFBFF
orw $0x0, %cx
movw %cx, (%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xa2d6
jmp 0xa33f
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0x9e50
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movslq -0x24(%rbp), %rdx
shlq $0x2, %rdx
callq 0x97a0
movq $0x0, -0x20(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nop