// File: /workspace/github_cpp_makefile_star2_O2/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 0xcc68
movq %rdi, %r14
testq %rdi, %rdi
je 0xcc87
movq %rsi, %rbx
leaq 0x18(%rsi), %rdi
callq 0x63f0
leaq 0x30(%rsp), %rcx
movq %rcx, 0x8(%rcx)
movq %rcx, (%rcx)
andq $0x0, 0x10(%rcx)
movq %rax, %r12
movb $0x0, 0x6(%rsp)
movq %r14, 0x28(%rsp)
movq %r14, %rdi
callq 0x4500
movq %rbx, 0x10(%rsp)
movq %r14, 0x20(%rsp)
movq %r14, %rdi
callq 0x4270
movq %rax, %r13
leaq 0x8(%rsp), %rax
andq $0x0, (%rax)
leaq 0x7(%rsp), %rbx
movb $0x0, (%rbx)
xorl %r15d, %r15d
leaq 0x6(%rsp), %r14
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0xd580
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 0xcb67
cmpb $0x0, 0x6(%rsp)
jne 0xcb7e
movb 0x7(%rsp), %cl
testq %rax, %rax
je 0xcb5a
testb $0x1, %cl
je 0xcb5c
andl $0x0, 0x1c(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x1c(%rsp), %rdx
callq 0xd0e8
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x8(%rsp), %rdx
movq %r13, %rdi
callq 0x4440
movq 0x8(%rsp), %rax
addq %rax, %r15
movb 0x7(%rsp), %cl
jmp 0xcb5c
xorl %eax, %eax
testb $0x1, %cl
jne 0xcad7
jmp 0xcb7e
cmpb $0x0, 0x7(%rsp)
je 0xcbb4
movq %r13, %rdi
movq %rax, %rsi
callq 0x43f0
movq 0x8(%rsp), %rax
movb 0x6(%rsp), %cl
testq %rax, %rax
jne 0xcbb8
orb %bpl, %cl
testb $0x1, %cl
movq 0x10(%rsp), %rbx
jne 0xcc04
movslq (%r12), %rax
movslq 0x4(%r12), %rdx
addq %rax, %rdx
movl 0xc(%r12), %ecx
pushq $0x2
popq %rsi
movq 0x20(%rsp), %rdi
callq 0x40c0
jmp 0xcc04
movb 0x6(%rsp), %cl
movq 0x10(%rsp), %rbx
testb $0x1, %cl
jne 0xcc04
movq %r13, %rdi
callq 0x43b0
movq 0x8(%rsp), %rdx
movslq 0x8(%r12), %rsi
addq %rdx, %rsi
subq %rax, %rsi
setbe %al
orb %bpl, %al
jne 0xcbef
movq %r13, %rdi
callq 0x41c0
movq 0x8(%rsp), %rdx
movl 0xc(%r12), %ecx
addq %rdx, %rcx
pushq $0x2
popq %rsi
movq 0x20(%rsp), %rdi
callq 0x40c0
leaq 0x28(%rsp), %rdi
callq 0xd0c8
testq %r15, %r15
je 0xcc2b
movq 0x8(%rbx), %rdi
movq 0x190(%rbx), %rsi
leaq 0x30(%rsp), %rdx
movq %r15, %rcx
callq 0x8a54
testb %bpl, %bpl
jne 0xcc37
cmpb $0x1, 0x6(%rsp)
jne 0xcc4f
movq 0x8(%rbx), %rdi
movq 0x190(%rbx), %rsi
callq 0x8b58
movq %rbx, %rdi
callq 0xbe76
leaq 0x30(%rsp), %rdi
callq 0x999a
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4e49(%rip), %rdi      # 0x11ab8
leaq 0x4d1e(%rip), %rsi      # 0x11994
leaq 0x4fa1(%rip), %rcx      # 0x11c1e
movl $0x169, %edx            # imm = 0x169
callq 0x4260
leaq 0x4bb3(%rip), %rdi      # 0x11841
leaq 0x4cff(%rip), %rsi      # 0x11994
leaq 0x4f82(%rip), %rcx      # 0x11c1e
movl $0x16a, %edx            # imm = 0x16A
callq 0x4260
jmp 0xccb7
jmp 0xccb7
jmp 0xccb7
jmp 0xccb7
jmp 0xccb0
movq %rax, %rbx
jmp 0xccc4
jmp 0xccb7
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0xd0c8
leaq 0x30(%rsp), %rdi
callq 0x999a
movq %rbx, %rdi
callq 0x4660