// File: Alcaro[P]bridges/arlib/string.cpp
// Function: cstring::lastindexof(cstring) const
size_t cstring::lastindexof(cstring other) const
{
	size_t ret = -1;
	const uint8_t* start = this->ptr();
	const uint8_t* find = start;
	const uint8_t* find_end = find + this->length();
	if (!other) return this->length();
	
	while (true)
	{
		find = (uint8_t*)memmem(find, find_end-find, other.ptr(), other.length());
		if (!find) return ret;
		ret = find-start;
		find += 1;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rsi, -0xa8(%rbp)
movq %rdx, -0xa0(%rbp)
movq %rdi, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq $-0x1, -0xb8(%rbp)
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
cmpl $0x0, %eax
jl 0x37b9a
movq -0xd8(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x37ba8
movq -0xd8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0xe0(%rbp), %rax
movq -0x28(%rbp), %rcx
movq %rcx, -0xc0(%rbp)
movq -0xc0(%rbp), %rcx
movq %rcx, -0xc8(%rbp)
movq -0xc8(%rbp), %rcx
movq %rcx, -0xf0(%rbp)
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
cmpl $0x0, %eax
jl 0x37c1c
movq -0xe8(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
xorl $0xf, %eax
movzbl %al, %eax
movl %eax, -0x54(%rbp)
jmp 0x37c29
movq -0xe8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x54(%rbp)
movq -0xf0(%rbp), %rax
movl -0x54(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0xd0(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x9a10
testb $0x1, %al
jne 0x37cb6
movq -0xe0(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
cmpl $0x0, %eax
jl 0x37c9a
movq -0xf8(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
xorl $0xf, %eax
movzbl %al, %eax
movl %eax, -0x6c(%rbp)
jmp 0x37ca7
movq -0xf8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movq %rax, -0x98(%rbp)
jmp 0x37e07
jmp 0x37cb8
movq -0xc8(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0xd0(%rbp), %rax
movq -0xc8(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x108(%rbp)
leaq -0xa8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x100(%rbp)
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
cmpl $0x0, %eax
jl 0x37d16
movq -0x100(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x37d24
movq -0x100(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x120(%rbp)
leaq -0xa8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x118(%rbp)
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
cmpl $0x0, %eax
jl 0x37d85
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, -0x84(%rbp)
jmp 0x37d95
movq -0x118(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x84(%rbp)
movq -0x120(%rbp), %rdx
movq -0x108(%rbp), %rsi
movq -0x110(%rbp), %rdi
movl -0x84(%rbp), %eax
movl %eax, %ecx
callq 0x2d1d0
movq %rax, -0xc8(%rbp)
cmpq $0x0, -0xc8(%rbp)
jne 0x37dd8
movq -0xb8(%rbp), %rax
movq %rax, -0x98(%rbp)
jmp 0x37e07
movq -0xc8(%rbp), %rax
movq -0xc0(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0xb8(%rbp)
movq -0xc8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xc8(%rbp)
jmp 0x37cb8
movq -0x98(%rbp), %rax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopw (%rax,%rax)