// File: /workspace/github_cpp_makefile_star2_O1/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 0x35507(%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 0x124a4
movq 0x51186(%rip), %rcx     # 0x62fb0
cmpb $0x0, (%rcx)
je 0x124b3
incl 0x8(%rax)
jmp 0x124a4
movq (%r12), %rdi
leaq 0x4f1fa(%rip), %rsi     # 0x61040
leaq 0x4f3b3(%rip), %rdx     # 0x61200
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x124b9
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11dd9
movq (%r12), %rdi
leaq 0x4f1c3(%rip), %rsi     # 0x61040
leaq 0x4f37c(%rip), %rdx     # 0x61200
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x124be
addq $0x18, %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11dd9
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4f2cb(%rip), %rax     # 0x61198
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x10(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x190f2
jmp 0x1247f
movq (%r12), %rdi
leaq 0x4f146(%rip), %rsi     # 0x61040
leaq 0x4f60f(%rip), %rdx     # 0x61510
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x124b9
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x118f8
movq (%r12), %rdi
leaq 0x4f10f(%rip), %rsi     # 0x61040
leaq 0x4f5d8(%rip), %rdx     # 0x61510
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x124c3
addq $0x18, %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x118f8
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4f527(%rip), %rax     # 0x614a8
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x10(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x19222
leaq 0x4f553(%rip), %rax     # 0x614f8
jmp 0x1247b
movq (%r12), %rdi
leaq 0x4f08b(%rip), %rsi     # 0x61040
leaq 0x4f1b4(%rip), %rdx     # 0x61170
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x124b9
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11dd9
movq (%r12), %rdi
leaq 0x4f054(%rip), %rsi     # 0x61040
leaq 0x4f17d(%rip), %rdx     # 0x61170
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x124c8
addq $0x18, %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11dd9
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4f0cc(%rip), %rax     # 0x61108
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x10(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x18fc2
jmp 0x1247f
movq (%r12), %rdi
leaq 0x4efd7(%rip), %rsi     # 0x61040
leaq 0x4f380(%rip), %rdx     # 0x613f0
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x124b9
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x118f8
movq (%r12), %rdi
leaq 0x4efa0(%rip), %rsi     # 0x61040
leaq 0x4f349(%rip), %rdx     # 0x613f0
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x124cd
addq $0x18, %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x118f8
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4f298(%rip), %rax     # 0x61388
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x10(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x19222
leaq 0x4f2c4(%rip), %rax     # 0x613d8
jmp 0x1247b
movq (%r12), %rdi
leaq 0x4ef1c(%rip), %rsi     # 0x61040
leaq 0x4ef25(%rip), %rdx     # 0x61050
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x124b9
addq $0x8, %rax
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11dd9
leaq 0x8(%rsp), %rdi
movq $0x0, -0x8(%rdi)
movq %rsp, %rsi
leaq 0x27(%rsp), %rdx
movq %r12, %rcx
callq 0x18d06
movq (%rsp), %rax
movq %rax, (%rbx)
xorl %eax, %eax
movq %rax, 0x8(%rbx)
movq 0x8(%rsp), %rcx
movq %rax, 0x8(%rsp)
movq %rcx, 0x8(%rbx)
movq %rax, (%rsp)
movq 0x18(%rsp), %rdi
jmp 0x1249a
movq (%r12), %rdi
leaq 0x4ee9a(%rip), %rsi     # 0x61040
leaq 0x4ef33(%rip), %rdx     # 0x610e0
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x124b9
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11dd9
movq (%r12), %rdi
leaq 0x4ee63(%rip), %rsi     # 0x61040
leaq 0x4eefc(%rip), %rdx     # 0x610e0
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x124d2
addq $0x18, %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11dd9
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4ee4b(%rip), %rax     # 0x61078
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x10(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x18e92
jmp 0x1247f
movq (%r12), %rdi
leaq 0x4ede6(%rip), %rsi     # 0x61040
leaq 0x4f047(%rip), %rdx     # 0x612a8
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x124b9
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x118f8
movq (%r12), %rdi
leaq 0x4edaf(%rip), %rsi     # 0x61040
leaq 0x4f010(%rip), %rdx     # 0x612a8
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x124d7
addq $0x18, %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x118f8
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4ef47(%rip), %rax     # 0x61228
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x10(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x19222
leaq 0x4ef73(%rip), %rax     # 0x61278
jmp 0x1247b
movq (%r12), %rdi
leaq 0x4ed2b(%rip), %rsi     # 0x61040
leaq 0x4f164(%rip), %rdx     # 0x61480
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x124b9
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x118f8
movq (%r12), %rdi
leaq 0x4ecf4(%rip), %rsi     # 0x61040
leaq 0x4f12d(%rip), %rdx     # 0x61480
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x124dc
addq $0x18, %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x118f8
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4f07c(%rip), %rax     # 0x61418
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x10(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x19222
leaq 0x4f0a8(%rip), %rax     # 0x61468
jmp 0x1247b
movq (%r12), %rdi
leaq 0x4ec70(%rip), %rsi     # 0x61040
leaq 0x4ef89(%rip), %rdx     # 0x61360
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x124b9
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x118f8
movq (%r12), %rdi
leaq 0x4ec39(%rip), %rsi     # 0x61040
leaq 0x4ef52(%rip), %rdx     # 0x61360
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x124e1
addq $0x18, %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x118f8
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4eea1(%rip), %rax     # 0x612f8
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x10(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x19222
leaq 0x4eecd(%rip), %rax     # 0x61348
movq %rax, 0x10(%r14)
movq %r15, (%rbx)
movq %r14, 0x8(%rbx)
movq 0x8(%r12), %rdi
testq %rdi, %rdi
je 0x12495
callq 0xaa12
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x124a4
callq 0xaa12
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
lock
incl 0x8(%rax)
jmp 0x124a4
callq 0x9530
callq 0x9530
callq 0x9530
callq 0x9530
callq 0x9530
callq 0x9530
callq 0x9530
callq 0x9530
callq 0x9530
jmp 0x124f4
jmp 0x124f4
jmp 0x124f4
jmp 0x124f4
jmp 0x124f4
jmp 0x124f4
jmp 0x124f4
movq %rax, %rbx
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x12523
callq 0xaa12
jmp 0x12523
movq %rax, %rbx
movq 0x18(%rsp), %rdi
jmp 0x12528
jmp 0x12520
jmp 0x12520
jmp 0x12520
jmp 0x12520
jmp 0x12520
jmp 0x12520
jmp 0x12520
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x12532
callq 0xaa12
movq %rbx, %rdi
callq 0x94e0