// File: /workspace/github_c_makefile_star2_O0/wahern[P]cqueues/src/lib/socket.c
// Function: so_peek
size_t so_peek(struct socket *so, void *dst, size_t lim, int flags, int *_error) {
	int rstlowat = so->todo & SO_S_RSTLOWAT;
	long count;
	int lowat, error;

	so->todo &= ~SO_S_RSTLOWAT;

	error = so_exec(so);

	so->todo |= rstlowat;

	if (error)
		goto error;

	if (flags & SO_F_PEEKALL)
		so->events &= ~POLLIN;
retry:
	count = recv(so->fd, dst, lim, MSG_PEEK);

	if (count == -1)
		goto soerr;

	if ((size_t)count == lim || !(flags & SO_F_PEEKALL))
		return count;
pollin:
	if (!(so->todo & SO_S_RSTLOWAT)) {
		if (0 != getsockopt(so->fd, SOL_SOCKET, SO_RCVLOWAT, &so->olowat, &(socklen_t){ sizeof so->olowat }))
			goto soerr;

		if (lim > INT_MAX) {
			error = EOVERFLOW;

			goto error;
		}

		lowat = (int)lim;

		if (0 != setsockopt(so->fd, SOL_SOCKET, SO_RCVLOWAT, &lowat, sizeof lowat))
			goto soerr;

		so->todo |= SO_S_RSTLOWAT;
	}

	so->events |= POLLIN;

	*_error = SO_EAGAIN;

	return 0;
soerr:
	error = so_soerr();

	switch (error) {
	case SO_EINTR:
		goto retry;
#if SO_EWOULDBLOCK != SO_EAGAIN
	case SO_EWOULDBLOCK:
		/* FALL THROUGH */
#endif
	case SO_EAGAIN:
		if (flags & SO_F_PEEKALL)
			goto pollin;

		break;
	} /* switch() */
error:
	*_error = error;

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0xb8(%rax), %eax
andl $0x200, %eax            # imm = 0x200
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movl 0xb8(%rax), %ecx
andl $0xfffffdff, %ecx       # imm = 0xFFFFFDFF
movl %ecx, 0xb8(%rax)
movq -0x10(%rbp), %rdi
callq 0x2dbb0
movl %eax, -0x48(%rbp)
movl -0x34(%rbp), %ecx
movq -0x10(%rbp), %rax
orl 0xb8(%rax), %ecx
movl %ecx, 0xb8(%rax)
cmpl $0x0, -0x48(%rbp)
je 0x2fa7d
jmp 0x2fbfd
movl -0x24(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2fa9d
movq -0x10(%rbp), %rax
movswl 0xb0(%rax), %ecx
andl $-0x2, %ecx
movw %cx, 0xb0(%rax)
jmp 0x2fa9f
movq -0x10(%rbp), %rax
movl 0x58(%rax), %edi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl $0x2, %ecx
callq 0xf490
movq %rax, -0x40(%rbp)
cmpq $-0x1, -0x40(%rbp)
jne 0x2fac8
jmp 0x2fbc3
movq -0x40(%rbp), %rax
cmpq -0x20(%rbp), %rax
je 0x2fadd
movl -0x24(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x2faea
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x2fc0e
jmp 0x2faec
movq -0x10(%rbp), %rax
movl 0xb8(%rax), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
jne 0x2fb9a
movq -0x10(%rbp), %rax
movl 0x58(%rax), %edi
movq -0x10(%rbp), %rcx
addq $0xc0, %rcx
movl $0x4, -0x4c(%rbp)
movl $0x1, %esi
movl $0x12, %edx
leaq -0x4c(%rbp), %r8
callq 0xfa30
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x2fb3d
jmp 0x2fbc3
cmpq $0x7fffffff, -0x20(%rbp) # imm = 0x7FFFFFFF
jbe 0x2fb53
movl $0x4b, -0x48(%rbp)
jmp 0x2fbfd
movq -0x20(%rbp), %rax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movl 0x58(%rax), %edi
movl $0x1, %esi
movl $0x12, %edx
leaq -0x44(%rbp), %rcx
movl $0x4, %r8d
callq 0x109f0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x2fb84
jmp 0x2fbc3
movq -0x10(%rbp), %rax
movl 0xb8(%rax), %ecx
orl $0x200, %ecx            # imm = 0x200
movl %ecx, 0xb8(%rax)
movq -0x10(%rbp), %rax
movswl 0xb0(%rax), %ecx
orl $0x1, %ecx
movw %cx, 0xb0(%rax)
movq -0x30(%rbp), %rax
movl $0xb, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x2fc0e
callq 0xf0a0
movl (%rax), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x50(%rbp)
subl $0x4, %eax
je 0x2fbe4
jmp 0x2fbda
movl -0x50(%rbp), %eax
subl $0xb, %eax
je 0x2fbe9
jmp 0x2fbfb
jmp 0x2fa9f
movl -0x24(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2fbf9
jmp 0x2faec
jmp 0x2fbfb
jmp 0x2fbfd
movl -0x48(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)