// File: /workspace/github_c_makefile_star2_O0/qq-smart[P]qq_sh_server/os/qq_tcp_recv.c
// Function: qq_tcp_recv
ssize_t
qq_tcp_recv(qq_connection_t *c, u_char *buf, size_t size)
{
    ssize_t       n;
    qq_err_t      err;
    qq_event_t   *rev;

    rev = c->read;

#if (QQ_HAVE_EPOLLRDHUP)
    qq_log_debug("recv: eof:%d, avail:%d", rev->pending_eof, rev->available);
    if (!rev->available && !rev->pending_eof) {
        rev->ready = 0;
        return QQ_AGAIN;
    }
#endif

    do {
        n = recv(c->fd, buf, size, 0);
        qq_log_debug("recv: fd:%d n:%d of size:%d", c->fd, n, size);

        if (n == 0) {
            rev->ready = 0;
            rev->eof = 1;
            return 0;
        }

        if (n > 0) {
#if (QQ_HAVE_EPOLLRDHUP)
            if ((size_t) n < size) {
                if (!rev->pending_eof) {
                    rev->ready = 0;
                }
                rev->available = 0;
            }
            return n;
#endif

            if ((size_t) n < size) {
                rev->ready = 0;
            }
            return n;
        }

        err = errno;
        if (err == QQ_EAGAIN || err == QQ_EINTR) {
            qq_log_debug("recv() not ready");
            n = QQ_AGAIN;
        } else {
            qq_log_debug("recv() failed");
            n = QQ_ERROR;
            break;
        }
    } while (err == QQ_EINTR);

    rev->ready = 0;
    rev->error = 1;

    return n;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movl 0x8(%rax), %esi
shrl $0xe, %esi
andl $0x1, %esi
movq -0x38(%rbp), %rax
movl 0x8(%rax), %edx
shrl $0x14, %edx
andl $0x1, %edx
leaq 0x2f0e(%rip), %rdi      # 0xffff
movb $0x0, %al
callq 0x9e70
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
shrl $0x14, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xd139
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
shrl $0xe, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xd139
movq -0x38(%rbp), %rax
movl 0x8(%rax), %ecx
andl $-0x21, %ecx
orl $0x0, %ecx
movl %ecx, 0x8(%rax)
movq $-0x2, -0x8(%rbp)
jmp 0xd27f
jmp 0xd13b
movq -0x10(%rbp), %rax
movl 0x18(%rax), %edi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
xorl %ecx, %ecx
callq 0x20b0
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %esi
movq -0x28(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq 0x2eab(%rip), %rdi      # 0x10016
movb $0x0, %al
callq 0x9e70
cmpq $0x0, -0x28(%rbp)
jne 0xd1ac
movq -0x38(%rbp), %rax
movl 0x8(%rax), %ecx
andl $-0x21, %ecx
orl $0x0, %ecx
movl %ecx, 0x8(%rax)
movq -0x38(%rbp), %rax
movl 0x8(%rax), %ecx
andl $0xfffffeff, %ecx       # imm = 0xFFFFFEFF
orl $0x100, %ecx            # imm = 0x100
movl %ecx, 0x8(%rax)
movq $0x0, -0x8(%rbp)
jmp 0xd27f
cmpq $0x0, -0x28(%rbp)
jle 0xd1ff
movq -0x28(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0xd1f2
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
shrl $0xe, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xd1df
movq -0x38(%rbp), %rax
movl 0x8(%rax), %ecx
andl $-0x21, %ecx
orl $0x0, %ecx
movl %ecx, 0x8(%rax)
movq -0x38(%rbp), %rax
movl 0x8(%rax), %ecx
andl $0xffefffff, %ecx       # imm = 0xFFEFFFFF
orl $0x0, %ecx
movl %ecx, 0x8(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xd27f
callq 0x2030
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
cmpl $0xb, -0x2c(%rbp)
je 0xd215
cmpl $0x4, -0x2c(%rbp)
jne 0xd22d
leaq 0x2e16(%rip), %rdi      # 0x10032
movb $0x0, %al
callq 0x9e70
movq $-0x2, -0x28(%rbp)
jmp 0xd245
leaq 0x2e0f(%rip), %rdi      # 0x10043
movb $0x0, %al
callq 0x9e70
movq $-0x1, -0x28(%rbp)
jmp 0xd251
jmp 0xd247
cmpl $0x4, -0x2c(%rbp)
je 0xd13b
movq -0x38(%rbp), %rax
movl 0x8(%rax), %ecx
andl $-0x21, %ecx
orl $0x0, %ecx
movl %ecx, 0x8(%rax)
movq -0x38(%rbp), %rax
movl 0x8(%rax), %ecx
andl $0xfffffdff, %ecx       # imm = 0xFFFFFDFF
orl $0x200, %ecx            # imm = 0x200
movl %ecx, 0x8(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)