// File: /workspace/github_cpp_makefile_star2_O1/pfnet-research[P]pml/src/logic.cpp
// Function: logic::subst(std::shared_ptr<logic::term_t> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::shared_ptr<logic::formula_t> const&)
ptr<term_t> subst(
        ptr<term_t> const& t,
        std::string const& var, ptr<formula_t> const& f) {
    switch (t->kind()) {
    case term_kind_t::Add:
        return make<add_term_t>(
                subst(logic::cast<add_term_t>(*t).lhs, var, f),
                subst(logic::cast<add_term_t>(*t).rhs, var, f));
    case term_kind_t::Sub:
        return make<sub_term_t>(
                subst(logic::cast<sub_term_t>(*t).lhs, var, f),
                subst(logic::cast<sub_term_t>(*t).rhs, var, f));
    case term_kind_t::Mul:
        return make<mul_term_t>(
                subst(logic::cast<mul_term_t>(*t).lhs, var, f),
                subst(logic::cast<mul_term_t>(*t).rhs, var, f));
    case term_kind_t::Div:
        return make<div_term_t>(
                subst(logic::cast<div_term_t>(*t).lhs, var, f),
                subst(logic::cast<div_term_t>(*t).rhs, var, f));
    case term_kind_t::Prob:
        return make<prob_term_t>(subst(cast<prob_term_t>(*t).inner, var ,f));
    case term_kind_t::Var:
    case term_kind_t::Int:
        return t;
    }
}

// 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 0x34dd6(%rip), %rcx     # 0x47338
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 0x1292e
movq 0x50a25(%rip), %rcx     # 0x62fb0
cmpb $0x0, (%rcx)
je 0x1293d
incl 0x8(%rax)
jmp 0x1292e
movq (%r12), %rdi
leaq 0x4e761(%rip), %rsi     # 0x60d08
leaq 0x4e83a(%rip), %rdx     # 0x60de8
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x12943
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x1253a
movq (%r12), %rdi
leaq 0x4e72a(%rip), %rsi     # 0x60d08
leaq 0x4e803(%rip), %rdx     # 0x60de8
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x12948
addq $0x18, %rax
leaq 0x18(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x1253a
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4e752(%rip), %rax     # 0x60d80
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x18(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x18928
leaq 0x4e77e(%rip), %rax     # 0x60dd0
jmp 0x12905
movq (%r12), %rdi
leaq 0x4e6a6(%rip), %rsi     # 0x60d08
leaq 0x4e6c7(%rip), %rdx     # 0x60d30
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x12943
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x1253a
movq (%r12), %rdi
leaq 0x4e66f(%rip), %rsi     # 0x60d08
leaq 0x4e690(%rip), %rdx     # 0x60d30
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x1294d
addq $0x18, %rax
leaq 0x18(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x1253a
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4e5b7(%rip), %rax     # 0x60ca0
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x18(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x18928
leaq 0x4e5e3(%rip), %rax     # 0x60cf0
jmp 0x12905
movq (%r12), %rdi
leaq 0x4e5eb(%rip), %rsi     # 0x60d08
leaq 0x4e7e4(%rip), %rdx     # 0x60f08
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x12943
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x1253a
movq (%r12), %rdi
leaq 0x4e5b4(%rip), %rsi     # 0x60d08
leaq 0x4e7ad(%rip), %rdx     # 0x60f08
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x12952
addq $0x18, %rax
leaq 0x18(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x1253a
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4e6fc(%rip), %rax     # 0x60ea0
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x18(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x18928
leaq 0x4e728(%rip), %rax     # 0x60ef0
jmp 0x12905
movq (%r12), %rdi
leaq 0x4e530(%rip), %rsi     # 0x60d08
leaq 0x4e7b9(%rip), %rdx     # 0x60f98
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x12943
addq $0x8, %rax
leaq 0x18(%rsp), %r12
movq %r12, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x129a0
leaq 0x8(%rsp), %rdi
movq $0x0, -0x8(%rdi)
movq %rsp, %rsi
leaq 0x17(%rsp), %rdx
movq %r12, %rcx
callq 0x18be2
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 0x20(%rsp), %rdi
jmp 0x12924
movq (%r12), %rdi
leaq 0x4e4ae(%rip), %rsi     # 0x60d08
leaq 0x4e617(%rip), %rdx     # 0x60e78
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x12943
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x1253a
movq (%r12), %rdi
leaq 0x4e477(%rip), %rsi     # 0x60d08
leaq 0x4e5e0(%rip), %rdx     # 0x60e78
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x12957
addq $0x18, %rax
leaq 0x18(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x1253a
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4e52f(%rip), %rax     # 0x60e10
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x18(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x18928
leaq 0x4e55b(%rip), %rax     # 0x60e60
movq %rax, 0x10(%r14)
movq %r15, (%rbx)
movq %r14, 0x8(%rbx)
movq 0x8(%r12), %rdi
testq %rdi, %rdi
je 0x1291f
callq 0xaa12
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x1292e
callq 0xaa12
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
lock
incl 0x8(%rax)
jmp 0x1292e
callq 0x9530
callq 0x9530
callq 0x9530
callq 0x9530
callq 0x9530
jmp 0x12962
jmp 0x12962
jmp 0x12962
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x12989
callq 0xaa12
jmp 0x12989
movq %rax, %rbx
movq 0x20(%rsp), %rdi
jmp 0x1298e
jmp 0x12986
jmp 0x12986
jmp 0x12986
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x12998
callq 0xaa12
movq %rbx, %rdi
callq 0x94e0