// File: /workspace/github_cpp_makefile_star2_O3/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 0x35b32(%rip), %rcx     # 0x472ec
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%r12), %r13
leaq 0x4e562(%rip), %rsi     # 0x5fd30
leaq 0x4e803(%rip), %rdx     # 0x5ffd8
movq %r13, %rdi
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x11bec
movq 0x8(%r15), %rdx
cmpq 0x10(%rax), %rdx
jne 0x1180f
testq %rdx, %rdx
je 0x11bdd
movq 0x8(%rax), %rsi
movq (%r15), %rdi
callq 0x9300
testl %eax, %eax
je 0x11bdd
movq %r13, (%rbx)
jmp 0x11a4f
movq (%r12), %rdi
leaq 0x4e50e(%rip), %rsi     # 0x5fd30
leaq 0x4e677(%rip), %rdx     # 0x5fea0
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x11bec
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11790
movq (%r12), %rdi
leaq 0x4e4d7(%rip), %rsi     # 0x5fd30
leaq 0x4e640(%rip), %rdx     # 0x5fea0
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x11bf1
addq $0x18, %rax
leaq 0x20(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11790
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4e58f(%rip), %rax     # 0x5fe38
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x20(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x1873e
leaq 0x4e5bb(%rip), %rax     # 0x5fe88
jmp 0x11b2f
movq (%r12), %rdi
leaq 0x4e453(%rip), %rsi     # 0x5fd30
leaq 0x4e474(%rip), %rdx     # 0x5fd58
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x11bec
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11790
movq (%r12), %rdi
leaq 0x4e41c(%rip), %rsi     # 0x5fd30
leaq 0x4e43d(%rip), %rdx     # 0x5fd58
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x11bf6
addq $0x18, %rax
leaq 0x20(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11790
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4e364(%rip), %rax     # 0x5fcc8
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x20(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x1873e
leaq 0x4e390(%rip), %rax     # 0x5fd18
jmp 0x11b2f
movq (%r12), %rdi
leaq 0x4e398(%rip), %rsi     # 0x5fd30
leaq 0x4e471(%rip), %rdx     # 0x5fe10
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x11bec
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11790
movq (%r12), %rdi
leaq 0x4e361(%rip), %rsi     # 0x5fd30
leaq 0x4e43a(%rip), %rdx     # 0x5fe10
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x11bfb
addq $0x18, %rax
leaq 0x20(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11790
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4e389(%rip), %rax     # 0x5fda8
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x20(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x1873e
leaq 0x4e3b5(%rip), %rax     # 0x5fdf8
jmp 0x11b2f
movq (%r12), %rax
movq %rax, (%rbx)
movq 0x8(%r12), %rax
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x11bc6
movq 0x50548(%rip), %rcx     # 0x61fb0
cmpb $0x0, (%rcx)
je 0x11bd7
incl 0x8(%rax)
jmp 0x11bc6
movq (%r12), %rdi
leaq 0x4e2ac(%rip), %rsi     # 0x5fd30
leaq 0x4e4a5(%rip), %rdx     # 0x5ff30
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x11bec
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11790
movq (%r12), %rdi
leaq 0x4e275(%rip), %rsi     # 0x5fd30
leaq 0x4e46e(%rip), %rdx     # 0x5ff30
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x11c00
addq $0x18, %rax
leaq 0x20(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11790
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4e3bd(%rip), %rax     # 0x5fec8
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x20(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x1873e
leaq 0x4e3e9(%rip), %rax     # 0x5ff18
movq %rax, 0x10(%r14)
movq %r15, (%rbx)
movq %r14, 0x8(%rbx)
movq 0x8(%r12), %rdi
testq %rdi, %rdi
je 0x11b49
callq 0xa946
movq 0x8(%rsp), %rdi
jmp 0x11bbc
movq (%r12), %rdi
leaq 0x4e1d5(%rip), %rsi     # 0x5fd30
leaq 0x4e45e(%rip), %rdx     # 0x5ffc0
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x11bec
addq $0x8, %rax
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x11c49
leaq 0x8(%rsp), %rdi
movq $0x0, -0x8(%rdi)
movq %rsp, %rsi
leaq 0x1f(%rsp), %rdx
movq %r12, %rcx
callq 0x189e6
movaps (%rsp), %xmm0
xorl %eax, %eax
movq %rax, 0x8(%rsp)
movups %xmm0, (%rbx)
movq %rax, (%rsp)
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x11bc6
callq 0xa946
movq %rbx, %rax
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
lock
incl 0x8(%rax)
jmp 0x11bc6
movq (%r14), %rax
movq %rax, (%rbx)
movq 0x8(%r14), %rax
jmp 0x11a54
callq 0x9530
callq 0x9530
callq 0x9530
callq 0x9530
callq 0x9530
jmp 0x11c0b
jmp 0x11c0b
jmp 0x11c0b
movq %rax, %rbx
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x11c32
callq 0xa946
jmp 0x11c32
movq %rax, %rbx
movq 0x28(%rsp), %rdi
jmp 0x11c37
jmp 0x11c2f
jmp 0x11c2f
jmp 0x11c2f
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x11c41
callq 0xa946
movq %rbx, %rdi
callq 0x94e0