// File: /workspace/github_cpp_makefile_star2_O2/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 $0x148, %rsp            # imm = 0x148
movq %rdx, 0x48(%rsp)
movq %rsi, %r14
movq %rdi, %r12
leaq 0xc0(%rsp), %rbx
leaq 0x10(%rsp), %r15
leaq 0x50(%rsp), %rbp
xorl %r13d, %r13d
testq %r14, %r14
je 0x25865
movq %r13, 0xb8(%rsp)
xorl %eax, %eax
cmpb (%r12), %al
jno 0x2587a
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1b196
movq 0xd0(%rsp), %r13
testq %r13, %r13
je 0x2585d
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movzbl 0xda(%rsp), %eax
cmpl $0x1c, %eax
je 0x256df
cmpl $0x14, %eax
je 0x25604
cmpl $0x11, %eax
jne 0x257d9
movq %r12, 0x8(%rsp)
movups %xmm0, 0x18(%rsp)
movq %rbx, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0x58(%rsp)
movaps %xmm0, 0x10(%rsp)
leaq 0x480(%rip), %rax       # 0x25966
movq %rax, 0x60(%rsp)
andq $0x0, 0x28(%rsp)
leaq 0x440(%rip), %rax       # 0x25938
movq %rax, 0x68(%rsp)
movq %r15, %rdi
callq 0x8d90
andq $0x0, 0x18(%rsp)
movq %rbx, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
movaps 0x90(%rsp), %xmm0
movaps 0xa0(%rsp), %xmm1
movaps %xmm0, 0x10(%rsp)
movq %rax, 0x90(%rsp)
movq %rcx, 0x98(%rsp)
leaq 0x472(%rip), %rax       # 0x259b8
movq %rax, 0xa0(%rsp)
movaps %xmm1, 0x20(%rsp)
leaq 0x432(%rip), %rax       # 0x2598c
movq %rax, 0xa8(%rsp)
movq %r15, %rdi
callq 0x8d90
movq 0xe0(%rsp), %r12
movq 0xe8(%rsp), %rbp
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
callq 0x9360
movq %rbx, %rdi
leaq 0x4718(%rip), %rsi      # 0x29ca9
callq 0x11924
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq (%r12,%rbp), %rdx
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
callq 0x8e92
movq %rbx, %rdi
movq %r15, %rsi
callq 0x869a
movq %r15, %rdi
callq 0x71d0
leaq 0x70(%rsp), %rdi
callq 0x86e4
movq %r15, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x12e4c
movq 0x48(%rsp), %rdi
movq %r15, %rsi
leaq 0x50(%rsp), %rbp
movq %rbp, %rdx
leaq 0x90(%rsp), %rcx
callq 0x25a22
jmp 0x257c2
movq %r14, 0x8(%rsp)
movq 0xe0(%rsp), %r15
movq 0xe8(%rsp), %rbp
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
callq 0x9360
movq %r12, %r14
movq %rbx, %rdi
leaq 0x468e(%rip), %rsi      # 0x29cc1
callq 0x15362
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq (%r15,%rbp), %rdx
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rsi
callq 0x8e92
movq %rbx, %rdi
movq %r12, %rsi
callq 0x869a
movq %r12, %rdi
callq 0x71d0
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
callq 0x86e4
leaq 0x16840(%rip), %rax     # 0x3bec0
incq 0x78(%rax)
movq %r12, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x12e4c
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movq 0x48(%rsp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x25a42
movq %r12, %r15
movq %rbx, %rdi
callq 0x8d90
movq %r12, %rdi
callq 0x11e84
leaq 0xc0(%rsp), %rbx
movq %r14, %r12
movq 0x8(%rsp), %r14
leaq 0x50(%rsp), %rbp
jmp 0x2582f
movq %r12, 0x8(%rsp)
movups %xmm0, 0x18(%rsp)
movq %rbx, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0x58(%rsp)
movaps %xmm0, 0x10(%rsp)
leaq 0x2ee(%rip), %rax       # 0x259fc
movq %rax, 0x60(%rsp)
andq $0x0, 0x28(%rsp)
leaq 0x2be(%rip), %rax       # 0x259de
movq %rax, 0x68(%rsp)
movq %r15, %rdi
callq 0x8d90
movq 0xe0(%rsp), %r12
movq 0xe8(%rsp), %rbp
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
callq 0x9360
movq %rbx, %rdi
leaq 0x4560(%rip), %rsi      # 0x29cb4
callq 0x1d036
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq (%r12,%rbp), %rdx
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
callq 0x8e92
movq %rbx, %rdi
movq %r15, %rsi
callq 0x869a
movq %r15, %rdi
callq 0x71d0
leaq 0x70(%rsp), %rdi
callq 0x86e4
movq %r15, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x12e4c
movq 0x48(%rsp), %rdi
movq %r15, %rsi
leaq 0x50(%rsp), %rbp
movq %rbp, %rdx
leaq 0x90(%rsp), %rcx
callq 0x25a22
movq %r15, %rdi
callq 0x11e84
leaq 0xc0(%rsp), %rbx
movq 0x8(%rsp), %r12
jmp 0x2582f
movq %r15, %rdi
callq 0x865e
movq %r15, %rdi
leaq 0x44e4(%rip), %rsi      # 0x29ccf
callq 0xecbe
cmpb $0x1, (%rax)
jne 0x2580e
movq 0x8(%rax), %rcx
movq (%rcx), %rdx
movq -0x18(%rdx), %rdx
movl 0x18(%rcx,%rdx), %esi
andl $-0x4b, %esi
orl $0x8, %esi
movl %esi, 0x18(%rcx,%rdx)
movzbl 0xda(%rsp), %ecx
movl %ecx, 0x70(%rsp)
movq %rax, %rdi
leaq 0x70(%rsp), %rsi
callq 0xf382
movq %r15, %rdi
callq 0x86e4
addq %r13, %r12
subq %r13, %r14
movq 0xb8(%rsp), %rax
addq %r13, %rax
movq %rax, %r13
leaq 0x90(%rsp), %rdi
callq 0x8d90
movq %rbp, %rdi
callq 0x8d90
jmp 0x2543b
movq 0xb8(%rsp), %r13
movq %r13, %rax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x7240
movq %rax, %r14
leaq 0x4404(%rip), %rsi      # 0x29c90
movq %rax, %rdi
callq 0x7190
movq 0x15755(%rip), %rsi     # 0x3aff0
movq 0x156ce(%rip), %rdx     # 0x3af70
movq %r14, %rdi
callq 0x7950
jmp 0x258cb
jmp 0x258da
jmp 0x258eb
jmp 0x258eb
jmp 0x25908
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x8d90
jmp 0x258ce
jmp 0x258da
jmp 0x258eb
jmp 0x258eb
jmp 0x25908
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x11e84
jmp 0x2590b
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x71d0
jmp 0x258ee
jmp 0x258eb
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x86e4
jmp 0x2590b
jmp 0x25908
jmp 0x258fe
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
jmp 0x258f3
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x8d90
leaq 0x50(%rsp), %rdi
callq 0x8d90
movq %rbx, %rdi
callq 0x7990
movq %rax, %rbx
movq %r14, %rdi
callq 0x7390
jmp 0x25922
nop