// File: /workspace/github_cpp_makefile_star2_O2/eryxcc[P]lois/src/element.cpp
// Function: lois::aggressive_simplify(std::vector<std::shared_ptr<lois::Variable>, std::allocator<std::shared_ptr<lois::Variable>>>&, lois::rbool&, std::shared_ptr<lois::Context>&, std::function<bool (std::shared_ptr<lois::Variable>)>, std::function<void (std::vector<std::pair<std::shared_ptr<lois::Variable>, lois::term>, std::allocator<std::pair<std::shared_ptr<lois::Variable>, lois::term>>> const&)>)
void aggressive_simplify(varlist& selvar, rbool& selphi, contextptr& ain, std::function<bool(vptr)> a_isused, std::function<void(const varsubstlist&)> a_alpha) {
  if(selphi.isTrue()) return;
  if(!aggressive_simplification_tries) return;

  int size1 = selphi->formulasize();
  
  simplifyWhat = selphi;
  
  rbool phi ( std::make_shared<FormulaQ> (false, rbool(simplifier), selvar) );
  
  phi = outenv(phi, false, emptycontext, ain);

  if(notForInternalSolver(phi)) return;

  simplifyWhat->clearinfo();

  // cout << "AGGRESSIVE SIMPLIFY " << phi << endl;
  
  checkid++;
  phi->initDomains();

  triesleft = aggressive_simplification_tries; 
  try { phi->verify();
  } catch(unsolvable_exception) {
    triesleft = -1;
    }

  if(triesleft <= 0) {
    std::cout << "simplification failed for rbool of size " << size1 << std::endl;
    std::cout << phi << std::endl;
    std::cout << "NFI is : " << notForInternalSolver(phi) << std::endl;
    std::cout << "features are: ";

    featurelist fl;
    phi->listFeatures(fl);
    for(auto r: fl.relations) std::cout << (r->getName()); std::cout << std::endl;

    exit(1);
    return;
    }
  
  rbool orig = selphi;
  
  selphi = simplifyWhat->qsimplify();
  // cout << "simplification result: " << sel.phi << endl;

  int size3 = selphi->formulasize();
  
  if(size1 == size3) {
    // printf("Not Simplified: %d in %d tries\n", size1, aggressive_simplification_tries-triesleft);
    // cout << "orig: " << orig << endl;
    return;
    }

  if(simplifyVerbosity >= 1) 
     printf("Simplified: %d to %d in %d tries\n", size1, size3, aggressive_simplification_tries-triesleft);

  // std::cout << "FROM: " << phi << std::endl << "TO: " << selphi << std::endl;
  
  varlist var2;
  swap(var2, selvar);
  
  for(auto w: var2) 
    if(selphi->uses(w) || a_isused(w)) {
      term w1 = selphi->valueKnown(w, false);
      if(w1.p) {
        varsubstlist l = { make_pair(w, w1) };
        selphi = substitute(selphi,l);
        a_alpha(l);
        }
      else selvar.push_back(w);
      }
    
  aggressive_simplify(selvar, selphi, ain, a_isused, a_alpha);
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %r8, 0x30(%rsp)
movq %rcx, 0x38(%rsp)
movq %rdi, 0x10(%rsp)
movq (%rsi), %rdi
leaq 0x1a1bc(%rip), %rax     # 0x497b0
cmpq (%rax), %rdi
je 0x2fac7
cmpl $0x0, 0x1a5d4(%rip)     # 0x49bd8
je 0x2fac7
movq %rdx, %r13
movq %rsi, %rbx
movq (%rdi), %rax
callq *0x50(%rax)
movl %eax, %ebp
leaq 0x1a599(%rip), %rdi     # 0x49bb8
movq %rbx, 0x8(%rsp)
movq %rbx, %rsi
callq 0x11250
leaq 0x1f0(%rsp), %rbx
movb $0x0, (%rbx)
leaq 0x1a58a(%rip), %rsi     # 0x49bc8
leaq 0x130(%rsp), %r15
movq %r15, %rdi
callq 0x2ff24
leaq 0x50(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0xf04a
leaq 0x140(%rsp), %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq 0x10(%rsp), %rcx
callq 0x2233a
leaq 0x1a8(%rsp), %rbx
leaq 0x148(%rsp), %r15
movaps -0x8(%r15), %xmm0
movaps %xmm0, -0x8(%rbx)
xorps %xmm0, %xmm0
movaps %xmm0, -0x8(%r15)
leaq 0x18(%rsp), %r12
leaq 0x1a0(%rsp), %rsi
movq %r12, %rdi
callq 0xf04a
movq %rbx, %rdi
callq 0xefce
movq %r15, %rdi
callq 0xefce
leaq 0x58(%rsp), %rdi
callq 0xefce
leaq 0x138(%rsp), %rdi
callq 0xefce
leaq 0x120(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0xf04a
leaq 0x1a073(%rip), %rsi     # 0x49760
leaq 0x110(%rsp), %r15
movq %r15, %rdi
callq 0xf7c2
leaq 0x100(%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0xf7c2
leaq 0x140(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %r15, %rcx
movq %r12, %r8
callq 0x1e4fb
leaq 0x18(%rsp), %rbx
leaq 0x140(%rsp), %rsi
movq %rbx, %rdi
callq 0xf3dc
leaq 0x148(%rsp), %r12
movq %r12, %rdi
callq 0xefce
leaq 0x108(%rsp), %rdi
callq 0xefce
leaq 0x118(%rsp), %rdi
callq 0xefce
leaq 0x128(%rsp), %rdi
callq 0xefce
leaq 0xf0(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0xf04a
movq %r15, %rdi
callq 0x27e00
movl %eax, %ebx
leaq 0xf8(%rsp), %rdi
callq 0xefce
testb %bl, %bl
jne 0x2fabd
movq 0x1a40b(%rip), %rdi     # 0x49bb8
movq (%rdi), %rax
callq *0x48(%rax)
leaq 0x19fee(%rip), %rax     # 0x497a8
incl (%rax)
movq 0x18(%rsp), %rdi
movq (%rdi), %rax
callq *0x38(%rax)
movl 0x1a40b(%rip), %eax     # 0x49bd8
leaq 0x19fcc(%rip), %r15     # 0x497a0
movl %eax, (%r15)
movq 0x18(%rsp), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
cmpl $0x0, (%r15)
jle 0x2fad9
leaq 0xc0(%rsp), %rdi
movq 0x8(%rsp), %r12
movq %r12, %rsi
callq 0xf04a
movq 0x1a3b0(%rip), %rsi     # 0x49bb8
leaq 0x140(%rsp), %rdi
callq 0x224ae
leaq 0x140(%rsp), %rsi
movq %r12, %rdi
callq 0xf3dc
leaq 0x148(%rsp), %rdi
callq 0xefce
movq (%r12), %rdi
movq (%rdi), %rax
callq *0x50(%rax)
cmpl %eax, %ebp
je 0x2fab0
movq %r13, 0x70(%rsp)
cmpl $0x0, 0x1a38c(%rip)     # 0x49bdc
jle 0x2f86d
movl 0x1a380(%rip), %ecx     # 0x49bd8
subl (%r15), %ecx
leaq 0x3a7f(%rip), %rdi      # 0x332e1
movl %ebp, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x7040
movq 0x10(%rsp), %rcx
movq (%rcx), %r13
movq %r13, 0x50(%rsp)
movq 0x8(%rcx), %rax
movq %rax, 0x78(%rsp)
movq %rax, 0x58(%rsp)
movq 0x10(%rcx), %rax
movq %rax, 0x60(%rsp)
leaq 0x48(%rsp), %rax
movq %rax, 0x28(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rcx)
andq $0x0, 0x10(%rcx)
leaq 0xb0(%rsp), %rbp
leaq 0x140(%rsp), %r14
leaq 0x1f0(%rsp), %r15
cmpq 0x78(%rsp), %r13
je 0x2fa46
movq %r15, %rbx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x1160e
movq (%r12), %r12
leaq 0x80(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
callq 0x1160e
movq (%r12), %rax
movq %r12, %rdi
movq %r15, %rsi
callq *0x28(%rax)
testb %al, %al
je 0x2f913
leaq 0x88(%rsp), %rdi
callq 0xefce
movq 0x8(%rsp), %r12
jmp 0x2f961
leaq 0xa0(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
callq 0x1160e
movq 0x38(%rsp), %rdi
movq %r15, %rsi
callq 0x2fe36
movl %eax, %r12d
leaq 0xa8(%rsp), %rdi
callq 0xefce
leaq 0x88(%rsp), %rdi
callq 0xefce
testb %r12b, %r12b
movq %rbx, %r15
movq 0x8(%rsp), %r12
je 0x2fa30
movq (%r12), %r12
leaq 0x90(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
callq 0x1160e
movq (%r12), %rax
leaq 0x40(%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq *0x30(%rax)
leaq 0x98(%rsp), %rdi
callq 0xefce
cmpq $0x0, 0x40(%rsp)
movq %rbx, %r15
je 0x2fa14
movq %r14, %rbx
movq %r14, %rdi
movq %rbp, %rsi
leaq 0x40(%rsp), %rdx
callq 0x116b4
movq %r15, %rdi
movq %r14, %rsi
pushq $0x1
popq %rdx
leaq 0x7(%rsp), %rcx
callq 0x2fe4a
movq 0x8(%rsp), %r12
movq %rbx, %rdi
callq 0x11678
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x216a8
movq %r12, %rdi
movq %rbx, %rsi
callq 0xf3dc
leaq 0x148(%rsp), %rdi
callq 0xefce
movq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x2fe84
movq %r15, %rdi
callq 0x11692
jmp 0x2fa26
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x11466
movq 0x8(%rsp), %r12
leaq 0x48(%rsp), %rdi
callq 0xefce
leaq 0xb8(%rsp), %rdi
callq 0xefce
addq $0x10, %r13
jmp 0x2f8be
leaq 0x1d0(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x2fe98
leaq 0x1b0(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x2fede
movq 0x70(%rsp), %rdx
leaq 0x1d0(%rsp), %rcx
leaq 0x1b0(%rsp), %r8
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x2f5ca
leaq 0x1b0(%rsp), %rdi
callq 0x11a68
leaq 0x1d0(%rsp), %rdi
callq 0x11a68
leaq 0x50(%rsp), %rdi
callq 0x114e6
leaq 0xc8(%rsp), %rdi
callq 0xefce
leaq 0x20(%rsp), %rdi
callq 0xefce
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x194f0(%rip), %rdi     # 0x48fd0
leaq 0x37b8(%rip), %rsi      # 0x3329f
callq 0x7230
movq %rax, %rdi
movl %ebp, %esi
callq 0x7400
movq %rax, %rdi
callq 0x7130
leaq 0xe0(%rsp), %rbx
leaq 0x18(%rsp), %rsi
movq %rbx, %rdi
callq 0xf04a
movq 0x194b6(%rip), %rdi     # 0x48fd0
movq %rbx, %rsi
callq 0x1ef1c
movq %rax, %rdi
callq 0x7130
leaq 0xe8(%rsp), %rdi
callq 0xefce
movq 0x19492(%rip), %rdi     # 0x48fd0
leaq 0x3783(%rip), %rsi      # 0x332c8
callq 0x7230
movq %rax, %rbx
leaq 0xd0(%rsp), %r14
leaq 0x18(%rsp), %rsi
movq %r14, %rdi
callq 0xf04a
movq %r14, %rdi
callq 0x27e00
movzbl %al, %esi
movq %rbx, %rdi
callq 0x73d0
movq %rax, %rdi
callq 0x7130
leaq 0xd8(%rsp), %rdi
callq 0xefce
movq 0x1943f(%rip), %rdi     # 0x48fd0
leaq 0x373a(%rip), %rsi      # 0x332d2
callq 0x7230
movq %r12, %rax
leaq 0x178(%rsp), %r12
andl $0x0, -0x30(%r12)
andq $0x0, -0x28(%r12)
movq %rax, -0x20(%r12)
movq %rax, -0x18(%r12)
andq $0x0, -0x10(%r12)
andl $0x0, (%r12)
andq $0x0, 0x8(%r12)
movq %r12, 0x10(%r12)
movq %r12, 0x18(%r12)
andq $0x0, 0x20(%r12)
movq 0x18(%rsp), %rdi
movq (%rdi), %rax
leaq 0x140(%rsp), %rsi
callq *0x40(%rax)
movq 0x188(%rsp), %r15
leaq 0x50(%rsp), %rbx
movq 0x193ca(%rip), %r14     # 0x48fd0
cmpq %r12, %r15
je 0x2fc38
movq 0x20(%r15), %rsi
movq (%rsi), %rax
movq %rbx, %rdi
callq *0x38(%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7210
movq %rbx, %rdi
callq 0x7478
movq %r15, %rdi
callq 0x7290
movq %rax, %r15
jmp 0x2fc06
movq 0x19391(%rip), %rdi     # 0x48fd0
callq 0x7130
pushq $0x1
popq %rdi
callq 0x72c0
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x7478
jmp 0x2fc60
jmp 0x2fc5d
movq %rax, %rbx
leaq 0x140(%rsp), %rdi
callq 0x28770
jmp 0x2fdfe
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
jmp 0x2fdf9
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
jmp 0x2fdf9
movq %rax, %rbx
leaq 0x1b0(%rsp), %rdi
callq 0x11a68
jmp 0x2fca7
movq %rax, %rbx
leaq 0x1d0(%rsp), %rdi
callq 0x11a68
jmp 0x2fde7
movq %rax, %rbx
jmp 0x2fde7
jmp 0x2fcc3
movq %rax, %rbx
jmp 0x2fdf1
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x2fdfe
movq %rbx, %rdi
callq 0x72d0
leaq 0x17cc2(%rip), %rax     # 0x479a8
leaq 0x140(%rsp), %r12
movq %rax, (%r12)
movq %rbx, %rdi
callq 0x7110
orl $-0x1, (%r15)
movq %r12, %rdi
callq 0x7480
callq 0x73c0
leaq 0x148(%rsp), %r12
jmp 0x2f7e2
jmp 0x2fd6e
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
jmp 0x2fdf9
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0xefce
leaq 0x118(%rsp), %rdi
callq 0xefce
leaq 0x128(%rsp), %rdi
jmp 0x2fdf9
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0xefce
leaq 0x138(%rsp), %rdi
jmp 0x2fe03
movq %rax, %rbx
jmp 0x2fdfe
movq %rax, %rbx
jmp 0x2fdc3
jmp 0x2fd7d
movq %rax, %rbx
leaq 0x1f0(%rsp), %rdi
callq 0x11692
jmp 0x2fdc3
movq %rax, %rbx
leaq 0x140(%rsp), %rdi
callq 0x11678
jmp 0x2fdc3
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0xefce
jmp 0x2fdcd
movq %rax, %rbx
leaq 0x98(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rdi
jmp 0x2fdd5
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0xefce
leaq 0xb8(%rsp), %rdi
callq 0xefce
leaq 0x50(%rsp), %rdi
callq 0x114e6
leaq 0xc8(%rsp), %rdi
callq 0xefce
leaq 0x20(%rsp), %rdi
callq 0xefce
movq %rbx, %rdi
callq 0x7410