// File: Alcaro[P]bridges/arlib/bytepipe.cpp
// Function: bytepipe::pull_line(unsigned long)
bytesr bytepipe::pull_line(size_t skip)
{
	size_t skipped = 0;
	bytesr chunk1 = buf1.slice(buf1st, buf1end-buf1st);
	if (skip <= chunk1.size())
	{
		chunk1 = chunk1.skip(skip);
		skipped += skip;
		skip = 0;
		const uint8_t * nl1 = (uint8_t*)memchr(chunk1.ptr(), '\n', chunk1.size());
		if (nl1)
			return pull(skipped + nl1+1 - chunk1.ptr());
	}
	else
	{
		skip -= chunk1.size();
	}
	
	bytesr chunk2 = buf2.slice(buf2st, buf2end-buf2st);
	chunk2 = chunk2.skip(skip);
	skipped += skip;
	const uint8_t * nl2 = (uint8_t*)memchr(chunk2.ptr(), '\n', chunk2.size());
	if (nl2)
		return pull(skipped + nl2+1 - chunk2.ptr() + chunk1.size());
	
	return {};
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq -0x18(%rbp), %rsi
movq %rsi, -0xc8(%rbp)
movq $0x0, -0x28(%rbp)
movq 0x10(%rsi), %rdx
movq 0x18(%rsi), %rcx
subq 0x10(%rsi), %rcx
leaq -0x48(%rbp), %rdi
callq 0xc4c0
movq -0x48(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x6290
movq %rax, %rcx
movq -0xc0(%rbp), %rax
cmpq %rcx, %rax
ja 0xc150
movq -0x20(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0xc500
movq %rax, -0x58(%rbp)
movq %rdx, -0x50(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x20(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x62c0
movq %rax, -0xd0(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x6290
movq -0xd0(%rbp), %rdi
movq %rax, %rdx
movl $0xa, %esi
callq 0x43a0
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0xc14e
movq -0x28(%rbp), %rax
addq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xd8(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x62c0
movq -0xd8(%rbp), %rdx
movq -0xc8(%rbp), %rsi
subq %rax, %rdx
leaq -0x70(%rbp), %rdi
callq 0xc540
movq -0x70(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xc2a8
jmp 0xc167
leaq -0x38(%rbp), %rdi
callq 0x6290
movq %rax, %rcx
movq -0x20(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, %rsi
addq $0x20, %rsi
movq 0x30(%rax), %rdx
movq 0x38(%rax), %rcx
subq 0x30(%rax), %rcx
leaq -0x90(%rbp), %rdi
callq 0xc4c0
movq -0x90(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x20(%rbp), %rsi
leaq -0x80(%rbp), %rdi
callq 0xc500
movq %rax, -0xa0(%rbp)
movq %rdx, -0x98(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x20(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x62c0
movq %rax, -0xe0(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x6290
movq -0xe0(%rbp), %rdi
movq %rax, %rdx
movl $0xa, %esi
callq 0x43a0
movq %rax, -0xa8(%rbp)
cmpq $0x0, -0xa8(%rbp)
je 0xc28f
movq -0x28(%rbp), %rax
addq -0xa8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xf0(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x62c0
movq %rax, %rcx
movq -0xf0(%rbp), %rax
subq %rcx, %rax
movq %rax, -0xe8(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x6290
movq -0xe8(%rbp), %rdx
movq -0xc8(%rbp), %rsi
addq %rax, %rdx
leaq -0xb8(%rbp), %rdi
callq 0xc540
movq -0xb8(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xc2a8
leaq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x4170
leaq -0x10(%rbp), %rdi
callq 0x5f10
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rdx
addq $0xf0, %rsp
popq %rbp
retq
nopl (%rax)