// File: /workspace/github_c_makefile_star2_O3/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), %rax
movq %rsp, %r14
leaq 0x60e5a(%rip), %r12     # 0xc740c
movzbl -0x1(%rax), %r13d
movl %r13d, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x66626
movslq (%r12,%rcx,4), %rcx
addq %r12, %rcx
jmpq *%rcx
shrl $0x3, %r13d
jmp 0x665e9
movq -0x11(%rax), %r13
jmp 0x665e9
movzwl -0x5(%rax), %r13d
jmp 0x665e9
movl -0x9(%rax), %r13d
jmp 0x665e9
movzbl -0x3(%rax), %r13d
cmpl $0x7, %r13d
jbe 0x66629
cmpl $0x8, %r13d
jne 0x66612
cmpl $0x626d4352, (%rax)     # imm = 0x626D4352
jne 0x666bb
movl 0x4(%rax), %eax
bswapl %eax
cmpl $0x89f, %eax            # imm = 0x89F
ja 0x66617
jmp 0x666bb
movl 0x4(%rax), %eax
bswapl %eax
subl %r13d, %eax
movl $0x10d0, %ecx           # imm = 0x10D0
cmpl %ecx, %eax
cmovael %ecx, %eax
jmp 0x66631
xorl %r13d, %r13d
movl $0x8, %eax
subl %r13d, %eax
movl %eax, %edx
movl %ebp, %edi
movq %r14, %rsi
callq 0x26340
cmpq $-0x1, %rax
je 0x6669c
movq %rax, %r15
testq %rax, %rax
jle 0x666a8
movq 0x18(%rbx), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x36ad1
movq %rax, 0x18(%rbx)
addl %r13d, %r15d
cmpl $0x8, %r15d
jb 0x665b2
movl 0x4(%rax), %ecx
bswapl %ecx
cmpl %r15d, %ecx
jne 0x665b2
movq %rbx, %rdi
callq 0x67880
testl %eax, %eax
je 0x666ef
movq 0x18(%rbx), %rdi
callq 0x36330
callq 0x3628d
movq %rax, 0x18(%rbx)
jmp 0x665b2
callq 0x26880
cmpl $0xb, (%rax)
jne 0x666af
jmp 0x666ef
je 0x666d0
callq 0x26880
movl (%rax), %edi
callq 0x26680
movq %rax, %rdx
jmp 0x666d7
leaq 0x6193e(%rip), %rsi     # 0xc8000
movl $0x3, %edi
xorl %eax, %eax
callq 0x2fdad
jmp 0x666e7
leaq 0x61989(%rip), %rdx     # 0xc8060
leaq 0x6195d(%rip), %rsi     # 0xc803b
xorl %edi, %edi
xorl %eax, %eax
callq 0x2fdad
movq %rbx, %rdi
callq 0x6651c
addq $0x10d8, %rsp           # imm = 0x10D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq