// File: /workspace/github_c_makefile_star2_O3/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 0x8254
movq %rdi, %rbx
cmpq $0x0, 0x28(%rdi)
jne 0x8273
movq %rsi, %r14
movq %rdx, 0x10(%rbx)
movq %rcx, 0x18(%rbx)
movq 0x40(%rbx), %r15
movq 0x48(%rbx), %rdx
movq %rdx, %r13
subq %r15, %r13
cmpq %rsi, %r13
jae 0x81fc
movq 0x38(%rbx), %r12
cmpq %r14, %r12
jae 0x8198
addq %r12, %r12
cmpq %r14, %r12
cmovbeq %r14, %r12
movq %r12, %rdi
callq 0x2220
testq %rax, %rax
je 0x823e
movq %rax, %rbp
movq 0x30(%rbx), %rax
movq %rax, (%rsp)
addq %rax, %r15
movq %rbp, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x2200
movq (%rsp), %rdi
callq 0x2040
movq %rbp, 0x30(%rbx)
movq %r12, 0x38(%rbx)
movq 0x48(%rbx), %rdx
subq 0x40(%rbx), %rdx
movq %rdx, 0x48(%rbx)
movq $0x0, 0x40(%rbx)
xorl %r15d, %r15d
subq %r15, %r12
cmpq %r14, %r12
jae 0x81c7
movq 0x30(%rbx), %rdi
leaq (%rdi,%r15), %rsi
subq %r15, %rdx
callq 0x22a0
movq 0x48(%rbx), %rdx
subq 0x40(%rbx), %rdx
movq %rdx, 0x48(%rbx)
movq $0x0, 0x40(%rbx)
xorl %r15d, %r15d
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x30(%rbx), %rsi
addq %rdx, %rsi
subq %rdx, %rax
subq %rdx, %r14
addq %r15, %r14
testq %rdi, %rdi
je 0x821a
leaq 0xe2(%rip), %r8         # 0x82cd
movq %rax, %rdx
movq %r14, %rcx
movq %rbx, %r9
callq *0x3a4de(%rip)          # 0x426d8
jmp 0x8231
leaq 0x8f(%rip), %rdi        # 0x8292
xorl %ebp, %ebp
movq %rbx, %rsi
xorl %edx, %edx
callq 0x2d94
movq %rax, 0x28(%rbx)
testq %rax, %rax
jne 0x8243
jmp 0x823e
movl (%rbx), %edi
leaq 0xaa(%rip), %r8         # 0x82cd
movq %rax, %rdx
movq %r14, %rcx
movq %rbx, %r9
callq 0x88e4
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x823e
xorl %ebp, %ebp
jmp 0x8243
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 0x3f24(%rip), %rdi      # 0xc17f
leaq 0x3f34(%rip), %rsi      # 0xc196
leaq 0x3f51(%rip), %rcx      # 0xc1ba
movl $0x98, %edx
callq 0x2180
leaq 0x3f91(%rip), %rdi      # 0xc20b
leaq 0x3f15(%rip), %rsi      # 0xc196
leaq 0x3f32(%rip), %rcx      # 0xc1ba
movl $0x99, %edx
callq 0x2180