// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r9d, %r12d
movl %r8d, %r15d
movq %rcx, 0x20(%rsp)
movl %edx, 0xc(%rsp)
movq %rsi, 0x10(%rsp)
leaq 0x10(%rdi), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rdi), %rax
subq 0x10(%rdi), %rax
sarq $0x2, %rax
leal 0x2(%r15), %ecx
movslq %ecx, %rsi
cmpq %rsi, %rax
jae 0x344a5
movq 0x18(%rsp), %rdi
callq 0x33b0c
testl %r15d, %r15d
jne 0x344e2
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leal 0x1(%r12), %r8d
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movl 0xc(%rsp), %esi
movq 0x20(%rsp), %rdx
xorl %ecx, %ecx
callq 0x2b9a6
movb 0x10(%rbx), %r14b
cmpb %al, %r14b
jne 0x345c4
testl %r15d, %r15d
jle 0x34523
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl %r15d, %ecx
cmpl %r15d, -0x4(%rax,%rcx,4)
jne 0x34523
incl %r12d
movq 0x10(%rsp), %rdi
movl 0xc(%rsp), %esi
movq 0x20(%rsp), %rdx
movl %r15d, %ecx
movl %r12d, %r8d
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2b9a6
movq %r12, 0x28(%rsp)
testl %r15d, %r15d
setg %r13b
jle 0x345d0
movl %r15d, %r12d
movq 0x28(%rsp), %rax
leal 0x1(%rax), %ebp
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl $0x0, (%rax,%r12,4)
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movl 0xc(%rsp), %esi
movq 0x20(%rsp), %rdx
movl %r15d, %ecx
movl %ebp, %r8d
callq 0x2b9a6
movb 0x10(%rbx), %r14b
cmpb %al, %r14b
jne 0x345be
movl $0x1, %r13d
movq 0x10(%rsp), %rbx
cmpl %r13d, %r15d
je 0x345cd
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl %r13d, (%rax,%r12,4)
movq %rbx, %rdi
movl 0xc(%rsp), %esi
movq 0x20(%rsp), %rdx
movl %r15d, %ecx
movl %ebp, %r8d
callq 0x2b9a6
movb 0x10(%rbx), %r14b
incl %r13d
cmpb %al, %r14b
je 0x34580
decl %r13d
cmpl %r15d, %r13d
setl %r13b
xorb $0x1, %r14b
jmp 0x345d0
xorb $0x1, %r14b
jmp 0x3476e
xorl %r13d, %r13d
testb %r13b, %r13b
jne 0x3476e
movb %r14b, 0xb(%rsp)
testl %r15d, %r15d
setg %r12b
jle 0x34683
movl %r15d, %ebp
movq 0x28(%rsp), %rax
incl %eax
movl %eax, 0x38(%rsp)
movq %rbp, %rax
negq %rax
movq %rax, 0x30(%rsp)
movl $0x1, %r13d
movq 0x18(%rsp), %rbx
movq (%rbx), %rax
movl -0x4(%rax,%r13,4), %ecx
movl %ecx, (%rax,%rbp,4)
movl %r15d, -0x4(%rax,%r13,4)
movq %r15, %rcx
movq 0x10(%rsp), %r15
movq %r15, %rdi
movl 0xc(%rsp), %esi
movq 0x20(%rsp), %rdx
movq %rcx, %r14
movl 0x38(%rsp), %r8d
callq 0x2b9a6
movq (%rbx), %rcx
movl (%rcx,%rbp,4), %edx
movl %edx, -0x4(%rcx,%r13,4)
movb 0x10(%r15), %cl
cmpb %al, %cl
je 0x3465c
movl %ecx, %edx
xorb $0x1, %dl
movb %dl, 0xb(%rsp)
cmpb %al, %cl
jne 0x34680
cmpq %rbp, %r13
setb %r12b
movq 0x30(%rsp), %rax
addq %r13, %rax
incq %rax
incq %r13
cmpq $0x1, %rax
movq %r14, %r15
jne 0x3460f
jmp 0x34683
movq %r14, %r15
testb $0x1, %r12b
je 0x34693
movb 0xb(%rsp), %r14b
jmp 0x3476e
testl %r15d, %r15d
setg %cl
movb 0xb(%rsp), %r14b
jle 0x34760
leal 0x1(%r15), %r12d
movq %r15, 0x38(%rsp)
movl %r15d, %edx
movq 0x28(%rsp), %rax
incl %eax
movq %rax, 0x28(%rsp)
movq %rdx, %rax
negq %rax
movq %rax, 0x40(%rsp)
movl $0x1, %ebp
movq %rdx, 0x30(%rsp)
movq 0x20(%rsp), %r13
movq 0x18(%rsp), %rbx
movq 0x10(%rsp), %r15
movb %cl, 0xb(%rsp)
movq (%r13), %rax
incl (%rax)
movq (%rbx), %rax
movl -0x4(%rax,%rbp,4), %ecx
movl %ecx, (%rax,%r12,4)
movl %r12d, -0x4(%rax,%rbp,4)
movl %r12d, (%rax,%rdx,4)
movq %r15, %rdi
movl 0xc(%rsp), %esi
movq %r13, %rdx
movq 0x38(%rsp), %rcx
movq 0x28(%rsp), %r8
callq 0x2b9a6
movq (%rbx), %rcx
movl (%rcx,%r12,4), %edx
movl %edx, -0x4(%rcx,%rbp,4)
movq (%r13), %rcx
decl (%rcx)
movb 0x10(%r15), %cl
cmpb %al, %cl
je 0x34737
movl %ecx, %r14d
xorb $0x1, %r14b
cmpb %al, %cl
movq 0x30(%rsp), %rdx
jne 0x3475c
cmpq %rdx, %rbp
setb %cl
movq 0x40(%rsp), %rax
addq %rbp, %rax
incq %rax
incq %rbp
cmpq $0x1, %rax
jne 0x346e0
jmp 0x34760
movb 0xb(%rsp), %cl
testb $0x1, %cl
jne 0x3476e
movq 0x10(%rsp), %rax
movb 0x10(%rax), %r14b
andb $0x1, %r14b
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq