// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x4(%rbp)
movq 0xd71e(%rip), %rax      # 0x113b0
movslq -0x4(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x20(%rbp)
movq 0xd6ec(%rip), %rax      # 0x113b0
movslq -0x4(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpl $0x4, 0x18(%rax)
je 0x3f23
jmp 0x3cdb
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x3d15
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x20(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movl $0x1000, -0x28(%rbp)    # imm = 0x1000
jmp 0x3d5d
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jbe 0x3d45
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
addq $0x1000, %rax           # imm = 0x1000
movq -0x20(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq %rcx, %rax
movl %eax, -0x28(%rbp)
jmp 0x3d5b
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq %rcx, %rax
movl %eax, -0x28(%rbp)
jmp 0x3d5d
cmpl $0x0, -0x28(%rbp)
jne 0x3d77
movl -0x4(%rbp), %edi
movq 0xd69b(%rip), %rsi      # 0x11408
callq 0x3fd0
jmp 0x3f21
movl -0x4(%rbp), %edi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
movslq -0x28(%rbp), %rdx
movl $0x4000, %ecx           # imm = 0x4000
callq 0x2050
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jle 0x3ee4
movl -0x24(%rbp), %edx
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
movslq %edx, %rdx
addq %rdx, %rcx
movq %rcx, 0x8(%rax)
movl -0x24(%rbp), %ecx
movq -0x20(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movb $0x1, 0x38(%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x30(%rcx), %rcx
addq $0x1000, %rcx           # imm = 0x1000
cmpq %rcx, %rax
jne 0x3df1
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
cmpl $0x2, 0x4c(%rax)
jl 0x3ed2
movq -0x18(%rbp), %rax
cmpq $0x0, 0x130(%rax)
je 0x3ed0
movq -0x18(%rbp), %rax
movq 0x130(%rax), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
cmpq %rcx, %rax
jle 0x3e70
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, %edx
movq -0x18(%rbp), %rax
movq 0x130(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x130(%rax)
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
jmp 0x3ece
movq -0x18(%rbp), %rax
movq 0x130(%rax), %rdx
movq -0x20(%rbp), %rax
movl (%rax), %ecx
subq %rdx, %rcx
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movq 0x130(%rax), %rcx
movq -0x20(%rbp), %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x30(%rcx), %rcx
addq $0x1000, %rcx           # imm = 0x1000
cmpq %rcx, %rax
jb 0x3ecc
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rcx
addq $-0x1000, %rcx          # imm = 0xF000
movq %rcx, 0x10(%rax)
jmp 0x3ece
jmp 0x3ed0
jmp 0x3ed2
movslq -0x24(%rbp), %rcx
movq -0x20(%rbp), %rax
addq 0x28(%rax), %rcx
movq %rcx, 0x28(%rax)
jmp 0x3f21
cmpl $0x0, -0x24(%rbp)
jne 0x3ef4
movq -0x18(%rbp), %rax
movb $0x2, 0x38(%rax)
jmp 0x3f21
callq 0x2070
cmpl $0xb, (%rax)
jne 0x3f00
jmp 0x3f21
movq -0x18(%rbp), %rax
movb $0x3, 0x38(%rax)
movq 0xd4a1(%rip), %rax      # 0x113b0
movslq -0x4(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl $0x4, 0x18(%rax)
jmp 0x3f44
movq -0x18(%rbp), %rax
movb $0x3, 0x38(%rax)
movq 0xd47e(%rip), %rax      # 0x113b0
movslq -0x4(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl $0x4, 0x18(%rax)
movq -0x18(%rbp), %rax
movsbl 0x38(%rax), %eax
cmpl $0x0, %eax
je 0x3fb1
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
cmpl $0x0, 0x30(%rax)
je 0x3f94
movl -0x4(%rbp), %edi
movq 0xd49f(%rip), %rsi      # 0x11408
callq 0x4000
cmpl $0x0, %eax
je 0x3f94
movq -0x18(%rbp), %rdi
addq $0x8, %rdi
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movl 0x30(%rax), %edx
leaq 0xd483(%rip), %rsi      # 0x11410
callq 0x4030
jmp 0x3fa1
movq -0x18(%rbp), %rdi
addq $0x8, %rdi
callq 0x40e0
movq -0x10(%rbp), %rsi
leaq 0xd40c(%rip), %rdi      # 0x113b8
callq 0x4110
movq -0x18(%rbp), %rax
movsbl 0x38(%rax), %edx
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl $0x0, %edx
cmovel %ecx, %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)