// File: /workspace/github_cpp_makefile_star2_O3/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 $0x118, %rsp            # imm = 0x118
movq %rdx, 0x78(%rsp)
testq %rsi, %rsi
je 0x330be
movq %rsi, %r14
movq %rdi, %r15
leaq 0xa8(%rsp), %r13
leaq 0x30(%rsp), %rbp
movq %rsp, %r12
xorl %eax, %eax
movq %rax, 0xa0(%rsp)
xorl %eax, %eax
cmpb (%r15), %al
jno 0x330dc
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1f006
movq 0xb8(%rsp), %rbx
testq %rbx, %rbx
je 0x330c2
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movzbl 0xc2(%rsp), %eax
cmpl $0x1c, %eax
je 0x32eb3
cmpl $0x14, %eax
je 0x32d6f
cmpl $0x11, %eax
jne 0x32ffa
movq %r13, 0x50(%rsp)
xorl %eax, %eax
movq %rax, 0x58(%rsp)
leaq 0x615(%rip), %rcx       # 0x3323c
movq %rcx, 0x60(%rsp)
leaq 0x5db(%rip), %rcx       # 0x3320e
movq %rcx, 0x68(%rsp)
movq %r13, 0x80(%rsp)
movq %rax, 0x88(%rsp)
leaq 0x63f(%rip), %rax       # 0x3328e
movq %rax, 0x90(%rsp)
leaq 0x604(%rip), %rax       # 0x33262
movq %rax, 0x98(%rsp)
movq 0xc8(%rsp), %r13
movq %rbp, %rdi
movq 0xd0(%rsp), %rbp
leaq 0x13e08(%rip), %rax     # 0x46a88
movl (%rax), %eax
xorl %esi, %esi
cmpl $0x3, %eax
setge %sil
leaq 0x15b5(%rip), %rdx      # 0x34247
callq 0x96e6
cmpb $0x1, 0x30(%rsp)
jne 0x32cb4
movq 0x38(%rsp), %rdi
movl $0xa, %edx
leaq 0x503a(%rip), %rsi      # 0x37ce9
callq 0x7570
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq %rbp, %rdx
addq %r13, %rdx
movq %r12, %rdi
movq %rbp, %rsi
callq 0x9760
cmpb $0x1, 0x30(%rsp)
jne 0x32ce8
movq 0x38(%rsp), %rdi
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x7570
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x32d03
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x7500
leaq 0x30(%rsp), %rdi
callq 0x8f4e
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq %rbp, 0x18(%rsp)
movq %r13, 0x20(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
callq 0xb822
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 %r12, %rsi
leaq 0x50(%rsp), %rdx
leaq 0x80(%rsp), %rcx
callq 0x1ee94
leaq 0xa8(%rsp), %r13
jmp 0x32fdd
movq 0xc8(%rsp), %r13
movq %rbp, %rdi
movq 0xd0(%rsp), %rbp
leaq 0x13cff(%rip), %rax     # 0x46a88
movl (%rax), %eax
xorl %esi, %esi
cmpl $0x3, %eax
setge %sil
leaq 0x14ac(%rip), %rdx      # 0x34247
callq 0x96e6
cmpb $0x1, 0x30(%rsp)
jne 0x32dbd
movq 0x38(%rsp), %rdi
movl $0xd, %edx
leaq 0x4f49(%rip), %rsi      # 0x37d01
callq 0x7570
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq %rbp, %rdx
addq %r13, %rdx
movq %r12, %rdi
movq %rbp, %rsi
callq 0x9760
cmpb $0x1, 0x30(%rsp)
jne 0x32df1
movq 0x38(%rsp), %rdi
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x7570
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x32e0c
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x7500
leaq 0x30(%rsp), %r12
movq %r12, %rdi
callq 0x8f4e
leaq 0x140a0(%rip), %rax     # 0x46ec0
incq 0x78(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq %rbp, 0x18(%rsp)
movq %r13, 0x20(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
callq 0xb822
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 %r12, %rdx
callq 0x332fa
leaq 0xa8(%rsp), %r13
movq %r12, %rbp
movq 0x40(%rsp), %rax
testq %rax, %rax
je 0x32e9e
movq %rbp, %rdi
movq %rbp, %rsi
movl $0x3, %edx
callq *%rax
movq (%rsp), %rdi
testq %rdi, %rdi
movq %rsp, %r12
jne 0x32feb
jmp 0x3306a
movq %r13, 0x50(%rsp)
movq $0x0, 0x58(%rsp)
leaq 0x40c(%rip), %rax       # 0x332d4
movq %rax, 0x60(%rsp)
leaq 0x3e0(%rip), %rax       # 0x332b4
movq %rax, 0x68(%rsp)
movq 0xc8(%rsp), %r13
movq %rbp, %rdi
movq 0xd0(%rsp), %rbp
leaq 0x13b95(%rip), %rax     # 0x46a88
movl (%rax), %eax
xorl %esi, %esi
cmpl $0x3, %eax
setge %sil
leaq 0x1342(%rip), %rdx      # 0x34247
callq 0x96e6
cmpb $0x1, 0x30(%rsp)
jne 0x32f27
movq 0x38(%rsp), %rdi
movl $0xc, %edx
leaq 0x4dd2(%rip), %rsi      # 0x37cf4
callq 0x7570
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq %rbp, %rdx
addq %r13, %rdx
movq %r12, %rdi
movq %rbp, %rsi
callq 0x9760
cmpb $0x1, 0x30(%rsp)
jne 0x32f5b
movq 0x38(%rsp), %rdi
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x7570
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x32f76
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x7500
leaq 0x30(%rsp), %rdi
callq 0x8f4e
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq %rbp, 0x18(%rsp)
movq %r13, 0x20(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
callq 0xb822
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 %r12, %rsi
leaq 0x50(%rsp), %rdx
leaq 0x80(%rsp), %rcx
callq 0x1ee94
leaq 0xa8(%rsp), %r13
movq (%rsp), %rdi
testq %rdi, %rdi
leaq 0x30(%rsp), %rbp
je 0x3306a
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x7500
jmp 0x3306a
leaq 0x13a87(%rip), %rax     # 0x46a88
movl (%rax), %esi
notl %esi
shrl $0x1f, %esi
movq %r12, %rdi
leaq 0x11b4(%rip), %rdx      # 0x341c6
callq 0x96e6
movb (%rsp), %al
cmpb $0x1, %al
jne 0x33037
movq 0x8(%rsp), %rdi
movl $0x1b, %edx
leaq 0x4ce0(%rip), %rsi      # 0x37d0f
callq 0x7570
movb (%rsp), %al
testb $0x1, %al
je 0x33062
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
movl 0x18(%rdi,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%rdi,%rax)
movzbl 0xc2(%rsp), %esi
callq 0x7330
movq %r12, %rdi
callq 0x8f4e
movq 0x90(%rsp), %rax
testq %rax, %rax
je 0x33089
leaq 0x80(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x60(%rsp), %rax
testq %rax, %rax
je 0x330a2
leaq 0x50(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
addq %rbx, %r15
subq %rbx, %r14
movq 0xa0(%rsp), %rax
addq %rbx, %rax
testq %r14, %r14
jne 0x32ba2
jmp 0x330ca
xorl %eax, %eax
jmp 0x330ca
movq 0xa0(%rsp), %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x7220
movq %rax, %r14
leaq 0x4be0(%rip), %rsi      # 0x37cd0
movq %rax, %rdi
callq 0x7190
movq 0x12ef1(%rip), %rsi     # 0x45ff0
movq 0x12e6a(%rip), %rdx     # 0x45f70
movq %r14, %rdi
callq 0x7960
jmp 0x3311c
jmp 0x331a0
jmp 0x3311c
jmp 0x331a0
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x331a3
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x7500
jmp 0x331a3
jmp 0x331a0
jmp 0x33140
movq %rax, %rbx
movq %rsp, %rdi
jmp 0x331a8
jmp 0x33205
jmp 0x3315a
jmp 0x33205
jmp 0x331a0
jmp 0x331af
jmp 0x331af
movq %rax, %rbx
jmp 0x33184
jmp 0x33205
jmp 0x331a0
jmp 0x331af
movq %rax, %rbx
movq 0x40(%rsp), %rax
testq %rax, %rax
je 0x33184
leaq 0x30(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x331b2
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x7500
jmp 0x331b2
jmp 0x33205
jmp 0x33205
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x8f4e
jmp 0x331b2
movq %rax, %rbx
movq 0x90(%rsp), %rax
testq %rax, %rax
je 0x331d1
leaq 0x80(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x60(%rsp), %rax
testq %rax, %rax
je 0x331f7
leaq 0x50(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x331f7
movq %rax, %rbx
movq %r14, %rdi
callq 0x7370
movq %rbx, %rdi
callq 0x79a0
jmp 0x33205
jmp 0x33205
jmp 0x33205
movq %rax, %rdi
callq 0x8f80
nop