// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/redis-cli.c
// Function: pipeMode
static void pipeMode(void) {
    int fd = context->fd;
    long long errors = 0, replies = 0, obuf_len = 0, obuf_pos = 0;
    char ibuf[1024*16], obuf[1024*16]; /* Input and output buffers */
    char aneterr[ANET_ERR_LEN];
    redisReader *reader = redisReaderCreate();
    redisReply *reply;
    int eof = 0; /* True once we consumed all the standard input. */
    int done = 0;
    char magic[20]; /* Special reply we recognize. */
    time_t last_read_time = time(NULL);

    srand(time(NULL));

    /* Use non blocking I/O. */
    if (anetNonBlock(aneterr,fd) == ANET_ERR) {
        fprintf(stderr, "Can't set the socket in non blocking mode: %s\n",
            aneterr);
        exit(1);
    }

    /* Transfer raw protocol and read replies from the server at the same
     * time. */
    while(!done) {
        int mask = AE_READABLE;

        if (!eof || obuf_len != 0) mask |= AE_WRITABLE;
        mask = aeWait(fd,mask,1000);

        /* Handle the readable state: we can read replies from the server. */
        if (mask & AE_READABLE) {
            ssize_t nread;

            /* Read from socket and feed the hiredis reader. */
            do {
                nread = read(fd,ibuf,sizeof(ibuf));
                if (nread == -1 && errno != EAGAIN && errno != EINTR) {
                    fprintf(stderr, "Error reading from the server: %s\n",
                        strerror(errno));
                    exit(1);
                }
                if (nread > 0) {
                    redisReaderFeed(reader,ibuf,nread);
                    last_read_time = time(NULL);
                }
            } while(nread > 0);

            /* Consume replies. */
            do {
                if (redisReaderGetReply(reader,(void**)&reply) == REDIS_ERR) {
                    fprintf(stderr, "Error reading replies from server\n");
                    exit(1);
                }
                if (reply) {
                    if (reply->type == REDIS_REPLY_ERROR) {
                        fprintf(stderr,"%s\n", reply->str);
                        errors++;
                    } else if (eof && reply->type == REDIS_REPLY_STRING &&
                                      reply->len == 20) {
                        /* Check if this is the reply to our final ECHO
                         * command. If so everything was received
                         * from the server. */
                        if (memcmp(reply->str,magic,20) == 0) {
                            printf("Last reply received from server.\n");
                            done = 1;
                            replies--;
                        }
                    }
                    replies++;
                    freeReplyObject(reply);
                }
            } while(reply);
        }

        /* Handle the writable state: we can send protocol to the server. */
        if (mask & AE_WRITABLE) {
            ssize_t loop_nwritten = 0;

            while(1) {
                /* Transfer current buffer to server. */
                if (obuf_len != 0) {
                    ssize_t nwritten = write(fd,obuf+obuf_pos,obuf_len);

                    if (nwritten == -1) {
                        if (errno != EAGAIN && errno != EINTR) {
                            fprintf(stderr, "Error writing to the server: %s\n",
                                strerror(errno));
                            exit(1);
                        } else {
                            nwritten = 0;
                        }
                    }
                    obuf_len -= nwritten;
                    obuf_pos += nwritten;
                    loop_nwritten += nwritten;
                    if (obuf_len != 0) break; /* Can't accept more data. */
                }
                /* If buffer is empty, load from stdin. */
                if (obuf_len == 0 && !eof) {
                    ssize_t nread = read(STDIN_FILENO,obuf,sizeof(obuf));

                    if (nread == 0) {
                        /* The ECHO sequence starts with a "\r\n" so that if there
                         * is garbage in the protocol we read from stdin, the ECHO
                         * will likely still be properly formatted.
                         * CRLF is ignored by Redis, so it has no effects. */
                        char echo[] =
                        "\r\n*2\r\n$4\r\nECHO\r\n$20\r\n01234567890123456789\r\n";
                        int j;

                        eof = 1;
                        /* Everything transferred, so we queue a special
                         * ECHO command that we can match in the replies
                         * to make sure everything was read from the server. */
                        for (j = 0; j < 20; j++)
                            magic[j] = rand() & 0xff;
                        memcpy(echo+21,magic,20);
                        memcpy(obuf,echo,sizeof(echo)-1);
                        obuf_len = sizeof(echo)-1;
                        obuf_pos = 0;
                        printf("All data transferred. Waiting for the last reply...\n");
                    } else if (nread == -1) {
                        fprintf(stderr, "Error reading from stdin: %s\n",
                            strerror(errno));
                        exit(1);
                    } else {
                        obuf_len = nread;
                        obuf_pos = 0;
                    }
                }
                if ((obuf_len == 0 && eof) ||
                    loop_nwritten > PIPEMODE_WRITE_LOOP_MAX_BYTES) break;
            }
        }

        /* Handle timeout, that is, we reached EOF, and we are not getting
         * replies from the server for a few seconds, nor the final ECHO is
         * received. */
        if (eof && config.pipe_timeout > 0 &&
            time(NULL)-last_read_time > config.pipe_timeout)
        {
            fprintf(stderr,"No replies for %d seconds: exiting.\n",
                config.pipe_timeout);
            errors++;
            break;
        }
    }
    redisReaderFree(reader);
    printf("errors: %lld, replies: %lld\n", errors, replies);
    if (errors)
        exit(1);
    else
        exit(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x81e0, %rsp           # imm = 0x81E0
movq 0x8c7e6(%rip), %rax     # 0xa15d8
movl 0x84(%rax), %eax
movl %eax, -0x4(%rbp)
movq $0x0, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
callq 0x1b370
movq %rax, -0x8138(%rbp)
movl $0x0, -0x8144(%rbp)
movl $0x0, -0x8148(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x103c0
movq %rax, -0x8168(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x103c0
movl %eax, %edi
callq 0x102c0
leaq -0x8130(%rbp), %rdi
movl -0x4(%rbp), %esi
callq 0x109b0
cmpl $-0x1, %eax
jne 0x14e98
movq 0x8a17a(%rip), %rax     # 0x9eff0
movq (%rax), %rdi
leaq -0x8130(%rbp), %rdx
leaq 0x771af(%rip), %rsi     # 0x8c036
movb $0x0, %al
callq 0x10360
movl $0x1, %edi
callq 0x10600
jmp 0x14e9a
cmpl $0x0, -0x8148(%rbp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x14eaf
jmp 0x153b6
movl $0x1, -0x816c(%rbp)
cmpl $0x0, -0x8144(%rbp)
je 0x14ec9
cmpq $0x0, -0x20(%rbp)
je 0x14ed8
movl -0x816c(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x816c(%rbp)
movl -0x4(%rbp), %edi
movl -0x816c(%rbp), %esi
movl $0x3e8, %edx            # imm = 0x3E8
callq 0x1b090
movl %eax, -0x816c(%rbp)
movl -0x816c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x150dd
jmp 0x14f05
movl -0x4(%rbp), %edi
leaq -0x4030(%rbp), %rsi
movl $0x4000, %edx           # imm = 0x4000
callq 0x102b0
movq %rax, -0x8178(%rbp)
cmpq $-0x1, -0x8178(%rbp)
jne 0x14f7d
callq 0x10080
cmpl $0xb, (%rax)
je 0x14f7d
callq 0x10080
cmpl $0x4, (%rax)
je 0x14f7d
movq 0x8a0ab(%rip), %rax     # 0x9eff0
movq (%rax), %rax
movq %rax, -0x81d0(%rbp)
callq 0x10080
movl (%rax), %edi
callq 0x10660
movq -0x81d0(%rbp), %rdi
movq %rax, %rdx
leaq 0x770f9(%rip), %rsi     # 0x8c065
movb $0x0, %al
callq 0x10360
movl $0x1, %edi
callq 0x10600
cmpq $0x0, -0x8178(%rbp)
jle 0x14fb1
movq -0x8138(%rbp), %rdi
leaq -0x4030(%rbp), %rsi
movq -0x8178(%rbp), %rdx
callq 0x1b4c0
xorl %eax, %eax
movl %eax, %edi
callq 0x103c0
movq %rax, -0x8168(%rbp)
jmp 0x14fb3
cmpq $0x0, -0x8178(%rbp)
jg 0x14f05
jmp 0x14fc3
movq -0x8138(%rbp), %rdi
leaq -0x8140(%rbp), %rsi
callq 0x1b7d0
cmpl $-0x1, %eax
jne 0x14ffd
movq 0x8a00e(%rip), %rax     # 0x9eff0
movq (%rax), %rdi
leaq 0x7709c(%rip), %rsi     # 0x8c088
movb $0x0, %al
callq 0x10360
movl $0x1, %edi
callq 0x10600
cmpq $0x0, -0x8140(%rbp)
je 0x150cb
movq -0x8140(%rbp), %rax
cmpl $0x6, (%rax)
jne 0x15048
movq 0x89fd2(%rip), %rax     # 0x9eff0
movq (%rax), %rdi
movq -0x8140(%rbp), %rax
movq 0x18(%rax), %rdx
leaq 0x76f08(%rip), %rsi     # 0x8bf3b
movb $0x0, %al
callq 0x10360
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x150b3
cmpl $0x0, -0x8144(%rbp)
je 0x150b1
movq -0x8140(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x150b1
movq -0x8140(%rbp), %rax
cmpl $0x14, 0x10(%rax)
jne 0x150b1
movq -0x8140(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x8160(%rbp), %rsi
movl $0x14, %edx
callq 0x102d0
cmpl $0x0, %eax
jne 0x150af
leaq 0x77019(%rip), %rdi     # 0x8c0ab
movb $0x0, %al
callq 0x101d0
movl $0x1, -0x8148(%rbp)
movq -0x18(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x150b1
jmp 0x150b3
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x8140(%rbp), %rdi
callq 0x1b290
jmp 0x150cd
cmpq $0x0, -0x8140(%rbp)
jne 0x14fc3
jmp 0x150dd
movl -0x816c(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x15357
movq $0x0, -0x8180(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x151d1
movl -0x4(%rbp), %edi
leaq -0x8030(%rbp), %rsi
addq -0x28(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x10150
movq %rax, -0x8188(%rbp)
cmpq $-0x1, -0x8188(%rbp)
jne 0x1518d
callq 0x10080
cmpl $0xb, (%rax)
je 0x15180
callq 0x10080
cmpl $0x4, (%rax)
je 0x15180
movq 0x89ea8(%rip), %rax     # 0x9eff0
movq (%rax), %rax
movq %rax, -0x81d8(%rbp)
callq 0x10080
movl (%rax), %edi
callq 0x10660
movq -0x81d8(%rbp), %rdi
movq %rax, %rdx
leaq 0x76f5e(%rip), %rsi     # 0x8c0cd
movb $0x0, %al
callq 0x10360
movl $0x1, %edi
callq 0x10600
movq $0x0, -0x8188(%rbp)
jmp 0x1518d
movq -0x8188(%rbp), %rcx
movq -0x20(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x8188(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x8188(%rbp), %rax
addq -0x8180(%rbp), %rax
movq %rax, -0x8180(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x151cf
jmp 0x15355
jmp 0x151d1
cmpq $0x0, -0x20(%rbp)
jne 0x15331
cmpl $0x0, -0x8144(%rbp)
jne 0x15331
leaq -0x8030(%rbp), %rsi
xorl %edi, %edi
movl $0x4000, %edx           # imm = 0x4000
callq 0x102b0
movq %rax, -0x8190(%rbp)
cmpq $0x0, -0x8190(%rbp)
jne 0x152d1
leaq -0x81c0(%rbp), %rdi
leaq 0x77c01(%rip), %rsi     # 0x8ce20
movl $0x2c, %edx
callq 0x103b0
movl $0x1, -0x8144(%rbp)
movl $0x0, -0x81c4(%rbp)
cmpl $0x14, -0x81c4(%rbp)
jge 0x15271
callq 0x106c0
andl $0xff, %eax
movb %al, %cl
movslq -0x81c4(%rbp), %rax
movb %cl, -0x8160(%rbp,%rax)
movl -0x81c4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x81c4(%rbp)
jmp 0x1523d
movq -0x8160(%rbp), %rax
movq %rax, -0x81ab(%rbp)
movq -0x8158(%rbp), %rax
movq %rax, -0x81a3(%rbp)
movl -0x8150(%rbp), %eax
movl %eax, -0x819b(%rbp)
leaq -0x8030(%rbp), %rdi
leaq -0x81c0(%rbp), %rsi
movl $0x2b, %edx
callq 0x103b0
movq $0x2b, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
leaq 0x76e26(%rip), %rdi     # 0x8c0ee
movb $0x0, %al
callq 0x101d0
jmp 0x1532f
cmpq $-0x1, -0x8190(%rbp)
jne 0x1531a
movq 0x89d0e(%rip), %rax     # 0x9eff0
movq (%rax), %rax
movq %rax, -0x81e0(%rbp)
callq 0x10080
movl (%rax), %edi
callq 0x10660
movq -0x81e0(%rbp), %rdi
movq %rax, %rdx
leaq 0x76e1a(%rip), %rsi     # 0x8c123
movb $0x0, %al
callq 0x10360
movl $0x1, %edi
callq 0x10600
movq -0x8190(%rbp), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
jmp 0x1532f
jmp 0x15331
cmpq $0x0, -0x20(%rbp)
jne 0x15341
cmpl $0x0, -0x8144(%rbp)
jne 0x1534e
cmpq $0x20000, -0x8180(%rbp) # imm = 0x20000
jle 0x15350
jmp 0x15355
jmp 0x150fa
jmp 0x15357
cmpl $0x0, -0x8144(%rbp)
je 0x153b1
cmpl $0x0, 0x8c189(%rip)     # 0xa14f0
jle 0x153b1
xorl %eax, %eax
movl %eax, %edi
callq 0x103c0
subq -0x8168(%rbp), %rax
movslq 0x8c170(%rip), %rcx     # 0xa14f0
cmpq %rcx, %rax
jle 0x153b1
movq 0x89c64(%rip), %rax     # 0x9eff0
movq (%rax), %rdi
movl 0x8c15b(%rip), %edx     # 0xa14f0
leaq 0x76da5(%rip), %rsi     # 0x8c141
movb $0x0, %al
callq 0x10360
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x153b6
jmp 0x14e9a
movq -0x8138(%rbp), %rdi
callq 0x1b430
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq 0x76d95(%rip), %rdi     # 0x8c166
movb $0x0, %al
callq 0x101d0
cmpq $0x0, -0x10(%rbp)
je 0x153e9
movl $0x1, %edi
callq 0x10600
xorl %edi, %edi
callq 0x10600