// File: /workspace/github_cpp_makefile_star2_O1/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 0xf21e
addq %rax, %r13
cmpq %r13, %r14
jae 0xf123
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 0xf16a
movq 0x28(%rsp), %r13
movq 0x10(%r15), %rsi
movq 0x18(%r15), %rdx
cmpq %rdx, %rsi
je 0xf1c2
subq %rsi, %rdx
movq %r13, %rdi
callq 0x4370
testl %eax, %eax
je 0xf1c2
movb $0x1, (%r12)
xorl %eax, %eax
jmp 0xf1d3
movq %rbx, 0x8(%rsp)
leaq 0x10(%rsp), %rbx
leaq 0x7(%rsp), %rdx
movq %rbx, %rdi
movq %r13, %rsi
callq 0xefb0
movq (%rbx), %rsi
movq %rbp, %rdi
movq %r13, %rdx
callq 0x4060
cmpl %eax, %r13d
jne 0xf23d
movq 0x10(%r15), %rsi
movq 0x18(%r15), %rdx
cmpq %rdx, %rsi
je 0xf1dd
movq 0x10(%rsp), %rdi
subq %rsi, %rdx
callq 0x4370
testl %eax, %eax
je 0xf1dd
movb $0x1, (%r12)
xorl %ebx, %ebx
jmp 0xf1f1
movslq (%r15), %rax
movl (%r13,%rax), %eax
movslq 0x8(%r15), %r15
addq %rax, %r15
movb $0x1, %al
testb %al, %al
je 0xf10e
jmp 0xf20d
movq 0x10(%rsp), %rax
movslq (%r15), %rcx
movl (%rax,%rcx), %eax
movslq 0x8(%r15), %r15
addq %rax, %r15
movb $0x1, %bl
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xf200
callq 0x4340
testb %bl, %bl
movq 0x8(%rsp), %rbx
je 0xf10e
cmpq %r15, %r14
jb 0xf111
movb $0x1, (%rbx)
jmp 0xf111
leaq 0x4bed(%rip), %rdi      # 0x13e12
leaq 0x4c07(%rip), %rsi      # 0x13e33
leaq 0x4c10(%rip), %rcx      # 0x13e43
movl $0x23, %edx
callq 0x4260
leaq 0x4c58(%rip), %rdi      # 0x13e9c
leaq 0x4be8(%rip), %rsi      # 0x13e33
leaq 0x4bf1(%rip), %rcx      # 0x13e43
movl $0x32, %edx
callq 0x4260
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xf26e
callq 0x4340
movq %rbx, %rdi
callq 0x4640
nop