// File: /workspace/github_cpp_makefile_star2_O3/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 0xe7e2
movq %rdi, %r14
testq %rdi, %rdi
je 0xe801
movq %rsi, %rbx
leaq 0x18(%rsi), %rdi
callq 0x6fb0
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, 0x18(%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 0xef1c
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 0xe6d9
cmpb $0x0, 0x6(%rsp)
jne 0xe6f0
movb 0x7(%rsp), %cl
testq %rax, %rax
je 0xe6cc
testb $0x1, %cl
je 0xe6ce
movq %r14, %r12
movq %rbx, %r14
movq %r15, %rbx
movl $0x0, 0x24(%rsp)
leaq 0x28(%rsp), %r15
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
leaq 0x24(%rsp), %rdx
callq 0xee64
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
movq 0x8(%rsp), %rax
addq %rax, %r15
movb 0x7(%rsp), %cl
jmp 0xe6ce
xorl %eax, %eax
testb $0x1, %cl
jne 0xe614
jmp 0xe6f0
cmpb $0x0, 0x7(%rsp)
je 0xe72b
movq %r13, %rdi
movq %rax, %rsi
callq 0x43e0
movq 0x8(%rsp), %rax
movb 0x6(%rsp), %cl
testq %rax, %rax
jne 0xe72f
orb %bpl, %cl
testb $0x1, %cl
movq 0x18(%rsp), %rbx
movq 0x10(%rsp), %r14
jne 0xe780
movslq (%r12), %rax
movslq 0x4(%r12), %rdx
addq %rax, %rdx
movl 0xc(%r12), %ecx
movq %r14, %rdi
movl $0x2, %esi
callq 0x40c0
jmp 0xe780
movb 0x6(%rsp), %cl
movq 0x18(%rsp), %rbx
movq 0x10(%rsp), %r14
testb $0x1, %cl
jne 0xe780
movq %r13, %rdi
callq 0x43a0
movq 0x8(%rsp), %rdx
movslq 0x8(%r12), %rsi
addq %rdx, %rsi
subq %rax, %rsi
setbe %al
orb %bpl, %al
jne 0xe76b
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 0xe7a5
movq 0x8(%rbx), %rdi
movq 0x190(%rbx), %rsi
leaq 0x28(%rsp), %rdx
movq %r15, %rcx
callq 0x99d0
testb %bpl, %bpl
jne 0xe7b1
cmpb $0x1, 0x6(%rsp)
jne 0xe7c9
movq 0x8(%rbx), %rdi
movq 0x190(%rbx), %rsi
callq 0x9b36
movq %rbx, %rdi
callq 0xd7a0
leaq 0x28(%rsp), %rdi
callq 0xab34
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x52c7(%rip), %rdi      # 0x13ab0
leaq 0x519c(%rip), %rsi      # 0x1398c
leaq 0x541f(%rip), %rcx      # 0x13c16
movl $0x169, %edx            # imm = 0x169
callq 0x4260
leaq 0x5033(%rip), %rdi      # 0x1383b
leaq 0x517d(%rip), %rsi      # 0x1398c
leaq 0x5400(%rip), %rcx      # 0x13c16
movl $0x16a, %edx            # imm = 0x16A
callq 0x4260
jmp 0xe833
jmp 0xe833
jmp 0xe833
jmp 0xe852
jmp 0xe833
jmp 0xe82c
movq %rax, %rbx
jmp 0xe840
jmp 0xe833
movq %rax, %rbx
movq 0x10(%rsp), %rdi
callq 0x45e0
leaq 0x28(%rsp), %rdi
callq 0xab34
movq %rbx, %rdi
callq 0x4640
movq %rax, %rdi
callq 0xaa1e