// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/liball/../libcperciva/netbuf/netbuf_read.c
// Function: netbuf_read_wait
int
netbuf_read_wait(struct netbuf_read * R, size_t len,
    int (* callback)(void *, int), void * cookie)
{

	/* Sanity-check: We shouldn't be reading already. */
	assert(R->read_cookie == NULL);
	assert(R->immediate_cookie == NULL);

	/* Record parameters for future reference. */
	R->callback = callback;
	R->cookie = cookie;

	/* If we have enough data already, schedule a callback. */
	if (R->datalen - R->bufpos >= len) {
		if ((R->immediate_cookie =
		    events_immediate_register(callback_success, R, 0)) == NULL)
			goto err0;
		else
			goto done;
	}

	/* Resize the buffer if needed. */
	if ((R->buflen < len) && netbuf_read_resize_buffer(R, len))
		goto err0;

	/* Move data to start of buffer if needed. */
	if (R->buflen - R->bufpos < len) {
		memmove(R->buf, &R->buf[R->bufpos], R->datalen - R->bufpos);
		R->datalen -= R->bufpos;
		R->bufpos = 0;
	}

	/* Read data into the buffer. */
	if (R->ssl) {
		if ((R->read_cookie = (netbuf_read_ssl_func)(R->ssl,
		    &R->buf[R->datalen], R->buflen - R->datalen,
		    R->bufpos + len - R->datalen, callback_read, R)) == NULL)
			goto err0;
	} else {
		if ((R->read_cookie = network_read(R->s, &R->buf[R->datalen],
		    R->buflen - R->datalen, R->bufpos + len - R->datalen,
		    callback_read, R)) == NULL)
			goto err0;
	}

done:
	/* Success! */
	return (0);

err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jne 0xb705
jmp 0xb724
leaq 0x4b52(%rip), %rdi      # 0x1025e
leaq 0x4b62(%rip), %rsi      # 0x10275
movl $0x98, %edx
leaq 0x4b7a(%rip), %rcx      # 0x10299
callq 0x21a0
movq -0x10(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jne 0xb731
jmp 0xb750
leaq 0x4bb2(%rip), %rdi      # 0x102ea
leaq 0x4b36(%rip), %rsi      # 0x10275
movl $0x99, %edx
leaq 0x4b4e(%rip), %rcx      # 0x10299
callq 0x21a0
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x10(%rbp), %rcx
subq 0x40(%rcx), %rax
cmpq -0x18(%rbp), %rax
jb 0xb7a8
movq -0x10(%rbp), %rsi
leaq 0x197(%rip), %rdi       # 0xb920
xorl %edx, %edx
callq 0x2fb0
movq -0x10(%rbp), %rcx
movq %rax, 0x28(%rcx)
cmpq $0x0, %rax
jne 0xb7a3
jmp 0xb907
jmp 0xb8fe
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
cmpq -0x18(%rbp), %rax
jae 0xb7cd
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xb990
cmpl $0x0, %eax
je 0xb7cd
jmp 0xb907
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x10(%rbp), %rcx
subq 0x40(%rcx), %rax
cmpq -0x18(%rbp), %rax
jae 0xb833
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
movq -0x10(%rbp), %rax
addq 0x40(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdx
movq -0x10(%rbp), %rax
subq 0x40(%rax), %rdx
callq 0x22b0
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xb8a0
movq 0x3aea3(%rip), %rax     # 0x466e8
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rsi
movq -0x10(%rbp), %rcx
addq 0x48(%rcx), %rsi
movq -0x10(%rbp), %rcx
movq 0x38(%rcx), %rdx
movq -0x10(%rbp), %rcx
subq 0x48(%rcx), %rdx
movq -0x10(%rbp), %rcx
movq 0x40(%rcx), %rcx
addq -0x18(%rbp), %rcx
movq -0x10(%rbp), %r8
subq 0x48(%r8), %rcx
movq -0x10(%rbp), %r9
leaq 0x1d4(%rip), %r8        # 0xba60
callq *%rax
movq -0x10(%rbp), %rcx
movq %rax, 0x20(%rcx)
cmpq $0x0, %rax
jne 0xb89e
jmp 0xb907
jmp 0xb8fc
movq -0x10(%rbp), %rax
movl (%rax), %edi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
movq -0x10(%rbp), %rax
addq 0x48(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdx
movq -0x10(%rbp), %rax
subq 0x48(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rcx
addq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
subq 0x48(%rax), %rcx
movq -0x10(%rbp), %r9
leaq 0x17b(%rip), %r8        # 0xba60
callq 0xc510
movq -0x10(%rbp), %rcx
movq %rax, 0x20(%rcx)
cmpq $0x0, %rax
jne 0xb8fa
jmp 0xb907
jmp 0xb8fc
jmp 0xb8fe
movl $0x0, -0x4(%rbp)
jmp 0xb90e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)