// File: mbourand[P]webserv/srcs/Utils/URL.cpp
// Function: URL::URL(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
URL::URL(const std::string& url)
	: _is_directory(false)
{
	if (url.size() == 0)
		throw std::invalid_argument("Empty url");

	if (url == "*")
	{
		_path = "*";
		return;
	}
	else if (url[0] == '/')
		parse_partial(url);
	else
		parse_full(url);

	if (_port.empty())
		_port = "80";
	if (_path.empty())
		_path = "/";

	if (_path.find_first_not_of('/') != std::string::npos && _path[_path.size() - 1] == '/')
	{
		while (_path[_path.size() - 1] == '/')
			_path = _path.substr(0, _path.size() - 1);
		_is_directory = true;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x48(%rbp)
leaq 0x60846(%rip), %rax     # 0x8ec08
addq $0x10, %rax
movq %rax, (%rdi)
addq $0x8, %rdi
movq %rdi, -0x80(%rbp)
callq 0x98c0
movq -0x48(%rbp), %rdi
addq $0x28, %rdi
movq %rdi, -0x78(%rbp)
callq 0x98c0
movq -0x48(%rbp), %rdi
addq $0x48, %rdi
movq %rdi, -0x70(%rbp)
callq 0x98c0
movq -0x48(%rbp), %rdi
addq $0x68, %rdi
movq %rdi, -0x68(%rbp)
callq 0x98c0
movq -0x48(%rbp), %rdi
addq $0x88, %rdi
movq %rdi, -0x60(%rbp)
callq 0x98c0
movq -0x48(%rbp), %rdi
addq $0xa8, %rdi
movq %rdi, -0x58(%rbp)
callq 0x98c0
movq -0x48(%rbp), %rdi
addq $0xc8, %rdi
movq %rdi, -0x50(%rbp)
callq 0x98c0
movq -0x48(%rbp), %rax
movb $0x0, 0xe8(%rax)
movq -0x10(%rbp), %rdi
callq 0x9480
cmpq $0x0, %rax
jne 0x2e4d1
movl $0x10, %edi
callq 0x9340
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x88(%rbp)
leaq 0x3c9b6(%rip), %rsi     # 0x6ae33
callq 0x9be0
jmp 0x2e484
movq -0x88(%rbp), %rdi
movq 0x60b36(%rip), %rsi     # 0x8efc8
movq 0x60b1f(%rip), %rdx     # 0x8efb8
callq 0x9aa0
jmp 0x2e704
movq -0x88(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x94c0
jmp 0x2e6bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x2e6bc
movq -0x10(%rbp), %rdi
leaq 0x3c2fb(%rip), %rsi     # 0x6a7d7
callq 0xdf50
movb %al, -0x89(%rbp)
jmp 0x2e4e9
movb -0x89(%rbp), %al
testb $0x1, %al
jne 0x2e4f5
jmp 0x2e513
movq -0x48(%rbp), %rdi
addq $0x88, %rdi
leaq 0x3c2d0(%rip), %rsi     # 0x6a7d7
callq 0x98a0
jmp 0x2e50e
jmp 0x2e6b3
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x9720
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0x2e539
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2e710
jmp 0x2e537
jmp 0x2e54a
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2ea30
jmp 0x2e548
jmp 0x2e54a
jmp 0x2e54c
movq -0x48(%rbp), %rdi
addq $0x68, %rdi
callq 0x9a50
testb $0x1, %al
jne 0x2e55f
jmp 0x2e577
movq -0x48(%rbp), %rdi
addq $0x68, %rdi
leaq 0x3c8cf(%rip), %rsi     # 0x6ae3d
callq 0x98a0
jmp 0x2e575
jmp 0x2e577
movq -0x48(%rbp), %rdi
addq $0x88, %rdi
callq 0x9a50
testb $0x1, %al
jne 0x2e58d
jmp 0x2e5a8
movq -0x48(%rbp), %rdi
addq $0x88, %rdi
leaq 0x3c4b9(%rip), %rsi     # 0x6aa58
callq 0x98a0
jmp 0x2e5a6
jmp 0x2e5a8
movq -0x48(%rbp), %rdi
addq $0x88, %rdi
movl $0x2f, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x9600
cmpq $-0x1, %rax
je 0x2e6b3
movq -0x48(%rbp), %rdi
addq $0x88, %rdi
movq %rdi, -0xa0(%rbp)
callq 0x9480
movq -0xa0(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x9c70
movq %rax, -0x98(%rbp)
jmp 0x2e5fd
movq -0x98(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0x2e6b3
jmp 0x2e612
movq -0x48(%rbp), %rdi
addq $0x88, %rdi
movq %rdi, -0xb0(%rbp)
callq 0x9480
movq -0xb0(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x9c70
movq %rax, -0xa8(%rbp)
jmp 0x2e644
movq -0xa8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0x2e6a8
movq -0x48(%rbp), %rdi
addq $0x88, %rdi
movq %rdi, -0xb8(%rbp)
callq 0x9480
movq -0xb8(%rbp), %rsi
movq %rax, %rcx
decq %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x40(%rbp), %rdi
callq 0x96b0
jmp 0x2e686
movq -0x48(%rbp), %rdi
addq $0x88, %rdi
leaq -0x40(%rbp), %rsi
callq 0x97e0
leaq -0x40(%rbp), %rdi
callq 0x9c98
jmp 0x2e612
movq -0x48(%rbp), %rax
movb $0x1, 0xe8(%rax)
addq $0xc0, %rsp
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x9c98
movq -0x58(%rbp), %rdi
callq 0x9c98
movq -0x60(%rbp), %rdi
callq 0x9c98
movq -0x68(%rbp), %rdi
callq 0x9c98
movq -0x70(%rbp), %rdi
callq 0x9c98
movq -0x78(%rbp), %rdi
callq 0x9c98
movq -0x80(%rbp), %rdi
callq 0x9c98
movq -0x18(%rbp), %rdi
callq 0x9af0
nopw %cs:(%rax,%rax)