// File: richardposner[P]BioNetFit2/src/code/Swarm.cpp
// Function: Swarm::update_finished_running_particles()
std::vector<unsigned int> Swarm::update_finished_running_particles(){

	//unsigned int nFinishedParticles = runningParticles_.size();
	unsigned int i , j, pID, subPID, maxSubPID, maxPID, nModels;
	std::set<unsigned int>::iterator it;
	std::vector<unsigned int> NewlyFinishedParticles;
	nModels=options.models.size(); NewlyFinishedParticles.clear(); //razi: init

	if (!runningSubParticles_.empty())
		for (it = runningSubParticles_.begin(); it != runningSubParticles_.end(); ++it){
			pID = fcalcParID(*it, nModels);
			if (runningParticles_.find(pID) == runningParticles_.end())  //razi: add if already does not exist
				runningParticles_.insert(pID);
		}

	if (!failedSubParticles_.empty())
		for (it = failedSubParticles_.begin(); it != failedSubParticles_.end(); ++it){
			pID = fcalcParID(*it, nModels);
			if (failedParticles_.find(pID) ==  failedParticles_.end())  //razi: add if already does not exist
				failedParticles_.insert(pID);
		}


	if (finishedSubParticles_.empty()){
		if(options.verbosity>=1){
			cout<<"finished subPartcile list is empty ...."<<endl;

		}
	}else{



		maxSubPID=0;
		for (std::set<unsigned int>::iterator maxIndex = finishedSubParticles_.begin(); maxIndex!=finishedSubParticles_.end(); ++maxIndex){
			if (options.verbosity >= 3) {
				cout<<*maxIndex<<", ";
			}
			if ((*maxIndex) > maxSubPID)
				maxSubPID = * maxIndex;
		}

		if (maxSubPID== (unsigned) -1){
			cout<<"finished subPartcile list does not include valid max id ...."<<endl;
			return NewlyFinishedParticles;
		}else{
			maxPID = fcalcParID(maxSubPID, nModels);
			if (options.verbosity >= 3) {
				cout<<"Updating finished particles. Max subParticle: " <<  maxSubPID<<"  Max Particle:" << maxPID <<endl;
			}

			bool allfinished;
			for (i = 1; i <= maxPID; i++){
				allfinished = true;
				for (j=0; j< nModels; j++){
					subPID = fcalcsubParID(i, j, nModels);
					if (finishedSubParticles_.find(subPID) == finishedSubParticles_.end())
						allfinished = false;
				}
				if (allfinished){
					if (options.verbosity >= 3) {
						cout<< "Particle: " << i<<" is completed. Adding to the list"<<endl;
					}
					if (finishedParticles_.find(i) == finishedParticles_.end()){
						finishedParticles_.insert(i);
						NewlyFinishedParticles.push_back(i);
					}
					else{
						if (options.verbosity >= 3) {
							cout<< "Particle: " << i<<" already included in the list of finished particles."<<endl;
						}
					}
				}

			}
		}
	}
	if (options.verbosity >= 3) {
		cout << "updated number of finished susb" << finishedSubParticles_.size();
		cout << "updated number of new finished subs" << NewlyFinishedParticles.size();
	}

	return NewlyFinishedParticles;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1f0, %rsp            # imm = 0x1F0
movq %rdi, -0x108(%rbp)
movq %rdi, %rax
movq %rax, -0x110(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x100(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x120d90
movq -0x108(%rbp), %rdi
movb $0x0, -0x39(%rbp)
callq 0xb2010
movq -0x100(%rbp), %rdi
addq $0x14c0, %rdi           # imm = 0x14C0
addq $0x100, %rdi            # imm = 0x100
callq 0x45170
movq -0x108(%rbp), %rdi
movl %eax, -0x2c(%rbp)
callq 0x122bf0
movq -0x100(%rbp), %rdi
addq $0x1820, %rdi           # imm = 0x1820
callq 0x1260f0
testb $0x1, %al
jne 0x10a0ac
movq -0x100(%rbp), %rdi
addq $0x1820, %rdi           # imm = 0x1820
callq 0x123360
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x100(%rbp), %rdi
addq $0x1820, %rdi           # imm = 0x1820
callq 0x1233c0
movq %rax, -0x50(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x123390
testb $0x1, %al
jne 0x109fc8
jmp 0x10a0aa
leaq -0x38(%rbp), %rdi
callq 0x1233f0
movl (%rax), %edi
movl -0x2c(%rbp), %esi
callq 0x17d3f0
movl %eax, -0x114(%rbp)
jmp 0x109fe3
movq -0x100(%rbp), %rdi
movl -0x114(%rbp), %eax
movl %eax, -0x1c(%rbp)
addq $0x1998, %rdi           # imm = 0x1998
leaq -0x1c(%rbp), %rsi
callq 0x123530
movq %rax, -0x120(%rbp)
jmp 0x10a00c
movq -0x100(%rbp), %rdi
movq -0x120(%rbp), %rax
movq %rax, -0x68(%rbp)
addq $0x1998, %rdi           # imm = 0x1998
callq 0x1233c0
movq %rax, -0x70(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x123570
testb $0x1, %al
jne 0x10a041
jmp 0x10a09a
movq -0x100(%rbp), %rdi
addq $0x1998, %rdi           # imm = 0x1998
leaq -0x1c(%rbp), %rsi
callq 0x123270
movb %dl, -0x129(%rbp)
movq %rax, -0x128(%rbp)
jmp 0x10a067
movb -0x129(%rbp), %al
movq -0x128(%rbp), %rcx
movq %rcx, -0x80(%rbp)
movb %al, -0x78(%rbp)
jmp 0x10a09a
movq -0x108(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0xb2400
jmp 0x10a76b
jmp 0x10a09c
leaq -0x38(%rbp), %rdi
callq 0x123410
jmp 0x109f9b
jmp 0x10a0ac
movq -0x100(%rbp), %rdi
addq $0x1858, %rdi           # imm = 0x1858
callq 0x1260f0
testb $0x1, %al
jne 0x10a1f6
movq -0x100(%rbp), %rdi
addq $0x1858, %rdi           # imm = 0x1858
callq 0x123360
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x100(%rbp), %rdi
addq $0x1858, %rdi           # imm = 0x1858
callq 0x1233c0
movq %rax, -0x90(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x123390
testb $0x1, %al
jne 0x10a11f
jmp 0x10a1f4
leaq -0x38(%rbp), %rdi
callq 0x1233f0
movl (%rax), %edi
movl -0x2c(%rbp), %esi
callq 0x17d3f0
movl %eax, -0x130(%rbp)
jmp 0x10a13a
movq -0x100(%rbp), %rdi
movl -0x130(%rbp), %eax
movl %eax, -0x1c(%rbp)
addq $0x19d0, %rdi           # imm = 0x19D0
leaq -0x1c(%rbp), %rsi
callq 0x123530
movq %rax, -0x138(%rbp)
jmp 0x10a163
movq -0x100(%rbp), %rdi
movq -0x138(%rbp), %rax
movq %rax, -0x98(%rbp)
addq $0x19d0, %rdi           # imm = 0x19D0
callq 0x1233c0
movq %rax, -0xa0(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x123570
testb $0x1, %al
jne 0x10a1a4
jmp 0x10a1e4
movq -0x100(%rbp), %rdi
addq $0x19d0, %rdi           # imm = 0x19D0
leaq -0x1c(%rbp), %rsi
callq 0x123270
movb %dl, -0x141(%rbp)
movq %rax, -0x140(%rbp)
jmp 0x10a1ca
movb -0x141(%rbp), %al
movq -0x140(%rbp), %rcx
movq %rcx, -0xb0(%rbp)
movb %al, -0xa8(%rbp)
jmp 0x10a1e6
leaq -0x38(%rbp), %rdi
callq 0x123410
jmp 0x10a0ec
jmp 0x10a1f6
movq -0x100(%rbp), %rdi
addq $0x1890, %rdi           # imm = 0x1890
callq 0x1260f0
testb $0x1, %al
jne 0x10a20f
jmp 0x10a257
movq -0x100(%rbp), %rax
cmpl $0x1, 0x1614(%rax)
jb 0x10a252
movq 0x1cad2a(%rip), %rdi    # 0x2d4f50
leaq 0xda76f(%rip), %rsi     # 0x1e499c
callq 0x2ff50
movq %rax, -0x150(%rbp)
jmp 0x10a23b
movq -0x150(%rbp), %rdi
movq 0x1cad7f(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10a250
jmp 0x10a252
jmp 0x10a6b0
movq -0x100(%rbp), %rdi
movl $0x0, -0x24(%rbp)
addq $0x1890, %rdi           # imm = 0x1890
callq 0x123360
movq %rax, -0xb8(%rbp)
movq -0x100(%rbp), %rdi
addq $0x1890, %rdi           # imm = 0x1890
callq 0x1233c0
movq %rax, -0xc0(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x123390
testb $0x1, %al
jne 0x10a2ae
jmp 0x10a32f
movq -0x100(%rbp), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x10a2f8
leaq -0xb8(%rbp), %rdi
callq 0x1233f0
movl (%rax), %esi
movq 0x1cac7d(%rip), %rdi    # 0x2d4f50
callq 0x30640
movq %rax, -0x158(%rbp)
jmp 0x10a2e1
movq -0x158(%rbp), %rdi
leaq 0xd07ca(%rip), %rsi     # 0x1daab9
callq 0x2ff50
jmp 0x10a2f6
jmp 0x10a2f8
leaq -0xb8(%rbp), %rdi
callq 0x1233f0
movl (%rax), %eax
cmpl -0x24(%rbp), %eax
jbe 0x10a31c
leaq -0xb8(%rbp), %rdi
callq 0x1233f0
movl (%rax), %eax
movl %eax, -0x24(%rbp)
jmp 0x10a31e
leaq -0xb8(%rbp), %rdi
callq 0x123410
jmp 0x10a278
cmpl $-0x1, -0x24(%rbp)
jne 0x10a379
movq 0x1cac14(%rip), %rdi    # 0x2d4f50
leaq 0xda681(%rip), %rsi     # 0x1e49c4
callq 0x2ff50
movq %rax, -0x160(%rbp)
jmp 0x10a351
movq -0x160(%rbp), %rdi
movq 0x1cac69(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10a366
movb $0x1, -0x39(%rbp)
movl $0x1, -0xc4(%rbp)
jmp 0x10a749
movl -0x24(%rbp), %edi
movl -0x2c(%rbp), %esi
callq 0x17d3f0
movl %eax, -0x164(%rbp)
jmp 0x10a38c
movq -0x100(%rbp), %rax
movl -0x164(%rbp), %ecx
movl %ecx, -0x28(%rbp)
cmpl $0x3, 0x1614(%rax)
jb 0x10a424
movq 0x1caba4(%rip), %rdi    # 0x2d4f50
leaq 0xda64e(%rip), %rsi     # 0x1e4a01
callq 0x2ff50
movq %rax, -0x170(%rbp)
jmp 0x10a3c1
movq -0x170(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x30640
movq %rax, -0x178(%rbp)
jmp 0x10a3d9
movq -0x178(%rbp), %rdi
leaq 0xda649(%rip), %rsi     # 0x1e4a30
callq 0x2ff50
movq %rax, -0x180(%rbp)
jmp 0x10a3f5
movq -0x180(%rbp), %rdi
movl -0x28(%rbp), %esi
callq 0x30640
movq %rax, -0x188(%rbp)
jmp 0x10a40d
movq -0x188(%rbp), %rdi
movq 0x1cabad(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10a422
jmp 0x10a424
movl $0x1, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x28(%rbp), %eax
ja 0x10a6ac
movb $0x1, -0xc5(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jae 0x10a4e8
movl -0x14(%rbp), %edi
movl -0x18(%rbp), %esi
movl -0x2c(%rbp), %edx
callq 0x17d3a0
movl %eax, -0x18c(%rbp)
jmp 0x10a467
movq -0x100(%rbp), %rdi
movl -0x18c(%rbp), %eax
movl %eax, -0x20(%rbp)
addq $0x1890, %rdi           # imm = 0x1890
leaq -0x20(%rbp), %rsi
callq 0x123530
movq %rax, -0x198(%rbp)
jmp 0x10a490
movq -0x100(%rbp), %rdi
movq -0x198(%rbp), %rax
movq %rax, -0xd0(%rbp)
addq $0x1890, %rdi           # imm = 0x1890
callq 0x1233c0
movq %rax, -0xd8(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x123570
testb $0x1, %al
jne 0x10a4d1
jmp 0x10a4d8
movb $0x0, -0xc5(%rbp)
jmp 0x10a4da
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x10a445
testb $0x1, -0xc5(%rbp)
je 0x10a69c
movq -0x100(%rbp), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x10a56c
movq 0x1caa44(%rip), %rdi    # 0x2d4f50
leaq 0xda512(%rip), %rsi     # 0x1e4a25
callq 0x2ff50
movq %rax, -0x1a0(%rbp)
jmp 0x10a521
movq -0x1a0(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x30640
movq %rax, -0x1a8(%rbp)
jmp 0x10a539
movq -0x1a8(%rbp), %rdi
leaq 0xda4f9(%rip), %rsi     # 0x1e4a40
callq 0x2ff50
movq %rax, -0x1b0(%rbp)
jmp 0x10a555
movq -0x1b0(%rbp), %rdi
movq 0x1caa65(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10a56a
jmp 0x10a56c
movq -0x100(%rbp), %rdi
addq $0x18c0, %rdi           # imm = 0x18C0
leaq -0x14(%rbp), %rsi
callq 0x123530
movq %rax, -0x1b8(%rbp)
jmp 0x10a58c
movq -0x100(%rbp), %rdi
movq -0x1b8(%rbp), %rax
movq %rax, -0xe0(%rbp)
addq $0x18c0, %rdi           # imm = 0x18C0
callq 0x1233c0
movq %rax, -0xe8(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x123570
testb $0x1, %al
jne 0x10a5cd
jmp 0x10a621
movq -0x100(%rbp), %rdi
addq $0x18c0, %rdi           # imm = 0x18C0
leaq -0x14(%rbp), %rsi
callq 0x123270
movb %dl, -0x1c1(%rbp)
movq %rax, -0x1c0(%rbp)
jmp 0x10a5f3
movq -0x108(%rbp), %rdi
movb -0x1c1(%rbp), %al
movq -0x1c0(%rbp), %rcx
movq %rcx, -0xf8(%rbp)
movb %al, -0xf0(%rbp)
leaq -0x14(%rbp), %rsi
callq 0xb4640
jmp 0x10a61f
jmp 0x10a69a
movq -0x100(%rbp), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x10a698
movq 0x1ca918(%rip), %rdi    # 0x2d4f50
leaq 0xda3e6(%rip), %rsi     # 0x1e4a25
callq 0x2ff50
movq %rax, -0x1d0(%rbp)
jmp 0x10a64d
movq -0x1d0(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x30640
movq %rax, -0x1d8(%rbp)
jmp 0x10a665
movq -0x1d8(%rbp), %rdi
leaq 0xda3ef(%rip), %rsi     # 0x1e4a62
callq 0x2ff50
movq %rax, -0x1e0(%rbp)
jmp 0x10a681
movq -0x1e0(%rbp), %rdi
movq 0x1ca939(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10a696
jmp 0x10a698
jmp 0x10a69a
jmp 0x10a69c
jmp 0x10a69e
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x10a42b
jmp 0x10a6ae
jmp 0x10a6b0
movq -0x100(%rbp), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x10a73b
movq 0x1ca889(%rip), %rdi    # 0x2d4f50
leaq 0xda3c9(%rip), %rsi     # 0x1e4a97
callq 0x2ff50
movq %rax, -0x1e8(%rbp)
jmp 0x10a6dc
movq -0x100(%rbp), %rdi
addq $0x1890, %rdi           # imm = 0x1890
callq 0x123340
movq -0x1e8(%rbp), %rdi
movq %rax, %rsi
callq 0x30cf0
jmp 0x10a700
movq 0x1ca849(%rip), %rdi    # 0x2d4f50
leaq 0xda3a9(%rip), %rsi     # 0x1e4ab7
callq 0x2ff50
movq %rax, -0x1f0(%rbp)
jmp 0x10a71c
movq -0x108(%rbp), %rdi
callq 0xb46f0
movq -0x1f0(%rbp), %rdi
movq %rax, %rsi
callq 0x30cf0
jmp 0x10a739
jmp 0x10a73b
movb $0x1, -0x39(%rbp)
movl $0x1, -0xc4(%rbp)
testb $0x1, -0x39(%rbp)
jne 0x10a75b
movq -0x108(%rbp), %rdi
callq 0xb2400
movq -0x110(%rbp), %rax
addq $0x1f0, %rsp            # imm = 0x1F0
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x30170
nopw %cs:(%rax,%rax)