// File: mbourand[P]webserv/srcs/Utils/Utils.cpp
// Function: ft::get_extension(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
std::string ft::get_extension(std::string path)
{
	if (path[path.size() - 1] == '/')
		path.erase(--path.end());

	if (!ft::contains(path, '.'))
		return "";

	if (!ft::contains(path, '/'))
	{
		if (path.rfind('.') == 0)
			return "";
		return path.substr(path.rfind('.'));
	}

	if (!ft::contains(path.substr(path.rfind('/') + 1), '.'))
		return "";

	if (path.substr(path.rfind('/') + 1).rfind('.') == 0)
		return "";

	return path.substr(path.rfind('/') + 1 + (path.rfind('.') - path.rfind('/') - 1));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rsi, -0x98(%rbp)
movq %rdi, %rax
movq -0x98(%rbp), %rdi
movq %rax, -0xa8(%rbp)
movq %rax, %rcx
movq %rcx, -0xa0(%rbp)
movq %rax, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
callq 0x9480
movq -0x98(%rbp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
callq 0x9c70
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0x329be
movq -0x98(%rbp), %rdi
callq 0x9400
movq %rax, -0x20(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x32ef0
movq %rax, %rsi
leaq -0x18(%rbp), %rdi
callq 0x32f10
movq -0x98(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x97f0
movq %rax, -0x28(%rbp)
movq -0x98(%rbp), %rdi
movb $0x2e, -0x29(%rbp)
leaq -0x29(%rbp), %rsi
callq 0x143d0
xorb $-0x1, %al
testb $0x1, %al
jne 0x329da
jmp 0x32a2e
leaq -0x2a(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x9b10
movq -0xa8(%rbp), %rdi
movq -0xb0(%rbp), %rdx
leaq 0x38371(%rip), %rsi     # 0x6ad70
callq 0xa780
jmp 0x32a06
leaq -0x2a(%rbp), %rdi
callq 0x9700
jmp 0x32d46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x2a(%rbp), %rdi
callq 0x9700
jmp 0x32d56
movq -0x98(%rbp), %rdi
movb $0x2f, -0x3d(%rbp)
leaq -0x3d(%rbp), %rsi
callq 0x143d0
xorb $-0x1, %al
testb $0x1, %al
jne 0x32a4d
jmp 0x32af9
movq -0x98(%rbp), %rdi
movl $0x2e, %esi
movq $-0x1, %rdx
callq 0x9c40
cmpq $0x0, %rax
jne 0x32abf
leaq -0x3e(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0x9b10
movq -0xa8(%rbp), %rdi
movq -0xb8(%rbp), %rdx
leaq 0x382e0(%rip), %rsi     # 0x6ad70
callq 0xa780
jmp 0x32a97
leaq -0x3e(%rbp), %rdi
callq 0x9700
jmp 0x32d46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x3e(%rbp), %rdi
callq 0x9700
jmp 0x32d56
movq -0x98(%rbp), %rdi
movl $0x2e, %esi
movq $-0x1, %rdx
callq 0x9c40
movq -0xa8(%rbp), %rdi
movq -0x98(%rbp), %rsi
movq %rax, %rdx
movq $-0x1, %rcx
callq 0x96b0
jmp 0x32d46
movq -0x98(%rbp), %rdi
movl $0x2f, %esi
movq $-0x1, %rdx
movq %rdx, -0xd0(%rbp)
callq 0x9c40
movq -0x98(%rbp), %rsi
movq -0xd0(%rbp), %rcx
movq %rax, %rdx
incq %rdx
leaq -0x60(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0x96b0
movq -0xc8(%rbp), %rdi
movb $0x2e, -0x61(%rbp)
leaq -0x61(%rbp), %rsi
callq 0x143d0
movb %al, -0xb9(%rbp)
jmp 0x32b58
movb -0xb9(%rbp), %al
xorb $-0x1, %al
movb %al, -0xd1(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x9c98
movb -0xd1(%rbp), %al
testb $0x1, %al
jne 0x32b7b
jmp 0x32be9
leaq -0x62(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x9b10
movq -0xa8(%rbp), %rdi
movq -0xe0(%rbp), %rdx
leaq 0x381d0(%rip), %rsi     # 0x6ad70
callq 0xa780
jmp 0x32ba7
leaq -0x62(%rbp), %rdi
callq 0x9700
jmp 0x32d46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x9c98
jmp 0x32d56
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x62(%rbp), %rdi
callq 0x9700
jmp 0x32d56
movq -0x98(%rbp), %rdi
movl $0x2f, %esi
movq $-0x1, %rdx
callq 0x9c40
movq -0x98(%rbp), %rsi
movq %rax, %rdx
addq $0x1, %rdx
leaq -0x88(%rbp), %rdi
movq $-0x1, %rcx
callq 0x96b0
leaq -0x88(%rbp), %rdi
movl $0x2e, %esi
movq $-0x1, %rdx
callq 0x9c40
movq %rax, -0xe8(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x9c98
movq -0xe8(%rbp), %rax
cmpq $0x0, %rax
jne 0x32cb7
leaq -0x89(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x9b10
movq -0xa8(%rbp), %rdi
movq -0xf0(%rbp), %rdx
leaq 0x380ee(%rip), %rsi     # 0x6ad70
callq 0xa780
jmp 0x32c89
leaq -0x89(%rbp), %rdi
callq 0x9700
jmp 0x32d46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x89(%rbp), %rdi
callq 0x9700
jmp 0x32d56
movq -0x98(%rbp), %rdi
movl $0x2f, %esi
movq $-0x1, %rdx
callq 0x9c40
movq -0x98(%rbp), %rdi
addq $0x1, %rax
movq %rax, -0x100(%rbp)
movl $0x2e, %esi
movq $-0x1, %rdx
callq 0x9c40
movq -0x98(%rbp), %rdi
movq %rax, -0xf8(%rbp)
movl $0x2f, %esi
movq $-0x1, %rdx
callq 0x9c40
movq -0x100(%rbp), %rdx
movq -0xa8(%rbp), %rdi
movq -0x98(%rbp), %rsi
movq %rax, %rcx
movq -0xf8(%rbp), %rax
subq %rcx, %rax
subq $0x1, %rax
addq %rax, %rdx
movq $-0x1, %rcx
callq 0x96b0
movq -0xa0(%rbp), %rax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x9af0
nop