// File: /workspace/github_cpp_makefile_star2_O2/m1c0l[P]http-client-server/web-client.cpp
// Function: main
int main(int argc, char **argv) {
	if (argc < 2) {
		cerr << "usage: " << argv[0] << " [URL] [URL] ..." << '\n';
		return 1;
	}

	Url *url = new Url[argc];
	thread *t = new thread[argc];
	HttpRequest **req = new HttpRequest*[argc];
	sockaddr_in *serverAddr = new sockaddr_in[argc];

	// send a request for each url
	for (int i = 1; i < argc; i++) {

		url[i] = parseUrl(argv[i]);
		serverAddr[i] = getServerAddr(url[i].host, url[i].port);

		// set up HTTP request
		req[i] = new HttpRequest();
		req[i]->setMethod("GET");
		req[i]->setUrl(url[i].path);
		req[i]->setVersion("HTTP/1.0");
		req[i]->setHeader("Host", url[i].host);

		// send the request and retrieve the file
		t[i] = thread(processRequest, (sockaddr*)&serverAddr[i], req[i],
			url[i].path);
	}

	// join threads
	for (int i = 1; i < argc; i++) {
		t[i].join();
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movq %rsi, %rbx
cmpl $0x1, %edi
jg 0x7675
movq 0xa9b4(%rip), %rdi      # 0x11ff0
leaq 0x3ac3(%rip), %rsi      # 0xb106
callq 0x5300
movq (%rbx), %rsi
movq %rax, %rdi
callq 0x5300
leaq 0x3ab4(%rip), %rsi      # 0xb10e
movq %rax, %rdi
callq 0x5300
pushq $0xa
popq %rsi
movq %rax, %rdi
callq 0x5380
pushq $0x1
popq %rax
jmp 0x7994
movq %rbx, 0x40(%rsp)
movl %edi, %ebx
imulq $0x60, %rbx, %r12
leaq 0x8(%r12), %rdi
callq 0x5030
movq %rbx, 0x18(%rsp)
movq %rbx, (%rax)
movq %rax, 0x8(%rsp)
leaq 0x8(%rax), %rbx
movq %rbx, %rdi
callq 0x7a28
addq $0x60, %rbx
addq $-0x60, %r12
jne 0x769b
movq 0x18(%rsp), %r15
leaq (,%r15,8), %r12
leaq 0x8(,%r15,8), %rdi
callq 0x5030
movq %rax, %r13
movq %r15, (%rax)
leaq 0x8(%rax), %rdi
xorl %r14d, %r14d
xorl %esi, %esi
movq %r12, %rdx
callq 0x51c0
movq %r12, %rdi
movq %r13, %r12
callq 0x5030
movq %rax, %r13
movq %r15, %rdi
shlq $0x4, %rdi
callq 0x5030
movq %rax, %rbx
leaq -0x8(,%r15,8), %rcx
movq %rcx, 0x48(%rsp)
addq $0x10, %r12
addq $0x8, %r13
movq %r13, 0x20(%rsp)
addq $0x10, %rbx
addq $0xa8, 0x8(%rsp)
leaq 0x78(%rsp), %r15
movq %rbx, 0x38(%rsp)
movq %r12, 0x30(%rsp)
cmpq %r14, 0x48(%rsp)
je 0x7976
movq %rbx, 0x50(%rsp)
movq 0x40(%rsp), %rax
movq 0x8(%rax,%r14), %rsi
movq %r15, %rdi
leaq 0x28(%rsp), %rdx
callq 0x5bba
movq %r14, 0x10(%rsp)
leaq 0x158(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x6a0c
movq 0x8(%rsp), %r13
leaq -0x40(%r13), %rbp
movq %rbp, %rdi
movq %r14, %rsi
callq 0x7fba
movq %r14, %rdi
callq 0x7a5a
movq %r15, %rdi
callq 0x5140
leaq 0x138(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
callq 0x5420
leaq -0x20(%r13), %rsi
leaq 0x118(%rsp), %r13
movq %r13, %rdi
callq 0x5420
movq %r14, %rdi
movq %r13, %rsi
callq 0x6c6d
movq 0x38(%rsp), %rcx
movq 0x10(%rsp), %rbx
movq %rax, (%rcx,%rbx,2)
andq $0x0, 0x8(%rcx,%rbx,2)
movq %r13, %rdi
callq 0x5140
movq %r14, %rdi
callq 0x5140
movl $0xa0, %edi
callq 0x5310
movq %rax, %r12
movl $0xa0, %edx
movq %rax, %rdi
xorl %esi, %esi
callq 0x51c0
movq %r12, %rdi
callq 0x7ff2
movq 0x20(%rsp), %rax
movq %r12, (%rax,%rbx)
leaq 0xf8(%rsp), %r14
movq %r14, %rdi
leaq 0x3810(%rip), %rsi      # 0xb039
leaq 0x158(%rsp), %rdx
callq 0x5bba
movq %r12, %rdi
movq %r14, %rsi
callq 0x6230
movq 0x20(%rsp), %rax
movq 0x10(%rsp), %rcx
leaq (%rax,%rcx), %r12
movq %r14, %rdi
callq 0x5140
movq (%r12), %r13
leaq 0xd8(%rsp), %r14
movq %r14, %rdi
movq 0x8(%rsp), %rsi
callq 0x5420
movq %r13, %rdi
movq %r14, %rsi
callq 0x624c
movq %r14, %rdi
callq 0x5140
movq (%r12), %r13
leaq 0xb8(%rsp), %r14
movq %r14, %rdi
leaq 0x37ad(%rip), %rsi      # 0xb046
leaq 0x158(%rsp), %rdx
callq 0x5bba
movq %r13, %rdi
movq %r14, %rsi
callq 0x56ec
movq %r14, %rdi
callq 0x5140
movq (%r12), %r13
leaq 0x58(%rsp), %rdi
leaq 0x3829(%rip), %rsi      # 0xb0f2
leaq 0x158(%rsp), %rdx
callq 0x5bba
leaq 0x98(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
callq 0x5420
movq %r13, %rdi
leaq 0x58(%rsp), %r14
movq %r14, %rsi
movq %r15, %rdx
callq 0x5708
movq 0x50(%rsp), %rbx
movq %r15, %rdi
callq 0x5140
movq %r14, %rdi
callq 0x5140
movq %rbx, 0x28(%rsp)
leaq 0x158(%rsp), %rbp
movq %rbp, %rdi
leaq -0xbac(%rip), %rsi      # 0x6d7c
leaq 0x28(%rsp), %rdx
movq %r12, %rcx
movq 0x8(%rsp), %r13
movq %r13, %r8
callq 0x803a
movq 0x30(%rsp), %r12
movq 0x10(%rsp), %r14
leaq (%r12,%r14), %rdi
movq %rbp, %rsi
callq 0x80d0
movq %rbp, %rdi
callq 0x80ea
addq $0x8, %r14
addq $0x10, %rbx
addq $0x60, %r13
movq %r13, 0x8(%rsp)
leaq 0x78(%rsp), %r15
jmp 0x7731
movq 0x18(%rsp), %rbx
decq %rbx
subq $0x1, %rbx
jb 0x7992
movq %r12, %rdi
callq 0x55a8
addq $0x8, %r12
jmp 0x797e
xorl %eax, %eax
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
jmp 0x7a16
jmp 0x7a1d
jmp 0x7a1d
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
jmp 0x7a16
movq %rax, %rbx
jmp 0x79db
movq %rax, %rbx
jmp 0x79f2
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x5140
leaq 0x58(%rsp), %rdi
jmp 0x7a16
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
callq 0x5140
leaq 0x138(%rsp), %rdi
jmp 0x7a16
jmp 0x7a1d
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
jmp 0x7a16
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x5140
jmp 0x7a20
movq %rax, %rbx
movq %rbx, %rdi
callq 0x5500