// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]spiped/liball/../lib/proto/proto_pipe.c
// Function: callback_pipe_read
static int
callback_pipe_read(void * cookie, int status)
{
	struct pipe_cookie * P = cookie;
	uint8_t * inbuf;
	size_t inlen;
	size_t inpos = 0;
	size_t outpos = 0;
	size_t loop_inlen;
	ssize_t loop_outlen;

	/* Did we read EOF? */
	if (status == 1)
		goto eof;

	/* Did the read fail? */
	if (status == -1)
		goto fail;

	/* Get data. */
	netbuf_read_peek(P->R, &inbuf, &inlen);

	/* Process as many packets as possible. */
	while (inlen > 0) {
		/* Stop processing if we don't have space for more output. */
		if (outpos + P->full_buflen > OUTBUFSIZE)
			break;

		/* How many bytes should we process this time? */
		loop_inlen = (inlen > P->full_buflen) ? P->full_buflen : inlen;

		/*
		 * If we don't have enough data to decrypt, leave it until the
		 * next time callback_pipe_read() is called.
		 */
		if ((P->decr) && (loop_inlen < PCRYPT_ESZ))
			break;

		/* Encrypt or decrypt the data. */
		if (P->decr) {
			if ((loop_outlen = proto_crypt_dec(&inbuf[inpos],
			    &P->outbuf[outpos], P->k)) == -1)
				goto fail;
		} else {
			proto_crypt_enc(&inbuf[inpos], loop_inlen,
			    &P->outbuf[outpos], P->k);
			loop_outlen = PCRYPT_ESZ;
		}

		/* We've processed this data. */
		inlen -= loop_inlen;
		inpos += loop_inlen;
		outpos += (size_t)loop_outlen;
	}

	/* Let netbuf layer know what we've used. */
	netbuf_read_consume(P->R, inpos);

	/* Write the encrypted or decrypted data. */
	P->wlen = (ssize_t)outpos;
	if ((P->write_cookie = network_write(P->s_out, P->outbuf,
	    (size_t)P->wlen, (size_t)P->wlen, callback_pipe_write,
	    P)) == NULL)
		goto err0;

	/* Success! */
	return (0);

eof:
	/* We aren't going to write any more. */
	if (shutdown(P->s_out, SHUT_WR)) {
		switch (errno) {
		case EBADF:
		case EINVAL:
		case ENOTSOCK:
			/* Should never happen. */
			goto err0;
		case ENOTCONN:
		case ECONNRESET:
			/* Simultaneous closes; not a problem. */
			break;
		default:
			/*
			 * Unexpected error; treat this as a broken connection
			 * but don't die in case the error originates from some
			 * sort of network issue rather than from an error in
			 * spiped itself.
			 */
			goto fail;
		}
	}

	/* Record that we have reached EOF. */
	*(P->status) = 0;

	/* Inform the upstream that our status has changed. */
	return ((P->callback)(P->cookie));

fail:
	/* Record that this connection is broken. */
	*(P->status) = -1;

	/* Inform the upstream that our status has changed. */
	return ((P->callback)(P->cookie));

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r8
cmpl $-0x1, %esi
je 0xc586
cmpl $0x1, %esi
jne 0xc45d
movl 0x1c(%r8), %edi
movl $0x1, %esi
movq %r8, %rbx
callq 0x2090
movq %rbx, %r8
testl %eax, %eax
je 0xc43e
callq 0x2370
movl (%rax), %eax
cmpl $0x57, %eax
jle 0xc572
cmpl $0x58, %eax
je 0xc57f
movq %rbx, %r8
cmpl $0x6b, %eax
je 0xc43e
cmpl $0x68, %eax
jne 0xc586
movq 0x10(%r8), %rax
movl $0x0, (%rax)
movq 0x8(%r8), %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *(%r8)
movq 0x2150(%r8), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x8(%rsp), %rbx
movq %rbx, %rdx
movq %r8, %r12
callq 0xcd4d
movq (%rbx), %rcx
xorl %ebx, %ebx
testq %rcx, %rcx
je 0xc525
leaq 0x30(%r12), %r13
xorl %r14d, %r14d
xorl %r15d, %r15d
movq %r12, %r8
movq 0x2170(%r8), %r12
leaq (%r12,%r14), %rax
cmpq $0x2120, %rax           # imm = 0x2120
ja 0xc52e
cmpq %r12, %rcx
cmovbq %rcx, %r12
movl 0x20(%r8), %eax
testl %eax, %eax
setne %cl
cmpq $0x424, %r12            # imm = 0x424
setb %dl
testb %cl, %dl
jne 0xc52e
movq 0x10(%rsp), %rdi
addq %r15, %rdi
leaq (%r14,%r13), %rdx
movq %r8, %rbp
movq 0x28(%r8), %rcx
testl %eax, %eax
je 0xc4fa
movq %rdx, %rsi
movq %rcx, %rdx
callq 0x6048
cmpq $-0x1, %rax
movq %rbp, %r8
jne 0xc50a
jmp 0xc586
movq %r12, %rsi
callq 0x5f43
movl $0x424, %eax            # imm = 0x424
movq %rbp, %r8
movq 0x8(%rsp), %rcx
addq %r12, %r15
addq %rax, %r14
subq %r12, %rcx
movq %rcx, 0x8(%rsp)
jne 0xc495
jmp 0xc52e
xorl %r15d, %r15d
xorl %r14d, %r14d
movq %r12, %r8
movq 0x2150(%r8), %rdi
movq %r15, %rsi
movq %r8, %r15
callq 0xcfde
movq %r14, 0x2160(%r15)
movl 0x1c(%r15), %edi
leaq 0x30(%r15), %rsi
leaq 0x8a(%rip), %r8         # 0xc5e0
movq %r14, %rdx
movq %r14, %rcx
movq %r15, %r9
callq 0xd5ac
movq %rax, 0x2158(%r15)
testq %rax, %rax
jne 0xc599
jmp 0xc57f
cmpl $0x9, %eax
je 0xc57f
movq %rbx, %r8
cmpl $0x16, %eax
jne 0xc586
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0xc599
movq 0x10(%r8), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq 0x8(%r8), %rdi
callq *(%r8)
movl %eax, %ebx
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq