// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpq $0x0, 0x20(%rdi)
jne 0x821a
movq %rdi, %rbx
cmpq $0x0, 0x28(%rdi)
jne 0x8239
movq %rsi, %r14
movq %rdx, 0x10(%rbx)
movq %rcx, 0x18(%rbx)
movq 0x40(%rbx), %r13
movq 0x48(%rbx), %r12
subq %r13, %r12
cmpq %rsi, %r12
jae 0x81c5
movq 0x38(%rbx), %r15
cmpq %r14, %r15
jae 0x815a
addq %r15, %r15
cmpq %r14, %r15
cmovbeq %r14, %r15
movq %r15, %rdi
callq 0x2220
testq %rax, %rax
je 0x8204
movq %rax, %rbp
movq 0x30(%rbx), %rax
movq %rax, (%rsp)
addq %rax, %r13
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x2200
movq (%rsp), %rdi
callq 0x2040
movq %rbp, 0x30(%rbx)
movq %r15, 0x38(%rbx)
movq 0x40(%rbx), %rax
subq %rax, 0x48(%rbx)
movq $0x0, 0x40(%rbx)
movq 0x38(%rbx), %rcx
movq 0x40(%rbx), %rax
subq %rax, %rcx
cmpq %r14, %rcx
jae 0x818e
movq 0x30(%rbx), %rdi
movq 0x48(%rbx), %rdx
leaq (%rdi,%rax), %rsi
subq %rax, %rdx
callq 0x22a0
movq 0x40(%rbx), %rax
subq %rax, 0x48(%rbx)
movq $0x0, 0x40(%rbx)
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rdx
movq 0x48(%rbx), %rax
movq 0x30(%rbx), %rsi
addq %rax, %rsi
subq %rax, %rdx
subq %rax, %r14
addq 0x40(%rbx), %r14
testq %rdi, %rdi
je 0x81e3
leaq 0xdc(%rip), %r8         # 0x8293
movq %r14, %rcx
movq %rbx, %r9
callq *0x3a515(%rip)          # 0x426d8
jmp 0x81f7
leaq 0x8c(%rip), %rdi        # 0x8258
xorl %ebp, %ebp
movq %rbx, %rsi
xorl %edx, %edx
callq 0x2d70
movq %rax, 0x28(%rbx)
testq %rax, %rax
jne 0x8209
jmp 0x8204
movl (%rbx), %edi
leaq 0xa7(%rip), %r8         # 0x8293
movq %r14, %rcx
movq %rbx, %r9
callq 0x88cc
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x8204
xorl %ebp, %ebp
jmp 0x8209
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3f30(%rip), %rdi      # 0xc151
leaq 0x3f40(%rip), %rsi      # 0xc168
leaq 0x3f5d(%rip), %rcx      # 0xc18c
movl $0x98, %edx
callq 0x2180
leaq 0x3f9d(%rip), %rdi      # 0xc1dd
leaq 0x3f21(%rip), %rsi      # 0xc168
leaq 0x3f3e(%rip), %rcx      # 0xc18c
movl $0x99, %edx
callq 0x2180