// File: /workspace/github_cpp_makefile_star2_O2/muzuka[P]Cards-Against-Humanity-Online/Server.cpp
// Function: main
int main(int argc, char *argv[]) {
	
	blackDeck.clear();
	whiteDeck.clear();
	discard.clear();
	players.clear();
	
	if (argc != 4) {
		printf("Usage: %s <Listening Port> <Black Deck File> <White Deck File>\n", argv[0]);
		exit(1);
	}
	
	initServer(serverSock, atoi(argv[1]));
	
	string line;
	ifstream blackCardReader, whiteCardReader;
	blackCardReader.open(argv[2]);
	whiteCardReader.open(argv[3]);
	
	
	if (!blackCardReader.is_open() || !whiteCardReader.is_open()) {
		printf("File open failed\n");
		blackCardReader.close();
		whiteCardReader.close();
		exit(1);
	}
	
	while(getline(blackCardReader, line)) {
		char* lineDiv[2];
		if (line[0] == 'q') {
			splitString(lineDiv, (char*)line.c_str(), "\"");
			string temp(lineDiv[1]);
			Card nBlack(temp, 'b', 1);
			blackDeck.push_back(nBlack);
		}
		else if (line[0] == 's') {
			splitString(lineDiv, (char*)line.c_str(), "\"");
			string temp(lineDiv[1]);
			int answers = countChars(lineDiv[1], '_');
			Card nBlack(temp, 'b', answers);
			blackDeck.push_back(nBlack);
		}
	}
	
	while (getline(whiteCardReader, line)) {
		Card nWhite(line, 'w', 0);
		whiteDeck.push_back(nWhite);
	}
	
	blackDeck = shuffle(blackDeck, atoi(argv[1]));
	whiteDeck = shuffle(whiteDeck, atoi(argv[1]));
	FD_ZERO(&recvSockSet);
	
	FD_SET(serverSock, &recvSockSet);
	maxDesc = max(maxDesc, serverSock);
	
	while (!terminated) {
		
		memcpy(&tempRecvSockSet, &recvSockSet, sizeof(recvSockSet));
		
		selectTime = timeout;
		int ready = select(maxDesc + 1, &tempRecvSockSet, NULL, NULL, &selectTime);
		if (ready < 0) {
			printf("select() failed\n");
			break;
		}
		
		if (FD_ISSET(serverSock, &tempRecvSockSet)) {
			unsigned int size = sizeof(clientAddr);
			
			if ((clientSock = accept(serverSock, (struct sockaddr *) &clientAddr, &size)) < 0) {
				break;
			}
			printf("A new player has connected.\n");
			
			bool nameOK = false;
			bool foundName = false;
			
			while (!nameOK) {
				
				memset(&inBuffer, 0, sizeof(inBuffer));
				bytesRecv = 0;
				while (bytesRecv <= 0) {
					bytesRecv = recv(clientSock, (char*)&inBuffer, 20, 0);
				}
				printf("%s\n", inBuffer);
				
				if (players.size() < 1) {
					printf("Players is Empty.\n");
					outBuffer[0] = 'y';
					printf("Name hasn't been taken.\n");
					bytesSent = send(clientSock, (char*)&outBuffer, 1, 0);
					if (bytesSent <= 0) {
						printf("Couldn't send confirmation.\n");
						exit(1);
					}
					nameOK = !nameOK;
				}
				else {
					printf("Players isn't empty.\n");
					foundName = false;
					for (int i = 0; i < players.size(); i++) {
						if (players[i].getName().compare(inBuffer) == 0) {
							outBuffer[0] = 'n';
							bytesSent = 0;
							printf("Name is already taken.\n");
							bytesSent = send(clientSock, (char*)&outBuffer, 1, 0);
							if (bytesSent <= 0) {
								printf("Couldn't send denial.\n");
								exit(1);
							}
							foundName = true;
							break;
						}
					}
					if (!foundName) {
						outBuffer[0] = 'y';
						printf("Name hasn't been taken.\n");
						bytesSent = send(clientSock, (char*)&outBuffer, 1, 0);
						if (bytesSent <= 0) {
							printf("Couldn't send confirmation.\n");
							exit(1);
						}
						nameOK = !nameOK;
					}
				}
			}
			printf("Name checks out.\n");
			string n(inBuffer);
			Player newPlayer(n, clientSock);
			players.push_back(newPlayer);
			
			printf("About to send Cards.\n");
			for (int i = 0; i < 10; i++) {
				
				bytesSent = 0;
				if (whiteDeck.size() == 0) {
					refill();
				}
				string out = composeSENDMessage('d', whiteDeck[whiteDeck.size()-1]);
				players[players.size()-1].addCard(whiteDeck[whiteDeck.size()-1]);
				whiteDeck.pop_back();
				bytesSent = send(clientSock, (char*)out.c_str(), 100, 0);
				if (bytesSent <= 0) {
					printf("No Card was sent.\n");
					exit(1);
				}
			}
			
			FD_SET(clientSock, &recvSockSet);
			maxDesc = max(maxDesc, clientSock);
		}
		else {
			if(players.size() > 3) {
				string message;
				switch (step % 3) {
						// Choose judge and NOTIFY the others
					case 0:
						printf("Choosing a judge.\n");
						players = shuffle(players, atoi(argv[1])-step);
						judge = players[0];
						
						message = composeNOTIFYMessage('j', judge.getName());
						for (int i = 0; i < players.size(); i++) {
							bytesSent = send(players[i].getSocket(), (char*)message.c_str(), 100, 0);
							if (bytesSent <= 0) {
								printf("Judge message couldn't be sent.\n");
								exit(1);
							}
						}
						
						step++;
						break;
						// choose black card and POST it
					case 1:
						if (blackDeck.size() == 0) {
							shutdown();
						}
						printf("Choosing a black card.\n");
						blackCard = blackDeck[blackDeck.size() - 1];
						blackDeck.pop_back();
						
						message = composeSENDMessage('p', blackCard);
						for (int i = 0; i < players.size(); i++) {
							bytesSent = send(players[i].getSocket(), (char*)message.c_str(), 300, 0);
							if(bytesSent <= 0) {
								printf("Couldn't post black card.\n");
								exit(1);
							}
						}
						step++;
						break;
						// Handles answers and requests
					case 2:
						answers.clear();
						// Receive answers from others
						for (int i = 1; i < players.size(); i++) {
							for (int j = 0; j < blackCard.numOfAnswers; j++) {
								memset(&inBuffer, 0, sizeof(inBuffer));
								bytesRecv = 0;
								while(bytesRecv <= 0) {
									bytesRecv = recv(players[i].getSocket(), (char*)&inBuffer, 100, 0);
								}
								printf("player %d sent:\n%s.\n", i, (char*)string(inBuffer).c_str());
								parseAnswer(string(inBuffer), answers);
							}
						}
						printf("Received all answers.\n");
						// send expected # of answers to judge
						message = composeNOTIFYMessage('n', string("Server"));
						printf("About to send:\n%s\n", message.c_str());
						bytesSent = send(judge.getSocket(), (char*)message.c_str(), 100, 0);
						if(bytesSent <= 0) {
							printf("Failed to send NOTIFY to judge.\n");
							exit(1);
						}
						printf("Sent answers size.\n");
						// Send answers to judge
						for (int i = 0; i < answers.size(); i++) {
							message = composeSENDMessage('n', answers[i]);
							printf("About to send ANSWER to judge:\n%s\n", message.c_str());
							bytesSent = send(judge.getSocket(), (char*)message.c_str(), 100, 0);
							if(bytesSent <= 0) {
								printf("Failed to send ANSWER to judge.\n");
								i--;
							}
						}
						printf("Sent Answers to judge.\n");
						// Receive requests
						for (int i = 1; i < players.size(); i++) {
							for (int j = 0; j < blackCard.numOfAnswers; j++) {
								memset(&inBuffer, 0, sizeof(inBuffer));
								bytesRecv = 0;
								while (bytesRecv <= 0) {
									bytesRecv = recv(players[i].getSocket(), (char*)&inBuffer, 100, 0);
								}
								parseMessage(string(inBuffer));
							}
						}
						printf("Received all of the requests from clients.\n");

						// receives winner
						bytesRecv = 0;
						memset(&inBuffer, 0, sizeof(inBuffer));
						while (bytesRecv <= 0) {
							bytesRecv = recv(judge.getSocket(), (char*)&inBuffer, 100, 0);
						}
						parseMessage(string(inBuffer));

						// Tell everybody else
						for (int i = 1; i < players.size(); i++) {
							string winningMesssage = composeNOTIFYMessage('w', winner.getName());
							bytesSent = send(players[i].getSocket(), (char*)winningMesssage.c_str(), 100, 0);
							if(bytesSent <= 0) {
								printf("Failed to winner message.\n");
								exit(1);
							}
						}
						step++;
						break;
					default:
						break;
				}
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x7b8, %rsp            # imm = 0x7B8
movq %rsi, %r14
movl %edi, %ebx
leaq 0x74cc(%rip), %rdi      # 0xa608
callq 0x5140
leaq 0x74d8(%rip), %rdi      # 0xa620
callq 0x5140
leaq 0x749c(%rip), %rdi      # 0xa5f0
callq 0x5140
leaq 0x74d8(%rip), %rdi      # 0xa638
callq 0x514e
cmpl $0x4, %ebx
jne 0x3fde
movq %r14, -0x50(%rbp)
movq 0x8(%r14), %rdi
callq 0x22d0
leaq 0x72b6(%rip), %rdi      # 0xa438
movl %eax, %esi
callq 0x424d
leaq -0xf0(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x7d8(%rbp), %rdi
callq 0x2250
leaq -0x5d0(%rbp), %rdi
callq 0x2250
movq -0x50(%rbp), %rbx
movq 0x10(%rbx), %rsi
leaq -0x7d8(%rbp), %rdi
pushq $0x8
popq %rdx
callq 0x2190
movq 0x18(%rbx), %rsi
leaq -0x5d0(%rbp), %rdi
pushq $0x8
popq %rdx
callq 0x2190
leaq -0x760(%rbp), %rdi
callq 0x2090
testb %al, %al
je 0x3fb8
leaq -0x558(%rbp), %rdi
callq 0x2090
testb %al, %al
je 0x3fb8
leaq -0xb8(%rbp), %r15
leaq -0x268(%rbp), %r12
pushq $0x62
popq %rbx
leaq -0x7d8(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x2070
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3361
movq -0x100(%rbp), %rsi
movzbl (%rsi), %eax
cmpl $0x73, %eax
je 0x32b7
cmpl $0x71, %eax
jne 0x3217
leaq -0xe0(%rbp), %rdi
leaq 0x2e12(%rip), %rdx      # 0x6070
callq 0x4301
movq -0xd8(%rbp), %rsi
leaq -0x48(%rbp), %r14
movq %r14, %rdi
movq %r15, %rdx
callq 0x515c
leaq -0x288(%rbp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x2290
movq %r15, %rdi
movq %r13, %rsi
movl %ebx, %edx
pushq $0x1
popq %rcx
callq 0x26ca
movq %r13, %rdi
callq 0x2140
leaq 0x735e(%rip), %rdi      # 0xa608
movq %r15, %rsi
callq 0x2c5e
jmp 0x334b
movl %ebx, %r13d
movq %r12, %rbx
leaq -0xe0(%rbp), %rdi
leaq 0x2da5(%rip), %rdx      # 0x6070
callq 0x4301
movq -0xd8(%rbp), %r14
leaq -0x48(%rbp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x515c
leaq -0x2a8(%rbp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x515c
movq %r12, %rdi
pushq $0x5f
popq %rsi
callq 0x4336
movl %eax, %r14d
movq %r12, %rdi
callq 0x2140
movq %rbx, %r12
movq %rbx, %rdi
leaq -0x48(%rbp), %rsi
callq 0x2290
movq %r15, %rdi
movq %r12, %rsi
movl %r13d, %ebx
movl %r13d, %edx
movl %r14d, %ecx
callq 0x26ca
movq %r12, %rdi
callq 0x2140
leaq 0x72c5(%rip), %rdi      # 0xa608
movq %r15, %rsi
callq 0x2c5e
movq %r15, %rdi
callq 0x2d36
leaq -0x48(%rbp), %rdi
callq 0x2140
jmp 0x3217
leaq -0x100(%rbp), %r14
leaq -0x248(%rbp), %r15
leaq -0xb8(%rbp), %r12
pushq $0x77
popq %r13
leaq 0x729f(%rip), %rbx      # 0xa620
leaq -0x5d0(%rbp), %rdi
movq %r14, %rsi
callq 0x2070
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x33d6
movq %r15, %rdi
movq %r14, %rsi
callq 0x2290
movq %r12, %rdi
movq %r15, %rsi
movl %r13d, %edx
xorl %ecx, %ecx
callq 0x26ca
movq %r15, %rdi
callq 0x2140
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2c5e
movq %r12, %rdi
callq 0x2d36
jmp 0x3381
leaq 0x722b(%rip), %rsi      # 0xa608
leaq -0x130(%rbp), %rdi
callq 0x2cdc
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x22d0
leaq -0xb8(%rbp), %rdi
leaq -0x130(%rbp), %rsi
movl %eax, %edx
callq 0x435f
leaq 0x71f6(%rip), %rdi      # 0xa608
leaq -0xb8(%rbp), %rbx
movq %rbx, %rsi
callq 0x30ae
movq %rbx, %rdi
callq 0x2c32
leaq -0x130(%rbp), %rdi
callq 0x2c32
leaq 0x71e4(%rip), %rsi      # 0xa620
leaq -0x118(%rbp), %rdi
callq 0x2cdc
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x22d0
leaq -0xb8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
movl %eax, %edx
callq 0x435f
leaq 0x71af(%rip), %rdi      # 0xa620
movq %rbx, %rsi
callq 0x30ae
movq %rbx, %rdi
callq 0x2c32
leaq -0x118(%rbp), %rdi
callq 0x2c32
xorl %eax, %eax
leaq 0x6d72(%rip), %rdi      # 0xa208
cmpq $0x80, %rax
je 0x34a9
andq $0x0, (%rax,%rdi)
addq $0x8, %rax
jmp 0x3496
movl 0x6f89(%rip), %esi      # 0xa438
pushq $0x40
popq %rcx
movl %esi, %eax
cltd
idivl %ecx
movslq %eax, %rdx
shll $0x6, %eax
movl %esi, %ecx
subl %eax, %ecx
pushq $0x1
popq %rax
shlq %cl, %rax
orq %rax, (%rdi,%rdx,8)
movl 0x6d2f(%rip), %eax      # 0xa200
cmpl %esi, %eax
cmovgl %eax, %esi
movl %esi, 0x6d24(%rip)      # 0xa200
leaq 0x6dbd(%rip), %rbx      # 0xa2a0
leaq -0xb8(%rbp), %r13
cmpb $0x0, 0x6d97(%rip)      # 0xa288
jne 0x3f3f
pushq $0x10
popq %rcx
leaq 0x6f5f(%rip), %rax      # 0xa460
movq %rax, %rdi
leaq 0x6cfd(%rip), %rsi      # 0xa208
rep  movsq (%rsi), %es:(%rdi)
movups 0x6ccb(%rip), %xmm0     # 0xa1e0
movups %xmm0, 0x6f34(%rip)     # 0xa450
movl 0x6cde(%rip), %edi      # 0xa200
incl %edi
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
leaq 0x6f1e(%rip), %r8       # 0xa450
callq 0x2210
testl %eax, %eax
js 0x3f33
movl 0x6ef3(%rip), %edi      # 0xa438
movl %edi, %eax
cltd
pushq $0x40
popq %rcx
idivl %ecx
cltq
leaq 0x6f0a(%rip), %rcx      # 0xa460
movq (%rcx,%rax,8), %rax
btq %rdx, %rax
jae 0x3869
movl $0x10, -0x54(%rbp)
leaq 0x6ece(%rip), %rsi      # 0xa440
leaq -0x54(%rbp), %rdx
callq 0x20f0
movl %eax, 0x6ebb(%rip)      # 0xa43c
testl %eax, %eax
js 0x3f3f
leaq 0x2d32(%rip), %rdi      # 0x62c2
callq 0x22c0
xorl %r14d, %r14d
movl $0xc8, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2180
movl %r14d, 0x6cde(%rip)     # 0xa28c
testl %r14d, %r14d
jg 0x35cb
movl 0x6e83(%rip), %edi      # 0xa43c
movq %rbx, %rsi
pushq $0x14
popq %rdx
xorl %ecx, %ecx
callq 0x2100
movq %rax, %r14
jmp 0x35a7
movq %rbx, %rdi
callq 0x22c0
movq 0x7066(%rip), %rax      # 0xa640
cmpq 0x7057(%rip), %rax      # 0xa638
je 0x3ef8
leaq 0x2d28(%rip), %rdi      # 0x6316
callq 0x22c0
xorl %r12d, %r12d
pushq $-0x1
popq %r13
movq 0x703f(%rip), %rax      # 0xa640
movq 0x7030(%rip), %rsi      # 0xa638
subq %rsi, %rax
cqto
pushq $0x58
popq %rcx
idivq %rcx
incq %r13
cmpq %r13, %rax
jbe 0x3697
addq %r12, %rsi
leaq -0xb8(%rbp), %r15
movq %r15, %rdi
callq 0x291e
addq $0x58, %r12
movq %r15, %rdi
movq %rbx, %rsi
callq 0x20e0
movl %eax, %r14d
movq %r15, %rdi
callq 0x2140
testl %r14d, %r14d
jne 0x35fa
movb $0x6e, 0x6d1d(%rip)     # 0xa370
andl $0x0, 0x6c36(%rip)      # 0xa290
leaq 0x2cca(%rip), %rdi      # 0x632b
callq 0x22c0
movl 0x6dd0(%rip), %edi      # 0xa43c
leaq 0x6cfd(%rip), %rsi      # 0xa370
pushq $0x1
popq %rdx
xorl %ecx, %ecx
callq 0x2150
movl %eax, 0x6c0d(%rip)      # 0xa290
testl %eax, %eax
leaq -0xb8(%rbp), %r13
jg 0x3595
jmp 0x3faf
movb $0x79, 0x6cd2(%rip)     # 0xa370
leaq 0x2cc5(%rip), %rdi      # 0x636a
callq 0x22c0
movl 0x6d8c(%rip), %edi      # 0xa43c
leaq 0x6cb9(%rip), %rsi      # 0xa370
pushq $0x1
popq %rdx
xorl %ecx, %ecx
callq 0x2150
leaq -0xb8(%rbp), %r13
movl %eax, 0x6bc2(%rip)      # 0xa290
testl %eax, %eax
jle 0x3fa6
leaq 0x2c01(%rip), %rdi      # 0x62de
callq 0x22c0
leaq -0x48(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x515c
leaq -0x228(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x2290
movl 0x6d30(%rip), %edx      # 0xa43c
movq %r13, %rdi
movq %r15, %rsi
callq 0x28ae
movq %r15, %rdi
callq 0x2140
leaq 0x6f12(%rip), %rdi      # 0xa638
movq %r13, %rsi
callq 0x5198
leaq 0x2bba(%rip), %rdi      # 0x62ef
callq 0x22c0
pushq $0xa
popq %r13
subl $0x1, %r13d
jb 0x3812
andl $0x0, 0x6b41(%rip)      # 0xa290
movq 0x6ed2(%rip), %rsi      # 0xa628
cmpq 0x6ec3(%rip), %rsi      # 0xa620
jne 0x376b
callq 0x44a8
movq 0x6ebd(%rip), %rsi      # 0xa628
addq $-0x48, %rsi
leaq -0x3c8(%rbp), %r14
movq %r14, %rdi
callq 0x2c9a
leaq -0xe0(%rbp), %rdi
pushq $0x64
popq %rsi
movq %r14, %rdx
callq 0x4549
movq %r14, %rdi
callq 0x2d36
movq 0x6ea1(%rip), %r14      # 0xa640
movq 0x6e82(%rip), %rsi      # 0xa628
addq $-0x48, %rsi
leaq -0x380(%rbp), %r15
movq %r15, %rdi
callq 0x2c9a
addq $-0x58, %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x2976
movq %r15, %rdi
callq 0x2d36
leaq 0x6e49(%rip), %rdi      # 0xa620
callq 0x51d4
movl 0x6c5a(%rip), %edi      # 0xa43c
movq -0xe0(%rbp), %rsi
pushq $0x64
popq %rdx
xorl %ecx, %ecx
callq 0x2150
movl %eax, 0x6a97(%rip)      # 0xa290
testl %eax, %eax
jle 0x3f77
leaq -0xe0(%rbp), %rdi
callq 0x2140
jmp 0x373e
movl 0x6c24(%rip), %esi      # 0xa43c
movl %esi, %eax
cltd
pushq $0x40
popq %rcx
idivl %ecx
movslq %eax, %rdx
shll $0x6, %eax
movl %esi, %ecx
subl %eax, %ecx
pushq $0x1
popq %rax
shlq %cl, %rax
leaq 0x69d1(%rip), %rcx      # 0xa208
orq %rax, (%rcx,%rdx,8)
movl 0x69bf(%rip), %eax      # 0xa200
cmpl %esi, %eax
cmovgl %eax, %esi
movl %esi, 0x69b4(%rip)      # 0xa200
leaq -0xb8(%rbp), %r13
movq %r13, %rdi
callq 0x50ea
leaq -0x48(%rbp), %rdi
callq 0x2140
jmp 0x34ea
movq 0x6dd0(%rip), %rax      # 0xa640
subq 0x6dc1(%rip), %rax      # 0xa638
cqto
pushq $0x58
popq %rcx
idivq %rcx
cmpq $0x4, %rax
jb 0x34ea
leaq -0xa8(%rbp), %rax
movq %rax, -0xb8(%rbp)
andq $0x0, -0xb0(%rbp)
movb $0x0, -0xa8(%rbp)
movl 0x6da4(%rip), %eax      # 0xa650
cltd
pushq $0x3
popq %rcx
idivl %ecx
cmpl $0x2, %edx
je 0x3abf
cmpl $0x1, %edx
je 0x39dd
testl %edx, %edx
jne 0x3eeb
leaq 0x29bd(%rip), %rdi      # 0x6290
callq 0x22c0
leaq -0x148(%rbp), %r15
movq %r15, %rdi
leaq 0x6d4f(%rip), %rsi      # 0xa638
callq 0x51ee
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x22d0
subl 0x6d4f(%rip), %eax      # 0xa650
leaq -0x48(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
movl %eax, %edx
callq 0x4618
leaq 0x6d1f(%rip), %rdi      # 0xa638
movq %r14, %rsi
callq 0x5a8e
movq %r14, %rdi
callq 0x5114
movq %r15, %rdi
callq 0x5114
movq 0x6d00(%rip), %rsi      # 0xa638
leaq 0x6ba1(%rip), %rdi      # 0xa4e0
callq 0x5248
leaq -0x208(%rbp), %r15
movq %r15, %rdi
leaq 0x6b8b(%rip), %rsi      # 0xa4e0
callq 0x291e
movq %r14, %rdi
pushq $0x6a
popq %rsi
movq %r15, %rdx
callq 0x4761
movq %r13, %rdi
movq %r14, %rsi
callq 0x2270
movq %r14, %rdi
callq 0x2140
movq %r15, %rdi
callq 0x2140
xorl %r14d, %r14d
pushq $-0x1
popq %r12
movq 0x6caf(%rip), %rax      # 0xa640
movq 0x6ca0(%rip), %rdi      # 0xa638
subq %rdi, %rax
cqto
pushq $0x58
popq %rcx
idivq %rcx
incq %r12
cmpq %r12, %rax
jbe 0x3ee5
addq %r14, %rdi
callq 0x2940
movq -0xb8(%rbp), %rsi
movl %eax, %edi
pushq $0x64
popq %rdx
xorl %ecx, %ecx
callq 0x2150
addq $0x58, %r14
movl %eax, 0x68bc(%rip)      # 0xa290
testl %eax, %eax
jg 0x398a
jmp 0x3f8b
movq 0x6c2c(%rip), %rax      # 0xa610
cmpq 0x6c1d(%rip), %rax      # 0xa608
je 0x3ff1
leaq 0x2867(%rip), %rdi      # 0x625f
callq 0x22c0
movq 0x6c0c(%rip), %rsi      # 0xa610
addq $-0x48, %rsi
leaq 0x6b81(%rip), %rdi      # 0xa590
callq 0x5288
leaq 0x6bed(%rip), %rdi      # 0xa608
callq 0x51d4
leaq -0x338(%rbp), %r15
movq %r15, %rdi
leaq 0x6b5f(%rip), %rsi      # 0xa590
callq 0x2c9a
leaq -0x48(%rbp), %r14
movq %r14, %rdi
pushq $0x70
popq %rsi
movq %r15, %rdx
callq 0x4549
movq %r13, %rdi
movq %r14, %rsi
callq 0x2270
movq %r14, %rdi
callq 0x2140
movq %r15, %rdi
callq 0x2d36
xorl %r14d, %r14d
pushq $-0x1
popq %r12
movq 0x6bcf(%rip), %rax      # 0xa640
movq 0x6bc0(%rip), %rdi      # 0xa638
subq %rdi, %rax
cqto
pushq $0x58
popq %rcx
idivq %rcx
incq %r12
cmpq %r12, %rax
jbe 0x3ee5
addq %r14, %rdi
callq 0x2940
movq -0xb8(%rbp), %rsi
movl $0x12c, %edx            # imm = 0x12C
movl %eax, %edi
xorl %ecx, %ecx
callq 0x2150
addq $0x58, %r14
movl %eax, 0x67da(%rip)      # 0xa290
testl %eax, %eax
jg 0x3a6a
jmp 0x3f94
leaq 0x6b12(%rip), %rdi      # 0xa5d8
callq 0x5140
pushq $0x1
popq %rsi
movq 0x6b6b(%rip), %rax      # 0xa640
subq 0x6b5c(%rip), %rax      # 0xa638
cqto
pushq $0x58
popq %rcx
idivq %rcx
cmpq %rsi, %rax
jbe 0x3bc1
xorl %r12d, %r12d
movq %rsi, -0x60(%rbp)
imulq $0x58, %rsi, %r14
cmpl 0x6ab5(%rip), %r12d     # 0xa5b4
jge 0x3bb5
xorl %r13d, %r13d
movl $0xc8, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2180
movl %r13d, 0x676e(%rip)     # 0xa28c
testl %r13d, %r13d
jg 0x3b46
movq 0x6b0e(%rip), %rdi      # 0xa638
addq %r14, %rdi
callq 0x2940
movl %eax, %edi
movq %rbx, %rsi
pushq $0x64
popq %rdx
xorl %ecx, %ecx
callq 0x2100
movq %rax, %r13
jmp 0x3b17
leaq -0x48(%rbp), %r13
movq %r13, %rdi
movq %rbx, %rsi
leaq -0xe0(%rbp), %rdx
callq 0x515c
movq -0x48(%rbp), %rdx
leaq 0x250b(%rip), %rdi      # 0x6072
movq -0x60(%rbp), %rsi
xorl %eax, %eax
callq 0x2040
movq %r13, %rdi
callq 0x2140
leaq -0x1e8(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x515c
movq %r15, %rdi
leaq 0x6a3f(%rip), %rsi      # 0xa5d8
callq 0x493a
movq %r15, %rdi
callq 0x2140
incl %r12d
leaq -0xb8(%rbp), %r13
jmp 0x3af8
movq -0x60(%rbp), %rsi
incq %rsi
jmp 0x3ace
leaq 0x25d2(%rip), %rdi      # 0x619a
callq 0x22c0
leaq -0x1c8(%rbp), %r15
movq %r15, %rdi
leaq 0x257a(%rip), %rsi      # 0x6158
leaq -0xe0(%rbp), %rdx
callq 0x515c
leaq -0x48(%rbp), %r14
movq %r14, %rdi
pushq $0x6e
popq %rsi
movq %r15, %rdx
callq 0x4761
movq %r13, %rdi
movq %r14, %rsi
callq 0x2270
movq %r14, %rdi
callq 0x2140
movq %r15, %rdi
callq 0x2140
movq -0xb8(%rbp), %rsi
leaq 0x2462(%rip), %rdi      # 0x6087
xorl %eax, %eax
callq 0x2040
leaq 0x68ad(%rip), %rdi      # 0xa4e0
callq 0x2940
movq -0xb8(%rbp), %rsi
movl %eax, %edi
pushq $0x64
popq %rdx
xorl %ecx, %ecx
callq 0x2150
movl %eax, 0x663f(%rip)      # 0xa290
testl %eax, %eax
jle 0x3ff6
leaq 0x2550(%rip), %rdi      # 0x61b0
callq 0x22c0
xorl %r14d, %r14d
movslq %r14d, %rcx
movq 0x696e(%rip), %rax      # 0xa5e0
movq 0x695f(%rip), %rsi      # 0xa5d8
subq %rsi, %rax
cqto
pushq $0x48
popq %rdi
idivq %rdi
cmpq %rcx, %rax
jbe 0x3d25
imulq $0x48, %rcx, %rax
addq %rax, %rsi
leaq -0x2f0(%rbp), %r15
movq %r15, %rdi
callq 0x2c9a
leaq -0x48(%rbp), %r12
movq %r12, %rdi
pushq $0x6e
popq %rsi
movq %r15, %rdx
callq 0x4549
movq %r13, %rdi
movq %r12, %rsi
callq 0x2270
movq %r12, %rdi
callq 0x2140
movq %r15, %rdi
callq 0x2d36
movq -0xb8(%rbp), %rsi
leaq 0x23bc(%rip), %rdi      # 0x609a
xorl %eax, %eax
callq 0x2040
leaq 0x67f4(%rip), %rdi      # 0xa4e0
callq 0x2940
movq -0xb8(%rbp), %rsi
movl %eax, %edi
pushq $0x64
popq %rdx
xorl %ecx, %ecx
callq 0x2150
movl %eax, 0x6586(%rip)      # 0xa290
testl %eax, %eax
jg 0x3d1d
leaq 0x250a(%rip), %rdi      # 0x621f
callq 0x22c0
decl %r14d
incl %r14d
jmp 0x3c68
leaq 0x2497(%rip), %rdi      # 0x61c3
callq 0x22c0
pushq $0x1
popq %r12
movq 0x6904(%rip), %rax      # 0xa640
subq 0x68f5(%rip), %rax      # 0xa638
cqto
pushq $0x58
popq %rcx
idivq %rcx
cmpq %r12, %rax
jbe 0x3ddc
xorl %r13d, %r13d
cmpl 0x6856(%rip), %r13d     # 0xa5b4
jge 0x3dcd
xorl %r14d, %r14d
movl $0xc8, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2180
movl %r14d, 0x6513(%rip)     # 0xa28c
testl %r14d, %r14d
jg 0x3da2
imulq $0x58, %r12, %rdi
addq 0x68af(%rip), %rdi      # 0xa638
callq 0x2940
movl %eax, %edi
movq %rbx, %rsi
pushq $0x64
popq %rdx
xorl %ecx, %ecx
callq 0x2100
movq %rax, %r14
jmp 0x3d72
leaq -0x1a8(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
leaq -0x48(%rbp), %rdx
callq 0x515c
movq %r14, %rdi
callq 0x4b13
movq %r14, %rdi
callq 0x2140
incl %r13d
jmp 0x3d57
incq %r12
leaq -0xb8(%rbp), %r13
jmp 0x3d35
leaq 0x23f7(%rip), %rdi      # 0x61da
callq 0x22c0
andl $0x0, 0x649d(%rip)      # 0xa28c
xorl %r14d, %r14d
movl $0xc8, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2180
testl %r14d, %r14d
jg 0x3e2d
leaq 0x66d3(%rip), %rdi      # 0xa4e0
callq 0x2940
movl %eax, %edi
movq %rbx, %rsi
pushq $0x64
popq %rdx
xorl %ecx, %ecx
callq 0x2100
movq %rax, %r14
movl %r14d, 0x6461(%rip)     # 0xa28c
jmp 0x3e01
leaq -0x188(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
leaq -0x48(%rbp), %rdx
callq 0x515c
movq %r14, %rdi
callq 0x4b13
movq %r14, %rdi
callq 0x2140
pushq $0x58
popq %r14
pushq $0x1
popq %r12
movq 0x67de(%rip), %rax      # 0xa640
subq 0x67cf(%rip), %rax      # 0xa638
cqto
pushq $0x58
popq %rcx
idivq %rcx
cmpq %r12, %rax
jbe 0x3ee5
leaq -0x168(%rbp), %r15
movq %r15, %rdi
leaq 0x66b1(%rip), %rsi      # 0xa538
callq 0x291e
leaq -0x48(%rbp), %rdi
pushq $0x77
popq %rsi
movq %r15, %rdx
callq 0x4761
movq %r15, %rdi
callq 0x2140
movq 0x678e(%rip), %rdi      # 0xa638
addq %r14, %rdi
callq 0x2940
movq -0x48(%rbp), %rsi
movl %eax, %edi
pushq $0x64
popq %rdx
xorl %ecx, %ecx
callq 0x2150
movl %eax, 0x63c8(%rip)      # 0xa290
testl %eax, %eax
jle 0x3f9d
leaq -0x48(%rbp), %rdi
callq 0x2140
incq %r12
addq $0x58, %r14
jmp 0x3e5b
incl 0x6765(%rip)            # 0xa650
movq %r13, %rdi
callq 0x2140
jmp 0x34ea
leaq 0x2459(%rip), %rdi      # 0x6358
callq 0x22c0
movb $0x79, 0x6465(%rip)     # 0xa370
leaq 0x2458(%rip), %rdi      # 0x636a
callq 0x22c0
movl 0x651f(%rip), %edi      # 0xa43c
leaq 0x644c(%rip), %rsi      # 0xa370
pushq $0x1
popq %rdx
xorl %ecx, %ecx
callq 0x2150
jmp 0x36c8
leaq 0x2464(%rip), %rdi      # 0x639e
callq 0x22c0
leaq -0x5d0(%rbp), %rdi
callq 0x20c0
leaq -0x7d8(%rbp), %rdi
callq 0x20c0
leaq -0x100(%rbp), %rdi
callq 0x2140
xorl %eax, %eax
addq $0x7b8, %rsp            # imm = 0x7B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2386(%rip), %rdi      # 0x6304
callq 0x22c0
pushq $0x1
popq %rdi
callq 0x2260
leaq 0x2310(%rip), %rdi      # 0x62a2
jmp 0x3f7e
leaq 0x22db(%rip), %rdi      # 0x6276
jmp 0x3f7e
leaq 0x2261(%rip), %rdi      # 0x6205
jmp 0x3f7e
leaq 0x23d5(%rip), %rdi      # 0x6382
jmp 0x3f7e
leaq 0x238c(%rip), %rdi      # 0x6342
jmp 0x3f7e
leaq 0x21ca(%rip), %rdi      # 0x6189
callq 0x22c0
leaq -0x7d8(%rbp), %rdi
callq 0x2080
leaq -0x5d0(%rbp), %rdi
callq 0x2080
jmp 0x3f83
movq (%r14), %rsi
leaq 0x2048(%rip), %rdi      # 0x6030
xorl %eax, %eax
callq 0x2040
jmp 0x3f83
callq 0x4864
leaq 0x2242(%rip), %rdi      # 0x623f
jmp 0x3f7e
movq %rax, %rbx
leaq -0x188(%rbp), %rdi
jmp 0x4207
jmp 0x4212
movq %rax, %rbx
leaq -0x1c8(%rbp), %rdi
jmp 0x4207
jmp 0x4212
jmp 0x4212
movq %rax, %rbx
leaq -0x338(%rbp), %rdi
jmp 0x414f
jmp 0x4212
movq %rax, %rbx
leaq -0x208(%rbp), %rdi
jmp 0x4207
jmp 0x4212
movq %rax, %rbx
leaq -0x148(%rbp), %rdi
callq 0x5114
jmp 0x4215
jmp 0x4212
movq %rax, %rbx
leaq -0x118(%rbp), %rdi
jmp 0x408b
jmp 0x41c7
movq %rax, %rbx
leaq -0x130(%rbp), %rdi
callq 0x2c32
jmp 0x4221
jmp 0x41c7
movq %rax, %rbx
jmp 0x422d
movq %rax, %rbx
jmp 0x4239
jmp 0x4212
jmp 0x41c7
jmp 0x41c7
jmp 0x41b1
movq %rax, %rbx
leaq -0x228(%rbp), %rdi
jmp 0x4110
jmp 0x411a
jmp 0x41c7
jmp 0x41c7
jmp 0x41c7
jmp 0x40f2
movq %rax, %rbx
leaq -0x268(%rbp), %rdi
jmp 0x4110
jmp 0x411a
jmp 0x411a
jmp 0x41c7
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x2d36
jmp 0x41e7
movq %rax, %rbx
leaq -0x288(%rbp), %rdi
callq 0x2140
jmp 0x41e7
movq %rax, %rbx
jmp 0x41e7
jmp 0x41c7
jmp 0x41c7
movq %rax, %rbx
leaq -0x168(%rbp), %rdi
jmp 0x4207
jmp 0x4212
jmp 0x4212
movq %rax, %rbx
leaq -0x2f0(%rbp), %rdi
callq 0x2d36
jmp 0x4215
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
jmp 0x4207
jmp 0x4212
jmp 0x4212
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x2d36
jmp 0x4221
movq %rax, %rbx
leaq -0x248(%rbp), %rdi
jmp 0x421c
jmp 0x41c7
jmp 0x41c7
jmp 0x41c7
jmp 0x4212
jmp 0x4212
jmp 0x41b1
jmp 0x41c7
movq %rax, %rbx
leaq -0x380(%rbp), %rdi
callq 0x2d36
jmp 0x41cf
movq %rax, %rbx
jmp 0x41db
movq %rax, %rbx
leaq -0x3c8(%rbp), %rdi
callq 0x2d36
jmp 0x41db
movq %rax, %rbx
jmp 0x4221
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
callq 0x2140
leaq -0xb8(%rbp), %rdi
callq 0x50ea
leaq -0x48(%rbp), %rdi
jmp 0x421c
movq %rax, %rbx
leaq -0x1a8(%rbp), %rdi
jmp 0x4207
jmp 0x4212
jmp 0x4212
movq %rax, %rbx
leaq -0x1e8(%rbp), %rdi
callq 0x2140
jmp 0x4215
jmp 0x4212
jmp 0x4212
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x2140
leaq -0x5d0(%rbp), %rdi
callq 0x20c0
leaq -0x7d8(%rbp), %rdi
callq 0x20c0
leaq -0x100(%rbp), %rdi
callq 0x2140
movq %rbx, %rdi
callq 0x2320