// File: /workspace/github_cpp_makefile_star2_O3/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 0x43a0
movq %rax, %r14
movslq (%r15), %rax
movslq 0x4(%r15), %r13
xorl %ecx, %ecx
movb %cl, (%rbx)
movb %cl, (%r12)
cmpq $0x4, %r13
jne 0xf063
addq %rax, %r13
cmpq %r13, %r14
jae 0xef77
xorl %r15d, %r15d
movq %r15, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x28(%rsp), %rcx
movq %rbp, %rdi
movq %r13, %rsi
xorl %edx, %edx
movl $0x1, %r8d
callq 0x46b0
cmpl $0x1, %eax
jne 0xefc0
movq 0x28(%rsp), %r13
movq 0x10(%r15), %rsi
movq 0x18(%r15), %rdx
cmpq %rdx, %rsi
je 0xf02a
subq %rsi, %rdx
movq %r13, %rdi
callq 0x4370
testl %eax, %eax
je 0xf02a
movb $0x1, (%r12)
jmp 0xef62
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rdx
movq %r13, %rsi
callq 0xee04
leaq 0x10(%rsp), %rax
movq (%rax), %rsi
movq %rbp, %rdi
movq %r13, %rdx
callq 0x4060
cmpl %eax, %r13d
jne 0xf082
movq 0x10(%r15), %rsi
movq 0x18(%r15), %rdx
movq 0x10(%rsp), %r13
cmpq %rdx, %rsi
je 0xf03b
subq %rsi, %rdx
movq %r13, %rdi
callq 0x4370
testl %eax, %eax
je 0xf03b
movb $0x1, (%r12)
testq %r13, %r13
je 0xef62
movq %r13, %rdi
callq 0x4340
jmp 0xef62
movslq (%r15), %rax
movl (%r13,%rax), %eax
movslq 0x8(%r15), %r15
addq %rax, %r15
jmp 0xf052
movslq (%r15), %rax
movl (%r13,%rax), %eax
movslq 0x8(%r15), %r15
addq %rax, %r15
movq %r13, %rdi
callq 0x4340
cmpq %r15, %r14
jb 0xef65
movb $0x1, (%rbx)
jmp 0xef65
leaq 0x4da0(%rip), %rdi      # 0x13e0a
leaq 0x4dba(%rip), %rsi      # 0x13e2b
leaq 0x4dc3(%rip), %rcx      # 0x13e3b
movl $0x23, %edx
callq 0x4260
leaq 0x4e0b(%rip), %rdi      # 0x13e94
leaq 0x4d9b(%rip), %rsi      # 0x13e2b
leaq 0x4da4(%rip), %rcx      # 0x13e3b
movl $0x32, %edx
callq 0x4260
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xf0b3
callq 0x4340
movq %rbx, %rdi
callq 0x4640
nop