// File: /workspace/github_cpp_makefile_star2_O1/theuni[P]libbtcnet/src/connectionbase.cpp
// Function: ConnectionBase::read_cb_message(bufferevent*, void*)
void ConnectionBase::read_cb_message(bufferevent* bev, void* ctx)
{
    assert(ctx);
    assert(bev);
    ConnectionBase* base = static_cast<ConnectionBase*>(ctx);
    const CNetworkConfig& netconfig = base->m_connection.GetNetConfig();
    std::list<std::vector<unsigned char> > msgs;
    size_t totalsize = 0;
    bool fTooBig = false;
    bool fBadMsgStart = false;
    {
        BufferEventLocker lock(bev);
        evbuffer* input = bufferevent_get_input(bev);

        uint64_t msgsize = 0;
        bool fComplete = false;
        do {
            msgsize = first_complete_message_size(netconfig, input, fComplete, fBadMsgStart);
            if (netconfig.message_max_size > 0 && msgsize > netconfig.message_max_size) {
                DEBUG_PRINT(LOGWARN, "id:", base->m_id, "Received an oversized message");
                if (fComplete) {
                    evbuffer_drain(input, msgsize);
                }
                fTooBig = true;
                break;
            } else if (fBadMsgStart) {
                DEBUG_PRINT(LOGWARN, "id:", base->m_id, "Received a bad message start");
                break;
            } else if ((msgsize != 0u) && fComplete) {
                msgs.emplace_back(msgsize, 0);
                evbuffer_remove(input, msgs.back().data(), msgsize);
                totalsize += msgsize;
            }
        } while (fComplete);

        if ((msgsize != 0u) && !fBadMsgStart) {
            size_t buflen = evbuffer_get_length(input);
            if (buflen < msgsize + netconfig.header_size && !fTooBig)
                evbuffer_expand(input, msgsize + netconfig.header_size - buflen);
            bufferevent_setwatermark(bev, EV_READ, msgsize, msgsize + netconfig.message_max_size);
            DEBUG_PRINT(LOGVERBOSE, "id:", base->m_id, "watermark set to", msgsize);
        } else if (!fBadMsgStart && !fTooBig) {
            size_t watermark = netconfig.header_msg_size_offset + netconfig.header_msg_size_size;
            bufferevent_setwatermark(bev, EV_READ, watermark, netconfig.message_max_size);
            DEBUG_PRINT(LOGVERBOSE, "id:", base->m_id, "watermark set to", watermark);
        }
    }

    if (totalsize != 0u) {
        DEBUG_PRINT(LOGINFO, "id:", base->m_id, "Received", msgs.size(), "messages");
        base->m_handler.OnReceiveMessages(base->m_id, std::move(msgs), totalsize);
    }

    if (fTooBig || fBadMsgStart) {
        base->m_handler.OnMalformedMessage(base->m_id);
        base->DisconnectInt(0);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
testq %rsi, %rsi
je 0xe983
movq %rdi, %r14
testq %rdi, %rdi
je 0xe9a2
movq %rsi, %rbx
leaq 0x18(%rsi), %rdi
callq 0x7022
movq %rax, %r12
leaq 0x28(%rsp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
movq $0x0, 0x10(%rax)
movb $0x0, 0x6(%rsp)
movq %r14, %rdi
callq 0x44e0
movq %rbx, 0x20(%rsp)
movq %r14, 0x10(%rsp)
movq %r14, %rdi
callq 0x4270
movq %rax, %r13
leaq 0x8(%rsp), %rax
movq $0x0, (%rax)
leaq 0x7(%rsp), %r14
movb $0x0, (%r14)
xorl %r15d, %r15d
leaq 0x6(%rsp), %rbx
movq %r12, 0x40(%rsp)
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0xf0c8
movq %rax, 0x8(%rsp)
movl 0xc(%r12), %ecx
testq %rcx, %rcx
setne %dl
cmpq %rcx, %rax
seta %bpl
andb %dl, %bpl
cmpb $0x1, %bpl
je 0xe884
cmpb $0x0, 0x6(%rsp)
jne 0xe896
testq %rax, %rax
je 0xe877
cmpb $0x1, 0x7(%rsp)
jne 0xe877
movq %r14, %r12
movq %rbx, %r14
movq %r15, %rbx
movl $0x0, 0x1c(%rsp)
leaq 0x28(%rsp), %r15
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
leaq 0x1c(%rsp), %rdx
callq 0xf010
movq %rax, %rdi
movq %r15, %rsi
callq 0x4070
incq 0x38(%rsp)
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x8(%rsp), %rdx
movq %r13, %rdi
callq 0x4440
movq %rbx, %r15
movq %r14, %rbx
movq %r12, %r14
movq 0x40(%rsp), %r12
addq 0x8(%rsp), %r15
cmpb $0x0, 0x7(%rsp)
jne 0xe7ca
jmp 0xe896
cmpb $0x1, 0x7(%rsp)
jne 0xe896
movq %r13, %rdi
movq %rax, %rsi
callq 0x43e0
cmpq $0x0, 0x8(%rsp)
je 0xe8a5
cmpb $0x0, 0x6(%rsp)
je 0xe8d8
movb 0x6(%rsp), %al
orb %bpl, %al
movq 0x20(%rsp), %rbx
movq 0x10(%rsp), %r14
jne 0xe921
movslq (%r12), %rax
movslq 0x4(%r12), %rdx
addq %rax, %rdx
movl 0xc(%r12), %ecx
movq %r14, %rdi
movl $0x2, %esi
callq 0x40c0
jmp 0xe921
movq %r13, %rdi
movq 0x10(%rsp), %r14
callq 0x43a0
movq 0x20(%rsp), %rbx
movslq 0x8(%r12), %rsi
addq 0x8(%rsp), %rsi
subq %rax, %rsi
setbe %al
orb %bpl, %al
jne 0xe907
movq %r13, %rdi
callq 0x41c0
movq 0x8(%rsp), %rdx
movl 0xc(%r12), %ecx
addq %rdx, %rcx
movq %r14, %rdi
movl $0x2, %esi
callq 0x40c0
movq %r14, %rdi
callq 0x45e0
testq %r15, %r15
je 0xe946
movq 0x8(%rbx), %rdi
movq 0x190(%rbx), %rsi
leaq 0x28(%rsp), %rdx
movq %r15, %rcx
callq 0x9a5e
testb %bpl, %bpl
jne 0xe952
cmpb $0x1, 0x6(%rsp)
jne 0xe96a
movq 0x8(%rbx), %rdi
movq 0x190(%rbx), %rsi
callq 0x9bca
movq %rbx, %rdi
callq 0xd944
leaq 0x28(%rsp), %rdi
callq 0xac9a
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x512e(%rip), %rdi      # 0x13ab8
leaq 0x5003(%rip), %rsi      # 0x13994
leaq 0x5286(%rip), %rcx      # 0x13c1e
movl $0x169, %edx            # imm = 0x169
callq 0x4260
leaq 0x4e9a(%rip), %rdi      # 0x13843
leaq 0x4fe4(%rip), %rsi      # 0x13994
leaq 0x5267(%rip), %rcx      # 0x13c1e
movl $0x16a, %edx            # imm = 0x16A
callq 0x4260
jmp 0xe9d4
jmp 0xe9d4
jmp 0xe9d4
jmp 0xe9f3
jmp 0xe9d4
jmp 0xe9cd
movq %rax, %rbx
jmp 0xe9e1
jmp 0xe9d4
movq %rax, %rbx
movq 0x10(%rsp), %rdi
callq 0x45e0
leaq 0x28(%rsp), %rdi
callq 0xac9a
movq %rbx, %rdi
callq 0x4640
movq %rax, %rdi
callq 0xab84
nop