// File: /workspace/github_c_makefile_star2_O1/wtarreau[P]httpterm/httpterm.c
// Function: event_cli_read
int event_cli_read(int fd) {
    struct task *t = fdtab[fd].owner;
    struct session *s = t->context;
    struct buffer *b = s->req;
    int ret, max;

    if (fdtab[fd].state != FD_STERROR) {
#ifdef FILL_BUFFERS
	while (1)
#else
	do
#endif
	{
	    if (b->l == 0) { /* let's realign the buffer to optimize I/O */
		b->r = b->w = b->h = b->lr  = b->data;
		max = BUFSIZE;
	    }
	    else if (b->r > b->w) {
		max = b->data + BUFSIZE - b->r;
	    }
	    else {
		max = b->w - b->r;
	    }
	    
	    if (max == 0) {  /* not anymore room to store data */
		my_fd_clr(fd, StaticReadEvent);
		break;
	    }
	    
#ifndef MSG_NOSIGNAL
	    {
		int skerr;
		socklen_t lskerr = sizeof(skerr);
		
		getsockopt(fd, SOL_SOCKET, SO_ERROR, &skerr, &lskerr);
		if (skerr)
		    ret = -1;
		else
		    ret = recv(fd, b->r, max, 0);
	    }
#else
	    ret = recv(fd, b->r, max, MSG_NOSIGNAL);
#endif
	    if (ret > 0) {
		b->r += ret;
		b->l += ret;
		s->res_cr = RES_DATA;
		
		if (b->r == b->data + BUFSIZE) {
		    b->r = b->data; /* wrap around the buffer */
		}

		if (s->cli_state >= CL_STWAIT) {
		    /* drain body data */
		    if (s->req_body) {
			if (s->req_body > (long long)b->l) {
			    s->req_body -= b->l;
			    b->r = b->w = b->lr = b->data;
			    b->l = 0;
			} else {
			    b->l -= s->req_body;
			    b->w += s->req_body;
			    if (b->w >= b->data + BUFSIZE)
				b->w -= BUFSIZE;
			}
		    }
		}

		b->total += ret;
		/* we hope to read more data or to get a close on next round */
		continue;
	    }
	    else if (ret == 0) {
		s->res_cr = RES_NULL;
		break;
	    }
	    else if (errno == EAGAIN) {/* ignore EAGAIN */
		break;
	    }
	    else {
		s->res_cr = RES_ERROR;
		fdtab[fd].state = FD_STERROR;
		break;
	    }
	} /* while(1) */
#ifndef FILL_BUFFERS
	while (0);
#endif
    }
    else {
	s->res_cr = RES_ERROR;
	fdtab[fd].state = FD_STERROR;
    }

    if (s->res_cr != RES_SILENT) {
	if (s->proxy->clitimeout && my_fd_isset(fd, StaticReadEvent))
	    tv_delayfrom(&s->crexpire, &now, s->proxy->clitimeout);
	else
	    tv_eternity(&s->crexpire);
	
	task_wakeup(&rq, t);
    }

    return (s->res_cr == RES_SILENT) ? -1 : 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl %edi, %ebx
movq 0x9fda(%rip), %rax      # 0xd380
movslq %edi, %r13
shlq $0x5, %r13
movq 0x10(%rax,%r13), %r15
movq 0x40(%r15), %r14
cmpl $0x4, 0x18(%rax,%r13)
jne 0x33d1
movb $0x3, 0x38(%r14)
movl $0x4, 0x18(%rax,%r13)
jmp 0x3526
movq 0x58(%r14), %r12
cmpl $0x0, (%r12)
je 0x33f9
movq 0x8(%r12), %rcx
movq 0x10(%r12), %rax
cmpq %rax, %rcx
jbe 0x3419
movl 0x30(%r12), %eax
subl %ecx, %eax
addl $0x1000, %eax           # imm = 0x1000
jmp 0x341b
movq 0x30(%r12), %rax
movq %rax, 0x20(%r12)
movq %rax, 0x18(%r12)
movq %rax, 0x10(%r12)
movq %rax, 0x8(%r12)
movl $0x1000, %eax           # imm = 0x1000
jmp 0x341b
subl %ecx, %eax
testl %eax, %eax
je 0x34bf
movq 0x8(%r12), %rsi
movslq %eax, %rdx
movl %ebx, %edi
movl $0x4000, %ecx           # imm = 0x4000
callq 0x2060
testl %eax, %eax
jle 0x34dc
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq 0x8(%r12), %rdi
addq %rcx, %rdi
movq %rdi, 0x8(%r12)
movl (%r12), %edx
addl %eax, %edx
movl %edx, (%r12)
movb $0x1, 0x38(%r14)
movq 0x30(%r12), %rsi
leaq 0x1000(%rsi), %rax
cmpq %rax, %rdi
jne 0x3479
movq %rsi, 0x8(%r12)
cmpl $0x2, 0x4c(%r14)
jl 0x3521
movq 0x130(%r14), %rdi
testq %rdi, %rdi
je 0x3521
movl %edx, %r9d
movq %rdi, %r8
subq %r9, %r8
jle 0x3500
movq %r8, 0x130(%r14)
movq %rsi, 0x20(%r12)
movq %rsi, 0x10(%r12)
movq %rsi, 0x8(%r12)
movl $0x0, (%r12)
jmp 0x3521
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
movl %ebx, %ecx
roll %cl, %eax
movq 0x9f29(%rip), %rcx      # 0xd3f8
movl %ebx, %edx
sarl $0x5, %edx
movslq %edx, %rdx
andl %eax, (%rcx,%rdx,4)
jmp 0x3526
je 0x34f9
callq 0x2080
cmpl $0xb, (%rax)
je 0x3526
movb $0x3, 0x38(%r14)
movq 0x9e8c(%rip), %rax      # 0xd380
jmp 0x33c3
movb $0x2, 0x38(%r14)
jmp 0x3526
subl %edi, %edx
movl %edx, (%r12)
addq 0x10(%r12), %rdi
movq %rdi, 0x10(%r12)
cmpq %rax, %rdi
jb 0x3521
addq $-0x1000, %rdi          # imm = 0xF000
movq %rdi, 0x10(%r12)
addq %rcx, 0x28(%r12)
cmpb $0x0, 0x38(%r14)
je 0x3583
movq 0x40(%r14), %rax
movl 0x30(%rax), %esi
testl %esi, %esi
je 0x355a
movq 0x9eb9(%rip), %rax      # 0xd3f8
movl %ebx, %ecx
sarl $0x5, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
btl %ebx, %eax
jae 0x355a
leaq 0x8(%r14), %rdi
callq 0x3596
jmp 0x3562
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r14)
cmpl $0x1, 0x20(%r15)
je 0x3583
movq 0x9e18(%rip), %rax      # 0xd388
movq %rax, 0x10(%r15)
movl $0x1, 0x20(%r15)
movq %r15, 0x9e05(%rip)      # 0xd388
xorl %eax, %eax
cmpb $0x1, 0x38(%r14)
sbbl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq