// File: /workspace/github_cpp_makefile_star2_O2/richardposner[P]BioNetFit2/src/code/Swarm.cpp
// Function: Swarm::launchSubParticle(unsigned int, unsigned int, bool)
void Swarm::launchSubParticle(unsigned int pID, unsigned int mid, bool nextGen) {

	//calculate new particle number
	unsigned int subParID = (pID - 1)* options.models.size()+ mid + 1;
	if (options.verbosity>= 3) {
		cout << "RAQUEL launchSUB suParID: " << subParID << endl;
	}
#ifdef TEST_SIMULATOR
//	if (subParID!=3){
//		cout<<"For test all subParticles are avoided except 3. Uncomment later.\n";
//		return;
//	}
#endif
	if (options.verbosity>= 1) {
		cout << "currentGeneration: " << currentGeneration << " options.useCluster: " << options.useCluster << " nextGen: " << nextGen << " bootstrapCounter: " << bootstrapCounter << endl;
	}
	if (currentGeneration == 1 && !options.useCluster && !nextGen && bootstrapCounter == 0) {

		// Construct command needed to run the particle
		//unsigned int mid = getParticleModelId(pID);

		string command = exePath_ + " -v -t particle -p " + toString(subParID) + " -a run -g " + toString(currentGeneration) + " -c " + sConf_[mid] + " -e " + expPaths_[mid][0];  //razi: consider more than 1 exp
		command = command + " -n " + toString(this->getNumModels());
command = command + " >> pOUT 2>&1";
		command = command + " &";

		//just for test, later uncomment
		if (options.verbosity >= 3) {
			cout << "Running SubParticle:"<<subParID<<"[" << pID <<"-"<< mid<<"] using command: "<< command << endl; //razi changed to show the command, was cout << "Running Particle " << pID <<endl;
		}

		if (runCommand(command) != 0) {
			cout << "Warning: Couldn't launch SubParticle:"<<subParID<<"[" << pID <<"-"<< mid<<"]  with command: " << command <<  endl;
			failedParticles_.insert(pID);
			failedSubParticles_.insert(subParID); //razi: add, later check consistency between the two lists
			return;
		}
	}
	if (options.verbosity >= 3) {
		cout << "Adding subparticle " << subParID << " to the list of running particles." << endl;
	}
	runningSubParticles_.insert(subParID); //razi: was //runningParticles_.insert(pID);
	//cout << "RAQUEL sending message to supar" << subParID << "message=NEXT_GEN" << endl;
	swarmComm->sendToSwarm(0, subParID, NEXT_GENERATION, false, swarmComm->univMessageSender);
	if (options.verbosity >= 3) cout << "Launching SubParticle:"<<subParID<<"[" << pID <<"-"<< mid<<"] finished, hence it is active now...\n\n";
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x180, %rsp            # imm = 0x180
movl %ecx, %ebp
movl %esi, %r14d
movq %rdi, %rbx
movl %esi, 0x1c(%rsp)
movl %edx, 0x18(%rsp)
leal -0x1(%r14), %eax
movq 0x15c8(%rdi), %rcx
subq 0x15c0(%rdi), %rcx
shrq $0x3, %rcx
imull %eax, %ecx
leal (%rdx,%rcx), %r15d
incl %r15d
movl %r15d, 0x14(%rsp)
movl 0x1614(%rdi), %eax
cmpl $0x3, %eax
jb 0x7657d
movq 0xefa40(%rip), %rdi     # 0x165f98
leaq 0x66f41(%rip), %rsi     # 0xdd4a0
callq 0x289f0
movl %r15d, %esi
movq %rax, %rdi
callq 0x286e0
movq %rax, %rdi
callq 0x284a0
movl 0x1614(%rbx), %eax
testl %eax, %eax
je 0x76600
movq 0xefa10(%rip), %rdi     # 0x165f98
leaq 0x66f2c(%rip), %rsi     # 0xdd4bb
callq 0x289f0
movl 0x13e8(%rbx), %esi
movq %rax, %rdi
callq 0x286e0
leaq 0x66f26(%rip), %rsi     # 0xdd4cf
movq %rax, %rdi
callq 0x289f0
movzbl 0x1631(%rbx), %esi
movq %rax, %rdi
callq 0x29180
leaq 0x66f1e(%rip), %rsi     # 0xdd4e5
movq %rax, %rdi
callq 0x289f0
movzbl %bpl, %esi
movq %rax, %rdi
callq 0x29180
leaq 0x66f0e(%rip), %rsi     # 0xdd4f0
movq %rax, %rdi
callq 0x289f0
movl 0x13ec(%rbx), %esi
movq %rax, %rdi
callq 0x286e0
movq %rax, %rdi
callq 0x284a0
cmpl $0x1, 0x13e8(%rbx)
movl %r14d, %r14d
jne 0x769f9
cmpb $0x0, 0x1631(%rbx)
jne 0x769f9
testb %bpl, %bpl
jne 0x769f9
cmpl $0x0, 0x13ec(%rbx)
jne 0x769f9
leaq 0x17e0(%rbx), %rsi
leaq 0x66ec3(%rip), %rdx     # 0xdd504
leaq 0x100(%rsp), %rdi
callq 0x334ed
movl 0x14(%rsp), %esi
leaq 0xe0(%rsp), %rdi
callq 0x9f56b
leaq 0x120(%rsp), %rdi
leaq 0x100(%rsp), %rsi
leaq 0xe0(%rsp), %rdx
callq 0x4e6ed
leaq 0x66e95(%rip), %rdx     # 0xdd518
leaq 0x140(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x3336c
movl 0x13e8(%rbx), %esi
leaq 0xc0(%rsp), %rdi
callq 0x9f56b
leaq 0x160(%rsp), %rdi
leaq 0x140(%rsp), %rsi
leaq 0xc0(%rsp), %rdx
callq 0x4e6ed
leaq 0x67cbb(%rip), %rdx     # 0xde38a
leaq 0x60(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x3336c
movl 0x18(%rsp), %edx
shlq $0x5, %rdx
addq 0x1938(%rbx), %rdx
leaq 0x80(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x334ce
leaq 0x8a07f(%rip), %rdx     # 0x100788
leaq 0x40(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x3336c
leaq 0x1908(%rbx), %rdi
leaq 0x18(%rsp), %rsi
callq 0x5ab04
movq (%rax), %rdx
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x334ce
leaq 0x40(%rsp), %rdi
callq 0x295a0
leaq 0x80(%rsp), %rdi
callq 0x295a0
leaq 0x60(%rsp), %rdi
callq 0x295a0
leaq 0x160(%rsp), %rdi
callq 0x295a0
leaq 0xc0(%rsp), %rdi
callq 0x295a0
leaq 0x140(%rsp), %rdi
callq 0x295a0
leaq 0x120(%rsp), %rdi
callq 0x295a0
leaq 0xe0(%rsp), %rdi
callq 0x295a0
leaq 0x100(%rsp), %rdi
callq 0x295a0
leaq 0x66d70(%rip), %rdx     # 0xdd524
leaq 0x80(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x334ed
movq 0x15c8(%rbx), %rsi
subq 0x15c0(%rbx), %rsi
shrq $0x3, %rsi
leaq 0x60(%rsp), %rdi
callq 0x9f56b
leaq 0x40(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0x60(%rsp), %rdx
callq 0x4e6ed
leaq 0x20(%rsp), %r15
leaq 0x40(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x28c40
movq %r12, %rdi
callq 0x295a0
leaq 0x60(%rsp), %rdi
callq 0x295a0
leaq 0x80(%rsp), %rdi
callq 0x295a0
leaq 0x66cf5(%rip), %rdx     # 0xdd529
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x334ed
leaq 0x20(%rsp), %r15
leaq 0x40(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x28c40
movq %r12, %rdi
callq 0x295a0
leaq 0x60299(%rip), %rdx     # 0xd6afe
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x334ed
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %r15
movq %r15, %rsi
callq 0x28c40
movq %r15, %rdi
callq 0x295a0
cmpl $0x3, 0x1614(%rbx)
jb 0x7690d
movq 0xef6fc(%rip), %rdi     # 0x165f98
leaq 0x66c94(%rip), %rsi     # 0xdd537
callq 0x289f0
movl 0x14(%rsp), %esi
movq %rax, %rdi
callq 0x286e0
leaq 0x674ad(%rip), %rsi     # 0xddd68
movq %rax, %rdi
callq 0x289f0
movq %rax, %rdi
movq %r14, %rsi
callq 0x286e0
leaq 0x68f95(%rip), %rsi     # 0xdf86a
movq %rax, %rdi
callq 0x289f0
movl 0x18(%rsp), %esi
movq %rax, %rdi
callq 0x286e0
leaq 0x66c5c(%rip), %rsi     # 0xdd54c
movq %rax, %rdi
callq 0x289f0
leaq 0x20(%rsp), %rsi
movq %rax, %rdi
callq 0x28910
movq %rax, %rdi
callq 0x284a0
leaq 0xa0(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x28dd0
leaq 0xa0(%rsp), %rdi
callq 0x9f543
movl %eax, %ebp
leaq 0xa0(%rsp), %rdi
callq 0x295a0
testl %ebp, %ebp
je 0x769ef
movq 0xef64e(%rip), %rdi     # 0x165f98
leaq 0x66c0d(%rip), %rsi     # 0xdd55e
callq 0x289f0
movl 0x14(%rsp), %esi
movq %rax, %rdi
callq 0x286e0
leaq 0x673ff(%rip), %rsi     # 0xddd68
movq %rax, %rdi
callq 0x289f0
movq %rax, %rdi
movq %r14, %rsi
callq 0x286e0
leaq 0x68ee7(%rip), %rsi     # 0xdf86a
movq %rax, %rdi
callq 0x289f0
movl 0x18(%rsp), %esi
movq %rax, %rdi
callq 0x286e0
leaq 0x66be6(%rip), %rsi     # 0xdd584
movq %rax, %rdi
callq 0x289f0
leaq 0x20(%rsp), %rsi
movq %rax, %rdi
callq 0x28910
movq %rax, %rdi
callq 0x284a0
leaq 0x19d0(%rbx), %rdi
leaq 0x1c(%rsp), %rsi
callq 0x8f830
addq $0x1858, %rbx           # imm = 0x1858
leaq 0x14(%rsp), %rsi
movq %rbx, %rdi
callq 0x8f830
leaq 0x20(%rsp), %rdi
callq 0x295a0
jmp 0x76ad2
leaq 0x20(%rsp), %rdi
callq 0x295a0
cmpl $0x3, 0x1614(%rbx)
jb 0x76a38
movq 0xef58f(%rip), %rdi     # 0x165f98
leaq 0x66b86(%rip), %rsi     # 0xdd596
callq 0x289f0
movl 0x14(%rsp), %esi
movq %rax, %rdi
callq 0x286e0
leaq 0x66b82(%rip), %rsi     # 0xdd5aa
movq %rax, %rdi
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
leaq 0x1820(%rbx), %rdi
leaq 0x14(%rsp), %r15
movq %r15, %rsi
callq 0x8f830
movq (%rbx), %rdi
movl (%r15), %edx
orl $-0x1, (%rsp)
pushq $0x12
popq %rcx
xorl %esi, %esi
xorl %r8d, %r8d
movq %rdi, %r9
callq 0x600c8
cmpl $0x3, 0x1614(%rbx)
jb 0x76ad2
movq 0xef522(%rip), %rdi     # 0x165f98
leaq 0x66b50(%rip), %rsi     # 0xdd5cd
callq 0x289f0
movl 0x14(%rsp), %esi
movq %rax, %rdi
callq 0x286e0
leaq 0x672d3(%rip), %rsi     # 0xddd68
movq %rax, %rdi
callq 0x289f0
movq %rax, %rdi
movq %r14, %rsi
callq 0x286e0
leaq 0x68dbb(%rip), %rsi     # 0xdf86a
movq %rax, %rdi
callq 0x289f0
movl 0x18(%rsp), %esi
movq %rax, %rdi
callq 0x286e0
leaq 0x66b1a(%rip), %rsi     # 0xdd5e4
movq %rax, %rdi
callq 0x289f0
addq $0x180, %rsp            # imm = 0x180
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
jmp 0x76b13
jmp 0x76bb9
jmp 0x76bb9
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x295a0
jmp 0x76b0b
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x295a0
jmp 0x76bbc
jmp 0x76bb9
movq %rax, %rbx
jmp 0x76b57
movq %rax, %rbx
jmp 0x76b64
movq %rax, %rbx
jmp 0x76b6e
movq %rax, %rbx
jmp 0x76b7b
movq %rax, %rbx
jmp 0x76b88
movq %rax, %rbx
jmp 0x76b95
movq %rax, %rbx
jmp 0x76ba2
movq %rax, %rbx
jmp 0x76baf
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x295a0
leaq 0x80(%rsp), %rdi
callq 0x295a0
leaq 0x60(%rsp), %rdi
callq 0x295a0
leaq 0x160(%rsp), %rdi
callq 0x295a0
leaq 0xc0(%rsp), %rdi
callq 0x295a0
leaq 0x140(%rsp), %rdi
callq 0x295a0
leaq 0x120(%rsp), %rdi
callq 0x295a0
leaq 0xe0(%rsp), %rdi
callq 0x295a0
leaq 0x100(%rsp), %rdi
jmp 0x76bc1
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x295a0
movq %rbx, %rdi
callq 0x292f0