// File: /workspace/github_cpp_makefile_star2_O1/cybozu[P]yrmcds/src/memcache/replication.cpp
// Function: yrmcds::memcache::repl_recv(char const*, unsigned long, cybozu::hash_map<yrmcds::memcache::object>&)
std::size_t repl_recv(const char* p, std::size_t len,
                      cybozu::hash_map<object>& hash) {
    std::size_t consumed = 0;
    while( len > 0 ) {
        if( ! is_binary_request(p) )
            throw std::runtime_error("Invalid replication data");

        binary_request parser(p, len);
        std::size_t n = parser.length();
        if( n == 0 ) break;
        p += n;
        len -= n;
        consumed += n;

        const char* key_data;
        std::size_t key_len;
        cybozu::hash_map<object>::handler h = nullptr;
        cybozu::hash_map<object>::creator c = nullptr;

        switch( parser.command() ) {
        case binary_command::SetQ:
            h = [&parser](const cybozu::hash_key&, object& obj) -> bool {
                const char* p2;
                std::size_t len2;
                std::tie(p2, len2) = parser.data();
                ++ g_stats.repl_updated;
                obj.set(p2, len2, parser.flags(), parser.exptime());
                return true;
            };
            c = [&parser](const cybozu::hash_key&) -> object {
                const char* p2;
                std::size_t len2;
                std::tie(p2, len2) = parser.data();
                ++ g_stats.repl_created;
                return object(p2, len2, parser.flags(), parser.exptime());
            };
            std::tie(key_data, key_len) = parser.key();
            cybozu::logger::debug() << "repl: set "
                                    << std::string(key_data, key_len);
            hash.apply_nolock(cybozu::hash_key(key_data, key_len), h, c);
            break;
        case binary_command::Touch:
            h = [&parser](const cybozu::hash_key&, object& obj) -> bool {
                ++ g_stats.repl_updated;
                obj.touch( parser.exptime() );
                return true;
            };
            std::tie(key_data, key_len) = parser.key();
            cybozu::logger::debug() << "repl: touch "
                                    << std::string(key_data, key_len);
            hash.apply_nolock(cybozu::hash_key(key_data, key_len), h, c);
            break;
        case binary_command::DeleteQ:
            std::tie(key_data, key_len) = parser.key();
            cybozu::logger::debug() << "repl: remove "
                                    << std::string(key_data, key_len);
            ++ g_stats.repl_removed;
            hash.remove_nolock(cybozu::hash_key(key_data, key_len), nullptr);
            break;
        default:
            cybozu::logger::error() << "Unknown replication command"
                                    << std::hex
                                    << (unsigned int)parser.command();
        }
    }
    return consumed;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %rdx, 0x78(%rsp)
movq %rsi, %r14
movq %rdi, %rbp
xorl %r12d, %r12d
leaq 0xb0(%rsp), %r13
leaq 0x30(%rsp), %r15
movq $0x0, 0xa0(%rsp)
testq %r14, %r14
je 0x33b66
cmpb (%rbp), %r12b
jno 0x33b80
movq %r13, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x1f802
movq 0xc0(%rsp), %rbx
testq %rbx, %rbx
je 0x33b5d
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movzbl 0xca(%rsp), %eax
cmpl $0x1c, %eax
je 0x33923
cmpl $0x14, %eax
je 0x337df
cmpl $0x11, %eax
jne 0x33aa4
movaps %xmm0, (%rsp)
movaps %xmm0, 0x10(%rsp)
movq %r13, (%rsp)
movq (%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x58(%rsp)
movaps %xmm0, (%rsp)
movq 0x60(%rsp), %rax
movq 0x68(%rsp), %rcx
movq %rax, 0x10(%rsp)
leaq 0x6e6(%rip), %rdx       # 0x33d0c
movq %rdx, 0x60(%rsp)
movq %rcx, 0x18(%rsp)
leaq 0x6a7(%rip), %rcx       # 0x33cde
movq %rcx, 0x68(%rsp)
testq %rax, %rax
je 0x3364e
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movaps %xmm0, 0x10(%rsp)
movq %r13, (%rsp)
leaq 0x6cd(%rip), %rdx       # 0x33d32
movq %rdx, 0x18(%rsp)
leaq 0x6ed(%rip), %rsi       # 0x33d5e
movq %rsi, 0x10(%rsp)
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
movaps 0x80(%rsp), %xmm0
movaps %xmm0, (%rsp)
movq %rax, 0x80(%rsp)
movq %rcx, 0x88(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %rsi, 0x90(%rsp)
movq 0x98(%rsp), %rcx
movq %rcx, 0x18(%rsp)
movq %rdx, 0x98(%rsp)
testq %rax, %rax
je 0x336d7
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0xd0(%rsp), %r12
movq 0xd8(%rsp), %r13
leaq 0x133aa(%rip), %rax     # 0x46a98
movl (%rax), %eax
xorl %esi, %esi
cmpl $0x3, %eax
setge %sil
movq %r15, %rdi
leaq 0xb44(%rip), %rdx       # 0x34247
callq 0x9718
cmpb $0x1, 0x30(%rsp)
jne 0x33725
movq 0x38(%rsp), %rdi
movl $0xa, %edx
leaq 0x4609(%rip), %rsi      # 0x37d29
callq 0x7580
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
leaq (%r12,%r13), %rdx
movq %rsp, %rdi
movq %r13, %rsi
callq 0x97a0
cmpb $0x1, 0x30(%rsp)
jne 0x33757
movq 0x38(%rsp), %rdi
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x7580
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x33772
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x7510
movq %r15, %rdi
callq 0x8f94
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq %r13, 0x18(%rsp)
movq %r12, 0x20(%rsp)
movq %r13, %rdi
movq %r12, %rsi
callq 0xb88a
movq %rax, 0x28(%rsp)
xorl %edx, %edx
movq 0x78(%rsp), %rcx
divq (%rcx)
leaq (%rdx,%rdx,2), %rdi
shlq $0x4, %rdi
addq 0x8(%rcx), %rdi
movq %rsp, %rsi
leaq 0x50(%rsp), %rdx
leaq 0x80(%rsp), %rcx
callq 0x1f686
xorl %r12d, %r12d
leaq 0xb0(%rsp), %r13
jmp 0x33a88
movq 0xd0(%rsp), %r12
movq 0xd8(%rsp), %r13
leaq 0x132a2(%rip), %rax     # 0x46a98
movl (%rax), %eax
xorl %esi, %esi
cmpl $0x3, %eax
setge %sil
movq %r15, %rdi
leaq 0xa3c(%rip), %rdx       # 0x34247
callq 0x9718
cmpb $0x1, 0x30(%rsp)
jne 0x3382d
movq 0x38(%rsp), %rdi
movl $0xd, %edx
leaq 0x4519(%rip), %rsi      # 0x37d41
callq 0x7580
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
leaq (%r12,%r13), %rdx
movq %rsp, %rdi
movq %r13, %rsi
callq 0x97a0
cmpb $0x1, 0x30(%rsp)
jne 0x3385f
movq 0x38(%rsp), %rdi
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x7580
movq %rbp, 0xa8(%rsp)
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x33882
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x7510
movq %r15, %rbp
movq %r15, %rdi
callq 0x8f94
leaq 0x1362c(%rip), %rax     # 0x46ec0
incq 0x78(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq %r13, 0x18(%rsp)
movq %r12, 0x20(%rsp)
movq %r13, %rdi
movq %r12, %rsi
callq 0xb88a
movq %rax, 0x28(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
xorl %edx, %edx
movq 0x78(%rsp), %rcx
divq (%rcx)
leaq (%rdx,%rdx,2), %rdi
shlq $0x4, %rdi
addq 0x8(%rcx), %rdi
movq %rsp, %rsi
movq %rbp, %rdx
callq 0x33dca
xorl %r12d, %r12d
leaq 0xb0(%rsp), %r13
movq 0x40(%rsp), %rax
testq %rax, %rax
movq 0xa8(%rsp), %rbp
je 0x33a88
movq %r15, %rdi
movq %r15, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x33a88
movaps %xmm0, (%rsp)
movaps %xmm0, 0x10(%rsp)
movq %r13, (%rsp)
movq (%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x58(%rsp)
movaps %xmm0, (%rsp)
movq 0x60(%rsp), %rax
movq 0x68(%rsp), %rcx
movq %rax, 0x10(%rsp)
leaq 0x447(%rip), %rdx       # 0x33da4
movq %rdx, 0x60(%rsp)
movq %rcx, 0x18(%rsp)
leaq 0x416(%rip), %rcx       # 0x33d84
movq %rcx, 0x68(%rsp)
testq %rax, %rax
je 0x33985
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0xd0(%rsp), %r12
movq 0xd8(%rsp), %r13
leaq 0x130fc(%rip), %rax     # 0x46a98
movl (%rax), %eax
xorl %esi, %esi
cmpl $0x3, %eax
setge %sil
movq %r15, %rdi
leaq 0x896(%rip), %rdx       # 0x34247
callq 0x9718
cmpb $0x1, 0x30(%rsp)
jne 0x339d3
movq 0x38(%rsp), %rdi
movl $0xc, %edx
leaq 0x4366(%rip), %rsi      # 0x37d34
callq 0x7580
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
leaq (%r12,%r13), %rdx
movq %rsp, %rdi
movq %r13, %rsi
callq 0x97a0
cmpb $0x1, 0x30(%rsp)
jne 0x33a05
movq 0x38(%rsp), %rdi
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x7580
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x33a20
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x7510
movq %r15, %rdi
callq 0x8f94
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq %r13, 0x18(%rsp)
movq %r12, 0x20(%rsp)
movq %r13, %rdi
movq %r12, %rsi
callq 0xb88a
movq %rax, 0x28(%rsp)
xorl %edx, %edx
movq 0x78(%rsp), %rcx
divq (%rcx)
leaq (%rdx,%rdx,2), %rdi
shlq $0x4, %rdi
addq 0x8(%rcx), %rdi
movq %rsp, %rsi
leaq 0x50(%rsp), %rdx
leaq 0x80(%rsp), %rcx
callq 0x1f686
xorl %r12d, %r12d
leaq 0xb0(%rsp), %r13
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x33b17
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x7510
jmp 0x33b17
leaq 0x12fed(%rip), %rax     # 0x46a98
movl (%rax), %esi
notl %esi
shrl $0x1f, %esi
movq %rsp, %rdi
leaq 0x70a(%rip), %rdx       # 0x341c6
callq 0x9718
cmpb $0x1, (%rsp)
jne 0x33add
movq 0x8(%rsp), %rdi
movl $0x1b, %edx
leaq 0x4277(%rip), %rsi      # 0x37d4f
callq 0x7580
cmpb $0x1, (%rsp)
jne 0x33b0f
movq 0x8(%rsp), %rax
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rax,%rcx)
movzbl 0xca(%rsp), %esi
movq 0x8(%rsp), %rdi
callq 0x7330
movq %rsp, %rdi
callq 0x8f94
movq 0x90(%rsp), %rax
testq %rax, %rax
je 0x33b36
leaq 0x80(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x60(%rsp), %rax
testq %rax, %rax
je 0x33b4f
leaq 0x50(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
addq %rbx, %rbp
subq %rbx, %r14
addq %rbx, 0xa0(%rsp)
testq %rbx, %rbx
jne 0x3357a
movq 0xa0(%rsp), %rax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x7220
movq %rax, %r14
leaq 0x417c(%rip), %rsi      # 0x37d10
movq %rax, %rdi
callq 0x7190
movq 0x1244d(%rip), %rsi     # 0x45ff0
movq 0x123c6(%rip), %rdx     # 0x45f70
movq %r14, %rdi
callq 0x7970
jmp 0x33bc0
jmp 0x33c75
jmp 0x33bc0
jmp 0x33c75
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x33c78
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x7510
jmp 0x33c78
jmp 0x33c75
jmp 0x33bee
movq %rax, %rbx
movq %rsp, %rdi
jmp 0x33c7d
jmp 0x33cd5
jmp 0x33cd5
jmp 0x33cd5
jmp 0x33cd5
jmp 0x33c53
jmp 0x33c53
jmp 0x33c58
jmp 0x33cd5
jmp 0x33c75
jmp 0x33c53
movq %rax, %rbx
movq 0x40(%rsp), %rax
testq %rax, %rax
je 0x33c38
leaq 0x30(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
leaq 0x30(%rsp), %rdi
movq %rsp, %rsi
callq 0x7f58
jmp 0x33c82
jmp 0x33cd5
jmp 0x33cd5
jmp 0x33c75
movq %rax, %rbx
jmp 0x33c82
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x33c82
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x7510
jmp 0x33c82
jmp 0x33cd5
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x8f94
movq 0x90(%rsp), %rax
testq %rax, %rax
je 0x33ca1
leaq 0x80(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x60(%rsp), %rax
testq %rax, %rax
je 0x33ccd
leaq 0x50(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x33ccd
jmp 0x33cd5
jmp 0x33cd5
jmp 0x33cd5
movq %rax, %rbx
movq %r14, %rdi
callq 0x7370
movq %rbx, %rdi
callq 0x79b0
movq %rax, %rdi
callq 0x8fc6
nop