// File: /workspace/github_cpp_makefile_star2_O2/theuni[P]libbtcnet/src/message.cpp
// Function: first_complete_message_size(CNetworkConfig const&, evbuffer*, bool&, bool&)
uint64_t first_complete_message_size(const CNetworkConfig& config, evbuffer* input, bool& fComplete, bool& fBadMsgStart)
{
    size_t nTotal = evbuffer_get_length(input);
    uint64_t nMessageSize;
    const int size_needed = config.header_msg_size_offset + config.header_msg_size_size;
    fComplete = false;
    fBadMsgStart = false;

    // Assume 4-bytes until there's a reason not to.
    assert(config.header_msg_size_size == 4);

    if (nTotal < static_cast<size_t>(size_needed))
        return 0;
    evbuffer_iovec v;
    if (evbuffer_peek(input, size_needed, nullptr, &v, 1) == 1) {
        const unsigned char* ptr = static_cast<const unsigned char*>(v.iov_base);
        if (!config.message_start.empty() && memcmp(ptr, &config.message_start[0], config.message_start.size()) != 0) {
            fBadMsgStart = true;
            return 0;
        }
        nMessageSize = get_message_length(ptr + config.header_msg_size_offset) + config.header_size;
    } else {
        std::vector<unsigned char> partial_header(size_needed);
        int ret = evbuffer_copyout(input, &partial_header[0], size_needed);
        assert(ret == size_needed);
        (void)ret;
        if (!config.message_start.empty() && memcmp(&partial_header[0], &config.message_start[0], config.message_start.size()) != 0) {
            fBadMsgStart = true;
            return 0;
        }
        nMessageSize = get_message_length(&partial_header[0] + config.header_msg_size_offset) + config.header_size;
    }
    if (nTotal >= nMessageSize)
        fComplete = true;
    return nMessageSize;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, %r12
movq %rdx, %rbx
movq %rsi, %rbp
movq %rdi, %r15
movq %rsi, %rdi
callq 0x43b0
movq %rax, %r14
movslq (%r15), %rax
movslq 0x4(%r15), %r13
xorl %ecx, %ecx
movb %cl, (%rbx)
movb %cl, (%r12)
cmpq $0x4, %r13
jne 0xd6bd
addq %rax, %r13
cmpq %r13, %r14
jae 0xd5ce
xorl %r15d, %r15d
jmp 0xd6ab
leaq 0x28(%rsp), %rcx
pushq $0x1
popq %r8
movq %rbp, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x46d0
cmpl $0x1, %eax
jne 0xd615
movq 0x28(%rsp), %r13
movq 0x10(%r15), %rsi
movq 0x18(%r15), %rdx
cmpq %rdx, %rsi
je 0xd66d
subq %rsi, %rdx
movq %r13, %rdi
callq 0x4380
testl %eax, %eax
je 0xd66d
xorl %r15d, %r15d
movq %r12, %rbx
jmp 0xd6a8
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rdx
movq %r13, %rsi
callq 0xd3e0
leaq 0x10(%rsp), %rax
movq (%rax), %rsi
movq %rbp, %rdi
movq %r13, %rdx
callq 0x4060
cmpl %eax, %r13d
jne 0xd6da
movq 0x10(%r15), %rsi
movq 0x18(%r15), %rdx
movq 0x10(%rsp), %r13
cmpq %rdx, %rsi
je 0xd67e
subq %rsi, %rdx
movq %r13, %rdi
callq 0x4380
testl %eax, %eax
je 0xd67e
movb $0x1, (%r12)
xorl %ebp, %ebp
jmp 0xd690
movslq (%r15), %rax
movl (%r13,%rax), %eax
movslq 0x8(%r15), %r15
addq %rax, %r15
jmp 0xd6a3
movslq (%r15), %rax
movl (%r13,%rax), %eax
movslq 0x8(%r15), %r15
addq %rax, %r15
movb $0x1, %bpl
leaq 0x10(%rsp), %rdi
callq 0x4fd0
testb %bpl, %bpl
je 0xd5c6
cmpq %r15, %r14
jb 0xd6ab
movb $0x1, (%rbx)
movq %r15, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x474e(%rip), %rdi      # 0x11e12
leaq 0x4768(%rip), %rsi      # 0x11e33
leaq 0x4771(%rip), %rcx      # 0x11e43
pushq $0x23
popq %rdx
callq 0x4260
leaq 0x47bb(%rip), %rdi      # 0x11e9c
leaq 0x474b(%rip), %rsi      # 0x11e33
leaq 0x4754(%rip), %rcx      # 0x11e43
pushq $0x32
jmp 0xd6d4
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x4fd0
movq %rbx, %rdi
callq 0x4660