// File: /workspace/github_c_makefile_star2_O2/zhou-yuxin[P]redis-aof-no-cow/src/redis-benchmark.c
// Function: readHandler
static void readHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
    client c = privdata;
    void *reply = NULL;
    UNUSED(el);
    UNUSED(fd);
    UNUSED(mask);

    /* Calculate latency only for the first read event. This means that the
     * server already sent the reply and we need to parse it. Parsing overhead
     * is not part of the latency, so calculate it only once, here. */
    if (c->latency < 0) c->latency = ustime()-(c->start);

    if (redisBufferRead(c->context) != REDIS_OK) {
        fprintf(stderr,"Error: %s\n",c->context->errstr);
        exit(1);
    } else {
        while(c->pending) {
            if (redisGetReply(c->context,&reply) != REDIS_OK) {
                fprintf(stderr,"Error: %s\n",c->context->errstr);
                exit(1);
            }
            if (reply != NULL) {
                if (reply == (void*)REDIS_REPLY_ERROR) {
                    fprintf(stderr,"Unexpected error reply, exiting...\n");
                    exit(1);
                }

                if (config.showerrors) {
                    static time_t lasterr_time = 0;
                    time_t now = time(NULL);
                    redisReply *r = reply;
                    if (r->type == REDIS_REPLY_ERROR && lasterr_time != now) {
                        lasterr_time = now;
                        printf("Error from server: %s\n", r->str);
                    }
                }

                freeReplyObject(reply);
                /* This is an OK for prefix commands such as auth and select.*/
                if (c->prefix_pending > 0) {
                    c->prefix_pending--;
                    c->pending--;
                    /* Discard prefix commands on first response.*/
                    if (c->prefixlen > 0) {
                        size_t j;
                        sdsrange(c->obuf, c->prefixlen, -1);
                        /* We also need to fix the pointers to the strings
                        * we need to randomize. */
                        for (j = 0; j < c->randlen; j++)
                            c->randptr[j] -= c->prefixlen;
                        c->prefixlen = 0;
                    }
                    continue;
                }

                if (config.requests_finished < config.requests)
                    config.latency[config.requests_finished++] = c->latency;
                c->pending--;
                if (c->pending == 0) {
                    clientDone(c);
                    break;
                }
            } else {
                break;
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
andq $0x0, (%rsp)
movq %rdx, %rbx
cmpq $0x0, 0x38(%rdx)
jns 0xe301
callq 0xe2bb
subq 0x30(%rbx), %rax
movq %rax, 0x38(%rbx)
movq (%rbx), %rdi
callq 0x10021
testl %eax, %eax
jne 0xe4bf
movq %rsp, %r14
pushq $-0x1
popq %rbp
leaq 0x262e2(%rip), %r15     # 0x34600
cmpl $0x0, 0x40(%rbx)
je 0xe4b4
movq (%rbx), %rdi
movq %r14, %rsi
callq 0x101cd
testl %eax, %eax
jne 0xe4bf
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xe4b4
cmpq $0x6, %rdi
je 0xe4e0
cmpl $0x0, 0x3a12b(%rip)     # 0x48484
je 0xe38d
xorl %edi, %edi
callq 0xb350
movq (%rsp), %rdi
cmpl $0x6, (%rdi)
jne 0xe38d
cmpq %rax, 0x3a16e(%rip)     # 0x484e0
je 0xe38d
movq %rax, 0x3a165(%rip)     # 0x484e0
movq 0x18(%rdi), %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0xb1c0
movq (%rsp), %rdi
callq 0xeca4
movl 0x44(%rbx), %eax
testl %eax, %eax
jle 0xe3dc
decl %eax
movl %eax, 0x44(%rbx)
decl 0x40(%rbx)
movl 0x48(%rbx), %esi
testl %esi, %esi
jle 0xe31e
movq 0x8(%rbx), %rdi
movl %ebp, %edx
callq 0x117b2
movq 0x18(%rbx), %rax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0xe3d3
movslq 0x48(%rbx), %rdx
movq 0x10(%rbx), %rsi
subq %rdx, (%rsi,%rcx,8)
incq %rcx
jmp 0xe3bd
andl $0x0, 0x48(%rbx)
jmp 0xe31e
movl 0x3a086(%rip), %eax     # 0x48468
movl 0x3a078(%rip), %ecx     # 0x48460
cmpl %ecx, %eax
jge 0xe406
movslq %eax, %rdx
movq 0x38(%rbx), %rsi
movq 0x3a09e(%rip), %rdi     # 0x48498
incl %eax
movl %eax, 0x3a066(%rip)     # 0x48468
movq %rsi, (%rdi,%rdx,8)
decl 0x40(%rbx)
jne 0xe31e
cmpl %ecx, %eax
jne 0xe42c
movq %rbx, %rdi
callq 0xe21c
movq 0x3a016(%rip), %rdi     # 0x48438
callq 0xb8f0
jmp 0xe4b4
cmpl $0x0, 0x3a049(%rip)     # 0x4847c
je 0xe498
movq 0x39ffc(%rip), %rdi     # 0x48438
movq (%rbx), %rax
movl 0x84(%rax), %esi
pushq $0x2
popq %rbp
movl %ebp, %edx
callq 0xb9b8
movq 0x39fe2(%rip), %rdi     # 0x48438
movq (%rbx), %rax
movl 0x84(%rax), %esi
pushq $0x1
popq %rdx
callq 0xb9b8
movq 0x39fca(%rip), %rdi     # 0x48438
movq (%rbx), %rax
movl 0x84(%rax), %esi
leaq -0x3d4(%rip), %rcx      # 0xe0aa
movl %ebp, %edx
movq %rbx, %r8
callq 0xb8f8
andq $0x0, 0x28(%rbx)
movl 0x39fed(%rip), %eax     # 0x48480
movl %eax, 0x40(%rbx)
jmp 0xe4b4
decl 0x39fbe(%rip)           # 0x4845c
movq %rbx, %rdi
callq 0xde0c
incl 0x39fb0(%rip)           # 0x4845c
movq %rbx, %rdi
callq 0xe21c
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x39b32(%rip), %rax     # 0x47ff8
movq (%rax), %rdi
movq (%rbx), %rdx
addq $0x4, %rdx
leaq 0x260fa(%rip), %rsi     # 0x345d1
xorl %eax, %eax
callq 0xb310
jmp 0xe4fc
movq 0x39b11(%rip), %rax     # 0x47ff8
movq (%rax), %rcx
leaq 0x260eb(%rip), %rdi     # 0x345dc
pushq $0x23
popq %rsi
pushq $0x1
popq %rdx
callq 0xb520
pushq $0x1
popq %rdi
callq 0xb500