// File: richardposner[P]BioNetFit2/src/code/Pheromones.cpp
// Function: Pheromones::recvMessage(int, int, int, bool, std::unordered_multimap<int, Pheromones::swarmMessage, std::hash<int>, std::equal_to<int>, std::allocator<std::pair<int const, Pheromones::swarmMessage>>>&, bool, int)
int Pheromones::recvMessage(signed int senderID, const int receiverID, int tag, bool block, swarmMsgHolder &messageHolder, bool eraseMessage, int messageID) {
	int numMessages = 0;
	std::string serializedMessage; //Raquel: moved this from inside the loop to here so it's not redeclared
	swarmMessage smessage;

	if (swarm_->options.useCluster) {
		//swarmMessage smessage;
		//std::string serializedMessage;
		//cout << "RRR recvMessage senderID: " << senderID << " receiverID: " << receiverID << " tag: " << tag <<endl;
		std::string msg;
		MPI_Status status;
		int flag = 0;

		while (1) {
			//std::cout << "rcv loop" << std::endl;
			//usleep(10000);

			MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, &status);
			//MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
			//if(status == MPI_SUCCESS)
			if (flag==1) {
				//cout << "status tag: " << recvStatus->tag() << std::endl;
				//cout << "status source: " << recvStatus->source() << std::endl;
				//boost::optional<int> msgLength = recvStatus->count<char>();
				//char smChar[*msgLength];
				//char smChar[MAX_SWARM_MESSAGE_SIZE];
				//cout << "recvStatus->tag() " << recvStatus->tag() << " DONE_BREEDING " << DONE_BREEDING << endl;
				int count;

				MPI_Get_count(&status, MPI_CHAR, &count);


				if (swarm_->options.verbosity>=3) {
					cout << "message size " << count << endl;
				}
				//if (block) 
				if (swarm_->options.verbosity>=3) {
					cout << "trying a blocking receive to receiverID " << receiverID << " from senderID " << senderID  << endl;
				}
				//cout << "Tag: " << tag << "; smChar length: " << sizeof(smChar) << "; *msgLength: " << *msgLength << endl;
				//world_->recv(senderID, tag, smChar, *msgLength);
				//world_->recv(senderID, recvStatus->tag(), smChar, *msgLength);
					//world_->recv(senderID, recvStatus->tag(), msg);
				char *buffer = new char[count + 1];
				MPI_Recv(buffer, count, MPI_CHAR, status.MPI_SOURCE, status.MPI_TAG, MPI_COMM_WORLD, &status);
				buffer[count] = '\0';
				msg = std::string(buffer);
				delete [] buffer;
				//cout <<"RRR received message is smChar = " << smChar << endl;
				if (swarm_->options.verbosity>=3) {
					cout <<"RRR received message is = " << msg << endl;
					cout << "Message size is " << msg.length() << endl;
				}
				//world_->recv(boost::mpi::any_source, tag, *msgLength);
				block = false;
			    if (swarm_->options.verbosity>=3) {

			    	cout << "RRR passed receive step." << endl;
			    }

				//smessage = deserializeSwarmMessage(std::string(smChar));
				if(msg.length()>0){
					smessage = deserializeSwarmMessage(msg);


				}else{
				    if (swarm_->options.verbosity>=3) {

				    	cout << "MESSAGE EMPTY!!!" << endl;
				    }
					//smessage.tag = std::to_string(recvStatus->tag());
					//smessage.sender = senderID;
					//smessage.id = messageID;
				}
			    if (swarm_->options.verbosity>=3) {

			    	cout << "RRR deserialized message" << endl;
			    }
				msg.clear();
			    if (swarm_->options.verbosity>=3) {

			    	cout << "Cleaned serialized message" << endl;
			    }
				// If we have any messages in our messageHolder, let's process them
				//std::cout << "messageholder not empty: " << smessage.tag << ":" << smessage.sender << std::endl;

				// Make sure our message matches the sender, tag, and id we requested
				if ( (tag == -1 || tag == stoi(smessage.tag)) && (senderID == -1 || senderID == smessage.sender) && (messageID == -1 || messageID == smessage.id)) {
					// Insert the message into our message holder and increment numMessages
				    if (swarm_->options.verbosity>=3) {

				    	std::cout << "inserting message in the holder" << std::endl;
				    }
					messageHolder.insert(std::pair<int, swarmMessage>(stoi(smessage.tag), smessage));

					++numMessages;

					// If user doesn't want to erase the message, put it back in the queue
					if (!eraseMessage) {
					    if (swarm_->options.verbosity>=3) {

					    	std::cout << "Not erasing message" << std::endl;
					    }
						sendToSwarm(senderID, receiverID, stoi(smessage.tag), false, smessage.message);
					}

					// Clear out the smessage for next use
					clearSwarmMessage(smessage);
				}
				else {
				    if (swarm_->options.verbosity>=3) {

				    	std::cout << "putting it back in the queue..." << std::endl;
				    	std::cout << "@@@@@@@@@@@@@@@@@@@@@@@ Expected: " << tag << "; Received: " << smessage.tag << "@@@@@@@@@@@@@@@@@@@@@@@@@@" << std::endl;
				    }
					sendToSwarm(smessage.sender, receiverID, stoi(smessage.tag), false, smessage.message);

					if(tag == DONE_BREEDING && stoi(smessage.tag) == SIMULATION_END ){

						if(swarm_->options.verbosity >= 3){
							std::cout << "SENDER REINSERTED = " << smessage.sender << endl;
						}
						swarm_->fixRunningParticle(smessage.sender);

						std::vector<unsigned int> NewlyFinishedParticles = swarm_->checkMasterMessages();

						for(auto i = NewlyFinishedParticles.begin(); i!=NewlyFinishedParticles.end(); ++i){
							if (swarm_->options.verbosity>=3) {
						    	std::cout << "@@@@@@@@@@@@@@@@@@@@@@@ PROCESSING LATE PAR: " << *i << std::endl;
						    	std::cout << "from pheromones: " << swarm_->subparticleCurrParamSets_.size() << std::endl;
						    }
							std::map<std::string,double> mysimParams;
							int mid = fcalcMID(*i, swarm_->options.models.size());
							int pID = fcalcParID(*i, swarm_->options.models.size());

							auto fp = swarm_->options.models.at(mid)->freeParams_.begin();

							for (unsigned int j = 0; j < swarm_->subparticleCurrParamSets_[pID][mid].size(); j++) {
//								std::map<unsigned int, std::map<unsigned int, std::vector<double> > > subparticleCurrParamSets_;   //razi: PID, MID, PARAMA VALUESS

								//paramSet.insert(pair<string, double> (fp->first, subparticleCurrParamSets_[bestP][mid][i])); //make this work later, to clone the best particle
								mysimParams.insert(pair<std::string, double> (fp->first, swarm_->subparticleCurrParamSets_[pID][mid][j]));

								++fp;
							}
							swarm_->processLateParticles(mysimParams, *i, true, 0);

						}



					}
				}

				break;
			}
			else if (!block) {
				break;
			}
		}
	}
	else {
		//cout << "RAQUEL entering recvMessage entering while loop" << endl;
		//cout << "RAQUEL receiver ID: " << receiverID << " senderID: " << senderID << endl;
		unsigned int priority = 0;

		while(1) {
			//cout << "RAQUEL inside recvMessage entered while loop" << endl;

			message_queue::size_type recvd_size;

			char buffer[MAX_SWARM_MESSAGE_SIZE];
			//std::cout << "rcv loop" << std::endl;
			if (block) {
//std::cout << "trying a blocking receive to " << receiverID << " from " << senderID << std::endl;

				smq_[receiverID]->receive(buffer, sizeof(buffer), recvd_size, priority);
				buffer[recvd_size] = '\0';


				block = false;
//std::cout << "blocking receive to " << receiverID << " from " << senderID << " succeeded with recv_size of " << recvd_size << " and message of " << buffer << std::endl;
			}
			else {

//std::cout << "trying a non-blocking receive to " << receiverID << " from " << senderID << std::endl;
				bool hasMessage = smq_[receiverID]->try_receive(buffer, sizeof(buffer), recvd_size, priority);
				buffer[recvd_size] = '\0';

//std::cout << "non-blocking receive to " << receiverID << " from " << senderID << " succeeded with recv_size of " << recvd_size << " and bool of " << hasMessage << std::endl;
				if (!hasMessage) {
//std::cout << "breaking" << std::endl;
					break;
				}
			}
			// If we have any messages in our messageHolder, let's process them

			// De-serialize the smessage
			swarmMessage smessage = deserializeSwarmMessage(buffer);


sleep(1);

			//razi: uncomment later
			//std::cout << "smessage not empty: " << smessage.tag << std::endl;
			//std::cout << "tag: " << tag << ":" << smessage.tag << std::endl;
			//std::cout << "sender: " << tag << ":" << smessage.sender << std::endl;
			//std::cout << "id: " << tag << ":" << smessage.id << std::endl;

			// Make sure our message matches the sender, tag, and id we requested
			if ( (tag == -1 || stoi(smessage.tag) == tag) && (senderID == -1 || senderID == smessage.sender) && (messageID == -1 || messageID == smessage.id)) {
				// Insert the message into our message holder and increment numMessages
				messageHolder.insert(std::pair<int, swarmMessage>(stoi(smessage.tag), smessage));
//std::cout << "storing pair with tag of " << stoi(smessage.tag) << std::endl;
				++numMessages;

				// If user doesn't want to erase the message, put it back in the queue
				if (!eraseMessage) {
					//std::cout << "noerase" << std::endl;
					sendToSwarm(senderID, receiverID, tag, false, smessage.message);
				}
			}
			else {
				// If this isn't our message, put it back in the queue. This will go SLOW
				// unless we use a different queue for every particle

//std::cout << "putting it back in the queue..." << std::endl;
				sendToSwarm(smessage.sender, receiverID, stoi(smessage.tag), false, smessage.message, smessage.id);

				if (!block) {
					break;
				}
			}
		}
	}
	//cout << "RAQUEL inside recvMessage exiting with num messages: " << numMessages << endl;

	return numMessages;





}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x970, %rsp            # imm = 0x970
movl %r8d, %eax
movl %ecx, -0x784(%rbp)
movl %edx, %ecx
movl -0x784(%rbp), %edx
movl %ecx, -0x780(%rbp)
movl %esi, %ecx
movl -0x780(%rbp), %esi
movl %ecx, -0x77c(%rbp)
movq %rdi, %r8
movl -0x77c(%rbp), %edi
movb %al, %cl
movl 0x18(%rbp), %eax
movb 0x10(%rbp), %al
movq %r8, -0x8(%rbp)
movl %edi, -0xc(%rbp)
movl %esi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
andb $0x1, %cl
movb %cl, -0x15(%rbp)
movq %r9, -0x20(%rbp)
andb $0x1, %al
movb %al, -0x21(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x778(%rbp)
movl $0x0, -0x28(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x2f880
leaq -0x88(%rbp), %rdi
callq 0xd0800
movq -0x778(%rbp), %rax
movq 0x50(%rax), %rax
testb $0x1, 0x1631(%rax)
je 0xcfe7a
leaq -0xa8(%rbp), %rdi
callq 0x2f880
movl $0x0, -0xc4(%rbp)
jmp 0xcf074
movq 0x205f15(%rip), %rdx    # 0x2d4f90
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
leaq -0xc4(%rbp), %rcx
leaq -0xc0(%rbp), %r8
movl %esi, %edi
callq 0x2fd40
jmp 0xcf097
cmpl $0x1, -0xc4(%rbp)
jne 0xcfe49
movq 0x205e75(%rip), %rsi    # 0x2d4f20
leaq -0xc0(%rbp), %rdi
leaq -0xd8(%rbp), %rdx
callq 0x2f390
jmp 0xcf0c0
movq -0x778(%rbp), %rax
movq 0x50(%rax), %rax
cmpl $0x3, 0x1614(%rax)
jb 0xcf139
movq 0x205e75(%rip), %rdi    # 0x2d4f50
leaq 0x10f437(%rip), %rsi    # 0x1de519
callq 0x2ff50
movq %rax, -0x790(%rbp)
jmp 0xcf0f0
movq -0x790(%rbp), %rdi
movl -0xd8(%rbp), %esi
callq 0x2f800
movq %rax, -0x798(%rbp)
jmp 0xcf10b
movq -0x798(%rbp), %rdi
movq 0x205eaf(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xcf120
jmp 0xcf139
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0xcfe69
movq -0x778(%rbp), %rax
movq 0x50(%rax), %rax
cmpl $0x3, 0x1614(%rax)
jb 0xcf1cc
movq 0x205dfc(%rip), %rdi    # 0x2d4f50
leaq 0x10f3cc(%rip), %rsi    # 0x1de527
callq 0x2ff50
movq %rax, -0x7a0(%rbp)
jmp 0xcf169
movq -0x7a0(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x2f800
movq %rax, -0x7a8(%rbp)
jmp 0xcf181
movq -0x7a8(%rbp), %rdi
leaq 0x10f3c1(%rip), %rsi    # 0x1de550
callq 0x2ff50
movq %rax, -0x7b0(%rbp)
jmp 0xcf19d
movq -0x7b0(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x2f800
movq %rax, -0x7b8(%rbp)
jmp 0xcf1b5
movq -0x7b8(%rbp), %rdi
movq 0x205e05(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xcf1ca
jmp 0xcf1cc
movl -0xd8(%rbp), %eax
incl %eax
movslq %eax, %rdi
callq 0x2fb80
movq %rax, -0x7c0(%rbp)
jmp 0xcf1e5
movq -0x7c0(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rdi
movl -0xd8(%rbp), %esi
movl -0xc0(%rbp), %ecx
movl -0xbc(%rbp), %r8d
movq %rsp, %rax
leaq -0xc0(%rbp), %rdx
movq %rdx, (%rax)
movq 0x205cff(%rip), %rdx    # 0x2d4f20
movq 0x205d68(%rip), %r9     # 0x2d4f90
callq 0x30410
jmp 0xcf22f
movq -0xe0(%rbp), %rax
movslq -0xd8(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0xe0(%rbp), %rax
movq %rax, -0x7d0(%rbp)
leaq -0x101(%rbp), %rdi
movq %rdi, -0x7c8(%rbp)
callq 0x30a70
movq -0x7d0(%rbp), %rsi
movq -0x7c8(%rbp), %rdx
leaq -0x100(%rbp), %rdi
callq 0x44470
jmp 0xcf27e
leaq -0xa8(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x2fd80
leaq -0x100(%rbp), %rdi
callq 0x311e8
leaq -0x101(%rbp), %rdi
callq 0x311c0
movq -0xe0(%rbp), %rax
movq %rax, -0x7d8(%rbp)
cmpq $0x0, %rax
je 0xcf2c9
movq -0x7d8(%rbp), %rdi
callq 0x2f910
movq -0x778(%rbp), %rax
movq 0x50(%rax), %rax
cmpl $0x3, 0x1614(%rax)
jb 0xcf3a8
movq 0x205c68(%rip), %rdi    # 0x2d4f50
leaq 0x10f271(%rip), %rsi    # 0x1de560
callq 0x2ff50
movq %rax, -0x7e0(%rbp)
jmp 0xcf2fd
movq -0x7e0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x2f780
movq %rax, -0x7e8(%rbp)
jmp 0xcf319
movq -0x7e8(%rbp), %rdi
movq 0x205ca1(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xcf32e
movq 0x205c1b(%rip), %rdi    # 0x2d4f50
leaq 0x10f23f(%rip), %rsi    # 0x1de57b
callq 0x2ff50
movq %rax, -0x7f0(%rbp)
jmp 0xcf34a
leaq -0xa8(%rbp), %rdi
callq 0x2ff30
movq -0x7f0(%rbp), %rdi
movq %rax, %rsi
callq 0x30cf0
movq %rax, -0x7f8(%rbp)
jmp 0xcf36e
movq -0x7f8(%rbp), %rdi
movq 0x205c4c(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xcf383
jmp 0xcf3a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x101(%rbp), %rdi
callq 0x311c0
jmp 0xcfe69
movq -0x778(%rbp), %rax
movb $0x0, -0x15(%rbp)
movq 0x50(%rax), %rax
cmpl $0x3, 0x1614(%rax)
jb 0xcf3f3
movq 0x205b89(%rip), %rdi    # 0x2d4f50
leaq 0x10f1be(%rip), %rsi    # 0x1de58c
callq 0x2ff50
movq %rax, -0x800(%rbp)
jmp 0xcf3dc
movq -0x800(%rbp), %rdi
movq 0x205bde(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xcf3f1
jmp 0xcf3f3
leaq -0xa8(%rbp), %rdi
callq 0x2ff30
cmpq $0x0, %rax
jbe 0xcf48a
leaq -0x168(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x2f300
jmp 0xcf41e
movq -0x778(%rbp), %rsi
leaq -0x148(%rbp), %rdi
leaq -0x168(%rbp), %rdx
callq 0xced70
jmp 0xcf43a
leaq -0x88(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0xd0bf0
leaq -0x148(%rbp), %rdi
callq 0xc1f00
leaq -0x168(%rbp), %rdi
callq 0x311e8
jmp 0xcf4d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x311e8
jmp 0xcfe69
movq -0x778(%rbp), %rax
movq 0x50(%rax), %rax
cmpl $0x3, 0x1614(%rax)
jb 0xcf4d1
movq 0x205aab(%rip), %rdi    # 0x2d4f50
leaq 0x10f0f9(%rip), %rsi    # 0x1de5a5
callq 0x2ff50
movq %rax, -0x808(%rbp)
jmp 0xcf4ba
movq -0x808(%rbp), %rdi
movq 0x205b00(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xcf4cf
jmp 0xcf4d1
jmp 0xcf4d3
movq -0x778(%rbp), %rax
movq 0x50(%rax), %rax
cmpl $0x3, 0x1614(%rax)
jb 0xcf51a
movq 0x205a62(%rip), %rdi    # 0x2d4f50
leaq 0x10f0c1(%rip), %rsi    # 0x1de5b6
callq 0x2ff50
movq %rax, -0x810(%rbp)
jmp 0xcf503
movq -0x810(%rbp), %rdi
movq 0x205ab7(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xcf518
jmp 0xcf51a
leaq -0xa8(%rbp), %rdi
callq 0x2fe00
movq -0x778(%rbp), %rax
movq 0x50(%rax), %rax
cmpl $0x3, 0x1614(%rax)
jb 0xcf56d
movq 0x205a0f(%rip), %rdi    # 0x2d4f50
leaq 0x10f087(%rip), %rsi    # 0x1de5cf
callq 0x2ff50
movq %rax, -0x818(%rbp)
jmp 0xcf556
movq -0x818(%rbp), %rdi
movq 0x205a64(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xcf56b
jmp 0xcf56d
cmpl $-0x1, -0x14(%rbp)
je 0xcf5ad
movl -0x14(%rbp), %eax
movl %eax, -0x820(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x88(%rbp), %rdi
movl $0xa, %edx
callq 0x44520
movl %eax, -0x81c(%rbp)
jmp 0xcf599
movl -0x820(%rbp), %eax
movl -0x81c(%rbp), %ecx
cmpl %ecx, %eax
jne 0xcf796
cmpl $-0x1, -0xc(%rbp)
je 0xcf5bf
movl -0xc(%rbp), %eax
cmpl -0x64(%rbp), %eax
jne 0xcf796
cmpl $-0x1, 0x18(%rbp)
je 0xcf5d1
movl 0x18(%rbp), %eax
cmpl -0x68(%rbp), %eax
jne 0xcf796
movq -0x778(%rbp), %rax
movq 0x50(%rax), %rax
cmpl $0x3, 0x1614(%rax)
jb 0xcf618
movq 0x205964(%rip), %rdi    # 0x2d4f50
leaq 0x10eff7(%rip), %rsi    # 0x1de5ea
callq 0x2ff50
movq %rax, -0x828(%rbp)
jmp 0xcf601
movq -0x828(%rbp), %rdi
movq 0x2059b9(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xcf616
jmp 0xcf618
movq -0x20(%rbp), %rax
movq %rax, -0x838(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x88(%rbp), %rdi
movl $0xa, %edx
callq 0x44520
movl %eax, -0x82c(%rbp)
jmp 0xcf640
movl -0x82c(%rbp), %eax
movl %eax, -0x1b4(%rbp)
leaq -0x1b0(%rbp), %rdi
leaq -0x1b4(%rbp), %rsi
leaq -0x88(%rbp), %rdx
callq 0xd0c70
jmp 0xcf668
movq -0x838(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0xd0c40
movq %rax, -0x840(%rbp)
jmp 0xcf684
movq -0x840(%rbp), %rax
movq %rax, -0x1c0(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0xd0cb0
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
testb $0x1, -0x21(%rbp)
jne 0xcf77c
movq -0x778(%rbp), %rax
movq 0x50(%rax), %rax
cmpl $0x3, 0x1614(%rax)
jb 0xcf71b
movq 0x205884(%rip), %rdi    # 0x2d4f50
leaq 0x10ef37(%rip), %rsi    # 0x1de60a
callq 0x2ff50
movq %rax, -0x848(%rbp)
jmp 0xcf6e1
movq -0x848(%rbp), %rdi
movq 0x2058d9(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xcf6f6
jmp 0xcf71b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0xd0cb0
jmp 0xcfe69
movl -0xc(%rbp), %eax
movl %eax, -0x854(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x850(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x88(%rbp), %rdi
movl $0xa, %edx
callq 0x44520
movl %eax, -0x84c(%rbp)
jmp 0xcf74a
movl -0x84c(%rbp), %ecx
movl -0x850(%rbp), %edx
movl -0x854(%rbp), %esi
movq -0x778(%rbp), %rdi
leaq -0x60(%rbp), %r9
movq %rsp, %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
xorl %r8d, %r8d
callq 0xcd520
jmp 0xcf77a
jmp 0xcf77c
movq -0x778(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0xd0280
jmp 0xcf791
jmp 0xcfe47
movq -0x778(%rbp), %rax
movq 0x50(%rax), %rax
cmpl $0x3, 0x1614(%rax)
jb 0xcf87e
movq 0x20579b(%rip), %rdi    # 0x2d4f50
leaq 0x10ee62(%rip), %rsi    # 0x1de61e
callq 0x2ff50
movq %rax, -0x860(%rbp)
jmp 0xcf7ca
movq -0x860(%rbp), %rdi
movq 0x2057f0(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xcf7df
movq 0x20576a(%rip), %rdi    # 0x2d4f50
leaq 0x10ee51(%rip), %rsi    # 0x1de63e
callq 0x2ff50
movq %rax, -0x868(%rbp)
jmp 0xcf7fb
movq -0x868(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x2f800
movq %rax, -0x870(%rbp)
jmp 0xcf813
movq -0x870(%rbp), %rdi
leaq 0x10ee40(%rip), %rsi    # 0x1de661
callq 0x2ff50
movq %rax, -0x878(%rbp)
jmp 0xcf82f
movq -0x878(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x2f780
movq %rax, -0x880(%rbp)
jmp 0xcf84b
movq -0x880(%rbp), %rdi
leaq 0x112a0d(%rip), %rsi    # 0x1e2266
callq 0x2ff50
movq %rax, -0x888(%rbp)
jmp 0xcf867
movq -0x888(%rbp), %rdi
movq 0x205753(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xcf87c
jmp 0xcf87e
movl -0x64(%rbp), %eax
movl %eax, -0x894(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x890(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x88(%rbp), %rdi
movl $0xa, %edx
callq 0x44520
movl %eax, -0x88c(%rbp)
jmp 0xcf8ad
movl -0x88c(%rbp), %ecx
movl -0x890(%rbp), %edx
movl -0x894(%rbp), %esi
movq -0x778(%rbp), %rdi
leaq -0x60(%rbp), %r9
movq %rsp, %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
xorl %r8d, %r8d
callq 0xcd520
jmp 0xcf8dd
cmpl $0x11, -0x14(%rbp)
jne 0xcfe45
xorl %eax, %eax
movl %eax, %esi
leaq -0x88(%rbp), %rdi
movl $0xa, %edx
callq 0x44520
movl %eax, -0x898(%rbp)
jmp 0xcf904
movl -0x898(%rbp), %eax
cmpl $0xd, %eax
jne 0xcfe45
movq -0x778(%rbp), %rax
movq 0x50(%rax), %rax
cmpl $0x3, 0x1614(%rax)
jb 0xcf972
movq 0x205622(%rip), %rdi    # 0x2d4f50
leaq 0x10ed39(%rip), %rsi    # 0x1de66e
callq 0x2ff50
movq %rax, -0x8a0(%rbp)
jmp 0xcf943
movq -0x8a0(%rbp), %rdi
movl -0x64(%rbp), %esi
callq 0x2f800
movq %rax, -0x8a8(%rbp)
jmp 0xcf95b
movq -0x8a8(%rbp), %rdi
movq 0x20565f(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xcf970
jmp 0xcf972
movq -0x778(%rbp), %rax
movq 0x50(%rax), %rdi
movl -0x64(%rbp), %esi
callq 0x109e60
jmp 0xcf987
movq -0x778(%rbp), %rax
movq 0x50(%rax), %rsi
leaq -0x1d8(%rbp), %rdi
callq 0x101490
jmp 0xcf9a0
leaq -0x1d8(%rbp), %rdi
callq 0xcc840
movq %rax, -0x1e0(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0xcc6d0
movq %rax, -0x1e8(%rbp)
leaq -0x1e0(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0xd0cd0
testb $0x1, %al
jne 0xcf9e2
jmp 0xcfe29
movq -0x778(%rbp), %rax
movq 0x50(%rax), %rax
cmpl $0x3, 0x1614(%rax)
jb 0xcfac7
movq 0x20554f(%rip), %rdi    # 0x2d4f50
leaq 0x10ec7b(%rip), %rsi    # 0x1de683
callq 0x2ff50
movq %rax, -0x8b0(%rbp)
jmp 0xcfa16
leaq -0x1e0(%rbp), %rdi
callq 0xd0d10
movq -0x8b0(%rbp), %rdi
movl (%rax), %esi
callq 0x30640
movq %rax, -0x8b8(%rbp)
jmp 0xcfa39
movq -0x8b8(%rbp), %rdi
movq 0x205581(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xcfa4e
movq 0x2054fb(%rip), %rdi    # 0x2d4f50
leaq 0x10ec55(%rip), %rsi    # 0x1de6b1
callq 0x2ff50
movq %rax, -0x8c0(%rbp)
jmp 0xcfa6a
movq -0x778(%rbp), %rax
movq 0x50(%rax), %rdi
addq $0x1460, %rdi           # imm = 0x1460
callq 0xd0d30
movq -0x8c0(%rbp), %rdi
movq %rax, %rsi
callq 0x30cf0
movq %rax, -0x8c8(%rbp)
jmp 0xcfa99
movq -0x8c8(%rbp), %rdi
movq 0x205521(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xcfaae
jmp 0xcfac7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0xcfe37
leaq -0x218(%rbp), %rdi
callq 0x8de30
leaq -0x1e0(%rbp), %rdi
callq 0xd0d10
movq %rax, %rcx
movq -0x778(%rbp), %rax
movl (%rcx), %ecx
movl %ecx, -0x8d0(%rbp)
movq 0x50(%rax), %rdi
addq $0x15c0, %rdi           # imm = 0x15C0
callq 0x45170
movl -0x8d0(%rbp), %edi
movl %eax, %esi
callq 0x17d3d0
movl %eax, -0x8cc(%rbp)
jmp 0xcfb16
movl -0x8cc(%rbp), %eax
movl %eax, -0x21c(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0xd0d10
movq %rax, %rcx
movq -0x778(%rbp), %rax
movl (%rcx), %ecx
movl %ecx, -0x8d8(%rbp)
movq 0x50(%rax), %rdi
addq $0x15c0, %rdi           # imm = 0x15C0
callq 0x45170
movl -0x8d8(%rbp), %edi
movl %eax, %esi
callq 0x17d3f0
movl %eax, -0x8d4(%rbp)
jmp 0xcfb65
movq -0x778(%rbp), %rax
movl -0x8d4(%rbp), %ecx
movl %ecx, -0x220(%rbp)
movq 0x50(%rax), %rdi
addq $0x15c0, %rdi           # imm = 0x15C0
movslq -0x21c(%rbp), %rsi
callq 0x45190
movq %rax, -0x8e0(%rbp)
jmp 0xcfb98
movq -0x8e0(%rbp), %rax
movq (%rax), %rdi
addq $0x30, %rdi
callq 0x44c70
movq %rax, -0x228(%rbp)
movl $0x0, -0x22c(%rbp)
movq -0x778(%rbp), %rax
movl -0x22c(%rbp), %ecx
movq %rcx, -0x8f0(%rbp)
movq 0x50(%rax), %rdi
addq $0x1460, %rdi           # imm = 0x1460
movl -0x220(%rbp), %eax
movl %eax, -0x230(%rbp)
leaq -0x230(%rbp), %rsi
callq 0xd0d50
movq %rax, -0x8e8(%rbp)
jmp 0xcfbfc
movq -0x8e8(%rbp), %rdi
movl -0x21c(%rbp), %eax
movl %eax, -0x234(%rbp)
leaq -0x234(%rbp), %rsi
callq 0xd0e30
movq %rax, -0x8f8(%rbp)
jmp 0xcfc24
movq -0x8f8(%rbp), %rdi
callq 0xb25c0
movq %rax, %rcx
movq -0x8f0(%rbp), %rax
cmpq %rcx, %rax
jae 0xcfd82
leaq -0x228(%rbp), %rdi
callq 0x44d00
movq %rax, %rcx
movq -0x778(%rbp), %rax
movq %rcx, -0x908(%rbp)
movq 0x50(%rax), %rdi
addq $0x1460, %rdi           # imm = 0x1460
movl -0x220(%rbp), %eax
movl %eax, -0x264(%rbp)
leaq -0x264(%rbp), %rsi
callq 0xd0d50
movq %rax, -0x900(%rbp)
jmp 0xcfc8c
movq -0x900(%rbp), %rdi
movl -0x21c(%rbp), %eax
movl %eax, -0x268(%rbp)
leaq -0x268(%rbp), %rsi
callq 0xd0e30
movq %rax, -0x910(%rbp)
jmp 0xcfcb4
movq -0x910(%rbp), %rdi
movl -0x22c(%rbp), %eax
movl %eax, %esi
callq 0xb2610
movq -0x908(%rbp), %rsi
movq %rax, %rdx
leaq -0x260(%rbp), %rdi
callq 0xd0f10
jmp 0xcfce0
leaq -0x218(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x8e720
movb %dl, -0x919(%rbp)
movq %rax, -0x918(%rbp)
jmp 0xcfd02
movb -0x919(%rbp), %al
movq -0x918(%rbp), %rcx
movq %rcx, -0x278(%rbp)
movb %al, -0x270(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x8e7a0
leaq -0x228(%rbp), %rdi
callq 0x44d20
movl -0x22c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x22c(%rbp)
jmp 0xcfbbc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0xcfe1b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x8e7a0
jmp 0xcfe1b
movq -0x778(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x928(%rbp)
leaq -0x2a8(%rbp), %rdi
leaq -0x218(%rbp), %rsi
callq 0x9c620
jmp 0xcfda9
leaq -0x1e0(%rbp), %rdi
callq 0xd0d10
movq -0x928(%rbp), %rdi
movl (%rax), %edx
leaq -0x2a8(%rbp), %rsi
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0x104010
jmp 0xcfdd4
leaq -0x2a8(%rbp), %rdi
callq 0x8de70
leaq -0x218(%rbp), %rdi
callq 0x8de70
leaq -0x1e0(%rbp), %rdi
callq 0xd0f50
jmp 0xcf9b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x2a8(%rbp), %rdi
callq 0x8de70
leaq -0x218(%rbp), %rdi
callq 0x8de70
jmp 0xcfe37
leaq -0x1d8(%rbp), %rdi
callq 0xb2400
jmp 0xcfe45
leaq -0x1d8(%rbp), %rdi
callq 0xb2400
jmp 0xcfe69
jmp 0xcfe47
jmp 0xcfe58
testb $0x1, -0x15(%rbp)
jne 0xcfe51
jmp 0xcfe58
jmp 0xcfe53
jmp 0xcf072
leaq -0xa8(%rbp), %rdi
callq 0x311e8
jmp 0xd0223
leaq -0xa8(%rbp), %rdi
callq 0x311e8
jmp 0xd025a
movl $0x0, -0x2ac(%rbp)
jmp 0xcfe86
testb $0x1, -0x15(%rbp)
je 0xcfef3
movq -0x778(%rbp), %rdi
addq $0x68, %rdi
movslq -0x10(%rbp), %rsi
callq 0xd0a60
movq (%rax), %rdi
leaq -0x6a0(%rbp), %rsi
movl $0x3e8, %edx            # imm = 0x3E8
leaq -0x2b8(%rbp), %rcx
leaq -0x2ac(%rbp), %r8
callq 0xd0ae0
jmp 0xcfec4
movq -0x2b8(%rbp), %rax
movb $0x0, -0x6a0(%rbp,%rax)
movb $0x0, -0x15(%rbp)
jmp 0xcff5e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0xd025a
movq -0x778(%rbp), %rdi
addq $0x68, %rdi
movslq -0x10(%rbp), %rsi
callq 0xd0a60
movq (%rax), %rdi
leaq -0x6a0(%rbp), %rsi
movl $0x3e8, %edx            # imm = 0x3E8
leaq -0x2b8(%rbp), %rcx
leaq -0x2ac(%rbp), %r8
callq 0xd0f70
movb %al, -0x929(%rbp)
jmp 0xcff31
movb -0x929(%rbp), %al
andb $0x1, %al
movb %al, -0x6a1(%rbp)
movq -0x2b8(%rbp), %rax
movb $0x0, -0x6a0(%rbp,%rax)
testb $0x1, -0x6a1(%rbp)
jne 0xcff5c
jmp 0xd0221
jmp 0xcff5e
leaq -0x709(%rbp), %rdi
movq %rdi, -0x938(%rbp)
callq 0x30a70
movq -0x938(%rbp), %rdx
leaq -0x708(%rbp), %rdi
leaq -0x6a0(%rbp), %rsi
callq 0x44470
jmp 0xcff8d
movq -0x778(%rbp), %rsi
leaq -0x6e8(%rbp), %rdi
leaq -0x708(%rbp), %rdx
callq 0xced70
jmp 0xcffa9
leaq -0x708(%rbp), %rdi
callq 0x311e8
leaq -0x709(%rbp), %rdi
callq 0x311c0
movl $0x1, %edi
callq 0x30ed0
jmp 0xcffcd
cmpl $-0x1, -0x14(%rbp)
je 0xcffff
xorl %eax, %eax
movl %eax, %esi
leaq -0x6e8(%rbp), %rdi
movl $0xa, %edx
callq 0x44520
movl %eax, -0x93c(%rbp)
jmp 0xcfff0
movl -0x93c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0xd016d
cmpl $-0x1, -0xc(%rbp)
je 0xd0014
movl -0xc(%rbp), %eax
cmpl -0x6c4(%rbp), %eax
jne 0xd016d
cmpl $-0x1, 0x18(%rbp)
je 0xd0029
movl 0x18(%rbp), %eax
cmpl -0x6c8(%rbp), %eax
jne 0xd016d
movq -0x20(%rbp), %rax
movq %rax, -0x948(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x6e8(%rbp), %rdi
movl $0xa, %edx
callq 0x44520
movl %eax, -0x940(%rbp)
jmp 0xd0051
movl -0x940(%rbp), %eax
movl %eax, -0x75c(%rbp)
leaq -0x758(%rbp), %rdi
leaq -0x75c(%rbp), %rsi
leaq -0x6e8(%rbp), %rdx
callq 0xd0c70
jmp 0xd0079
movq -0x948(%rbp), %rdi
leaq -0x758(%rbp), %rsi
callq 0xd0c40
movq %rax, -0x950(%rbp)
jmp 0xd0095
movq -0x950(%rbp), %rax
movq %rax, -0x768(%rbp)
leaq -0x758(%rbp), %rdi
callq 0xd0cb0
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
testb $0x1, -0x21(%rbp)
jne 0xd016b
movq -0x778(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movl -0x14(%rbp), %ecx
leaq -0x6c0(%rbp), %r9
movq %rsp, %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
xorl %r8d, %r8d
callq 0xcd520
jmp 0xd00ec
jmp 0xd016b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0xd0120
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x708(%rbp), %rdi
callq 0x311e8
leaq -0x709(%rbp), %rdi
callq 0x311c0
jmp 0xd025a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0xd0213
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x758(%rbp), %rdi
callq 0xd0cb0
jmp 0xd0213
jmp 0xd01ea
movl -0x6c4(%rbp), %eax
movl %eax, -0x95c(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x958(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x6e8(%rbp), %rdi
movl $0xa, %edx
callq 0x44520
movl %eax, -0x954(%rbp)
jmp 0xd019f
movl -0x954(%rbp), %ecx
movl -0x958(%rbp), %edx
movl -0x95c(%rbp), %esi
movq -0x778(%rbp), %rdi
leaq -0x6c0(%rbp), %r9
movl -0x6c8(%rbp), %r8d
movq %rsp, %rax
movl %r8d, (%rax)
xorl %r8d, %r8d
callq 0xcd520
jmp 0xd01d6
testb $0x1, -0x15(%rbp)
jne 0xd01e8
movl $0xb, -0x76c(%rbp)
jmp 0xd01f4
jmp 0xd01ea
movl $0x0, -0x76c(%rbp)
leaq -0x6e8(%rbp), %rdi
callq 0xc1f00
movl -0x76c(%rbp), %eax
testl %eax, %eax
je 0xd020e
jmp 0xd020c
jmp 0xd0221
jmp 0xcfe84
leaq -0x6e8(%rbp), %rdi
callq 0xc1f00
jmp 0xd025a
jmp 0xd0223
movl -0x28(%rbp), %eax
movl %eax, -0x960(%rbp)
movl $0x1, -0x76c(%rbp)
leaq -0x88(%rbp), %rdi
callq 0xc1f00
leaq -0x48(%rbp), %rdi
callq 0x311e8
movl -0x960(%rbp), %eax
addq $0x970, %rsp            # imm = 0x970
popq %rbp
retq
leaq -0x88(%rbp), %rdi
callq 0xc1f00
leaq -0x48(%rbp), %rdi
callq 0x311e8
movq -0xd0(%rbp), %rdi
callq 0x30170
nopl (%rax,%rax)