// File: /workspace/github_cpp_makefile_star2_O1/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 0x1ecf9(%rip), %rsi     # 0x3b215
leaq 0x1ecf9(%rip), %rdx     # 0x3b21c
leaq 0x8(%rsp), %rdi
callq 0x80f4
cmpq $0x0, 0x8(%r14)
je 0x1c66c
leaq 0x1ecde(%rip), %rsi     # 0x3b21d
movq %r14, %rdi
callq 0x7180
testl %eax, %eax
je 0x1c66c
leaq 0x1ecc9(%rip), %rsi     # 0x3b21f
movl $0xc, %ecx
movq %r14, %rdi
xorl %edx, %edx
callq 0x77a0
cmpq $-0x1, %rax
jne 0x1c7ca
movq (%r14), %rdi
movq 0x8(%r14), %rsi
testq %rsi, %rsi
je 0x1c59d
xorl %eax, %eax
xorl %ecx, %ecx
xorl %edx, %edx
cmpb $0x3a, (%rdi,%rax)
sete %dl
addq %rdx, %rcx
incq %rax
cmpq %rax, %rsi
jne 0x1c57f
cmpq $0x2, %rcx
jae 0x1c7ca
addq %rdi, %rsi
leaq 0x28(%rsp), %rdx
movb $0x3a, (%rdx)
callq 0xf3d7
movq (%r14), %rdx
movq 0x8(%r14), %rcx
leaq (%rdx,%rcx), %rsi
cmpq %rsi, %rax
je 0x1c694
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 0x1c64a
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 0x1c61c
cmpq $0x3, %rsi
jne 0x1c7fc
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x72c0
movq 0x50(%rsp), %rax
testq %rax, %rax
je 0x1c6d3
cmpq $0x6, %rax
jae 0x1c81a
leaq 0x48(%rsp), %rdi
callq 0x1bda4
movl %eax, %ebp
jmp 0x1c6d8
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x8a8a
movl $0x50, 0x20(%rbx)
jmp 0x1c789
testq %rcx, %rcx
je 0x1c756
xorl %eax, %eax
xorl %esi, %esi
xorl %edi, %edi
cmpb $0x2e, (%rdx,%rax)
sete %dil
addq %rdi, %rsi
incq %rax
cmpq %rax, %rcx
jne 0x1c6a1
cmpq $0x3, %rsi
jne 0x1c72f
movl $0x50, %ebp
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x72c0
jmp 0x1c76a
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 0x8a8a
movl %ebp, 0x20(%rbx)
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1c712
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1c789
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x1c789
testq %rcx, %rcx
je 0x1c756
xorl %eax, %eax
xorl %esi, %esi
xorl %edi, %edi
cmpb $0x2e, (%rdx,%rax)
sete %dil
addq %rdi, %rsi
incq %rax
cmpq %rax, %rcx
jne 0x1c738
testq %rsi, %rsi
jne 0x1c86d
cmpq $0x6, %rcx
jae 0x1c84c
movq %r14, %rdi
callq 0x1bda4
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 0x8a8a
movl %ebp, 0x20(%rbx)
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x1c7a0
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x68(%rsp), %rdi
cmpq %r15, %rdi
je 0x1c7b7
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 0x1ea4e(%rip), %rsi     # 0x3b22c
movq %rax, %rdi
callq 0x78c0
movq 0x317db(%rip), %rsi     # 0x4dfc8
movq 0x317bc(%rip), %rdx     # 0x4dfb0
movq %r14, %rdi
callq 0x77d0
movl $0x10, %edi
callq 0x7260
movq %rax, %r14
leaq 0x1ea1c(%rip), %rsi     # 0x3b22c
movq %rax, %rdi
callq 0x78c0
jmp 0x1c836
movl $0x10, %edi
callq 0x7260
movq %rax, %r14
leaq 0x1ea05(%rip), %rsi     # 0x3b233
movq %rax, %rdi
callq 0x78c0
movq 0x3178b(%rip), %rsi     # 0x4dfc8
movq 0x3176c(%rip), %rdx     # 0x4dfb0
movq %r14, %rdi
callq 0x77d0
movl $0x10, %edi
callq 0x7260
movq %rax, %r14
leaq 0x1e9d3(%rip), %rsi     # 0x3b233
movq %rax, %rdi
callq 0x78c0
jmp 0x1c7e6
movl $0x10, %edi
callq 0x7260
movq %rax, %r14
leaq 0x1e9ab(%rip), %rsi     # 0x3b22c
movq %rax, %rdi
callq 0x78c0
jmp 0x1c7e6
jmp 0x1c8a8
jmp 0x1c8a8
jmp 0x1c894
movq %rax, %rbx
movq %r14, %rdi
callq 0x7390
jmp 0x1c8b8
movq %rax, %rbx
jmp 0x1c8d3
jmp 0x1c8f5
movq %rax, %rbx
movq %r14, %rdi
callq 0x7390
jmp 0x1c8f8
movq %rax, %rbx
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1c8d3
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1c8f8
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x1c8f8
movq %rax, %rbx
jmp 0x1c90f
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
je 0x1c90f
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x68(%rsp), %rdi
cmpq %r15, %rdi
je 0x1c926
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x74b0
movq %rbx, %rdi
callq 0x7810