// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x1120, %rsp           # imm = 0x1120
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x1108(%rbp)
movq -0x1108(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x7cf60
movl %eax, -0x1110(%rbp)
cmpl $0x8, -0x1110(%rbp)
jae 0x7dcf9
movl $0x8, %eax
subl -0x1110(%rbp), %eax
movl %eax, -0x110c(%rbp)
jmp 0x7dda1
movq -0x1108(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x1100(%rbp)
cmpl $0x8, -0x1110(%rbp)
jne 0x7dd6c
movq -0x1100(%rbp), %rax
movl (%rax), %eax
subl $0x626d4352, %eax       # imm = 0x626D4352
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x7dd46
movq -0x1100(%rbp), %rax
movl 0x4(%rax), %edi
callq 0x265c0
movl %eax, %eax
cmpq $0x8a0, %rax            # imm = 0x8A0
jae 0x7dd6a
movl $0x3, %edi
leaq 0xc432f(%rip), %rsi     # 0x142081
movb $0x0, %al
callq 0x2fc60
movq -0x1108(%rbp), %rdi
callq 0x80fa0
jmp 0x7defa
jmp 0x7dd6c
movq -0x1100(%rbp), %rax
movl 0x4(%rax), %edi
callq 0x265c0
subl -0x1110(%rbp), %eax
movl %eax, -0x110c(%rbp)
movl -0x110c(%rbp), %eax
cmpq $0x10d0, %rax           # imm = 0x10D0
jbe 0x7dd9f
movl $0x10d0, -0x110c(%rbp)  # imm = 0x10D0
jmp 0x7dda1
movl -0xc(%rbp), %edi
leaq -0x10f0(%rbp), %rsi
movl -0x110c(%rbp), %eax
movl %eax, %edx
callq 0x26340
movq %rax, -0x10f8(%rbp)
cmpq $-0x1, -0x10f8(%rbp)
jne 0x7ddd8
callq 0x26880
cmpl $0xb, (%rax)
jne 0x7ddd8
jmp 0x7defa
cmpq $0x0, -0x10f8(%rbp)
jg 0x7de37
cmpq $0x0, -0x10f8(%rbp)
jne 0x7ddfc
leaq 0xc42ee(%rip), %rax     # 0x1420e1
movq %rax, -0x1118(%rbp)
jmp 0x7de0f
callq 0x26880
movl (%rax), %edi
callq 0x26690
movq %rax, -0x1118(%rbp)
movq -0x1118(%rbp), %rdx
xorl %edi, %edi
leaq 0xc429d(%rip), %rsi     # 0x1420bc
movb $0x0, %al
callq 0x2fc60
movq -0x1108(%rbp), %rdi
callq 0x80fa0
jmp 0x7defa
movq -0x1108(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x10f0(%rbp), %rsi
movq -0x10f8(%rbp), %rdx
callq 0x39040
movq %rax, %rcx
movq -0x1108(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x1108(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x1100(%rbp)
movq -0x10f8(%rbp), %rcx
movl -0x1110(%rbp), %eax
addq %rcx, %rax
movl %eax, -0x1110(%rbp)
cmpl $0x8, -0x1110(%rbp)
jb 0x7def5
movl -0x1110(%rbp), %eax
movl %eax, -0x111c(%rbp)
movq -0x1100(%rbp), %rax
movl 0x4(%rax), %edi
callq 0x265c0
movl %eax, %ecx
movl -0x111c(%rbp), %eax
cmpl %ecx, %eax
jne 0x7def5
movq -0x1108(%rbp), %rdi
callq 0x7f6f0
cmpl $0x0, %eax
je 0x7def1
movq -0x1108(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x38620
callq 0x384f0
movq %rax, %rcx
movq -0x1108(%rbp), %rax
movq %rcx, 0x18(%rax)
jmp 0x7def3
jmp 0x7defa
jmp 0x7def5
jmp 0x7dcc4
addq $0x1120, %rsp           # imm = 0x1120
popq %rbp
retq
nopw %cs:(%rax,%rax)