// File: /workspace/github_cpp_makefile_star2_O3/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 $0x28, %rsp
movl %r9d, %ebp
movl %r8d, %r12d
movq %rcx, 0x8(%rsp)
movl %edx, 0x4(%rsp)
movq %rsi, %rbx
leaq 0x10(%rdi), %r13
movq 0x18(%rdi), %rax
subq 0x10(%rdi), %rax
sarq $0x2, %rax
leal 0x2(%r12), %ecx
movslq %ecx, %rsi
cmpq %rsi, %rax
jae 0x34203
movq %r13, %rdi
callq 0x33940
testl %r12d, %r12d
je 0x3423f
jle 0x3426e
movq (%r13), %rax
movl %r12d, %r15d
cmpl %r12d, -0x4(%rax,%r15,4)
jne 0x34276
incl %ebp
movq %rbx, %rdi
movl 0x4(%rsp), %esi
movq 0x8(%rsp), %rdx
movl %r12d, %ecx
movl %ebp, %r8d
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2ba42
movq (%r13), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
incl %ebp
movq %rbx, %rdi
movl 0x4(%rsp), %esi
movq 0x8(%rsp), %rdx
xorl %ecx, %ecx
movl %ebp, %r8d
callq 0x2ba42
movl %eax, %ecx
movb 0x10(%rbx), %al
cmpb %cl, %al
jne 0x34381
movb 0x10(%rbx), %al
jmp 0x34383
incl %ebp
xorl %r14d, %r14d
movq (%r13), %rax
movl %r14d, (%rax,%r15,4)
movq %rbx, %rdi
movl 0x4(%rsp), %esi
movq 0x8(%rsp), %rdx
movl %r12d, %ecx
movl %ebp, %r8d
callq 0x2ba42
movl %eax, %ecx
movb 0x10(%rbx), %al
cmpb %cl, %al
jne 0x34381
incl %r14d
cmpl %r14d, %r12d
jne 0x3427b
movq (%r13), %rdx
xorl %r14d, %r14d
movl (%rdx,%r14,4), %eax
movl %eax, (%rdx,%r15,4)
movl %r12d, (%rdx,%r14,4)
movq %rbx, %rdi
movl 0x4(%rsp), %esi
movq 0x8(%rsp), %rdx
movl %r12d, %ecx
movl %ebp, %r8d
callq 0x2ba42
movl %eax, %ecx
movq (%r13), %rdx
movl (%rdx,%r15,4), %eax
movl %eax, (%rdx,%r14,4)
movb 0x10(%rbx), %al
cmpb %cl, %al
jne 0x34381
incq %r14
cmpq %r14, %r15
jne 0x342b6
movl %ebp, 0x14(%rsp)
leal 0x1(%r12), %eax
movq %rax, 0x20(%rsp)
movq 0x8(%rsp), %rax
movq (%rax), %rsi
movl (%rsi), %edi
movq %r13, 0x18(%rsp)
movq (%r13), %rdx
incl %edi
xorl %r14d, %r14d
movq 0x20(%rsp), %r13
movq 0x8(%rsp), %rbp
movl %edi, (%rsi)
movl (%rdx,%r14,4), %eax
movl %eax, (%rdx,%r13,4)
movl %r13d, (%rdx,%r14,4)
movl %r13d, (%rdx,%r15,4)
movq %rbx, %rdi
movl 0x4(%rsp), %esi
movq %rbp, %rdx
movl %r12d, %ecx
movl 0x14(%rsp), %r8d
callq 0x2ba42
movl %eax, %ecx
movq 0x18(%rsp), %rax
movq (%rax), %rdx
movl (%rdx,%r13,4), %eax
movl %eax, (%rdx,%r14,4)
movq (%rbp), %rsi
movl (%rsi), %edi
leal -0x1(%rdi), %eax
movl %eax, (%rsi)
movb 0x10(%rbx), %al
cmpb %cl, %al
jne 0x34381
incq %r14
cmpq %r14, %r15
jne 0x3432a
jmp 0x34383
xorb $0x1, %al
andb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq