// File: eryxcc[P]lois/src/relations.cpp
// Function: lois::SubRelTree::exists(lois::FormulaQ*, int, std::shared_ptr<lois::Subdomain>&, int, int)
bool exists(FormulaQ* q, int at, std::shared_ptr<Subdomain>& dom, int val, int rid) {

    if(parent.size() < val+2) parent.resize(val+2);
  
    // create a new tree
    if(val == 0) {
      parent[0] = -1;
      if(q->generateAll(at, dom, val, rid+1) != q->type) return !q->type;
      }
    
    // already created
    if(val > 0 && parent[val-1] == val) 
      return q->generateAll(at, dom, val, rid+1);
    
    // create a descendant
    for(int u=0; u<val; u++) {
      parent[val] = u;
      if(q->generateAll(at, dom, val, rid+1) != q->type) return !q->type;
      }
    
    // create an intermediate ancestor
    for(int u=0; u<val; u++) {
      parent[val] = parent[u]; parent[u] = val;
      bool b = q->generateAll(at, dom, val, rid+1);
      parent[u] = parent[val];
      if(b != q->type) return !q->type;
      }
    
    // create another child of an intermediate ancestor of u
    for(int u=0; u<val; u++) {
      dom->nextval++;
      parent[val+1] = parent[u]; parent[u] = val+1; parent[val] = val+1;
      bool b = q->generateAll(at, dom, val, rid+1);
      parent[u] = parent[val+1]; dom->nextval--;
      if(b != q->type) return !q->type;
      }
    
    return q->type;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movl %r9d, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x50(%rbp)
addq $0x10, %rdi
callq 0x4a5e0
movl -0x2c(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jae 0x59fe4
movq -0x50(%rbp), %rdi
addq $0x10, %rdi
movl -0x2c(%rbp), %eax
addl $0x2, %eax
movslq %eax, %rsi
callq 0x55e80
cmpl $0x0, -0x2c(%rbp)
jne 0x5a047
movq -0x50(%rbp), %rdi
addq $0x10, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x44e60
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movq -0x28(%rbp), %rdx
movl -0x2c(%rbp), %ecx
movl -0x30(%rbp), %r8d
addl $0x1, %r8d
callq 0x42c70
andb $0x1, %al
movzbl %al, %eax
movq -0x18(%rbp), %rcx
movb 0x10(%rcx), %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
je 0x5a045
movq -0x18(%rbp), %rax
movb 0x10(%rax), %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, -0x1(%rbp)
jmp 0x5a326
jmp 0x5a047
cmpl $0x0, -0x2c(%rbp)
jle 0x5a08f
movq -0x50(%rbp), %rdi
addq $0x10, %rdi
movl -0x2c(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x44e60
movl (%rax), %eax
cmpl -0x2c(%rbp), %eax
jne 0x5a08f
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movq -0x28(%rbp), %rdx
movl -0x2c(%rbp), %ecx
movl -0x30(%rbp), %r8d
addl $0x1, %r8d
callq 0x42c70
andb $0x1, %al
movb %al, -0x1(%rbp)
jmp 0x5a326
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x5a10b
movq -0x50(%rbp), %rdi
movl -0x34(%rbp), %eax
movl %eax, -0x54(%rbp)
addq $0x10, %rdi
movslq -0x2c(%rbp), %rsi
callq 0x44e60
movl -0x54(%rbp), %ecx
movl %ecx, (%rax)
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movq -0x28(%rbp), %rdx
movl -0x2c(%rbp), %ecx
movl -0x30(%rbp), %r8d
addl $0x1, %r8d
callq 0x42c70
andb $0x1, %al
movzbl %al, %eax
movq -0x18(%rbp), %rcx
movb 0x10(%rcx), %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
je 0x5a0fe
movq -0x18(%rbp), %rax
movb 0x10(%rax), %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, -0x1(%rbp)
jmp 0x5a326
jmp 0x5a100
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x5a096
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x5a1ee
movq -0x50(%rbp), %rdi
addq $0x10, %rdi
movslq -0x38(%rbp), %rsi
callq 0x44e60
movq -0x50(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x60(%rbp)
addq $0x10, %rdi
movslq -0x2c(%rbp), %rsi
callq 0x44e60
movl -0x60(%rbp), %ecx
movq -0x50(%rbp), %rdi
movl %ecx, (%rax)
movl -0x2c(%rbp), %eax
movl %eax, -0x5c(%rbp)
addq $0x10, %rdi
movslq -0x38(%rbp), %rsi
callq 0x44e60
movl -0x5c(%rbp), %ecx
movl %ecx, (%rax)
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movq -0x28(%rbp), %rdx
movl -0x2c(%rbp), %ecx
movl -0x30(%rbp), %r8d
addl $0x1, %r8d
callq 0x42c70
movq -0x50(%rbp), %rdi
andb $0x1, %al
movb %al, -0x39(%rbp)
addq $0x10, %rdi
movslq -0x2c(%rbp), %rsi
callq 0x44e60
movq -0x50(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x58(%rbp)
addq $0x10, %rdi
movslq -0x38(%rbp), %rsi
callq 0x44e60
movl -0x58(%rbp), %ecx
movl %ecx, (%rax)
movb -0x39(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movq -0x18(%rbp), %rcx
movb 0x10(%rcx), %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
je 0x5a1de
movq -0x18(%rbp), %rax
movb 0x10(%rax), %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, -0x1(%rbp)
jmp 0x5a326
jmp 0x5a1e0
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x5a112
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x5a31a
movq -0x28(%rbp), %rdi
callq 0x45010
movq -0x50(%rbp), %rdi
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
addq $0x10, %rdi
movslq -0x40(%rbp), %rsi
callq 0x44e60
movq -0x50(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x70(%rbp)
addq $0x10, %rdi
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x44e60
movl -0x70(%rbp), %ecx
movq -0x50(%rbp), %rdi
movl %ecx, (%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
addq $0x10, %rdi
movslq -0x40(%rbp), %rsi
callq 0x44e60
movl -0x6c(%rbp), %ecx
movq -0x50(%rbp), %rdi
movl %ecx, (%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
addq $0x10, %rdi
movslq -0x2c(%rbp), %rsi
callq 0x44e60
movl -0x68(%rbp), %ecx
movl %ecx, (%rax)
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movq -0x28(%rbp), %rdx
movl -0x2c(%rbp), %ecx
movl -0x30(%rbp), %r8d
addl $0x1, %r8d
callq 0x42c70
movq -0x50(%rbp), %rdi
andb $0x1, %al
movb %al, -0x41(%rbp)
addq $0x10, %rdi
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x44e60
movq -0x50(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x64(%rbp)
addq $0x10, %rdi
movslq -0x40(%rbp), %rsi
callq 0x44e60
movl -0x64(%rbp), %ecx
movl %ecx, (%rax)
movq -0x28(%rbp), %rdi
callq 0x45010
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
movb -0x41(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movq -0x18(%rbp), %rcx
movb 0x10(%rcx), %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
je 0x5a30a
movq -0x18(%rbp), %rax
movb 0x10(%rax), %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, -0x1(%rbp)
jmp 0x5a326
jmp 0x5a30c
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x5a1f5
movq -0x18(%rbp), %rax
movb 0x10(%rax), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)