// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
cmpl $0x1, -0x14(%rbp)
jne 0x149c2
jmp 0x14b66
cmpl $-0x1, -0x14(%rbp)
jne 0x149cd
jmp 0x14be1
movq -0x20(%rbp), %rax
movq 0x2150(%rax), %rdi
leaq -0x28(%rbp), %rsi
leaq -0x30(%rbp), %rdx
callq 0x15c40
cmpq $0x0, -0x30(%rbp)
jbe 0x14aec
movq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
addq 0x2170(%rcx), %rax
cmpq $0x2120, %rax           # imm = 0x2120
jbe 0x14a0c
jmp 0x14aec
movq -0x30(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x2170(%rcx), %rax
jbe 0x14a2e
movq -0x20(%rbp), %rax
movq 0x2170(%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0x14a36
movq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x20(%rax)
je 0x14a57
cmpq $0x424, -0x48(%rbp)     # imm = 0x424
jae 0x14a57
jmp 0x14aec
movq -0x20(%rbp), %rax
cmpl $0x0, 0x20(%rax)
je 0x14a93
movq -0x28(%rbp), %rdi
addq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rsi
addq $0x30, %rsi
addq -0x40(%rbp), %rsi
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rdx
callq 0x54a0
movq %rax, -0x50(%rbp)
cmpq $-0x1, %rax
jne 0x14a91
jmp 0x14be1
jmp 0x14ac0
movq -0x28(%rbp), %rdi
addq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x20(%rbp), %rdx
addq $0x30, %rdx
addq -0x40(%rbp), %rdx
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rcx
callq 0x5220
movq $0x424, -0x50(%rbp)     # imm = 0x424
movq -0x48(%rbp), %rcx
movq -0x30(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x48(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x50(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x149e5
movq -0x20(%rbp), %rax
movq 0x2150(%rax), %rdi
movq -0x38(%rbp), %rsi
callq 0x16150
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x2160(%rax)
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %edi
movq -0x20(%rbp), %rsi
addq $0x30, %rsi
movq -0x20(%rbp), %rax
movq 0x2160(%rax), %rdx
movq -0x20(%rbp), %rax
movq 0x2160(%rax), %rcx
movq -0x20(%rbp), %r9
leaq 0x151(%rip), %r8        # 0x14c90
callq 0x16820
movq -0x20(%rbp), %rcx
movq %rax, 0x2158(%rcx)
cmpq $0x0, %rax
jne 0x14b5a
jmp 0x14c05
movl $0x0, -0x4(%rbp)
jmp 0x14c0c
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %edi
movl $0x1, %esi
callq 0x2090
cmpl $0x0, %eax
je 0x14bbd
callq 0x2340
movl (%rax), %eax
movl %eax, -0x5c(%rbp)
subl $0x9, %eax
je 0x14bb5
jmp 0x14b8d
movl -0x5c(%rbp), %eax
subl $0x16, %eax
je 0x14bb5
jmp 0x14b97
movl -0x5c(%rbp), %eax
subl $0x58, %eax
je 0x14bb5
jmp 0x14ba1
movl -0x5c(%rbp), %eax
subl $0x68, %eax
je 0x14bb7
jmp 0x14bab
movl -0x5c(%rbp), %eax
subl $0x6b, %eax
je 0x14bb7
jmp 0x14bb9
jmp 0x14c05
jmp 0x14bbb
jmp 0x14be1
jmp 0x14bbd
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl $0x0, (%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x8(%rcx), %rdi
callq *%rax
movl %eax, -0x4(%rbp)
jmp 0x14c0c
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x8(%rcx), %rdi
callq *%rax
movl %eax, -0x4(%rbp)
jmp 0x14c0c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)