// File: /workspace/github_cpp_makefile_star2_O3/mbourand[P]webserv/srcs/Utils/Utils.cpp
// Function: ft::complete_ip(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
std::pair<std::string, int> ft::complete_ip(const std::string& incomplete_ip)
{
	std::pair<std::string, int> ret;

	std::string ip = "0.0.0.0";
	int port = 80;

	if (incomplete_ip.size() == 0 || incomplete_ip == ":")
		return std::make_pair(ip, port);
	if (incomplete_ip.find_first_not_of("0123456789:.") != std::string::npos || std::count(incomplete_ip.begin(), incomplete_ip.end(), ':') > 1)
		throw std::invalid_argument("Bad ip");

	if (ft::contains(incomplete_ip, ':'))
	{
		std::string part1 = incomplete_ip.substr(0, incomplete_ip.find(':'));
		std::string part2 = incomplete_ip.substr(incomplete_ip.find(':') + 1);
		if (part1.size() != 0)
		{
			if (std::count(part1.begin(), part1.end(), '.') != 3)
				throw std::invalid_argument("Bad ip");
			ip = part1;
		}
		if (part2.size() != 0)
		{
			if (part2.size() > 5)
				throw std::invalid_argument("Bad port");
			port = ft::toInt(part2);
		}
		return std::make_pair(ip, port);
	}
	if (std::count(incomplete_ip.begin(), incomplete_ip.end(), '.') == 3)
		ip = incomplete_ip;
	else if (std::count(incomplete_ip.begin(), incomplete_ip.end(), '.') == 0)
	{
		if (incomplete_ip.size() > 5)
			throw std::invalid_argument("Bad port");
		port = ft::toInt(incomplete_ip);
	}
	else
		throw std::invalid_argument("Bad ip");
	return std::make_pair(ip, port);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x90, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x78(%rsp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
movl $0x0, 0x10(%r15)
leaq 0x18(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x1effb(%rip), %rsi     # 0x3b215
leaq 0x1effb(%rip), %rdx     # 0x3b21c
leaq 0x8(%rsp), %rdi
callq 0x80f4
cmpq $0x0, 0x8(%r14)
je 0x1c36e
leaq 0x1efe0(%rip), %rsi     # 0x3b21d
movq %r14, %rdi
callq 0x7180
testl %eax, %eax
je 0x1c36e
leaq 0x1efcb(%rip), %rsi     # 0x3b21f
movl $0xc, %ecx
movq %r14, %rdi
xorl %edx, %edx
callq 0x77a0
cmpq $-0x1, %rax
jne 0x1c4c5
movq (%r14), %rdi
movq 0x8(%r14), %rsi
testq %rsi, %rsi
je 0x1c29b
xorl %eax, %eax
xorl %ecx, %ecx
xorl %edx, %edx
cmpb $0x3a, (%rdi,%rax)
sete %dl
addq %rdx, %rcx
incq %rax
cmpq %rax, %rsi
jne 0x1c27d
cmpq $0x2, %rcx
jae 0x1c4c5
addq %rdi, %rsi
leaq 0x28(%rsp), %rdx
movb $0x3a, (%rdx)
callq 0xf389
movq (%r14), %rdx
movq 0x8(%r14), %rcx
leaq (%rdx,%rcx), %rsi
cmpq %rsi, %rax
je 0x1c396
movq %r14, %rdi
movl $0x3a, %esi
xorl %edx, %edx
callq 0x75c0
leaq 0x28(%rsp), %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x74d0
movq %r14, %rdi
movl $0x3a, %esi
xorl %edx, %edx
callq 0x75c0
leaq 0x1(%rax), %rdx
leaq 0x48(%rsp), %rdi
movq %r14, %rsi
movq $-0x1, %rcx
callq 0x74d0
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0x1c348
movq 0x28(%rsp), %rcx
xorl %edx, %edx
xorl %esi, %esi
xorl %edi, %edi
cmpb $0x2e, (%rcx,%rdx)
sete %dil
addq %rdi, %rsi
incq %rdx
cmpq %rdx, %rax
jne 0x1c31a
cmpq $0x3, %rsi
jne 0x1c4f7
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x72c0
movq 0x50(%rsp), %rax
testq %rax, %rax
je 0x1c3d6
cmpq $0x6, %rax
jae 0x1c515
leaq 0x48(%rsp), %rdi
callq 0x1bab0
movl %eax, %ebp
jmp 0x1c3db
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x8a92
movl $0x50, 0x20(%rbx)
jmp 0x1c484
testq %rcx, %rcx
je 0x1c45b
xorl %esi, %esi
movq %rdx, %rdi
xorl %r8d, %r8d
cmpb $0x2e, (%rdi)
sete %r8b
addq %r8, %rsi
incq %rdi
cmpq %rax, %rdi
jne 0x1c3a4
cmpq $0x3, %rsi
jne 0x1c432
movl $0x50, %ebp
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x72c0
jmp 0x1c465
movl $0x50, %ebp
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x8a92
movl %ebp, 0x20(%rbx)
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1c415
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1c484
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x1c484
xorl %esi, %esi
xorl %edi, %edi
cmpb $0x2e, (%rdx)
sete %dil
addq %rdi, %rsi
incq %rdx
cmpq %rax, %rdx
jne 0x1c434
testq %rsi, %rsi
jne 0x1c547
cmpq $0x6, %rcx
jae 0x1c568
movq %r14, %rdi
callq 0x1bab0
movl %eax, %ebp
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x8a92
movl %ebp, 0x20(%rbx)
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x1c49b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x68(%rsp), %rdi
cmpq %r15, %rdi
je 0x1c4b2
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x74b0
movq %rbx, %rax
addq $0x90, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x7260
movq %rax, %r14
leaq 0x1ed53(%rip), %rsi     # 0x3b22c
movq %rax, %rdi
callq 0x78c0
movq 0x31ae0(%rip), %rsi     # 0x4dfc8
movq 0x31ac1(%rip), %rdx     # 0x4dfb0
movq %r14, %rdi
callq 0x77d0
movl $0x10, %edi
callq 0x7260
movq %rax, %r14
leaq 0x1ed21(%rip), %rsi     # 0x3b22c
movq %rax, %rdi
callq 0x78c0
jmp 0x1c531
movl $0x10, %edi
callq 0x7260
movq %rax, %r14
leaq 0x1ed0a(%rip), %rsi     # 0x3b233
movq %rax, %rdi
callq 0x78c0
movq 0x31a90(%rip), %rsi     # 0x4dfc8
movq 0x31a71(%rip), %rdx     # 0x4dfb0
movq %r14, %rdi
callq 0x77d0
movl $0x10, %edi
callq 0x7260
movq %rax, %r14
leaq 0x1ecd1(%rip), %rsi     # 0x3b22c
movq %rax, %rdi
callq 0x78c0
jmp 0x1c4e1
movl $0x10, %edi
callq 0x7260
movq %rax, %r14
leaq 0x1ecb7(%rip), %rsi     # 0x3b233
movq %rax, %rdi
callq 0x78c0
jmp 0x1c4e1
jmp 0x1c5a3
jmp 0x1c5a3
jmp 0x1c58f
movq %rax, %rbx
movq %r14, %rdi
callq 0x7390
jmp 0x1c5b3
movq %rax, %rbx
jmp 0x1c5ce
jmp 0x1c5f0
movq %rax, %rbx
movq %r14, %rdi
callq 0x7390
jmp 0x1c5f3
movq %rax, %rbx
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1c5ce
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1c5f3
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x1c5f3
movq %rax, %rbx
jmp 0x1c60a
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x1c60a
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x68(%rsp), %rdi
cmpq %r15, %rdi
je 0x1c621
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x74b0
movq %rbx, %rdi
callq 0x7810