// File: /workspace/github_c_makefile_star2_O1/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 0x9743
movq %rdx, %rbx
movl %esi, %r14d
leaq -0x2c(%rbp), %r15
movl $0x0, -0x2c(%rbp)
movq 0x40(%rbx), %rdi
movl %r14d, %esi
movq %r15, %rdx
callq 0x71cd
testq %rax, %rax
js 0x9508
jne 0x951a
movq %rbx, %rdi
callq 0x28dc
jmp 0x952e
movl $0x3, %eax
movl -0x2c(%rbp), %ecx
cmpl $0x4, %ecx
je 0x951f
cmpl $0xb, %ecx
jne 0x9526
movl $0x2, %eax
cmpl $0x3, %eax
je 0x94e1
jmp 0x9535
movq %rbx, %rdi
callq 0x2920
movl $0x1, %eax
jmp 0x951f
cmpl $0x2, %eax
jne 0x9734
movq 0x40(%rbx), %rdi
callq 0x8d84
testb %al, %al
je 0x95d1
leaq -0x30(%rbp), %rsi
movl $0x0, (%rsi)
movq 0x40(%rbx), %rdi
callq 0x8db6
testb %al, %al
je 0x95de
cmpl $0x0, -0x30(%rbp)
jne 0x9734
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 0x966a
movq 0x40(%rbx), %rdi
callq 0x8a46
movq %rax, %r14
testq %rax, %rax
je 0x9700
incl 0x60(%rbx)
cmpb $0x1, 0x6e(%rbx)
jne 0x96f8
cmpb $0x1, 0x8(%r14)
jne 0x95eb
movq (%r14), %rsi
leaq 0x1c2e(%rip), %rdi      # 0xb1fa
jmp 0x9691
movq %rbx, %rdi
callq 0x2975
jmp 0x9734
movq %rbx, %rdi
callq 0x29b9
jmp 0x9734
movq 0x20(%r14), %r12
testq %r12, %r12
je 0x9687
leaq 0x1(%r12), %rdi
callq 0x23a8
testq %rax, %rax
je 0x9762
movq %rax, %r15
movq 0x18(%r14), %rsi
movq %rax, %rdi
movq %r12, %rdx
callq 0x2200
movq 0x20(%r14), %rax
movb $0x0, (%r15,%rax)
movzbl (%r15), %eax
orl $0x20, %eax
cmpl $0x7b, %eax
jne 0x969a
movq %r15, %rdi
callq 0x4160
testq %rax, %rax
je 0x969a
movq %rax, %r12
movq (%r14), %r13
cmpb $0x1, 0x9(%r14)
jne 0x96c0
movq %r12, %rdi
callq 0x416e
leaq 0x1be0(%rip), %rdi      # 0xb23b
movq %r13, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2100
jmp 0x96e8
movq 0x6987(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x1b6b(%rip), %rsi      # 0xb1e6
xorl %eax, %eax
callq 0x21e0
jmp 0x9599
movq (%r14), %rsi
leaq 0x1c26(%rip), %rdi      # 0xb2b7
xorl %eax, %eax
callq 0x2100
jmp 0x96f8
movq (%r14), %rsi
cmpb $0x1, 0x9(%r14)
jne 0x96ad
leaq 0x1b90(%rip), %rdi      # 0xb23b
jmp 0x96b4
leaq 0x1bdf(%rip), %rdi      # 0xb293
movq %r15, %rdx
xorl %eax, %eax
callq 0x2100
jmp 0x96f0
movq 0x10(%r14), %rax
movq %rax, -0x38(%rbp)
movq %r12, %rdi
callq 0x416e
leaq 0x1b88(%rip), %rdi      # 0xb25f
movq %r13, %rsi
movq -0x38(%rbp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2100
movq %r12, %rdi
callq 0x3af0
movq %r15, %rdi
callq 0x23a0
movq %r14, %rdi
callq 0x859c
cmpl $0x0, 0x5c(%rbx)
jle 0x972c
testq %r14, %r14
jne 0x971d
movq %rbx, %rdi
callq 0x26bc
jmp 0x9734
movq %rbx, %rdi
callq 0x9781
subl $0x1, 0x54(%rbx)
jae 0x9715
movl $0x0, 0x54(%rbx)
jmp 0x9734
movq %rbx, %rdi
callq 0x8fc1
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1927(%rip), %rdi      # 0xb071
leaq 0x1851(%rip), %rsi      # 0xafa2
leaq 0x1928(%rip), %rcx      # 0xb080
movl $0x18c, %edx            # imm = 0x18C
callq 0x2150
leaq 0x18b8(%rip), %rdi      # 0xb021
leaq 0x1832(%rip), %rsi      # 0xafa2
leaq 0x1a97(%rip), %rcx      # 0xb20e
movl $0x1f4, %edx            # imm = 0x1F4
callq 0x2150