// File: /workspace/github_cpp_makefile_star2_O3/pfnet-research[P]pml/src/logic.cpp
// Function: logic::subst(std::shared_ptr<logic::formula_t> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::shared_ptr<logic::term_t> const&)
ptr<formula_t> subst(
        ptr<formula_t> const& f,
        std::string const& var, ptr<term_t> const& t) {
    switch (f->kind()) {
    case formula_kind_t::Neg:
        return make<neg_formula_t>(subst(cast<neg_formula_t>(*f).inner, var, t));
    case formula_kind_t::And:
        return make<and_formula_t>(
                subst(cast<and_formula_t>(*f).lhs, var, t),
                subst(cast<and_formula_t>(*f).rhs, var, t));
    case formula_kind_t::Or:
        return make<or_formula_t>(
                subst(cast<or_formula_t>(*f).lhs, var, t),
                subst(cast<or_formula_t>(*f).rhs, var, t));
    case formula_kind_t::Impl:
        return make<impl_formula_t>(
                subst(cast<impl_formula_t>(*f).lhs, var, t),
                subst(cast<impl_formula_t>(*f).rhs, var, t));
    case formula_kind_t::Eq:
        return make<eq_formula_t>(
                subst(cast<eq_formula_t>(*f).lhs, var, t),
                subst(cast<eq_formula_t>(*f).rhs, var, t));
    case formula_kind_t::Lt:
        return make<less_formula_t>(
                subst(cast<less_formula_t>(*f).lhs, var, t),
                subst(cast<less_formula_t>(*f).rhs, var, t));
    case formula_kind_t::Leq:
        return make<leq_formula_t>(
                subst(cast<leq_formula_t>(*f).lhs, var, t),
                subst(cast<leq_formula_t>(*f).rhs, var, t));
    case formula_kind_t::Geq:
        return make<geq_formula_t>(
                subst(cast<geq_formula_t>(*f).lhs, var, t),
                subst(cast<geq_formula_t>(*f).rhs, var, t));
    case formula_kind_t::Gt:
        return make<greater_formula_t>(
                subst(cast<greater_formula_t>(*f).lhs, var, t),
                subst(cast<greater_formula_t>(*f).rhs, var, t));
    case formula_kind_t::Var:
    case formula_kind_t::Top:
    case formula_kind_t::Bot:
        return f;
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
movq (%rsi), %rdi
movq (%rdi), %rax
callq *(%rax)
movl %eax, %eax
leaq 0x35697(%rip), %rcx     # 0x47308
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%r12), %rax
movq %rax, (%rbx)
movq 0x8(%r12), %rax
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x12307
movq 0x50316(%rip), %rcx     # 0x61fb0
cmpb $0x0, (%rcx)
je 0x12316
incl 0x8(%rax)
jmp 0x12307
movq (%r12), %rdi
leaq 0x4e3b2(%rip), %rsi     # 0x60068
leaq 0x4e56b(%rip), %rdx     # 0x60228
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x1231c
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11c49
movq (%r12), %rdi
leaq 0x4e37b(%rip), %rsi     # 0x60068
leaq 0x4e534(%rip), %rdx     # 0x60228
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x12321
addq $0x18, %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11c49
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4e483(%rip), %rax     # 0x601c0
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x10(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x18ed8
jmp 0x122e2
movq (%r12), %rdi
leaq 0x4e2fe(%rip), %rsi     # 0x60068
leaq 0x4e7c7(%rip), %rdx     # 0x60538
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x1231c
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11790
movq (%r12), %rdi
leaq 0x4e2c7(%rip), %rsi     # 0x60068
leaq 0x4e790(%rip), %rdx     # 0x60538
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x12326
addq $0x18, %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11790
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4e6df(%rip), %rax     # 0x604d0
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x10(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x19002
leaq 0x4e70b(%rip), %rax     # 0x60520
jmp 0x122de
movq (%r12), %rdi
leaq 0x4e243(%rip), %rsi     # 0x60068
leaq 0x4e36c(%rip), %rdx     # 0x60198
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x1231c
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11c49
movq (%r12), %rdi
leaq 0x4e20c(%rip), %rsi     # 0x60068
leaq 0x4e335(%rip), %rdx     # 0x60198
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x1232b
addq $0x18, %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11c49
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4e284(%rip), %rax     # 0x60130
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x10(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x18dae
jmp 0x122e2
movq (%r12), %rdi
leaq 0x4e18f(%rip), %rsi     # 0x60068
leaq 0x4e538(%rip), %rdx     # 0x60418
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x1231c
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11790
movq (%r12), %rdi
leaq 0x4e158(%rip), %rsi     # 0x60068
leaq 0x4e501(%rip), %rdx     # 0x60418
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x12330
addq $0x18, %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11790
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4e450(%rip), %rax     # 0x603b0
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x10(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x19002
leaq 0x4e47c(%rip), %rax     # 0x60400
jmp 0x122de
movq (%r12), %rdi
leaq 0x4e0d4(%rip), %rsi     # 0x60068
leaq 0x4e0dd(%rip), %rdx     # 0x60078
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x1231c
addq $0x8, %rax
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11c49
leaq 0x8(%rsp), %rdi
movq $0x0, -0x8(%rdi)
movq %rsp, %rsi
leaq 0x27(%rsp), %rdx
movq %r12, %rcx
callq 0x18b04
movaps (%rsp), %xmm0
xorl %eax, %eax
movq %rax, 0x8(%rsp)
movups %xmm0, (%rbx)
movq %rax, (%rsp)
movq 0x18(%rsp), %rdi
jmp 0x122fd
movq (%r12), %rdi
leaq 0x4e05f(%rip), %rsi     # 0x60068
leaq 0x4e0f8(%rip), %rdx     # 0x60108
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x1231c
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11c49
movq (%r12), %rdi
leaq 0x4e028(%rip), %rsi     # 0x60068
leaq 0x4e0c1(%rip), %rdx     # 0x60108
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x12335
addq $0x18, %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11c49
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4e010(%rip), %rax     # 0x600a0
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x10(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x18c84
jmp 0x122e2
movq (%r12), %rdi
leaq 0x4dfab(%rip), %rsi     # 0x60068
leaq 0x4e20c(%rip), %rdx     # 0x602d0
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x1231c
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11790
movq (%r12), %rdi
leaq 0x4df74(%rip), %rsi     # 0x60068
leaq 0x4e1d5(%rip), %rdx     # 0x602d0
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x1233a
addq $0x18, %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11790
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4e10c(%rip), %rax     # 0x60250
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x10(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x19002
leaq 0x4e138(%rip), %rax     # 0x602a0
jmp 0x122de
movq (%r12), %rdi
leaq 0x4def0(%rip), %rsi     # 0x60068
leaq 0x4e329(%rip), %rdx     # 0x604a8
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x1231c
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11790
movq (%r12), %rdi
leaq 0x4deb9(%rip), %rsi     # 0x60068
leaq 0x4e2f2(%rip), %rdx     # 0x604a8
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x1233f
addq $0x18, %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11790
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4e241(%rip), %rax     # 0x60440
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x10(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x19002
leaq 0x4e26d(%rip), %rax     # 0x60490
jmp 0x122de
movq (%r12), %rdi
leaq 0x4de35(%rip), %rsi     # 0x60068
leaq 0x4e14e(%rip), %rdx     # 0x60388
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x1231c
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11790
movq (%r12), %rdi
leaq 0x4ddfe(%rip), %rsi     # 0x60068
leaq 0x4e117(%rip), %rdx     # 0x60388
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x12344
addq $0x18, %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11790
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4e066(%rip), %rax     # 0x60320
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x10(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x19002
leaq 0x4e092(%rip), %rax     # 0x60370
movq %rax, 0x10(%r14)
movq %r15, (%rbx)
movq %r14, 0x8(%rbx)
movq 0x8(%r12), %rdi
testq %rdi, %rdi
je 0x122f8
callq 0xa946
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x12307
callq 0xa946
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
lock
incl 0x8(%rax)
jmp 0x12307
callq 0x9530
callq 0x9530
callq 0x9530
callq 0x9530
callq 0x9530
callq 0x9530
callq 0x9530
callq 0x9530
callq 0x9530
jmp 0x12357
jmp 0x12357
jmp 0x12357
jmp 0x12357
jmp 0x12357
jmp 0x12357
jmp 0x12357
movq %rax, %rbx
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x12386
callq 0xa946
jmp 0x12386
movq %rax, %rbx
movq 0x18(%rsp), %rdi
jmp 0x1238b
jmp 0x12383
jmp 0x12383
jmp 0x12383
jmp 0x12383
jmp 0x12383
jmp 0x12383
jmp 0x12383
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x12395
callq 0xa946
movq %rbx, %rdi
callq 0x94e0