// 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::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 0x34f73(%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 0x12784
movq 0x4fbc2(%rip), %rcx     # 0x61fb0
cmpb $0x0, (%rcx)
je 0x12793
incl 0x8(%rax)
jmp 0x12784
movq (%r12), %rdi
leaq 0x4d926(%rip), %rsi     # 0x5fd30
leaq 0x4d9ff(%rip), %rdx     # 0x5fe10
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x12799
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x1239d
movq (%r12), %rdi
leaq 0x4d8ef(%rip), %rsi     # 0x5fd30
leaq 0x4d9c8(%rip), %rdx     # 0x5fe10
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x1279e
addq $0x18, %rax
leaq 0x18(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x1239d
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4d917(%rip), %rax     # 0x5fda8
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x18(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x1873e
leaq 0x4d943(%rip), %rax     # 0x5fdf8
jmp 0x1275b
movq (%r12), %rdi
leaq 0x4d86b(%rip), %rsi     # 0x5fd30
leaq 0x4d88c(%rip), %rdx     # 0x5fd58
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x12799
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x1239d
movq (%r12), %rdi
leaq 0x4d834(%rip), %rsi     # 0x5fd30
leaq 0x4d855(%rip), %rdx     # 0x5fd58
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x127a3
addq $0x18, %rax
leaq 0x18(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x1239d
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4d77c(%rip), %rax     # 0x5fcc8
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x18(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x1873e
leaq 0x4d7a8(%rip), %rax     # 0x5fd18
jmp 0x1275b
movq (%r12), %rdi
leaq 0x4d7b0(%rip), %rsi     # 0x5fd30
leaq 0x4d9a9(%rip), %rdx     # 0x5ff30
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x12799
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x1239d
movq (%r12), %rdi
leaq 0x4d779(%rip), %rsi     # 0x5fd30
leaq 0x4d972(%rip), %rdx     # 0x5ff30
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x127a8
addq $0x18, %rax
leaq 0x18(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x1239d
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4d8c1(%rip), %rax     # 0x5fec8
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x18(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x1873e
leaq 0x4d8ed(%rip), %rax     # 0x5ff18
jmp 0x1275b
movq (%r12), %rdi
leaq 0x4d6f5(%rip), %rsi     # 0x5fd30
leaq 0x4d97e(%rip), %rdx     # 0x5ffc0
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x12799
addq $0x8, %rax
leaq 0x18(%rsp), %r12
movq %r12, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x127f6
leaq 0x8(%rsp), %rdi
movq $0x0, -0x8(%rdi)
movq %rsp, %rsi
leaq 0x17(%rsp), %rdx
movq %r12, %rcx
callq 0x189e6
movaps (%rsp), %xmm0
xorl %eax, %eax
movq %rax, 0x8(%rsp)
movups %xmm0, (%rbx)
movq %rax, (%rsp)
movq 0x20(%rsp), %rdi
jmp 0x1277a
movq (%r12), %rdi
leaq 0x4d680(%rip), %rsi     # 0x5fd30
leaq 0x4d7e9(%rip), %rdx     # 0x5fea0
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x12799
addq $0x8, %rax
movq %rsp, %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x1239d
movq (%r12), %rdi
leaq 0x4d649(%rip), %rsi     # 0x5fd30
leaq 0x4d7b2(%rip), %rdx     # 0x5fea0
xorl %ecx, %ecx
callq 0x9340
testq %rax, %rax
je 0x127ad
addq $0x18, %rax
leaq 0x18(%rsp), %rdi
movq %rax, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x1239d
movl $0x38, %edi
callq 0x92d0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x4d701(%rip), %rax     # 0x5fe38
movq %rax, (%r14)
movq %r14, %r15
addq $0x10, %r15
movq %rsp, %rsi
leaq 0x18(%rsp), %r12
movq %r15, %rdi
movq %r12, %rdx
callq 0x1873e
leaq 0x4d72d(%rip), %rax     # 0x5fe88
movq %rax, 0x10(%r14)
movq %r15, (%rbx)
movq %r14, 0x8(%rbx)
movq 0x8(%r12), %rdi
testq %rdi, %rdi
je 0x12775
callq 0xa946
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x12784
callq 0xa946
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
lock
incl 0x8(%rax)
jmp 0x12784
callq 0x9530
callq 0x9530
callq 0x9530
callq 0x9530
callq 0x9530
jmp 0x127b8
jmp 0x127b8
jmp 0x127b8
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x127df
callq 0xa946
jmp 0x127df
movq %rax, %rbx
movq 0x20(%rsp), %rdi
jmp 0x127e4
jmp 0x127dc
jmp 0x127dc
jmp 0x127dc
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x127ee
callq 0xa946
movq %rbx, %rdi
callq 0x94e0