// File: m1c0l[P]http-client-server/web-client.cpp
// Function: parseUrl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
Url parseUrl(string urlStr) {
	// remove http:// at start of URL
	if (urlStr.substr(0, 7) == "http://") {
		urlStr = urlStr.substr(7);
	}

	size_t colonPos = urlStr.find_first_of(":");
	size_t slashPos = urlStr.find_first_of("/");

	string hostname = urlStr;
	if (colonPos != string::npos) {
		hostname = urlStr.substr(0, colonPos);
	}
	else if (slashPos != string::npos) {
		hostname = urlStr.substr(0, slashPos);
	}

	string port = "80";
	if (colonPos != string::npos && slashPos != string::npos) {
		port = urlStr.substr(colonPos + 1, slashPos - colonPos - 1);
	}
	else if (colonPos != string::npos) {
		port = urlStr.substr(colonPos + 1);
	}

	string filename = "/";
	if (slashPos != string::npos) {
		filename = urlStr.substr(slashPos);
	}

	Url url;
	url.host = hostname;
	url.port = port;
	url.path = filename;
	return url;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movq %rsi, -0x1a8(%rbp)
movq %rdi, -0x1a0(%rbp)
movq %rdi, %rax
movq %rax, -0x198(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
xorl %eax, %eax
movl %eax, %edx
leaq -0x30(%rbp), %rdi
movq %rdi, -0x190(%rbp)
movl $0x7, %ecx
callq 0x53e0
movq -0x190(%rbp), %rdi
leaq 0x103df(%rip), %rsi     # 0x19031
callq 0x85d0
movb %al, -0x182(%rbp)
jmp 0x8c5f
leaq -0x30(%rbp), %rdi
callq 0x5240
movb -0x182(%rbp), %al
testb $0x1, %al
jne 0x8c74
jmp 0x8cc5
movq -0x1a8(%rbp), %rsi
leaq -0x60(%rbp), %rdi
movl $0x7, %edx
movq $-0x1, %rcx
callq 0x53e0
movq -0x1a8(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x5480
leaq -0x60(%rbp), %rdi
callq 0x5240
jmp 0x8cc5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x5240
jmp 0x9050
movq -0x1a8(%rbp), %rdi
leaq 0x10331(%rip), %rsi     # 0x19004
xorl %eax, %eax
movl %eax, %edx
callq 0x51e0
movq -0x1a8(%rbp), %rdi
movq %rax, -0x68(%rbp)
leaq 0x10349(%rip), %rsi     # 0x19037
xorl %eax, %eax
movl %eax, %edx
callq 0x51e0
movq -0x1a8(%rbp), %rsi
movq %rax, -0x70(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x5170
cmpq $-0x1, -0x68(%rbp)
je 0x8d64
movq -0x1a8(%rbp), %rsi
movq -0x68(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0xb0(%rbp), %rdi
callq 0x53e0
jmp 0x8d32
leaq -0x90(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x5480
leaq -0xb0(%rbp), %rdi
callq 0x5240
jmp 0x8da9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x9044
cmpq $-0x1, -0x70(%rbp)
je 0x8da7
movq -0x1a8(%rbp), %rsi
movq -0x70(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0xd0(%rbp), %rdi
callq 0x53e0
jmp 0x8d88
leaq -0x90(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x5480
leaq -0xd0(%rbp), %rdi
callq 0x5240
jmp 0x8da9
leaq -0xf1(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
callq 0x5630
movq -0x1b0(%rbp), %rdx
leaq 0x1034a(%rip), %rsi     # 0x19114
leaq -0xf0(%rbp), %rdi
callq 0x6180
jmp 0x8dd8
leaq -0xf1(%rbp), %rdi
callq 0x5420
cmpq $-0x1, -0x68(%rbp)
je 0x8e6a
cmpq $-0x1, -0x70(%rbp)
je 0x8e6a
movq -0x1a8(%rbp), %rsi
movq -0x68(%rbp), %rcx
movq %rcx, %rdx
incq %rdx
movq -0x70(%rbp), %rax
notq %rcx
addq %rax, %rcx
leaq -0x118(%rbp), %rdi
callq 0x53e0
jmp 0x8e1b
leaq -0xf0(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x5480
leaq -0x118(%rbp), %rdi
callq 0x5240
jmp 0x8eb5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xf1(%rbp), %rdi
callq 0x5420
jmp 0x9044
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x9038
cmpq $-0x1, -0x68(%rbp)
je 0x8eb3
movq -0x1a8(%rbp), %rsi
movq -0x68(%rbp), %rdx
incq %rdx
leaq -0x138(%rbp), %rdi
movq $-0x1, %rcx
callq 0x53e0
jmp 0x8e94
leaq -0xf0(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x5480
leaq -0x138(%rbp), %rdi
callq 0x5240
jmp 0x8eb5
leaq -0x159(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x5630
movq -0x1b8(%rbp), %rdx
leaq 0x10161(%rip), %rsi     # 0x19037
leaq -0x158(%rbp), %rdi
callq 0x6180
jmp 0x8ee4
leaq -0x159(%rbp), %rdi
callq 0x5420
cmpq $-0x1, -0x70(%rbp)
je 0x8f66
movq -0x1a8(%rbp), %rsi
movq -0x70(%rbp), %rdx
leaq -0x180(%rbp), %rdi
movq $-0x1, %rcx
callq 0x53e0
jmp 0x8f17
leaq -0x158(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x5480
leaq -0x180(%rbp), %rdi
callq 0x5240
jmp 0x8f66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x159(%rbp), %rdi
callq 0x5420
jmp 0x9038
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x902c
movq -0x1a0(%rbp), %rdi
movb $0x0, -0x181(%rbp)
callq 0xa8e0
movq -0x1a0(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x5050
jmp 0x8f8e
movq -0x1a0(%rbp), %rdi
addq $0x20, %rdi
leaq -0xf0(%rbp), %rsi
callq 0x5050
jmp 0x8fa7
movq -0x1a0(%rbp), %rdi
addq $0x40, %rdi
leaq -0x158(%rbp), %rsi
callq 0x5050
jmp 0x8fc0
movb $0x1, -0x181(%rbp)
testb $0x1, -0x181(%rbp)
jne 0x8ff8
jmp 0x8fec
movq -0x1a0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
callq 0xa920
jmp 0x902c
movq -0x1a0(%rbp), %rdi
callq 0xa920
leaq -0x158(%rbp), %rdi
callq 0x5240
leaq -0xf0(%rbp), %rdi
callq 0x5240
leaq -0x90(%rbp), %rdi
callq 0x5240
movq -0x198(%rbp), %rax
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
leaq -0x158(%rbp), %rdi
callq 0x5240
leaq -0xf0(%rbp), %rdi
callq 0x5240
leaq -0x90(%rbp), %rdi
callq 0x5240
movq -0x38(%rbp), %rdi
callq 0x5620
nopl (%rax)