// File: Alcaro[P]bridges/arlib/string.cpp
// Function: cstring::csplit(bool (*)(unsigned char const*, unsigned char const*&, unsigned char const*&), unsigned long) const
array<cstring> cstring::csplit(bool(*find)(const uint8_t * start, const uint8_t * & at, const uint8_t * & end), size_t limit) const
{
	array<cstring> ret;
	
	const uint8_t * data = ptr();
	const uint8_t * dataend = ptr()+length();
	
	const uint8_t * gstart = data;
	const uint8_t * at = gstart;
	
	while (ret.size() < limit && at < dataend)
	{
		const uint8_t * mat = at;
		const uint8_t * mend = dataend;
		if (!find(data, mat, mend) || (gstart == mat && mat == mend))
		{
			at++;
			continue;
		}
		
		ret.append(arrayview<uint8_t>(gstart, mat-gstart));
		gstart = mend;
		at = gstart;
	}
	ret.append(arrayview<uint8_t>(gstart, dataend-gstart));
	return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x108(%rbp)
movq %rdi, %rax
movq %rax, -0x100(%rbp)
movq %rdi, -0x58(%rbp)
movq %rsi, -0x60(%rbp)
movq %rdx, -0x68(%rbp)
movq %rcx, -0x70(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0xf8(%rbp)
movb $0x0, -0x71(%rbp)
callq 0x27080
movq -0xf8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
cmpl $0x0, %eax
jl 0x3b3c8
movq -0xf0(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x3b3d6
movq -0xf0(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0xf8(%rbp), %rax
movq -0x18(%rbp), %rcx
movq %rcx, -0x80(%rbp)
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x110(%rbp)
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
cmpl $0x0, %eax
jl 0x3b416
movq -0x110(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x3b424
movq -0x110(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0xf8(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, -0x120(%rbp)
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x118(%rbp)
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
cmpl $0x0, %eax
jl 0x3b47c
movq -0x118(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
xorl $0xf, %eax
movzbl %al, %eax
movl %eax, -0x44(%rbp)
jmp 0x3b489
movq -0x118(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x120(%rbp), %rax
movl -0x44(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x108(%rbp), %rdi
callq 0x12a40
movq %rax, %rcx
xorl %eax, %eax
cmpq -0x70(%rbp), %rcx
movb %al, -0x121(%rbp)
jae 0x3b4ea
movq -0x98(%rbp), %rax
cmpq -0x88(%rbp), %rax
setb %al
movb %al, -0x121(%rbp)
movb -0x121(%rbp), %al
testb $0x1, %al
jne 0x3b4f9
jmp 0x3b5dc
movq -0x98(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x68(%rbp), %rax
movq -0x80(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
leaq -0xa8(%rbp), %rdx
callq *%rax
testb $0x1, %al
jne 0x3b533
jmp 0x3b553
movq -0x90(%rbp), %rax
cmpq -0xa0(%rbp), %rax
jne 0x3b56a
movq -0xa0(%rbp), %rax
cmpq -0xa8(%rbp), %rax
jne 0x3b56a
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x3b4b6
movq -0x90(%rbp), %rsi
movq -0xa0(%rbp), %rdx
movq -0x90(%rbp), %rax
subq %rax, %rdx
leaq -0xc8(%rbp), %rdi
callq 0x5d70
movq -0xc8(%rbp), %rsi
movq -0xc0(%rbp), %rdx
leaq -0xb8(%rbp), %rdi
callq 0x2ac10
movq -0x108(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x267f0
movq -0xa8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x98(%rbp)
jmp 0x3b4b6
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
movq -0x90(%rbp), %rax
subq %rax, %rdx
leaq -0xe8(%rbp), %rdi
callq 0x5d70
movq -0xe8(%rbp), %rsi
movq -0xe0(%rbp), %rdx
leaq -0xd8(%rbp), %rdi
callq 0x2ac10
movq -0x108(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x267f0
movb $0x1, -0x71(%rbp)
testb $0x1, -0x71(%rbp)
jne 0x3b643
movq -0x108(%rbp), %rdi
callq 0x26f60
movq -0x100(%rbp), %rax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopw %cs:(%rax,%rax)