// File: 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
movq %rsp, %rbp
subq $0x350, %rsp            # imm = 0x350
movb %cl, %al
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x268(%rbp)
movl -0xc(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movq %rax, -0x270(%rbp)
addq $0x14c0, %rdi           # imm = 0x14C0
addq $0x100, %rdi            # imm = 0x100
callq 0x45170
movq -0x270(%rbp), %rcx
movq %rax, %rdx
movq -0x268(%rbp), %rax
imulq %rdx, %rcx
movl -0x10(%rbp), %edx
addq %rdx, %rcx
addq $0x1, %rcx
movl %ecx, -0x18(%rbp)
cmpl $0x3, 0x1614(%rax)
jb 0x1000a1
movq 0x1d4ed5(%rip), %rdi    # 0x2d4f50
leaq 0xe1d8e(%rip), %rsi     # 0x1e1e10
callq 0x2ff50
movq %rax, %rdi
movl -0x18(%rbp), %esi
callq 0x30640
movq %rax, %rdi
movq 0x1d4f2c(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
movq -0x268(%rbp), %rax
cmpl $0x1, 0x1614(%rax)
jb 0x100158
movq 0x1d4e94(%rip), %rdi    # 0x2d4f50
leaq 0xe1d68(%rip), %rsi     # 0x1e1e2b
callq 0x2ff50
movq %rax, %rdi
movq -0x268(%rbp), %rax
movl 0x13e8(%rax), %esi
callq 0x30640
movq %rax, %rdi
leaq 0xe1d58(%rip), %rsi     # 0x1e1e3f
callq 0x2ff50
movq %rax, %rdi
movq -0x268(%rbp), %rax
movb 0x1631(%rax), %al
andb $0x1, %al
movzbl %al, %esi
callq 0x2f690
movq %rax, %rdi
leaq 0xe1d45(%rip), %rsi     # 0x1e1e55
callq 0x2ff50
movq %rax, %rdi
movb -0x11(%rbp), %al
andb $0x1, %al
movzbl %al, %esi
callq 0x2f690
movq %rax, %rdi
leaq 0xe1d31(%rip), %rsi     # 0x1e1e60
callq 0x2ff50
movq %rax, %rdi
movq -0x268(%rbp), %rax
movl 0x13ec(%rax), %esi
callq 0x30640
movq %rax, %rdi
movq 0x1d4e75(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
movq -0x268(%rbp), %rax
cmpl $0x1, 0x13e8(%rax)
jne 0x1008ec
movq -0x268(%rbp), %rax
testb $0x1, 0x1631(%rax)
jne 0x1008ec
testb $0x1, -0x11(%rbp)
jne 0x1008ec
movq -0x268(%rbp), %rax
cmpl $0x0, 0x13ec(%rax)
jne 0x1008ec
movq -0x268(%rbp), %rsi
addq $0x17e0, %rsi           # imm = 0x17E0
leaq 0xe1cc1(%rip), %rdx     # 0x1e1e74
leaq -0x118(%rbp), %rdi
callq 0x447b0
movl -0x18(%rbp), %esi
leaq -0x138(%rbp), %rdi
callq 0x17e460
jmp 0x1001d0
leaq -0xf8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
leaq -0x138(%rbp), %rdx
callq 0x9c7d0
jmp 0x1001ec
leaq 0xe1c95(%rip), %rdx     # 0x1e1e88
leaq -0xd8(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x441f0
jmp 0x100208
movq -0x268(%rbp), %rax
movl 0x13e8(%rax), %esi
leaq -0x168(%rbp), %rdi
callq 0x17e460
jmp 0x100223
leaq -0xb8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
leaq -0x168(%rbp), %rdx
callq 0x9c7d0
jmp 0x10023f
leaq 0xe2b53(%rip), %rdx     # 0x1e2d99
leaq -0x98(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x441f0
jmp 0x10025b
movq -0x268(%rbp), %rdi
addq $0x1938, %rdi           # imm = 0x1938
movl -0x10(%rbp), %eax
movl %eax, %esi
callq 0x449e0
movq %rax, %rdx
leaq -0x78(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x44760
jmp 0x100288
leaq 0x10541d(%rip), %rdx    # 0x2056ac
leaq -0x58(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x441f0
jmp 0x10029e
movq -0x268(%rbp), %rdi
addq $0x1908, %rdi           # imm = 0x1908
leaq -0x10(%rbp), %rsi
callq 0xb5dc0
movq %rax, -0x278(%rbp)
jmp 0x1002be
movq -0x278(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x449e0
movq %rax, %rdx
leaq -0x38(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x44760
jmp 0x1002e0
leaq -0x58(%rbp), %rdi
callq 0x311e8
leaq -0x78(%rbp), %rdi
callq 0x311e8
leaq -0x98(%rbp), %rdi
callq 0x311e8
leaq -0xb8(%rbp), %rdi
callq 0x311e8
leaq -0x168(%rbp), %rdi
callq 0x311e8
leaq -0xd8(%rbp), %rdi
callq 0x311e8
leaq -0xf8(%rbp), %rdi
callq 0x311e8
leaq -0x138(%rbp), %rdi
callq 0x311e8
leaq -0x118(%rbp), %rdi
callq 0x311e8
leaq 0xe1b47(%rip), %rdx     # 0x1e1e94
leaq -0x1a8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x447b0
jmp 0x10035f
movq -0x268(%rbp), %rdi
callq 0x8dec0
movl %eax, -0x27c(%rbp)
jmp 0x100373
movl -0x27c(%rbp), %esi
leaq -0x1c8(%rbp), %rdi
callq 0x17e460
jmp 0x100387
leaq -0x188(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
leaq -0x1c8(%rbp), %rdx
callq 0x9c7d0
jmp 0x1003a3
leaq -0x38(%rbp), %rdi
movq %rdi, -0x288(%rbp)
leaq -0x188(%rbp), %rsi
movq %rsi, -0x290(%rbp)
callq 0x2fd80
movq -0x290(%rbp), %rdi
callq 0x311e8
leaq -0x1c8(%rbp), %rdi
callq 0x311e8
leaq -0x1a8(%rbp), %rdi
callq 0x311e8
movq -0x288(%rbp), %rsi
leaq 0xe1aa6(%rip), %rdx     # 0x1e1e99
leaq -0x1e8(%rbp), %rdi
callq 0x447b0
jmp 0x100401
leaq -0x38(%rbp), %rdi
movq %rdi, -0x298(%rbp)
leaq -0x1e8(%rbp), %rsi
movq %rsi, -0x2a0(%rbp)
callq 0x2fd80
movq -0x2a0(%rbp), %rdi
callq 0x311e8
movq -0x298(%rbp), %rsi
leaq 0xdb020(%rip), %rdx     # 0x1db459
leaq -0x208(%rbp), %rdi
callq 0x447b0
jmp 0x100447
leaq -0x38(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0x2fd80
leaq -0x208(%rbp), %rdi
callq 0x311e8
movq -0x268(%rbp), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x1006e5
movq 0x1d4ad2(%rip), %rdi    # 0x2d4f50
leaq 0xe1a22(%rip), %rsi     # 0x1e1ea7
callq 0x2ff50
movq %rax, -0x2a8(%rbp)
jmp 0x100493
movq -0x2a8(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0x30640
movq %rax, -0x2b0(%rbp)
jmp 0x1004ab
movq -0x2b0(%rbp), %rdi
leaq 0xe22be(%rip), %rsi     # 0x1e2777
callq 0x2ff50
movq %rax, -0x2b8(%rbp)
jmp 0x1004c7
movq -0x2b8(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x30640
movq %rax, -0x2c0(%rbp)
jmp 0x1004df
movq -0x2c0(%rbp), %rdi
leaq 0xe3e3f(%rip), %rsi     # 0x1e432c
callq 0x2ff50
movq %rax, -0x2c8(%rbp)
jmp 0x1004fb
movq -0x2c8(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x30640
movq %rax, -0x2d0(%rbp)
jmp 0x100513
movq -0x2d0(%rbp), %rdi
leaq 0xe199b(%rip), %rsi     # 0x1e1ebc
callq 0x2ff50
movq %rax, -0x2d8(%rbp)
jmp 0x10052f
movq -0x2d8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x2f780
movq %rax, -0x2e0(%rbp)
jmp 0x100548
movq -0x2e0(%rbp), %rdi
movq 0x1d4a72(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10055d
jmp 0x1006e5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
jmp 0x10067a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
jmp 0x10066e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
jmp 0x100662
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
jmp 0x100656
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
jmp 0x10064a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
jmp 0x10063e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
jmp 0x100632
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
jmp 0x100629
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x311e8
leaq -0x78(%rbp), %rdi
callq 0x311e8
leaq -0x98(%rbp), %rdi
callq 0x311e8
leaq -0xb8(%rbp), %rdi
callq 0x311e8
leaq -0x168(%rbp), %rdi
callq 0x311e8
leaq -0xd8(%rbp), %rdi
callq 0x311e8
leaq -0xf8(%rbp), %rdi
callq 0x311e8
leaq -0x138(%rbp), %rdi
callq 0x311e8
leaq -0x118(%rbp), %rdi
callq 0x311e8
jmp 0x100a00
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
jmp 0x1008de
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
jmp 0x1006d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
leaq -0x1c8(%rbp), %rdi
callq 0x311e8
leaq -0x1a8(%rbp), %rdi
callq 0x311e8
jmp 0x1008de
leaq -0x228(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x2f300
jmp 0x1006f7
leaq -0x228(%rbp), %rdi
callq 0x17e3f0
movl %eax, -0x2e4(%rbp)
jmp 0x10070b
leaq -0x228(%rbp), %rdi
callq 0x311e8
movl -0x2e4(%rbp), %eax
cmpl $0x0, %eax
je 0x1008b8
movq 0x1d4823(%rip), %rdi    # 0x2d4f50
leaq 0xe179a(%rip), %rsi     # 0x1e1ece
callq 0x2ff50
movq %rax, -0x2f0(%rbp)
jmp 0x100742
movq -0x2f0(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0x30640
movq %rax, -0x2f8(%rbp)
jmp 0x10075a
movq -0x2f8(%rbp), %rdi
leaq 0xe200f(%rip), %rsi     # 0x1e2777
callq 0x2ff50
movq %rax, -0x300(%rbp)
jmp 0x100776
movq -0x300(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x30640
movq %rax, -0x308(%rbp)
jmp 0x10078e
movq -0x308(%rbp), %rdi
leaq 0xe3b90(%rip), %rsi     # 0x1e432c
callq 0x2ff50
movq %rax, -0x310(%rbp)
jmp 0x1007aa
movq -0x310(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x30640
movq %rax, -0x318(%rbp)
jmp 0x1007c2
movq -0x318(%rbp), %rdi
leaq 0xe1724(%rip), %rsi     # 0x1e1ef4
callq 0x2ff50
movq %rax, -0x320(%rbp)
jmp 0x1007de
movq -0x320(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x2f780
movq %rax, -0x328(%rbp)
jmp 0x1007f7
movq -0x328(%rbp), %rdi
movq 0x1d47c3(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10080c
movq -0x268(%rbp), %rdi
addq $0x19d0, %rdi           # imm = 0x19D0
leaq -0xc(%rbp), %rsi
callq 0x123270
movb %dl, -0x331(%rbp)
movq %rax, -0x330(%rbp)
jmp 0x100832
movq -0x268(%rbp), %rdi
movb -0x331(%rbp), %al
movq -0x330(%rbp), %rcx
movq %rcx, -0x238(%rbp)
movb %al, -0x230(%rbp)
addq $0x1858, %rdi           # imm = 0x1858
leaq -0x18(%rbp), %rsi
callq 0x123270
movb %dl, -0x341(%rbp)
movq %rax, -0x340(%rbp)
jmp 0x100872
movb -0x341(%rbp), %al
movq -0x340(%rbp), %rcx
movq %rcx, -0x248(%rbp)
movb %al, -0x240(%rbp)
movl $0x1, -0x24c(%rbp)
jmp 0x1008c2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x311e8
jmp 0x1008de
movl $0x0, -0x24c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x311e8
movl -0x24c(%rbp), %eax
testl %eax, %eax
je 0x1008dc
jmp 0x1008d7
jmp 0x1009f7
jmp 0x1008ec
leaq -0x38(%rbp), %rdi
callq 0x311e8
jmp 0x100a00
movq -0x268(%rbp), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x100938
movq 0x1d464d(%rip), %rdi    # 0x2d4f50
leaq 0xe15fc(%rip), %rsi     # 0x1e1f06
callq 0x2ff50
movq %rax, %rdi
movl -0x18(%rbp), %esi
callq 0x30640
movq %rax, %rdi
leaq 0xe15f6(%rip), %rsi     # 0x1e1f1a
callq 0x2ff50
movq %rax, %rdi
movq 0x1d4695(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
movq -0x268(%rbp), %rdi
addq $0x1820, %rdi           # imm = 0x1820
leaq -0x18(%rbp), %rsi
callq 0x123270
movq %rax, %rcx
movq -0x268(%rbp), %rax
movq %rcx, -0x260(%rbp)
movb %dl, -0x258(%rbp)
movq (%rax), %rdi
movl -0x18(%rbp), %edx
movq (%rax), %r9
xorl %r8d, %r8d
movl $0x12, %ecx
movl %r8d, %esi
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
callq 0xcd520
movq -0x268(%rbp), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x1009f7
movq 0x1d45b3(%rip), %rdi    # 0x2d4f50
leaq 0xe1599(%rip), %rsi     # 0x1e1f3d
callq 0x2ff50
movq %rax, %rdi
movl -0x18(%rbp), %esi
callq 0x30640
movq %rax, %rdi
leaq 0xe1db9(%rip), %rsi     # 0x1e2777
callq 0x2ff50
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x30640
movq %rax, %rdi
leaq 0xe3954(%rip), %rsi     # 0x1e432c
callq 0x2ff50
movq %rax, %rdi
movl -0x10(%rbp), %esi
callq 0x30640
movq %rax, %rdi
leaq 0xe1562(%rip), %rsi     # 0x1e1f54
callq 0x2ff50
addq $0x350, %rsp            # imm = 0x350
popq %rbp
retq
movq -0x140(%rbp), %rdi
callq 0x30170
nopl (%rax)