// File: pfnet-research[P]pml/src/MDP.cpp
// Function: mdp::mdp_t::merge(mdp::mdp_t&&, mdp::mdp_t&&)
mdp_t mdp_t::merge(mdp_t&& lhs, mdp_t&& rhs) {
    mdp_t result{std::move(lhs)};

    result.variables.reserve(result.variables.size() + rhs.variables.size());
    for (auto&& var : rhs.variables) {
        if (var.is_int() && var.name == "location")
            continue;
        auto found = std::find_if(
                result.variables.begin(), result.variables.end(),
                [&](mdp::variable_t const& var_) {
                    return var_.name == var.name;
                });
        if (found != result.variables.end())
            continue;
        result.variables.emplace_back(std::move(var));
    }

    result.constants.reserve(result.constants.size() + rhs.constants.size());
    for (auto&& cnst : rhs.constants) {
        auto found = std::find_if(
                result.constants.begin(), result.constants.end(),
                [&](mdp::constant_t const& cnst_) {
                    return cnst_.name == cnst.name;
                });
        if (found != result.constants.end())
            continue;
        result.constants.emplace_back(std::move(cnst));
    }

    result.commands.reserve(result.commands.size() + rhs.commands.size());
    std::move(
            rhs.commands.begin(), rhs.commands.end(),
            std::back_inserter(result.commands));
    return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0xf8(%rbp)
movq %rdi, %rax
movq %rax, -0x100(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movb $0x0, -0x19(%rbp)
movq -0x10(%rbp), %rsi
callq 0xbb00
movq -0xf8(%rbp), %rdi
addq $0x20, %rdi
movq %rdi, -0xe8(%rbp)
callq 0xbc90
movq %rax, -0xf0(%rbp)
movq -0x18(%rbp), %rdi
addq $0x20, %rdi
callq 0xbc90
movq -0xf0(%rbp), %rsi
movq -0xe8(%rbp), %rdi
addq %rax, %rsi
callq 0xbb70
jmp 0xa9d8
movq -0x18(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0xbcc0
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
callq 0xbcf0
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0xbd20
testb $0x1, %al
jne 0xaa14
jmp 0xab2b
leaq -0x40(%rbp), %rdi
callq 0xbd60
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0xbd80
movb %al, -0x101(%rbp)
jmp 0xaa32
movb -0x101(%rbp), %al
testb $0x1, %al
jne 0xaa3e
jmp 0xaa84
movq -0x50(%rbp), %rdi
leaq 0x8e71b(%rip), %rsi     # 0x99164
callq 0xbdb0
movb %al, -0x102(%rbp)
jmp 0xaa56
movb -0x102(%rbp), %al
testb $0x1, %al
jne 0xaa62
jmp 0xaa84
jmp 0xab1d
movq -0xf8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
callq 0xc340
jmp 0xad80
movq -0xf8(%rbp), %rdi
addq $0x20, %rdi
movq %rdi, -0x118(%rbp)
callq 0xbcc0
movq -0x118(%rbp), %rdi
movq %rax, -0x60(%rbp)
callq 0xbcf0
movq %rax, -0x68(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x70(%rbp), %rdx
callq 0xad90
movq %rax, -0x110(%rbp)
jmp 0xaad1
movq -0xf8(%rbp), %rdi
movq -0x110(%rbp), %rax
movq %rax, -0x58(%rbp)
addq $0x20, %rdi
callq 0xbcf0
movq %rax, -0x78(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0xbd20
testb $0x1, %al
jne 0xab03
jmp 0xab05
jmp 0xab1d
movq -0xf8(%rbp), %rdi
addq $0x20, %rdi
movq -0x50(%rbp), %rsi
callq 0xbde0
jmp 0xab1b
jmp 0xab1d
leaq -0x40(%rbp), %rdi
callq 0xbe60
jmp 0xa9fe
movq -0xf8(%rbp), %rdi
addq $0x38, %rdi
movq %rdi, -0x120(%rbp)
callq 0xbf80
movq %rax, -0x128(%rbp)
movq -0x18(%rbp), %rdi
addq $0x38, %rdi
callq 0xbf80
movq -0x128(%rbp), %rsi
movq -0x120(%rbp), %rdi
addq %rax, %rsi
callq 0xbe80
jmp 0xab6e
movq -0x18(%rbp), %rax
addq $0x38, %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
callq 0xbfb0
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rdi
callq 0xbfe0
movq %rax, -0x90(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0xc010
testb $0x1, %al
jne 0xabb6
jmp 0xac97
leaq -0x88(%rbp), %rdi
callq 0xc050
movq -0xf8(%rbp), %rdi
movq %rax, -0x98(%rbp)
addq $0x38, %rdi
movq %rdi, -0x138(%rbp)
callq 0xbfb0
movq -0x138(%rbp), %rdi
movq %rax, -0xa8(%rbp)
callq 0xbfe0
movq %rax, -0xb0(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xa8(%rbp), %rdi
movq -0xb0(%rbp), %rsi
movq -0xb8(%rbp), %rdx
callq 0xadf0
movq %rax, -0x130(%rbp)
jmp 0xac2b
movq -0xf8(%rbp), %rdi
movq -0x130(%rbp), %rax
movq %rax, -0xa0(%rbp)
addq $0x38, %rdi
callq 0xbfe0
movq %rax, -0xc0(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0xc010
testb $0x1, %al
jne 0xac69
jmp 0xac6b
jmp 0xac86
movq -0xf8(%rbp), %rdi
addq $0x38, %rdi
movq -0x98(%rbp), %rsi
callq 0xc070
jmp 0xac84
jmp 0xac86
leaq -0x88(%rbp), %rdi
callq 0xc0f0
jmp 0xab9a
movq -0xf8(%rbp), %rdi
addq $0x50, %rdi
movq %rdi, -0x140(%rbp)
callq 0xc210
movq %rax, -0x148(%rbp)
movq -0x18(%rbp), %rdi
addq $0x50, %rdi
callq 0xc210
movq -0x148(%rbp), %rsi
movq -0x140(%rbp), %rdi
addq %rax, %rsi
callq 0xc110
jmp 0xacda
movq -0x18(%rbp), %rdi
addq $0x50, %rdi
callq 0xc2b0
movq %rax, -0xc8(%rbp)
movq -0x18(%rbp), %rdi
addq $0x50, %rdi
callq 0xc2e0
movq -0xf8(%rbp), %rdi
movq %rax, -0xd0(%rbp)
addq $0x50, %rdi
callq 0xc310
movq %rax, -0x150(%rbp)
jmp 0xad1b
movq -0x150(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xc8(%rbp), %rdi
movq -0xd0(%rbp), %rsi
movq -0xd8(%rbp), %rdx
callq 0xc240
movq %rax, -0x158(%rbp)
jmp 0xad4c
movq -0x158(%rbp), %rax
movq %rax, -0xe0(%rbp)
movb $0x1, -0x19(%rbp)
testb $0x1, -0x19(%rbp)
jne 0xad70
movq -0xf8(%rbp), %rdi
callq 0xc340
movq -0x100(%rbp), %rax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0xa650
nopl (%rax)