// File: /workspace/github_c_makefile_star2_O3/goghcrow[P]dubbo_ab/dubbo_client.c
// Function: cli_on_read
static void cli_on_read(struct aeEventLoop *el, int fd, void *ud, int mask)
{
    UNUSED(el);
    UNUSED(mask);

    struct dubbo_client *cli = (struct dubbo_client *)ud;
    assert(cli->connected);

    for (;;)
    {
        int errno_ = 0;
        ssize_t recv_n = buf_readFd(cli->rcv_buf, fd, &errno_);
        if (recv_n < 0)
        {
            if (errno_ == EINTR)
            {
                continue;
            }
            else if (errno_ == EAGAIN)
            {
            }
            else
            {
                LOG_ERROR("从 Dubbo 服务端读取数据: %s", strerror(errno));
                cli_reconnect(cli);
                return;
            }
        }
        else if (recv_n == 0)
        {
            LOG_ERROR("Dubbo 服务端断开连接");
            cli_reconnect(cli);
            return;
        }
        break;
    }

    if (!is_dubbo_pkt(cli->rcv_buf))
    {
        LOG_ERROR("接收到非 dubbo 数据包");
        cli_reconnect(cli);
        return;
    }

    int remaining = 0;
    if (!is_completed_dubbo_pkt(cli->rcv_buf, &remaining))
    {
        LOG_ERROR("接收到异常 dubbo 数据包");
        cli_reconnect(cli);
        return;
    }
    if (remaining) {
        return;
    }

    cli->pipe_left++;
    cli->req_left--;

    if (((cli->req_n - cli->req_left) % 1000) == 0)
    {
        fprintf(stderr, "已发送请求 %d\n", cli->req_n - cli->req_left);
    }

    bool ok = cli_decode_resp(cli);
    
    if (cli->req_left <= 0)
    {
        cli_end(cli);
    }
    else
    {
        if (ok)
        {
            cli_pipe_send(cli);
        }
        else
        {
            cli_reconnect(cli);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
cmpb $0x1, 0x6c(%rdx)
jne 0x95c9
movq %rdx, %rbx
movl %esi, %r14d
leaq -0x2c(%rbp), %rdx
movl $0x0, (%rdx)
movq 0x40(%rbx), %rdi
callq 0x7091
testq %rax, %rax
jns 0x9386
leaq -0x2c(%rbp), %r15
movl -0x2c(%rbp), %eax
cmpl $0x4, %eax
jne 0x9426
movl $0x0, -0x2c(%rbp)
movq 0x40(%rbx), %rdi
movl %r14d, %esi
movq %r15, %rdx
callq 0x7091
testq %rax, %rax
js 0x935f
testq %rax, %rax
je 0x94f0
movq 0x40(%rbx), %rdi
callq 0x8c4d
testb %al, %al
je 0x9448
leaq -0x30(%rbp), %rsi
movl $0x0, (%rsi)
movq 0x40(%rbx), %rdi
callq 0x8c7f
testb %al, %al
je 0x9455
cmpl $0x0, -0x30(%rbp)
jne 0x95ba
incl 0x54(%rbx)
movl 0x58(%rbx), %edx
movl 0x5c(%rbx), %eax
decl %eax
movl %eax, 0x5c(%rbx)
subl %eax, %edx
imull $0x26e978d5, %edx, %eax # imm = 0x26E978D5
addl $0x10624d8, %eax        # imm = 0x10624D8
rorl $0x3, %eax
cmpl $0x418936, %eax         # imm = 0x418936
jbe 0x9502
movq 0x40(%rbx), %rdi
callq 0x88fc
testq %rax, %rax
je 0x9439
movq %rax, %r14
movb 0x9(%rax), %r13b
incl 0x60(%rbx)
cmpb $0x1, 0x6e(%rbx)
jne 0x958b
cmpb $0x1, 0x8(%r14)
jne 0x9462
movq (%r14), %rsi
leaq 0x1dd9(%rip), %rdi      # 0xb1fa
jmp 0x9529
cmpl $0xb, %eax
je 0x938f
callq 0x2996
jmp 0x94f5
cmpl $0x0, 0x5c(%rbx)
jle 0x95a9
jmp 0x94f5
movq %rbx, %rdi
callq 0x28dc
jmp 0x95ba
movq %rbx, %rdi
callq 0x2920
jmp 0x95ba
movq 0x20(%r14), %r12
testq %r12, %r12
je 0x951f
leaq 0x1(%r12), %rdi
callq 0x23a8
testq %rax, %rax
je 0x95e8
movq %rax, %r15
movq 0x18(%r14), %rsi
movq %rax, %rdi
movq %r12, %rdx
callq 0x2200
movb $0x0, (%r15,%r12)
movzbl (%r15), %eax
orl $0x20, %eax
cmpl $0x7b, %eax
jne 0x9532
movq %r15, %rdi
callq 0x40c3
movb 0x9(%r14), %r13b
testq %rax, %rax
je 0x9532
movq %rax, %r12
movq (%r14), %rax
movq %rax, -0x38(%rbp)
testb $0x1, %r13b
je 0x9557
movq %r12, %rdi
callq 0x40d1
leaq 0x1d5e(%rip), %rdi      # 0xb23b
movq -0x38(%rbp), %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2100
jmp 0x957b
callq 0x2964
movq %rbx, %rdi
callq 0x26bc
jmp 0x95ba
movq 0x6aef(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x1cd3(%rip), %rsi      # 0xb1e6
xorl %eax, %eax
callq 0x21e0
jmp 0x93ee
movq (%r14), %rsi
leaq 0x1d8e(%rip), %rdi      # 0xb2b7
xorl %eax, %eax
callq 0x2100
jmp 0x958b
movq (%r14), %rsi
testb $0x1, %r13b
je 0x9544
leaq 0x1cf9(%rip), %rdi      # 0xb23b
jmp 0x954b
leaq 0x1d48(%rip), %rdi      # 0xb293
movq %r15, %rdx
xorl %eax, %eax
callq 0x2100
jmp 0x9583
movq 0x10(%r14), %r13
movq %r12, %rdi
callq 0x40d1
leaq 0x1cf5(%rip), %rdi      # 0xb25f
movq -0x38(%rbp), %rsi
movq %r13, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2100
movq %r12, %rdi
callq 0x3a9a
movq %r15, %rdi
callq 0x23a0
movq %r14, %rdi
callq 0x8464
cmpl $0x0, 0x5c(%rbx)
jle 0x95a9
subl $0x1, 0x54(%rbx)
jb 0x95b3
movq %rbx, %rdi
callq 0x9607
jmp 0x9599
movq %rbx, %rdi
callq 0x8e89
jmp 0x95ba
movl $0x0, 0x54(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1aa1(%rip), %rdi      # 0xb071
leaq 0x19cb(%rip), %rsi      # 0xafa2
leaq 0x1aa2(%rip), %rcx      # 0xb080
movl $0x18c, %edx            # imm = 0x18C
callq 0x2150
leaq 0x1a32(%rip), %rdi      # 0xb021
leaq 0x19ac(%rip), %rsi      # 0xafa2
leaq 0x1c11(%rip), %rcx      # 0xb20e
movl $0x1f4, %edx            # imm = 0x1F4
callq 0x2150