// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/cluster.c
// Function: clusterReadHandler
void clusterReadHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
    char buf[sizeof(clusterMsg)];
    ssize_t nread;
    clusterMsg *hdr;
    clusterLink *link = (clusterLink*) privdata;
    unsigned int readlen, rcvbuflen;
    UNUSED(el);
    UNUSED(mask);

    while(1) { /* Read as long as there is data to read. */
        rcvbuflen = sdslen(link->rcvbuf);
        if (rcvbuflen < 8) {
            /* First, obtain the first 8 bytes to get the full message
             * length. */
            readlen = 8 - rcvbuflen;
        } else {
            /* Finally read the full message. */
            hdr = (clusterMsg*) link->rcvbuf;
            if (rcvbuflen == 8) {
                /* Perform some sanity check on the message signature
                 * and length. */
                if (memcmp(hdr->sig,"RCmb",4) != 0 ||
                    ntohl(hdr->totlen) < CLUSTERMSG_MIN_LEN)
                {
                    serverLog(LL_WARNING,
                        "Bad message length or signature received "
                        "from Cluster bus.");
                    handleLinkIOError(link);
                    return;
                }
            }
            readlen = ntohl(hdr->totlen) - rcvbuflen;
            if (readlen > sizeof(buf)) readlen = sizeof(buf);
        }

        nread = read(fd,buf,readlen);
        if (nread == -1 && errno == EAGAIN) return; /* No more data ready. */

        if (nread <= 0) {
            /* I/O error... */
            serverLog(LL_DEBUG,"I/O error reading from node link: %s",
                (nread == 0) ? "connection closed" : strerror(errno));
            handleLinkIOError(link);
            return;
        } else {
            /* Read data and recast the pointer to the new buffer. */
            link->rcvbuf = sdscatlen(link->rcvbuf,buf,nread);
            hdr = (clusterMsg*) link->rcvbuf;
            rcvbuflen += nread;
        }

        /* Total length obtained? Process this packet. */
        if (rcvbuflen >= 8 && rcvbuflen == ntohl(hdr->totlen)) {
            if (clusterProcessPacket(link)) {
                sdsfree(link->rcvbuf);
                link->rcvbuf = sdsempty();
            } else {
                return; /* Link no longer valid. */
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10d8, %rsp           # imm = 0x10D8
movq %rdx, %rbx
movl %esi, %ebp
movq 0x18(%rdx), %r12
movq %rsp, %r14
movq %r12, %rdi
callq 0x5b5fd
movq %rax, %r15
cmpl $0x7, %r15d
ja 0x5be92
pushq $0x8
popq %rax
subl %r15d, %eax
jmp 0x5becd
cmpl $0x8, %r15d
jne 0x5beb9
cmpl $0x626d4352, (%r12)     # imm = 0x626D4352
jne 0x5bf5f
movl 0x4(%r12), %eax
bswapl %eax
cmpl $0x89f, %eax            # imm = 0x89F
ja 0x5bec0
jmp 0x5bf5f
movl 0x4(%r12), %eax
bswapl %eax
subl %r15d, %eax
movl $0x10d0, %ecx           # imm = 0x10D0
cmpl %ecx, %eax
cmovael %ecx, %eax
movl %eax, %edx
movl %ebp, %edi
movq %r14, %rsi
callq 0x26340
cmpq $-0x1, %rax
je 0x5bf40
movq %rax, %r13
testq %rax, %rax
jle 0x5bf4c
movq 0x18(%rbx), %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x31758
movq %rax, %r12
movq %rax, 0x18(%rbx)
addl %r15d, %r13d
cmpl $0x8, %r13d
jb 0x5be79
movl 0x4(%r12), %eax
bswapl %eax
cmpl %r13d, %eax
jne 0x5be79
movq %rbx, %rdi
callq 0x5cf60
testl %eax, %eax
je 0x5bf91
movq 0x18(%rbx), %rdi
callq 0x311c8
callq 0x3114c
movq %rax, %r12
movq %rax, 0x18(%rbx)
jmp 0x5be79
callq 0x26880
cmpl $0xb, (%rax)
jne 0x5bf53
jmp 0x5bf91
je 0x5bf72
callq 0x26880
movl (%rax), %edi
callq 0x26680
movq %rax, %rdx
jmp 0x5bf79
leaq 0x5d082(%rip), %rsi     # 0xb8fe8
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x2b699
jmp 0x5bf89
leaq 0x5d0cf(%rip), %rdx     # 0xb9048
leaq 0x5d0a3(%rip), %rsi     # 0xb9023
xorl %edi, %edi
xorl %eax, %eax
callq 0x2b699
movq %rbx, %rdi
callq 0x5bdf1
addq $0x10d8, %rsp           # imm = 0x10D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq