// File: /workspace/github_c_makefile_star2_O2/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 0x76ea
movq %rdi, %rbx
cmpq $0x0, 0x28(%rdi)
jne 0x7709
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 0x7694
movq 0x38(%rbx), %r12
cmpq %r14, %r12
jae 0x7633
addq %r12, %r12
cmpq %r14, %r12
cmovbeq %r14, %r12
movq %r12, %rdi
callq 0x2220
testq %rax, %rax
je 0x76d6
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)
andq $0x0, 0x40(%rbx)
xorl %r15d, %r15d
subq %r15, %r12
cmpq %r14, %r12
jae 0x765f
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)
andq $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 0x76b2
leaq 0xdd(%rip), %r8         # 0x7760
movq %rax, %rdx
movq %r14, %rcx
movq %rbx, %r9
callq *0x39046(%rip)          # 0x406d8
jmp 0x76c9
leaq 0x8d(%rip), %rdi        # 0x7728
xorl %ebp, %ebp
movq %rbx, %rsi
xorl %edx, %edx
callq 0x2b2c
movq %rax, 0x28(%rbx)
testq %rax, %rax
jne 0x76d9
jmp 0x76d6
movl (%rbx), %edi
leaq 0xa5(%rip), %r8         # 0x7760
movq %rax, %rdx
movq %r14, %rcx
movq %rbx, %r9
callq 0x7d38
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x76d6
xorl %ebp, %ebp
jmp 0x76d9
pushq $-0x1
popq %rbp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2a1e(%rip), %rdi      # 0xa10f
leaq 0x2a2e(%rip), %rsi      # 0xa126
leaq 0x2a4b(%rip), %rcx      # 0xa14a
movl $0x98, %edx
callq 0x2180
leaq 0x2a8b(%rip), %rdi      # 0xa19b
leaq 0x2a0f(%rip), %rsi      # 0xa126
leaq 0x2a2c(%rip), %rcx      # 0xa14a
movl $0x99, %edx
callq 0x2180