// File: theuni[P]libbtcnet/src/connectionbase.cpp
// Function: ConnectionBase::read_cb_chunk(bufferevent*, void*)
void ConnectionBase::read_cb_chunk(bufferevent* bev, void* ctx)
{
    assert(ctx);
    assert(bev);

    ConnectionBase* base = static_cast<ConnectionBase*>(ctx);
    const CNetworkConfig& netconfig = base->m_connection.GetNetConfig();
    assert(netconfig.chunk_size > 0);
    size_t chunk_size = netconfig.chunk_size;

    std::list<std::vector<unsigned char> > msgs;
    size_t remaining;
    evbuffer* input;
    {
        BufferEventLocker lock(bev);
        input = bufferevent_get_input(bev);
        remaining = evbuffer_get_length(input);
        while (remaining >= chunk_size) {
            msgs.emplace_back(chunk_size);
            evbuffer_remove(input, msgs.back().data(), chunk_size);
            remaining -= chunk_size;
        }
    }
    evbuffer_expand(input, chunk_size);
    if (!msgs.empty())
        base->m_handler.OnReceiveMessages(base->m_id, std::move(msgs), msgs.size() * chunk_size);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x1b8ec
jmp 0x1b90b
leaq 0xb2bc(%rip), %rdi      # 0x26baf
leaq 0xb07e(%rip), %rsi      # 0x26978
movl $0x14c, %edx            # imm = 0x14C
leaq 0xb3e5(%rip), %rcx      # 0x26ceb
callq 0x52e0
cmpq $0x0, -0x8(%rbp)
je 0x1b914
jmp 0x1b933
leaq 0xaf0a(%rip), %rdi      # 0x26825
leaq 0xb056(%rip), %rsi      # 0x26978
movl $0x14d, %edx            # imm = 0x14D
leaq 0xb3bd(%rip), %rcx      # 0x26ceb
callq 0x52e0
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
addq $0x18, %rdi
callq 0xa9e0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x28(%rax)
jle 0x1b958
jmp 0x1b977
leaq 0xb3cd(%rip), %rdi      # 0x26d2c
leaq 0xb012(%rip), %rsi      # 0x26978
movl $0x151, %edx            # imm = 0x151
leaq 0xb379(%rip), %rcx      # 0x26ceb
callq 0x52e0
movq -0x20(%rbp), %rax
movslq 0x28(%rax), %rax
movq %rax, -0x28(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x1c910
movq -0x8(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x1c730
jmp 0x1b99b
movq -0x8(%rbp), %rdi
callq 0x5300
movq %rax, -0x70(%rbp)
jmp 0x1b9aa
movq -0x70(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0x5440
movq %rax, -0x78(%rbp)
jmp 0x1b9c1
movq -0x78(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x28(%rbp), %rax
jb 0x1ba49
leaq -0x40(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1c930
jmp 0x1b9e2
movq -0x50(%rbp), %rax
movq %rax, -0x80(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x1c970
movq %rax, %rdi
callq 0xcee0
movq -0x80(%rbp), %rdi
movq %rax, %rsi
movq -0x28(%rbp), %rdx
callq 0x54e0
jmp 0x1ba0d
movq -0x28(%rbp), %rcx
movq -0x48(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x48(%rbp)
jmp 0x1b9c9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x1bad6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x1c760
jmp 0x1bad6
leaq -0x58(%rbp), %rdi
callq 0x1c760
movq -0x50(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x5200
jmp 0x1ba61
leaq -0x40(%rbp), %rdi
callq 0x1c9b0
testb $0x1, %al
jne 0x1bac4
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movq %rcx, -0x98(%rbp)
movq 0x190(%rax), %rax
movq %rax, -0x90(%rbp)
leaq -0x40(%rbp), %rdi
movq %rdi, -0x88(%rbp)
callq 0x1c9d0
movq -0x98(%rbp), %rdi
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
movq %rax, %rcx
movq -0x28(%rbp), %rax
imulq %rax, %rcx
callq 0xf9f0
jmp 0x1bac2
jmp 0x1bac4
leaq -0x40(%rbp), %rdi
callq 0x11a50
addq $0xa0, %rsp
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0x11a50
movq -0x60(%rbp), %rdi
callq 0x5710
nopl (%rax,%rax)