// 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::term_t> const&)
ptr<term_t> subst(
        ptr<term_t> const& t1,
        std::string const& var, ptr<term_t> const& t2) {
    switch (t1->kind()) {
    case term_kind_t::Add:
        return make<add_term_t>(
                subst(logic::cast<add_term_t>(*t1).lhs, var, t2),
                subst(logic::cast<add_term_t>(*t1).rhs, var, t2));
    case term_kind_t::Sub:
        return make<sub_term_t>(
                subst(logic::cast<sub_term_t>(*t1).lhs, var, t2),
                subst(logic::cast<sub_term_t>(*t1).rhs, var, t2));
    case term_kind_t::Mul:
        return make<mul_term_t>(
                subst(logic::cast<mul_term_t>(*t1).lhs, var, t2),
                subst(logic::cast<mul_term_t>(*t1).rhs, var, t2));
    case term_kind_t::Div:
        return make<div_term_t>(
                subst(logic::cast<div_term_t>(*t1).lhs, var, t2),
                subst(logic::cast<div_term_t>(*t1).rhs, var, t2));
    case term_kind_t::Prob:
        return make<prob_term_t>(subst(cast<prob_term_t>(*t1).inner, var ,t2));
    case term_kind_t::Var:
        if (var == cast<var_term_t>(*t1).name)
            return t2;
        else
            return t1;
    case term_kind_t::Int:
        return t1;
    }
}

// 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 0x297f4(%rip), %rcx     # 0x3860c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%r12), %rdi
leaq 0x4aef4(%rip), %rsi     # 0x59d20
leaq 0x4b195(%rip), %rdx     # 0x59fc8
xorl %ecx, %ecx
callq 0x9330
testq %rax, %rax
je 0xf02d
addq $0x8, %rax
movq %r15, %rdi
movq %rax, %rsi
callq 0xa5de
testb %al, %al
je 0xee5e
movq %rbx, %rdi
movq %r14, %rsi
jmp 0xee64
movq %rbx, %rdi
movq %r12, %rsi
callq 0x125ec
jmp 0xf01e
movq (%r12), %rdi
callq 0xf0a8
leaq 0x8(%rax), %rsi
movq %rsp, %rdi
movq %r15, %rdx
movq %r14, %rcx
callq 0xedf0
movq (%r12), %rdi
callq 0xf0a8
addq $0x18, %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0xedf0
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
leaq 0x10(%rsp), %rdx
callq 0x12047
jmp 0xefae
movq (%r12), %rdi
callq 0xf064
leaq 0x8(%rax), %rsi
movq %rsp, %rdi
movq %r15, %rdx
movq %r14, %rcx
callq 0xedf0
movq (%r12), %rdi
callq 0xf064
addq $0x18, %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0xedf0
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
leaq 0x10(%rsp), %rdx
callq 0x11c63
jmp 0xefae
movq (%r12), %rdi
callq 0xf086
leaq 0x8(%rax), %rsi
movq %rsp, %rdi
movq %r15, %rdx
movq %r14, %rcx
callq 0xedf0
movq (%r12), %rdi
callq 0xf086
addq $0x18, %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0xedf0
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
leaq 0x10(%rsp), %rdx
callq 0x11e70
jmp 0xefae
movq (%r12), %rdi
callq 0xf0ca
leaq 0x8(%rax), %rsi
movq %rsp, %rdi
movq %r15, %rdx
movq %r14, %rcx
callq 0xedf0
movq (%r12), %rdi
callq 0xf0ca
addq $0x18, %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0xedf0
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
leaq 0x10(%rsp), %rdx
callq 0x1221d
leaq 0x28(%rsp), %rdi
movaps -0x8(%rdi), %xmm0
andq $0x0, (%rdi)
movups %xmm0, (%rbx)
andq $0x0, -0x8(%rdi)
callq 0xa248
leaq 0x18(%rsp), %rdi
jmp 0xf00f
movq (%r12), %rdi
callq 0xf479
leaq 0x8(%rax), %rsi
movq %rsp, %r12
movq %r12, %rdi
movq %r15, %rdx
movq %r14, %rcx
callq 0xf0ec
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)
callq 0xa248
leaq 0x8(%rsp), %rdi
callq 0xa248
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
callq 0x9510
jmp 0xf038
jmp 0xf038
jmp 0xf038
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0xa248
jmp 0xf052
jmp 0xf04f
jmp 0xf04f
jmp 0xf04f
jmp 0xf04f
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0xa248
movq %rbx, %rdi
callq 0x94d0