// File: /workspace/github_cpp_makefile_star2_O1/mbourand[P]webserv/srcs/tcp-server.cpp
// Function: main
int	main(int argc, char **argv)
{
	std::cout << "\e[34m" << " __      __      ___.                              \n/  \\    /  \\ ____\\_ |__   ______ ______________  __\n\\   \\/\\/   // __ \\| __ \\ /  ___// __ \\_  __ \\  \\/ /\n \\        /\\  ___/| \\_\\ \\\\___ \\\\  ___/|  | \\/\\   / \n  \\__/\\  /  \\___  >___  /____  >\\___  >__|    \\_/  \n       \\/       \\/    \\/     \\/     \\/         V1.0.0\e[39m" << std::endl;
	std::cout << "\e[34m" << "Available commands are: help|stop|gzip|deflate|info|workers|uptime|logger|types|debug" << "\e[39m" << std::endl;
	Logger::setMode(SILENT);
	Logger::print("Webserv is starting...", NULL, INFO, SILENT);
	if (argc > 2)
	{
		std::cerr << "Format: ./webserv <path_to_config_file>" << std::endl;
		return 1;
	}

	try { g_webserv.init_config(std::string(argc == 1 ? "./config/default.conf" : argv[1])); }
	catch (std::exception& e) { return Logger::print(std::string("Invalid config file: ") + e.what(), 1, ERROR, SILENT); }

	g_webserv.creds = new Credentials();
	Threadpool* workers = new Threadpool(g_webserv.workers_amount);
	sighandler();

	try
	{
		fd_set							read_sockets, read_sockets_z, write_sockets, write_sockets_z, error_sockets, error_sockets_z;
		std::list<Client>				clients;
		std::list<Client>::iterator		it;
		int								highestFd = 0;
		int								serverFd = 0;
		int								readyfd = 0;
		struct timeval 					start_time;

		gettimeofday(&start_time, NULL);
		Logger::print("Webserv is ready, waiting for connection...", NULL, SUCCESS, SILENT);
		FD_ZERO(&read_sockets_z);
		FD_ZERO(&write_sockets_z);
		FD_ZERO(&error_sockets_z);
		for (std::map<int, ServerSocket*>::iterator its = g_webserv.sockets.begin(); its != g_webserv.sockets.end(); its++)
		{
			if (its->second->GetSocket() > serverFd)
				serverFd = its->second->GetSocket();
			FD_SET(its->second->GetSocket(), &read_sockets_z);
		}
		FD_SET(STDIN_FILENO, &read_sockets_z);
		highestFd = serverFd;
		while (g_webserv.run)
		{
			it = clients.begin();
			read_sockets = read_sockets_z;
			write_sockets = write_sockets_z;
			error_sockets = error_sockets_z;
			struct timeval timeout = {30, 0};
			readyfd = select(highestFd + 1, &read_sockets, &write_sockets, &error_sockets, &timeout);
			switch (readyfd)
			{
			case -1:
				if (g_webserv.run)
					Logger::print("Error select(): "+std::string(strerror(errno)), NULL, ERROR, SILENT);
				break;
			case 0:
				Logger::print(std::string("Idle.. Active Connections: ")+ft::toString(clients.size()), NULL, INFO, NORMAL);
				break;//webserv was idling for the past 30s
			default:
				if (FD_ISSET(STDIN_FILENO, &read_sockets))
				{
					std::string line;
					std::getline(std::cin, line);
					handle_terminal_input(line, clients, &start_time, workers);
					readyfd--;
				}
				for (std::map<int, ServerSocket*>::iterator its = g_webserv.sockets.begin(); its != g_webserv.sockets.end(); its++)
				{
					if (FD_ISSET(its->second->GetSocket(), &read_sockets))
					{
						int fd = 0;
						if ((fd = handle_new_connection(*its->second, clients)))
						{
							FD_SET(fd, &read_sockets_z);
							FD_SET(fd, &write_sockets_z);
							FD_SET(fd, &error_sockets_z);
							if (fd > highestFd)
								highestFd = fd;
						}
						readyfd--;
					}
				}
				it = clients.begin();
				while (readyfd && it != clients.end())
				{
					bool	error = false;
					if (FD_ISSET(it->sckt->GetSocket(), &error_sockets))
					{
						error = true;
						Logger::print("FD Error flagged by Select", NULL, WARNING, SILENT);
					}
					if (!error && FD_ISSET(it->sckt->GetSocket(), &read_sockets))
					{
						error = handle_client_request((*it));
						readyfd--;
					}
					if (!error && FD_ISSET(it->sckt->GetSocket(), &write_sockets))
					{
						if (it->req->isfinished())
							error = workers->AddJob((*it));
						readyfd--;
					}
					if (error)
					{
						bool busy = false;
						workers->Lock();
						if (!workers->getJobs().empty())
							for (std::deque<Client*>::const_iterator jobs_it = workers->getJobs().begin(); jobs_it != workers->getJobs().end(); jobs_it++)
								if (it->sckt == (*jobs_it)->sckt)
									busy = true;
						if (!workers->getCurrentJobs().empty())
							for (std::list<Client*>::const_iterator jobs_it = workers->getCurrentJobs().begin(); jobs_it != workers->getCurrentJobs().end(); jobs_it++)
								if (it->sckt == (*jobs_it)->sckt)
									busy = true;
						workers->Unlock();
						if (busy)
							continue;
						Logger::print("Client Disconnected", NULL, SUCCESS, NORMAL);
						FD_CLR(it->sckt->GetSocket(), &read_sockets_z);
						FD_CLR(it->sckt->GetSocket(), &write_sockets_z);
						FD_CLR(it->sckt->GetSocket(), &error_sockets_z);
						if (highestFd == it->sckt->GetSocket())
							highestFd = 0;
						delete it->sckt;
						delete it->req;
						it = clients.erase(it);
					}
					else
					{
						++it;
					}
				}
				if (!highestFd)
				{
					highestFd = serverFd;
					for (std::list<Client>::iterator its = clients.begin(); its != clients.end(); ++its)
					{
						if (its->sckt->GetSocket() > highestFd)
							highestFd = its->sckt->GetSocket();
					}
				}
				break;
			}
		}
		Logger::print("Webserv is shutting down...", NULL, INFO, SILENT);
		delete workers;
		it = clients.begin();
		while (it != clients.end())
		{
			Logger::print("Socket closed", NULL, SUCCESS, SILENT);
			delete it->sckt;
			delete it->req;
			it = clients.erase(it);
		}
	}
	catch(ServerSocket::ServerSocketException& e)
	{
		g_webserv.run = false;
		Logger::print(e.what(), NULL, ERROR, SILENT);
	}

	for (std::map<int, ServerSocket*>::iterator its = g_webserv.sockets.begin(); its != g_webserv.sockets.end(); its++)
		delete its->second;
	delete g_webserv.file_formatname;
	delete g_webserv.languages;
	delete g_webserv.creds;
	Logger::print("Webserv Shutdown complete", NULL, SUCCESS, SILENT);
	std::cout << std::flush;
	return (0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x508, %rsp            # imm = 0x508
movq %rsi, %rbx
movl %edi, %ebp
movq 0x1e66b(%rip), %r14     # 0x4dfa8
leaq 0xd88d(%rip), %r15      # 0x3d1d1
movl $0x5, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x7510
leaq 0xd87c(%rip), %rsi      # 0x3d1d7
movl $0x13e, %edx            # imm = 0x13E
movq %r14, %rdi
callq 0x7510
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x7490
movsbl %al, %esi
movq %r14, %rdi
callq 0x7050
movq %rax, %rdi
callq 0x7340
movl $0x5, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x7510
leaq 0xd970(%rip), %rsi      # 0x3d316
movl $0x55, %edx
movq %r14, %rdi
callq 0x7510
leaq 0xd956(%rip), %rsi      # 0x3d310
movl $0x5, %edx
movq %r14, %rdi
callq 0x7510
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x7490
movsbl %al, %esi
movq %r14, %rdi
callq 0x7050
movq %rax, %rdi
callq 0x7340
leaq 0x1e0(%rsp), %rsi
movl $0x2, (%rsi)
leaq 0x1eb4d(%rip), %rdi     # 0x4e550
callq 0x18448
leaq 0x1d0(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0xd950(%rip), %rsi      # 0x3d36c
leaq 0xd95f(%rip), %rdx      # 0x3d382
leaq 0x1c0(%rsp), %r14
movq %r14, %rdi
callq 0x80f4
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
movl $0x2, %ecx
callq 0xded8
movq 0x1c0(%rsp), %rdi
cmpq %r12, %rdi
je 0x2fa61
movq 0x1d0(%rsp), %rsi
incq %rsi
callq 0x74b0
cmpl $0x3, %ebp
jl 0x2fab2
movq 0x1e57b(%rip), %rbx     # 0x4dfe8
leaq 0xd90f(%rip), %rsi      # 0x3d383
movl $0x27, %edx
movq %rbx, %rdi
callq 0x7510
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x7490
movsbl %al, %esi
movq %rbx, %rdi
callq 0x7050
movq %rax, %rdi
callq 0x7340
movl $0x1, %ebx
jmp 0x307f5
cmpl $0x1, %ebp
jne 0x2fac0
leaq 0xd8ed(%rip), %rsi      # 0x3d3ab
jmp 0x2fac4
movq 0x8(%rbx), %rsi
leaq 0x1e0(%rsp), %rdi
leaq 0x280(%rsp), %rdx
callq 0xde9a
leaq 0x1ea88(%rip), %rdi     # 0x4e568
leaq 0x1e0(%rsp), %rsi
callq 0x26ba0
leaq 0x1f0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2fb0e
movq 0x1f0(%rsp), %rsi
incq %rsi
callq 0x74b0
movl $0x18, %edi
callq 0x74a0
movq %rax, %rbx
movq %rax, %rdi
callq 0x1718c
movq %rbx, 0x1eb0e(%rip)     # 0x4e638
movl $0xb8, %edi
callq 0x74a0
movl 0x1eaee(%rip), %esi     # 0x4e628
movq %rax, 0x10(%rsp)
movq %rax, %rdi
callq 0x18530
callq 0x18450
leaq 0x40(%rsp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
movq $0x0, 0x10(%rax)
leaq 0x270(%rsp), %rdi
xorl %esi, %esi
callq 0x7740
leaq 0x170(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xd855(%rip), %rsi      # 0x3d3d7
leaq 0xd879(%rip), %rdx      # 0x3d402
leaq 0x160(%rsp), %rdi
callq 0x80f4
leaq 0x160(%rsp), %rdi
xorl %esi, %esi
movl $0x1, %edx
movl $0x2, %ecx
callq 0xded8
movq 0x160(%rsp), %rdi
cmpq %rbx, %rdi
je 0x2fbcc
movq 0x170(%rsp), %rsi
incq %rsi
callq 0x74b0
xorps %xmm0, %xmm0
movaps %xmm0, 0x2f0(%rsp)
movaps %xmm0, 0x2e0(%rsp)
movaps %xmm0, 0x2d0(%rsp)
movaps %xmm0, 0x2c0(%rsp)
movaps %xmm0, 0x2b0(%rsp)
movaps %xmm0, 0x2a0(%rsp)
movaps %xmm0, 0x290(%rsp)
movaps %xmm0, 0x280(%rsp)
movaps %xmm0, 0x380(%rsp)
movaps %xmm0, 0x390(%rsp)
movaps %xmm0, 0x3a0(%rsp)
movaps %xmm0, 0x3b0(%rsp)
movaps %xmm0, 0x3c0(%rsp)
movaps %xmm0, 0x3d0(%rsp)
movaps %xmm0, 0x3e0(%rsp)
movaps %xmm0, 0x3f0(%rsp)
movaps %xmm0, 0x300(%rsp)
movaps %xmm0, 0x310(%rsp)
movaps %xmm0, 0x320(%rsp)
movaps %xmm0, 0x330(%rsp)
movaps %xmm0, 0x340(%rsp)
movaps %xmm0, 0x350(%rsp)
movaps %xmm0, 0x360(%rsp)
movaps %xmm0, 0x370(%rsp)
movq 0x1e902(%rip), %rbx     # 0x4e598
leaq 0x1e8eb(%rip), %r13     # 0x4e588
cmpq %r13, %rbx
je 0x2fd26
movl $0x0, 0xc(%rsp)
movq 0x28(%rbx), %rdi
callq 0x12c90
cmpl 0xc(%rsp), %eax
jle 0x2fcca
movq 0x28(%rbx), %rdi
callq 0x12c90
movl %eax, 0xc(%rsp)
movq 0x28(%rbx), %rdi
callq 0x12c90
movl %eax, %r15d
movq 0x28(%rbx), %rdi
callq 0x12c90
leal 0x3f(%r15), %ecx
testl %r15d, %r15d
cmovnsl %r15d, %ecx
andl $0xc0, %ecx
subl %ecx, %r15d
movl $0x1, %edx
movl %r15d, %ecx
shlq %cl, %rdx
leal 0x3f(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x6, %ecx
movslq %ecx, %rax
orq %rdx, 0x280(%rsp,%rax,8)
movq %rbx, %rdi
callq 0x7350
movq %rax, %rbx
cmpq %r13, %rax
jne 0x2fcae
jmp 0x2fd2e
movl $0x0, 0xc(%rsp)
orb $0x1, 0x280(%rsp)
cmpb $0x1, 0x1e82b(%rip)     # 0x4e568
jne 0x3059b
leaq 0x70(%rsp), %rbx
movl 0xc(%rsp), %eax
movq %rax, 0x18(%rsp)
movl $0x10, %ecx
leaq 0x1e0(%rsp), %rax
movq %rax, %rdi
leaq 0x280(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movl $0x10, %ecx
leaq 0x488(%rsp), %rdx
movq %rdx, %rdi
leaq 0x380(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movl $0x10, %ecx
leaq 0x408(%rsp), %r8
movq %r8, %rdi
leaq 0x300(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movups 0xd89f(%rip), %xmm0     # 0x3d648
movaps %xmm0, 0x260(%rsp)
movq 0x18(%rsp), %rcx
leal 0x1(%rcx), %edi
movq %rax, %rsi
movq %r8, %rcx
leaq 0x260(%rsp), %r8
callq 0x7480
movl %eax, %r12d
cmpl $-0x1, %eax
je 0x2fe82
testl %r12d, %r12d
jne 0x2ff07
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0xd61d(%rip), %rsi      # 0x3d414
leaq 0xd631(%rip), %rdx      # 0x3d42f
callq 0x80f4
movl 0x50(%rsp), %esi
leaq 0x80(%rsp), %rdi
callq 0x1c07f
movq 0x20(%rsp), %rcx
movl $0xf, %esi
leaq 0x30(%rsp), %rax
cmpq %rax, %rcx
je 0x2fe2d
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %r8
movq 0x88(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rsi, %rax
jbe 0x2fe6b
movl $0xf, %esi
leaq 0x90(%rsp), %rdi
cmpq %rdi, 0x80(%rsp)
je 0x2fe62
movq 0x90(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x30479
movq 0x80(%rsp), %rsi
leaq 0x20(%rsp), %rdi
callq 0x7190
jmp 0x3048a
cmpb $0x1, 0x1e6df(%rip)     # 0x4e568
jne 0x30589
callq 0x7070
movl (%rax), %edi
callq 0x71d0
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
leaq 0x80(%rsp), %rdx
callq 0xde9a
movl $0x10, %r8d
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0xd53c(%rip), %rcx      # 0x3d403
callq 0x7500
leaq 0xb0(%rsp), %rbx
movq %rbx, 0xa0(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x30516
movq %rdx, 0xa0(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xb0(%rsp)
jmp 0x3051c
testb $0x1, 0x1e0(%rsp)
je 0x2ff98
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
movb $0x0, 0x30(%rsp)
movq 0x1e09c(%rip), %rcx     # 0x4dfd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x7490
leaq 0x20(%rsp), %rbx
movsbl %al, %edx
movq 0x1e079(%rip), %rdi     # 0x4dfd0
movq %rbx, %rsi
callq 0x7890
movq %rbx, %rdi
leaq 0x40(%rsp), %rsi
leaq 0x270(%rsp), %rdx
movq 0x10(%rsp), %rcx
callq 0x30c44
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x2ff95
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x74b0
decl %r12d
movq 0x1e5f9(%rip), %rbx     # 0x4e598
cmpq %r13, %rbx
je 0x30045
movq 0x28(%rbx), %rdi
callq 0x12c90
leal 0x3f(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x6, %ecx
movslq %ecx, %rax
movq 0x1e0(%rsp,%rax,8), %r15
movq 0x28(%rbx), %rdi
callq 0x12c90
btq %rax, %r15
jae 0x30031
movq 0x28(%rbx), %rdi
leaq 0x40(%rsp), %rsi
callq 0x2e504
testl %eax, %eax
je 0x3002e
leal 0x3f(%rax), %edx
testl %eax, %eax
cmovnsl %eax, %edx
movl %edx, %esi
andl $-0x40, %esi
movl %eax, %ecx
subl %esi, %ecx
movl $0x1, %esi
shlq %cl, %rsi
sarl $0x6, %edx
movslq %edx, %rcx
orq %rsi, 0x280(%rsp,%rcx,8)
orq %rsi, 0x380(%rsp,%rcx,8)
orq %rsi, 0x300(%rsp,%rcx,8)
movq 0x18(%rsp), %rcx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movq %rcx, 0x18(%rsp)
decl %r12d
movq %rbx, %rdi
callq 0x7350
movq %rax, %rbx
cmpq %r13, %rax
jne 0x2ffa8
movq 0x40(%rsp), %rbp
testl %r12d, %r12d
setne %al
leaq 0x40(%rsp), %rcx
cmpq %rcx, %rbp
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x3041a
movq %rbp, %rax
movl %r12d, %ebp
movq %rax, %r14
movq 0x10(%rax), %rdi
callq 0x12c90
leaq 0x10(%r14), %r15
leal 0x3f(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x6, %ecx
movslq %ecx, %rax
movq 0x408(%rsp,%rax,8), %rbx
movq (%r15), %rdi
callq 0x12c90
btq %rax, %rbx
jae 0x3010b
leaq 0xd0(%rsp), %rax
movq %rax, 0xc0(%rsp)
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdi
leaq 0xd36e(%rip), %rsi      # 0x3d430
leaq 0xd381(%rip), %rdx      # 0x3d44a
callq 0x80f4
movq %rbx, %rdi
xorl %esi, %esi
movl $0x2, %edx
movl $0x2, %ecx
callq 0xded8
movq 0xc0(%rsp), %rdi
movb $0x1, %bl
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x3010d
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x3010d
xorl %ebx, %ebx
testb %bl, %bl
jne 0x3014f
movq (%r15), %rdi
callq 0x12c90
leal 0x3f(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x6, %ecx
movslq %ecx, %rax
movq 0x1e0(%rsp,%rax,8), %r12
movq (%r15), %rdi
callq 0x12c90
btq %rax, %r12
jae 0x3014f
movq %r15, %rdi
callq 0x2e9ee
movl %eax, %ebx
movl %ebp, %r12d
decl %r12d
jmp 0x30152
movl %ebp, %r12d
testb %bl, %bl
jne 0x301ac
movl %r12d, %ebp
movq (%r15), %rdi
callq 0x12c90
leal 0x3f(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x6, %ecx
movslq %ecx, %rax
movq 0x488(%rsp,%rax,8), %r12
movq (%r15), %rdi
callq 0x12c90
btq %rax, %r12
jae 0x301a9
movq 0x18(%r14), %rdi
callq 0x35faa
testb %al, %al
je 0x301a1
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x188dc
movl %eax, %ebx
movl %ebp, %r12d
decl %r12d
jmp 0x301ac
movl %ebp, %r12d
movq %r14, %rbp
testb %bl, %bl
je 0x3022f
movl %r12d, 0x5c(%rsp)
movq 0x10(%rsp), %rdi
callq 0x188b0
movq 0x10(%rsp), %rdi
callq 0x18b70
movq 0x30(%rax), %rcx
cmpq 0x10(%rax), %rcx
je 0x30244
movq 0x10(%rsp), %rdi
callq 0x18b70
movq 0x10(%rax), %rbx
movq 0x20(%rax), %rbp
movq 0x28(%rax), %r13
xorl %r12d, %r12d
movq 0x10(%rsp), %rdi
callq 0x18b70
cmpq 0x30(%rax), %rbx
je 0x30238
movq (%r15), %rax
movq (%rbx), %rcx
cmpq (%rcx), %rax
movzbl %r12b, %r12d
movl $0x1, %eax
cmovel %eax, %r12d
addq $0x8, %rbx
cmpq %rbp, %rbx
jne 0x301ef
movq 0x8(%r13), %rbx
addq $0x8, %r13
leaq 0x200(%rbx), %rbp
jmp 0x301ef
movq (%rbp), %rbp
jmp 0x30402
leaq 0x1e349(%rip), %r13     # 0x4e588
movq %r14, %rbp
jmp 0x30247
xorl %r12d, %r12d
movq 0x10(%rsp), %rdi
callq 0x18b76
cmpq %rax, (%rax)
je 0x3028e
movq 0x10(%rsp), %rdi
callq 0x18b76
movq %rax, %rbx
movq (%rbx), %rbx
movq 0x10(%rsp), %rdi
callq 0x18b76
cmpq %rax, %rbx
je 0x3028e
movq (%r15), %rax
movq 0x10(%rbx), %rcx
cmpq (%rcx), %rax
movzbl %r12b, %r12d
movl $0x1, %eax
cmovel %eax, %r12d
jmp 0x30263
movq 0x10(%rsp), %rdi
callq 0x188c6
testb $0x1, %r12b
je 0x302a8
movl 0x5c(%rsp), %r12d
jmp 0x30402
leaq 0x150(%rsp), %rbx
movq %rbx, 0x140(%rsp)
leaq 0x140(%rsp), %r12
movq %r12, %rdi
leaq 0xd181(%rip), %rsi      # 0x3d44b
leaq 0xd18d(%rip), %rdx      # 0x3d45e
callq 0x80f4
movq %r12, %rdi
xorl %esi, %esi
movl $0x1, %edx
movl $0x1, %ecx
callq 0xded8
movq 0x140(%rsp), %rdi
cmpq %rbx, %rdi
je 0x30307
movq 0x150(%rsp), %rsi
incq %rsi
callq 0x74b0
movq (%r15), %rdi
callq 0x12c90
movl %eax, %ebx
movq (%r15), %rdi
callq 0x12c90
movq $-0x2, %rdx
movl %ebx, %ecx
rolq %cl, %rdx
leal 0x3f(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x6, %ecx
movslq %ecx, %rax
andq %rdx, 0x280(%rsp,%rax,8)
movq (%r15), %rdi
callq 0x12c90
movl %eax, %ebx
movq (%r15), %rdi
callq 0x12c90
movq $-0x2, %rdx
movl %ebx, %ecx
rolq %cl, %rdx
leal 0x3f(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x6, %ecx
movslq %ecx, %rax
andq %rdx, 0x380(%rsp,%rax,8)
movq (%r15), %rdi
callq 0x12c90
movl %eax, %ebx
movq (%r15), %rdi
callq 0x12c90
movq $-0x2, %rdx
movl %ebx, %ecx
rolq %cl, %rdx
leal 0x3f(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x6, %ecx
movslq %ecx, %rax
andq %rdx, 0x300(%rsp,%rax,8)
movq (%r15), %rdi
callq 0x12c90
movq 0x18(%rsp), %rcx
cmpl %eax, %ecx
movl $0x0, %eax
cmovel %eax, %ecx
movq %rcx, 0x18(%rsp)
movq (%r15), %rdi
testq %rdi, %rdi
je 0x303cd
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x18(%rbp), %rdi
testq %rdi, %rdi
movl 0x5c(%rsp), %r12d
je 0x303e1
movq (%rdi), %rax
callq *0x8(%rax)
movq (%rbp), %rbx
decq 0x50(%rsp)
movq %rbp, %rdi
callq 0x7770
movl $0x20, %esi
movq %rbp, %rdi
callq 0x74b0
movq %rbx, %rbp
leaq 0x40(%rsp), %rax
cmpq %rax, %rbp
setne %al
testl %r12d, %r12d
je 0x3041a
testb %al, %al
jne 0x30066
cmpl $0x0, 0x18(%rsp)
jne 0x30589
movq 0x40(%rsp), %rbx
movl 0xc(%rsp), %eax
movq %rax, 0x18(%rsp)
leaq 0x40(%rsp), %rax
cmpq %rax, %rbx
je 0x30589
movl 0xc(%rsp), %eax
movq %rax, 0x18(%rsp)
movq 0x10(%rbx), %rdi
callq 0x12c90
cmpl 0x18(%rsp), %eax
jle 0x30467
movq 0x10(%rbx), %rdi
callq 0x12c90
movq %rax, 0x18(%rsp)
movq (%rbx), %rbx
leaq 0x40(%rsp), %rax
cmpq %rax, %rbx
jne 0x3044a
jmp 0x30589
leaq 0x80(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x7500
movq %rbx, 0x60(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x304aa
movq %rdx, 0x60(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x70(%rsp)
jmp 0x304b0
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x68(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0x60(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
movl $0x1, %ecx
callq 0xded8
movq 0x60(%rsp), %rdi
cmpq %rbx, %rdi
je 0x304f7
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x3056d
movq 0x90(%rsp), %rsi
jmp 0x30565
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq 0x8(%rax), %rdx
movq %rdx, 0xa8(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0xa0(%rsp), %rdi
xorl %esi, %esi
movl $0x3, %edx
movl $0x2, %ecx
callq 0xded8
movq 0xa0(%rsp), %rdi
cmpq %rbx, %rdi
je 0x3056d
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x30589
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x74b0
cmpb $0x0, 0x1dfd8(%rip)     # 0x4e568
leaq 0x70(%rsp), %rbx
jne 0x2fd51
leaq 0x130(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0xceb1(%rip), %rsi      # 0x3d45f
leaq 0xcec5(%rip), %rdx      # 0x3d47a
leaq 0x120(%rsp), %rdi
callq 0x80f4
leaq 0x120(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
movl $0x2, %ecx
callq 0xded8
movq 0x120(%rsp), %rdi
cmpq %rbx, %rdi
je 0x305f5
movq 0x130(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x186ee
movl $0xb8, %esi
movq %rbx, %rdi
callq 0x74b0
movq 0x40(%rsp), %rbx
leaq 0x40(%rsp), %rax
cmpq %rax, %rbx
je 0x306d3
leaq 0x110(%rsp), %r13
leaq 0xce4a(%rip), %r14      # 0x3d47b
leaq 0xce50(%rip), %r15      # 0x3d488
leaq 0x100(%rsp), %r12
movq %r13, 0x100(%rsp)
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x80f4
movq %r12, %rdi
xorl %esi, %esi
movl $0x1, %edx
movl $0x2, %ecx
callq 0xded8
movq 0x100(%rsp), %rdi
cmpq %r13, %rdi
je 0x30687
movq 0x110(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x10(%rbx), %rdi
testq %rdi, %rdi
je 0x30696
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x306a5
movq (%rdi), %rax
callq *0x8(%rax)
movq (%rbx), %rbp
decq 0x50(%rsp)
movq %rbx, %rdi
callq 0x7770
movl $0x20, %esi
movq %rbx, %rdi
callq 0x74b0
movq %rbp, %rbx
leaq 0x40(%rsp), %rax
cmpq %rax, %rbp
jne 0x30640
movq 0x40(%rsp), %rdi
leaq 0x40(%rsp), %r14
cmpq %r14, %rdi
je 0x306f7
movq (%rdi), %rbx
movl $0x20, %esi
callq 0x74b0
movq %rbx, %rdi
cmpq %r14, %rbx
jne 0x306e2
movq 0x1de9a(%rip), %rbx     # 0x4e598
leaq 0x1de83(%rip), %r14     # 0x4e588
cmpq %r14, %rbx
je 0x30729
movq 0x28(%rbx), %rdi
testq %rdi, %rdi
je 0x30719
movq (%rdi), %rax
callq *0x8(%rax)
movq %rbx, %rdi
callq 0x7350
movq %rax, %rbx
cmpq %r14, %rax
jne 0x3070a
movq 0x1de40(%rip), %rbx     # 0x4e570
testq %rbx, %rbx
je 0x3074a
movq %rbx, %rdi
callq 0x17f08
movl $0x10, %esi
movq %rbx, %rdi
callq 0x74b0
movq 0x1de27(%rip), %rbx     # 0x4e578
testq %rbx, %rbx
je 0x3076b
movq %rbx, %rdi
callq 0x17f08
movl $0x10, %esi
movq %rbx, %rdi
callq 0x74b0
movq 0x1dec6(%rip), %rbx     # 0x4e638
testq %rbx, %rbx
je 0x3078c
movq %rbx, %rdi
callq 0x175ec
movl $0x18, %esi
movq %rbx, %rdi
callq 0x74b0
leaq 0x190(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xccea(%rip), %rsi      # 0x3d489
leaq 0xccfc(%rip), %rdx      # 0x3d4a2
leaq 0x180(%rsp), %rbx
movq %rbx, %rdi
callq 0x80f4
movq %rbx, %rdi
xorl %esi, %esi
movl $0x1, %edx
movl $0x2, %ecx
callq 0xded8
movq 0x180(%rsp), %rdi
cmpq %r14, %rdi
je 0x307e7
movq 0x190(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x1d7ba(%rip), %rdi     # 0x4dfa8
callq 0x7340
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x508, %rsp            # imm = 0x508
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r14
movq %rax, %r15
movq 0x120(%rsp), %rdi
cmpq %rbx, %rdi
je 0x30b67
movq 0x130(%rsp), %rsi
jmp 0x30b47
jmp 0x30b61
movq %rdx, %r14
movq %rax, %r15
movq 0x160(%rsp), %rdi
cmpq %rbx, %rdi
je 0x30b67
movq 0x170(%rsp), %rsi
jmp 0x30b47
movq %rax, %r15
movq 0x180(%rsp), %rdi
cmpq %r14, %rdi
je 0x30a41
movq 0x190(%rsp), %rsi
jmp 0x30a39
jmp 0x30b61
movq %rax, %r15
movl $0xb8, %esi
movq 0x10(%rsp), %rdi
jmp 0x30a3c
movq %rax, %r15
movl $0x18, %esi
movq %rbx, %rdi
jmp 0x30a3c
movq %rdx, %rbx
movq %rax, %r15
leaq 0x1f0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x308cd
movq 0x1f0(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x308cd
movq %rdx, %rbx
movq %rax, %r15
cmpl $0x1, %ebx
jne 0x30a41
movq %r15, %rdi
callq 0x7210
movq %rax, %rbx
leaq 0x1f0(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xcacd(%rip), %rsi      # 0x3d3c1
leaq 0xcadb(%rip), %rdx      # 0x3d3d6
leaq 0x1e0(%rsp), %rdi
callq 0x80f4
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
leaq 0x1e0(%rsp), %rdi
movq %rax, %rsi
callq 0x78d0
leaq 0xf0(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x30952
movq %rdx, 0xe0(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xf0(%rsp)
jmp 0x3095a
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
leaq 0xe0(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl $0x1, %esi
movl $0x3, %edx
movl $0x2, %ecx
callq 0x12c94
movl %eax, %ebx
movq 0xe0(%rsp), %rdi
cmpq %r12, %rdi
je 0x309ac
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x1e0(%rsp), %rdi
cmpq %r14, %rdi
je 0x309c9
movq 0x1f0(%rsp), %rsi
incq %rsi
callq 0x74b0
callq 0x7780
jmp 0x307f5
movq %rax, %r15
movq 0xe0(%rsp), %rdi
cmpq %r12, %rdi
je 0x309f8
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x309f8
movq %rax, %r15
movq 0x1e0(%rsp), %rdi
cmpq %r14, %rdi
je 0x30a1a
movq 0x1f0(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x30a1a
movq %rax, %r15
callq 0x7780
jmp 0x30a41
movq %rax, %r15
movq 0x1c0(%rsp), %rdi
cmpq %r12, %rdi
je 0x30a41
movq 0x1d0(%rsp), %rsi
incq %rsi
callq 0x74b0
movq %r15, %rdi
callq 0x7810
movq %rdx, %r14
movq %rax, %r15
movq 0xa0(%rsp), %rdi
cmpq %rbx, %rdi
je 0x30ac6
movq 0xb0(%rsp), %rsi
jmp 0x30aaf
jmp 0x30ac0
jmp 0x30b61
movq %rdx, %r14
movq %rax, %r15
movq 0x60(%rsp), %rdi
cmpq %rbx, %rdi
je 0x30a92
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x30a92
movq %rdx, %r14
movq %rax, %r15
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x30ac6
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x30ac6
jmp 0x30ac0
jmp 0x30b61
movq %rdx, %r14
movq %rax, %r15
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x30b67
movq 0x30(%rsp), %rsi
jmp 0x30b47
jmp 0x30b61
jmp 0x30b61
movq %rdx, %r14
movq %rax, %r15
movq 0x100(%rsp), %rdi
cmpq %r13, %rdi
je 0x30b67
movq 0x110(%rsp), %rsi
jmp 0x30b47
movq %rdx, %r14
movq %rax, %r15
movq 0x140(%rsp), %rdi
cmpq %rbx, %rdi
je 0x30b67
movq 0x150(%rsp), %rsi
jmp 0x30b47
jmp 0x30b61
jmp 0x30b61
jmp 0x30b61
movq %rdx, %r14
movq %rax, %r15
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x30b67
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x30b67
jmp 0x30b61
jmp 0x30b61
jmp 0x30b61
jmp 0x30b61
jmp 0x30b61
jmp 0x30b61
jmp 0x30b61
jmp 0x30b61
movq %rdx, %r14
movq %rax, %r15
movq 0x40(%rsp), %rdi
leaq 0x40(%rsp), %r12
cmpq %r12, %rdi
je 0x30b8b
movq (%rdi), %rbx
movl $0x20, %esi
callq 0x74b0
movq %rbx, %rdi
cmpq %r12, %rbx
jne 0x30b76
cmpl $0x2, %r14d
jne 0x30a41
movq %r15, %rdi
callq 0x7210
movb $0x0, 0x1d9c4(%rip)     # 0x4e568
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
leaq 0x1a0(%rsp), %rdi
leaq 0x1e0(%rsp), %rdx
movq %rax, %rsi
callq 0xde9a
leaq 0x1a0(%rsp), %rdi
xorl %esi, %esi
movl $0x3, %edx
movl $0x2, %ecx
callq 0xded8
leaq 0x1b0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x30bff
movq 0x1b0(%rsp), %rsi
incq %rsi
callq 0x74b0
callq 0x7780
jmp 0x306f7
movq %rax, %r15
leaq 0x1b0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x30c32
movq 0x1b0(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x30c32
movq %rax, %r15
callq 0x7780
jmp 0x30a41
movq %rax, %rdi
callq 0x96cc