// File: /workspace/github_cpp_makefile_star2_O2/richardposner[P]BioNetFit2/src/code/Swarm.cpp
// Function: Swarm::processLateParticles(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, double, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, double>>>, int, bool, int)
void Swarm::processLateParticles(map<string, double> simParams_, int subParID, bool breed, int currGen) {

		//int found = 0;
			//for(auto i = 1; i<=options.swarmSize; i++){
			//	found = 0;
				//for(auto k = 0; k<options.models.size(); k++){
				//	for(auto j = finishedSubParticles_.begin(); j != finishedSubParticles_.end(); ++j){
						//subParID = fcalcsubParID(i, k, options.models.size());
					//	if(subParID == *j){
							//found = 1;

//						}

	//				}

		if(currGen==0){
			currGen = currentGeneration;

		}
	//
					//if(found==0){
		int pID = fcalcParID(subParID, options.models.size());
		int mid = fcalcMID(subParID, options.models.size());


						map<string, double> paramSet;

							vector<string> paramVals;
							vector<string> paramVecStr;

							//auto best = allGenFits.begin();

							//allGenFits.insert(pair<double, string>(fitCalc, order_params(paramsString, mid)));
							//swarmBestFits_.insert(pair<double, unsigned int>(fitCalc, pID));
							//subswarmBestFits_.insert(pair<double, unsigned int>(fitCalc, subParID));
							//currentsubswarmBestFits_.insert(pair<double, unsigned int>(fitCalc, subParID));

							int bestSP = 0;
							int bestMD = -1;
							int bestP = 0;

							//int mysize = subparticleBestFits_.size();
							//cout << "SIZE1 " << mysize << endl;
							//mysize = swarmBestFits_.size();
							//cout << "SIZE2 " << mysize << endl;

							if(simParams_.size()==0){

								//Raquel: we gotta fix this, make this loop work and discover why the variables are getting erased.
								for(auto pi = subparticleBestFits_.begin(); pi != subparticleBestFits_.end(); pi++){

									bestMD = fcalcMID(pi->second, options.models.size());
									if(bestMD == mid){
										bestSP = pi->second;
										bestP = fcalcParID(bestSP, options.models.size());
										break;
									}

								}


								//split(best->second, paramVals);

								auto fp = options.models.at(mid)->freeParams_.begin();
								for (unsigned int i = 1; i < subparticleCurrParamSets_[pID][mid].size(); i++) {
									//paramSet.insert(pair<string, double> (fp->first, subparticleCurrParamSets_[bestP][mid][i])); //make this work later, to clone the best particle
									paramSet.insert(pair<string, double> (fp->first, subparticleCurrParamSets_[pID][mid][i]));

									++fp;

									paramVecStr.push_back(toString(subparticleCurrParamSets_[bestP][mid][i]));
								}




							}else{

								for (auto i = simParams_.begin(); i != simParams_.end(); ++i) {
									//paramSet.insert(pair<string, double> (fp->first, subparticleCurrParamSets_[bestP][mid][i])); //make this work later, to clone the best particle
									paramSet.insert(pair<string, double> (i->first, i->second));

									paramVecStr.push_back(toString(i->second));
								}
							}

							if(breed){
								swarmComm->sendToSwarm(0, subParID, SEND_FINAL_PARAMS_TO_PARTICLE, false, paramVecStr);
							}
							if(options.verbosity>=3){
								cout << "@@@@@@@@@@@@@@@@@@@@@@@@ LATE SUBPARTICLE " << subParID << " @@@@@@@@@@@@@@@@@@@@@@@@@@@" << " paramvals size: " << paramVals.size() << " freeparam names size: " << options.models.at(mid)->freeParams_.size() << endl;
							}
							for (unsigned int r = 1; r <= options.smoothing; ++r) {
								string outputDir = options.jobOutputDir + toString(currGen) + "/";
								string bnglFilename = getModelName(mid, false)+"_" + toString(pID) + "_" + toString(r) + ".bngl";
								string suffix = toString(pID) + "_" + toString(r) ;
								//options.models[mid]->outputModelWithParams(paramSet, outputDir, bnglFilename, suffix, false, false, true, false, false);

								if (options.models[mid]->getHasGenerateNetwork()){
									// If we're using ODE solver, output .net file
									bnglFilename = boost::regex_replace(bnglFilename, boost::regex("bngl$"), string("net"));
									options.models[mid]->outputModelWithParams(simParams_, outputDir, bnglFilename, suffix,  false, false, true, false, false);
								}
								else {
									// If we're using network free simulation, output .bngl
									options.models[mid]->outputModelWithParams(simParams_, outputDir, bnglFilename, suffix, false, false, false, false, false);
								}


							}
						/*if(breed){
							int numFinishedBreeding = 0;
							while (numFinishedBreeding == 0) {
									if(options.verbosity>=3){

										cout << "checking for DONEBREED FOR LATE PARTICLE " << subParID << endl;
									}
									unsigned int numMessages = swarmComm->recvMessage(-1, 0, DONE_BREEDING, true, swarmComm->univMessageReceiver, true);

							//		int Pheromones::recvMessage(signed int senderID, const int receiverID, int tag, bool block, swarmMsgHolder &messageHolder, bool eraseMessage, int messageID) {

									numFinishedBreeding += numMessages;
									//cout << numFinishedBreeding << endl;
									if(options.verbosity>=3){

										cout << "RAQUEL numFinishedBreeding " << numFinishedBreeding << endl;
									}
							}
						}*/
					//}
				//}

			//}

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x318, %rsp            # imm = 0x318
movl %ecx, %r13d
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %r15
movl %r8d, 0x1c(%rsp)
testl %r8d, %r8d
jne 0x787f5
movl 0x13e8(%r15), %eax
movl %eax, 0x1c(%rsp)
leaq 0x15c0(%r15), %rax
movq %rax, 0x20(%rsp)
movq 0x15c8(%r15), %rsi
subq 0x15c0(%r15), %rsi
shrq $0x3, %rsi
movl %ebp, %edi
callq 0x9ec1e
movl %eax, 0xc(%rsp)
movq 0x15c8(%r15), %rsi
subq 0x15c0(%r15), %rsi
shrq $0x3, %rsi
movl %ebp, %edi
callq 0x9ec14
movl %eax, 0x8(%rsp)
leaq 0x150(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
xorps %xmm0, %xmm0
andq $0x0, 0xc0(%rsp)
movaps %xmm0, 0xb0(%rsp)
andq $0x0, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
xorl %eax, %eax
cmpq %rax, 0x28(%r12)
movq %r15, 0x40(%rsp)
movq %r12, 0x38(%rsp)
movl %ebp, 0x28(%rsp)
movl %r13d, 0x34(%rsp)
je 0x78915
movq 0x18(%r12), %r15
leaq 0x8(%r12), %rbp
leaq 0x68(%rsp), %rbx
leaq 0x148(%rsp), %r14
leaq 0x90(%rsp), %r12
cmpq %rbp, %r15
je 0x78aaf
leaq 0x20(%r15), %rsi
leaq 0x40(%r15), %r13
movq %rbx, %rdi
movq %r13, %rdx
callq 0x61e52
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4bce2
movq %rbx, %rdi
callq 0x295a0
movsd (%r13), %xmm0
movq %rbx, %rdi
callq 0x9f57b
movq %r12, %rdi
movq %rbx, %rsi
callq 0x5ec8c
movq %rbx, %rdi
callq 0x295a0
movq %r15, %rdi
callq 0x28700
movq %rax, %r15
jmp 0x788b8
movq 0x1a68(%r15), %rbx
leaq 0x1a58(%r15), %r14
cmpq %r14, %rbx
je 0x78958
cvttsd2si 0x28(%rbx), %rdi
movq 0x15c8(%r15), %rsi
subq 0x15c0(%r15), %rsi
shrq $0x3, %rsi
callq 0x9ec14
cmpl 0x8(%rsp), %eax
je 0x78962
movq %rbx, %rdi
callq 0x28700
movq %rax, %rbx
jmp 0x78923
movl $0x0, 0x10(%rsp)
jmp 0x78982
cvttsd2si 0x28(%rbx), %edi
movq 0x15c8(%r15), %rsi
subq 0x15c0(%r15), %rsi
shrq $0x3, %rsi
callq 0x9ec1e
movl %eax, 0x10(%rsp)
movslq 0x8(%rsp), %rsi
movq 0x20(%rsp), %rdi
callq 0x3374c
movq (%rax), %rax
movq 0x48(%rax), %r13
addq $0x1460, %r15           # imm = 0x1460
pushq $0x1
popq %r14
leaq 0x68(%rsp), %r12
leaq 0x48(%rsp), %rbp
leaq 0x128(%rsp), %rbx
movl 0xc(%rsp), %eax
movl %eax, 0x68(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x61db6
movl 0x8(%rsp), %ecx
movl %ecx, 0x48(%rsp)
movq %rax, %rdi
movq %rbp, %rsi
callq 0x61e04
movl %r14d, %r14d
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x3, %rcx
cmpq %r14, %rcx
jbe 0x78aaf
movl 0xc(%rsp), %eax
movl %eax, 0x48(%rsp)
movq %r15, %rdi
movq %rbp, %rsi
callq 0x61db6
movl 0x8(%rsp), %ecx
movl %ecx, 0x128(%rsp)
movq %rax, %rdi
movq %rbx, %rsi
callq 0x61e04
leaq 0x20(%r13), %rsi
leaq (,%r14,8), %rdx
addq (%rax), %rdx
movq %r12, %rdi
callq 0x61e52
leaq 0x148(%rsp), %rdi
movq %r12, %rsi
callq 0x4bce2
movq %r12, %rdi
callq 0x295a0
movq %r13, %rdi
callq 0x28700
movq %rax, %r13
movl 0x10(%rsp), %eax
movl %eax, 0x48(%rsp)
movq %r15, %rdi
movq %rbp, %rsi
callq 0x61db6
movl 0x8(%rsp), %ecx
movl %ecx, 0x128(%rsp)
movq %rax, %rdi
movq %rbx, %rsi
callq 0x61e04
movq (%rax), %rax
movsd (%rax,%r14,8), %xmm0
movq %r12, %rdi
callq 0x9f57b
leaq 0x90(%rsp), %rdi
movq %r12, %rsi
callq 0x5ec8c
movq %r12, %rdi
callq 0x295a0
incl %r14d
jmp 0x789b5
cmpb $0x0, 0x34(%rsp)
movq 0x40(%rsp), %r15
movl 0x28(%rsp), %ebx
je 0x78ae3
movq (%r15), %rdi
subq $0x10, %rsp
orl $-0x1, (%rsp)
pushq $0x15
popq %rcx
leaq 0xa0(%rsp), %r9
xorl %esi, %esi
movl %ebx, %edx
xorl %r8d, %r8d
callq 0x600c8
popq %rax
popq %rcx
cmpl $0x2, 0x1614(%r15)
jbe 0x78b87
movq 0xed4a0(%rip), %rdi     # 0x165f98
leaq 0x64d9e(%rip), %rsi     # 0xdd89d
callq 0x289f0
movq %rax, %rdi
movl %ebx, %esi
callq 0x29290
leaq 0x64db3(%rip), %rsi     # 0xdd8c8
movq %rax, %rdi
callq 0x289f0
leaq 0x64dc1(%rip), %rsi     # 0xdd8e5
movq %rax, %rdi
callq 0x289f0
movq 0xb8(%rsp), %rsi
subq 0xb0(%rsp), %rsi
sarq $0x5, %rsi
movq %rax, %rdi
callq 0x286e0
leaq 0x64da8(%rip), %rsi     # 0xdd8f7
movq %rax, %rdi
callq 0x289f0
movq %rax, %rbx
movslq 0x8(%rsp), %rsi
movq 0x20(%rsp), %rdi
movq %rsi, 0x10(%rsp)
callq 0x3374c
movq (%rax), %rax
movq 0x58(%rax), %rsi
movq %rbx, %rdi
callq 0x286e0
movq %rax, %rdi
callq 0x284a0
jmp 0x78b91
movslq 0x8(%rsp), %rax
movq %rax, 0x10(%rsp)
pushq $0x1
popq %r14
leaq 0x1520(%r15), %rax
movq %rax, 0x28(%rsp)
leaq 0x128(%rsp), %r12
cmpl 0x1658(%r15), %r14d
ja 0x78f69
movq %r12, %rdi
movl 0x1c(%rsp), %esi
callq 0x9e9c3
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
movq %r12, %rdx
callq 0x5a115
leaq 0x68(%rsp), %rdi
movq %rbx, %rsi
leaq 0x64dd1(%rip), %rdx     # 0xdd9b7
callq 0x3336c
movq %rbx, %rdi
callq 0x295a0
movq %r12, %rdi
callq 0x295a0
leaq 0x2f8(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movl 0x8(%rsp), %edx
xorl %ecx, %ecx
callq 0x6bd9a
leaq 0xc8(%rsp), %rdi
movq %rbx, %rsi
leaq 0x5d141(%rip), %r15     # 0xd5d67
movq %r15, %rdx
callq 0x3336c
leaq 0x218(%rsp), %r13
movq %r13, %rdi
movl 0xc(%rsp), %esi
callq 0x9e9c3
leaq 0xe8(%rsp), %rbp
movq %rbp, %rdi
leaq 0xc8(%rsp), %rsi
movq %r13, %rdx
callq 0x4e6ed
leaq 0x108(%rsp), %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x3336c
leaq 0x1f8(%rsp), %r13
movq %r13, %rdi
movl %r14d, %esi
callq 0x9f56b
movq %r12, %rdi
leaq 0x108(%rsp), %rsi
movq %r13, %rdx
callq 0x4e6ed
leaq 0x48(%rsp), %rdi
movq %r12, %rsi
leaq 0x5e57e(%rip), %rdx     # 0xd7223
callq 0x3336c
movq %r12, %rdi
callq 0x295a0
leaq 0x1f8(%rsp), %rdi
callq 0x295a0
leaq 0x108(%rsp), %rbp
movq %rbp, %rdi
callq 0x295a0
leaq 0xe8(%rsp), %r13
movq %r13, %rdi
callq 0x295a0
leaq 0x218(%rsp), %rdi
callq 0x295a0
leaq 0xc8(%rsp), %rdi
callq 0x295a0
movq %rbx, %rdi
callq 0x295a0
movq %r13, %rdi
movl 0xc(%rsp), %esi
callq 0x9e9c3
movq %rbp, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x3336c
leaq 0xc8(%rsp), %rbx
movq %rbx, %rdi
movl %r14d, %esi
callq 0x9f56b
movq %r12, %rdi
leaq 0x108(%rsp), %r13
movq %r13, %rsi
movq %rbx, %rdx
callq 0x4e6ed
leaq 0xe8(%rsp), %r15
movq %rbx, %rdi
callq 0x295a0
movq %r13, %rdi
callq 0x295a0
movq %r15, %rdi
callq 0x295a0
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rsp), %rcx
movq %r15, %rbx
movq (%rax,%rcx,8), %r15
cmpb $0x1, 0xb8(%r15)
jne 0x78e9c
movq %rbx, %rdi
leaq 0x5d10e(%rip), %rsi     # 0xd5e9e
xorl %edx, %edx
callq 0x33278
movq %rbx, %r15
leaq 0x2d8(%rsp), %rbp
movq %rbp, %rdi
leaq 0x5db9a(%rip), %rsi     # 0xd6946
leaq 0xc8(%rsp), %rdx
callq 0x33402
leaq 0x108(%rsp), %r13
movq %r13, %rdi
leaq 0x48(%rsp), %rbx
movq %rbx, %rsi
movq %r15, %rdx
movq %rbp, %rcx
xorl %r8d, %r8d
callq 0x4926c
movq %rbx, %rdi
movq %r13, %rsi
callq 0x28c40
movq %r13, %rdi
callq 0x295a0
movq %rbp, %rdi
callq 0x295a0
leaq 0xf0(%rsp), %rdi
callq 0x33e80
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %r15
leaq 0x2a8(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x4e96a
leaq 0x1d8(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x28dd0
leaq 0x1b8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x28dd0
leaq 0x288(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
callq 0x28dd0
movq %r15, %rdi
leaq 0x2a8(%rsp), %r15
movq %r15, %rsi
leaq 0x1d8(%rsp), %r13
movq %r13, %rdx
leaq 0x1b8(%rsp), %rbx
movq %rbx, %rcx
movq %rbp, %r8
xorl %r9d, %r9d
pushq $0x0
pushq $0x0
pushq $0x1
pushq $0x0
callq 0x4cf22
addq $0x20, %rsp
jmp 0x78f20
leaq 0x258(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x4e96a
leaq 0x198(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x28dd0
leaq 0x178(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x28dd0
leaq 0x238(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
callq 0x28dd0
movq %r15, %rdi
leaq 0x258(%rsp), %r15
movq %r15, %rsi
leaq 0x198(%rsp), %r13
movq %r13, %rdx
leaq 0x178(%rsp), %rbx
movq %rbx, %rcx
movq %rbp, %r8
xorl %r9d, %r9d
pushq $0x0
pushq $0x0
pushq $0x0
pushq $0x0
callq 0x4cf22
addq $0x20, %rsp
movq %rbp, %rdi
callq 0x295a0
movq %rbx, %rdi
callq 0x295a0
movq %r13, %rdi
callq 0x295a0
movq %r15, %rdi
callq 0x495ac
movq %r12, %rdi
callq 0x295a0
leaq 0x48(%rsp), %rdi
callq 0x295a0
leaq 0x68(%rsp), %rdi
callq 0x295a0
incl %r14d
movq 0x40(%rsp), %r15
jmp 0x78ba9
leaq 0x90(%rsp), %rdi
callq 0x3355a
leaq 0xb0(%rsp), %rdi
callq 0x3355a
leaq 0x148(%rsp), %rdi
callq 0x495ac
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x79144
jmp 0x79144
jmp 0x79144
jmp 0x79144
jmp 0x79144
jmp 0x7909a
jmp 0x79144
jmp 0x7909a
jmp 0x79144
jmp 0x79144
movq %rax, %rbx
jmp 0x79012
movq %rax, %rbx
leaq 0x238(%rsp), %rdi
callq 0x295a0
jmp 0x79005
movq %rax, %rbx
jmp 0x7903e
movq %rax, %rbx
jmp 0x7907f
movq %rax, %rbx
jmp 0x79065
movq %rax, %rbx
jmp 0x7901f
movq %rax, %rbx
leaq 0x178(%rsp), %rdi
callq 0x295a0
leaq 0x198(%rsp), %rdi
callq 0x295a0
leaq 0x258(%rsp), %rdi
jmp 0x79087
jmp 0x790d3
movq %rax, %rbx
leaq 0x2d8(%rsp), %rdi
callq 0x295a0
leaq 0xf0(%rsp), %rdi
callq 0x33e80
jmp 0x790d6
movq %rax, %rbx
jmp 0x79072
movq %rax, %rbx
leaq 0x288(%rsp), %rdi
callq 0x295a0
leaq 0x1b8(%rsp), %rdi
callq 0x295a0
leaq 0x1d8(%rsp), %rdi
callq 0x295a0
leaq 0x2a8(%rsp), %rdi
callq 0x495ac
jmp 0x790d6
jmp 0x79144
jmp 0x7909a
jmp 0x79144
movq %rax, %rbx
jmp 0x7919a
jmp 0x79144
jmp 0x79144
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x295a0
jmp 0x7914c
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x295a0
jmp 0x791d6
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
jmp 0x79129
movq %rax, %rbx
jmp 0x7912e
movq %rax, %rbx
jmp 0x7919a
movq %rax, %rbx
jmp 0x79121
movq %rax, %rbx
jmp 0x7918d
movq %rax, %rbx
jmp 0x79114
movq %rax, %rbx
jmp 0x79180
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x295a0
leaq 0x108(%rsp), %rdi
callq 0x295a0
leaq 0xe8(%rsp), %rdi
callq 0x295a0
leaq 0x48(%rsp), %rdi
jmp 0x79195
movq %rax, %rbx
jmp 0x79173
movq %rax, %rbx
jmp 0x79166
movq %rax, %rbx
jmp 0x79159
movq %rax, %rbx
jmp 0x791a4
movq %rax, %rbx
leaq 0x1f8(%rsp), %rdi
callq 0x295a0
leaq 0x108(%rsp), %rdi
callq 0x295a0
leaq 0xe8(%rsp), %rdi
callq 0x295a0
leaq 0x218(%rsp), %rdi
callq 0x295a0
leaq 0xc8(%rsp), %rdi
callq 0x295a0
leaq 0x2f8(%rsp), %rdi
callq 0x295a0
leaq 0x68(%rsp), %rdi
callq 0x295a0
leaq 0x90(%rsp), %rdi
callq 0x3355a
leaq 0xb0(%rsp), %rdi
callq 0x3355a
leaq 0x148(%rsp), %rdi
callq 0x495ac
movq %rbx, %rdi
callq 0x292f0
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
jmp 0x7919f