// 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::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 %r13
pushq %r12
pushq %rbx
subq $0x30, %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 0x359ca(%rip), %rcx     # 0x472ec
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%r12), %r13
leaq 0x4f3d2(%rip), %rsi     # 0x60d08
leaq 0x4f673(%rip), %rdx     # 0x60fb0
movq %r13, %rdi
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x11d7c
movq 0x8(%r15), %rdx
cmpq 0x10(%rax), %rdx
jne 0x11977
testq %rdx, %rdx
je 0x11d6d
movq 0x8(%rax), %rsi
movq (%r15), %rdi
callq 0x9300
testl %eax, %eax
je 0x11d6d
movq %r13, (%rbx)
jmp 0x11bc3
movq (%r12), %rdi
leaq 0x4f37e(%rip), %rsi     # 0x60d08
leaq 0x4f4e7(%rip), %rdx     # 0x60e78
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x11d7c
addq $0x8, %rax
leaq 0x8(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x118f8
movq (%r12), %rdi
leaq 0x4f345(%rip), %rsi     # 0x60d08
leaq 0x4f4ae(%rip), %rdx     # 0x60e78
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x11d81
addq $0x18, %rax
leaq 0x20(%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 0x4f3fd(%rip), %rax     # 0x60e10
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
leaq 0x8(%rsp), %rsi
leaq 0x20(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x18928
leaq 0x4f427(%rip), %rax     # 0x60e60
jmp 0x11ca7
movq (%r12), %rdi
leaq 0x4f2bf(%rip), %rsi     # 0x60d08
leaq 0x4f2e0(%rip), %rdx     # 0x60d30
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x11d7c
addq $0x8, %rax
leaq 0x8(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x118f8
movq (%r12), %rdi
leaq 0x4f286(%rip), %rsi     # 0x60d08
leaq 0x4f2a7(%rip), %rdx     # 0x60d30
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x11d86
addq $0x18, %rax
leaq 0x20(%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 0x4f1ce(%rip), %rax     # 0x60ca0
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
leaq 0x8(%rsp), %rsi
leaq 0x20(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x18928
leaq 0x4f1f8(%rip), %rax     # 0x60cf0
jmp 0x11ca7
movq (%r12), %rdi
leaq 0x4f200(%rip), %rsi     # 0x60d08
leaq 0x4f2d9(%rip), %rdx     # 0x60de8
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x11d7c
addq $0x8, %rax
leaq 0x8(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x118f8
movq (%r12), %rdi
leaq 0x4f1c7(%rip), %rsi     # 0x60d08
leaq 0x4f2a0(%rip), %rdx     # 0x60de8
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x11d8b
addq $0x18, %rax
leaq 0x20(%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 0x4f1ef(%rip), %rax     # 0x60d80
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
leaq 0x8(%rsp), %rsi
leaq 0x20(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x18928
leaq 0x4f219(%rip), %rax     # 0x60dd0
jmp 0x11ca7
movq (%r12), %rax
movq %rax, (%rbx)
movq 0x8(%r12), %rax
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x11d56
movq 0x513d4(%rip), %rcx     # 0x62fb0
cmpb $0x0, (%rcx)
je 0x11d67
incl 0x8(%rax)
jmp 0x11d56
movq (%r12), %rdi
leaq 0x4f110(%rip), %rsi     # 0x60d08
leaq 0x4f309(%rip), %rdx     # 0x60f08
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x11d7c
addq $0x8, %rax
leaq 0x8(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x118f8
movq (%r12), %rdi
leaq 0x4f0d7(%rip), %rsi     # 0x60d08
leaq 0x4f2d0(%rip), %rdx     # 0x60f08
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x11d90
addq $0x18, %rax
leaq 0x20(%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 0x4f21f(%rip), %rax     # 0x60ea0
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
leaq 0x8(%rsp), %rsi
leaq 0x20(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x18928
leaq 0x4f249(%rip), %rax     # 0x60ef0
movq %rax, 0x10(%r14)
movq %r15, (%rbx)
movq %r14, 0x8(%rbx)
movq 0x8(%r12), %rdi
testq %rdi, %rdi
je 0x11cc1
callq 0xaa12
movq 0x10(%rsp), %rdi
jmp 0x11d4c
movq (%r12), %rdi
leaq 0x4f032(%rip), %rsi     # 0x60d08
leaq 0x4f2bb(%rip), %rdx     # 0x60f98
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x11d7c
addq $0x8, %rax
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11dd9
leaq 0x10(%rsp), %rdi
movq $0x0, -0x8(%rdi)
leaq 0x8(%rsp), %rsi
leaq 0x1f(%rsp), %rdx
movq %r12, %rcx
callq 0x18be2
movq 0x8(%rsp), %rax
movq %rax, (%rbx)
xorl %eax, %eax
movq %rax, 0x8(%rbx)
movq 0x10(%rsp), %rcx
movq %rax, 0x10(%rsp)
movq %rcx, 0x8(%rbx)
movq %rax, 0x8(%rsp)
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x11d56
callq 0xaa12
movq %rbx, %rax
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
lock
incl 0x8(%rax)
jmp 0x11d56
movq (%r14), %rax
movq %rax, (%rbx)
movq 0x8(%r14), %rax
jmp 0x11bc8
callq 0x9530
callq 0x9530
callq 0x9530
callq 0x9530
callq 0x9530
jmp 0x11d9b
jmp 0x11d9b
jmp 0x11d9b
movq %rax, %rbx
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x11dc2
callq 0xaa12
jmp 0x11dc2
movq %rax, %rbx
movq 0x28(%rsp), %rdi
jmp 0x11dc7
jmp 0x11dbf
jmp 0x11dbf
jmp 0x11dbf
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x11dd1
callq 0xaa12
movq %rbx, %rdi
callq 0x94e0