// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %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 0x29195(%rip), %rcx     # 0x38658
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
movq %r12, %rsi
callq 0x125ec
jmp 0xf68f
movq (%r12), %rdi
callq 0xf086
leaq 0x8(%rax), %rsi
movq %rsp, %rdi
movq %r15, %rdx
movq %r14, %rcx
callq 0xf49b
movq (%r12), %rdi
callq 0xf086
addq $0x18, %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0xf49b
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
leaq 0x10(%rsp), %rdx
callq 0x11e70
jmp 0xf661
movq (%r12), %rdi
callq 0xf064
leaq 0x8(%rax), %rsi
movq %rsp, %rdi
movq %r15, %rdx
movq %r14, %rcx
callq 0xf49b
movq (%r12), %rdi
callq 0xf064
addq $0x18, %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0xf49b
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
leaq 0x10(%rsp), %rdx
callq 0x11c63
jmp 0xf661
movq (%r12), %rdi
callq 0xf0ca
leaq 0x8(%rax), %rsi
movq %rsp, %rdi
movq %r15, %rdx
movq %r14, %rcx
callq 0xf49b
movq (%r12), %rdi
callq 0xf0ca
addq $0x18, %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0xf49b
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
leaq 0x10(%rsp), %rdx
callq 0x1221d
jmp 0xf661
movq (%r12), %rdi
callq 0xf479
leaq 0x8(%rax), %rsi
movq %rsp, %r12
movq %r12, %rdi
movq %r15, %rdx
movq %r14, %rcx
callq 0xf6d0
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x12417
leaq 0x28(%rsp), %rdi
movaps -0x8(%rdi), %xmm0
andq $0x0, (%rdi)
movups %xmm0, (%rbx)
andq $0x0, -0x8(%rdi)
jmp 0xf680
movq (%r12), %rdi
callq 0xf0a8
leaq 0x8(%rax), %rsi
movq %rsp, %rdi
movq %r15, %rdx
movq %r14, %rcx
callq 0xf49b
movq (%r12), %rdi
callq 0xf0a8
addq $0x18, %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0xf49b
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
leaq 0x10(%rsp), %rdx
callq 0x12047
leaq 0x28(%rsp), %rdi
movaps -0x8(%rdi), %xmm0
andq $0x0, (%rdi)
movups %xmm0, (%rbx)
andq $0x0, -0x8(%rdi)
callq 0xa248
leaq 0x18(%rsp), %rdi
callq 0xa248
leaq 0x8(%rsp), %rdi
callq 0xa248
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
jmp 0xf6a4
jmp 0xf6a4
jmp 0xf6a4
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0xa248
jmp 0xf6be
jmp 0xf6bb
jmp 0xf6bb
jmp 0xf6bb
jmp 0xf6bb
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0xa248
movq %rbx, %rdi
callq 0x94d0