// File: Alcaro[P]bridges/arlib/string.cpp
// Function: cstring::crsplit(cstring, unsigned long) const
array<cstring> cstring::crsplit(cstring sep, size_t limit) const
{
	array<cstring> ret;
	const uint8_t * datastart = ptr();
	const uint8_t * data = ptr()+length();
	
	const uint8_t * sepp = sep.ptr();
	size_t sepl = sep.length();
	
	while (ret.size() < limit)
	{
		if (datastart+sepl > data) break;
		const uint8_t * next = data-sepl;
		while (memcmp(next, sepp, sepl) != 0)
		{
			if (datastart==next) goto done;
			next--;
		}
		ret.insert(0, arrayview<uint8_t>(next+sepl, data-(next+sepl)));
		data = next;
	}
done:
	ret.insert(0, arrayview<uint8_t>(datastart, data-datastart));
	return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x140(%rbp)
movq %rdi, %rax
movq %rax, -0x138(%rbp)
movq %rdi, -0x90(%rbp)
movq %rdx, -0xa0(%rbp)
movq %rcx, -0x98(%rbp)
movq %rsi, -0xa8(%rbp)
movq %r8, -0xb0(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x130(%rbp)
movb $0x0, -0xb1(%rbp)
callq 0x27080
movq -0x130(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x128(%rbp)
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
cmpl $0x0, %eax
jl 0x3a501
movq -0x128(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x3a50f
movq -0x128(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x130(%rbp), %rax
movq -0x20(%rbp), %rcx
movq %rcx, -0xc0(%rbp)
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x148(%rbp)
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
cmpl $0x0, %eax
jl 0x3a552
movq -0x148(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x3a560
movq -0x148(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x130(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rcx, -0x158(%rbp)
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x150(%rbp)
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
cmpl $0x0, %eax
jl 0x3a5b8
movq -0x150(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
xorl $0xf, %eax
movzbl %al, %eax
movl %eax, -0x64(%rbp)
jmp 0x3a5c5
movq -0x150(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x64(%rbp)
movq -0x158(%rbp), %rax
movl -0x64(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0xc8(%rbp)
leaq -0xa0(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x160(%rbp)
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
cmpl $0x0, %eax
jl 0x3a611
movq -0x160(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x3a61f
movq -0x160(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0xd0(%rbp)
leaq -0xa0(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x168(%rbp)
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
cmpl $0x0, %eax
jl 0x3a67d
movq -0x168(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
xorl $0xf, %eax
movzbl %al, %eax
movl %eax, -0x7c(%rbp)
jmp 0x3a68a
movq -0x168(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movq %rax, -0xd8(%rbp)
movq -0x140(%rbp), %rdi
callq 0x12a40
cmpq -0xb0(%rbp), %rax
jae 0x3a7a1
movq -0xc0(%rbp), %rax
addq -0xd8(%rbp), %rax
cmpq -0xc8(%rbp), %rax
jbe 0x3a6c9
jmp 0x3a7a1
movq -0xc8(%rbp), %rax
xorl %ecx, %ecx
subq -0xd8(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rdi
movq -0xd0(%rbp), %rsi
movq -0xd8(%rbp), %rdx
callq 0x4100
cmpl $0x0, %eax
je 0x3a72b
movq -0xc0(%rbp), %rax
cmpq -0xe0(%rbp), %rax
jne 0x3a717
jmp 0x3a7a3
movq -0xe0(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0xe0(%rbp)
jmp 0x3a6e3
movq -0xe0(%rbp), %rsi
addq -0xd8(%rbp), %rsi
movq -0xc8(%rbp), %rdx
movq -0xe0(%rbp), %rax
addq -0xd8(%rbp), %rax
subq %rax, %rdx
leaq -0x100(%rbp), %rdi
callq 0x5d70
movq -0x100(%rbp), %rsi
movq -0xf8(%rbp), %rdx
leaq -0xf0(%rbp), %rdi
callq 0x2ac10
movq -0x140(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq -0xf0(%rbp), %rdx
callq 0x26600
movq -0xe0(%rbp), %rax
movq %rax, -0xc8(%rbp)
jmp 0x3a694
jmp 0x3a7a3
movq -0xc0(%rbp), %rsi
movq -0xc8(%rbp), %rdx
movq -0xc0(%rbp), %rax
subq %rax, %rdx
leaq -0x120(%rbp), %rdi
callq 0x5d70
movq -0x120(%rbp), %rsi
movq -0x118(%rbp), %rdx
leaq -0x110(%rbp), %rdi
callq 0x2ac10
movq -0x140(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq -0x110(%rbp), %rdx
callq 0x26600
movb $0x1, -0xb1(%rbp)
testb $0x1, -0xb1(%rbp)
jne 0x3a814
movq -0x140(%rbp), %rdi
callq 0x26f60
movq -0x138(%rbp), %rax
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
nopw %cs:(%rax,%rax)