// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq 0x15c8(%rsi), %r15
subq 0x15c0(%rsi), %r15
shrq $0x3, %r15
movq (%rdi), %rax
cmpq %rax, 0x8(%rdi)
je 0x96244
movq %rax, 0x8(%rdi)
movq %rdi, 0x10(%rsp)
cmpq $0x0, 0x1848(%r14)
je 0x962e6
movq 0x1838(%r14), %r12
leaq 0x1828(%r14), %rbx
cmpq %rbx, %r12
je 0x962e6
leaq 0x1998(%r14), %r13
leaq 0x19a0(%r14), %rbp
movl 0x20(%r12), %edi
movl %r15d, %esi
callq 0xbf2b8
movl %eax, 0xc(%rsp)
movq 0x19a8(%r14), %rdx
movq %rbp, %rcx
testq %rdx, %rdx
je 0x962b2
movq %rbp, %rcx
xorl %esi, %esi
cmpl %eax, 0x20(%rdx)
setb %sil
cmovaeq %rdx, %rcx
movq 0x10(%rdx,%rsi,8), %rdx
testq %rdx, %rdx
jne 0x9629b
movq %rbp, %rdx
cmpq %rbp, %rcx
je 0x962c4
cmpl 0x20(%rcx), %eax
cmovbq %rbp, %rcx
movq %rcx, %rdx
cmpq %rbp, %rdx
jne 0x962d6
movq %r13, %rdi
leaq 0xc(%rsp), %rsi
callq 0xb01ce
movq %r12, %rdi
callq 0x22ad0
movq %rax, %r12
cmpq %rbx, %rax
jne 0x96278
cmpq $0x0, 0x1880(%r14)
je 0x96383
movq 0x1870(%r14), %r12
leaq 0x1860(%r14), %rbx
cmpq %rbx, %r12
je 0x96383
leaq 0x19d0(%r14), %r13
leaq 0x19d8(%r14), %rbp
movl 0x20(%r12), %edi
movl %r15d, %esi
callq 0xbf2b8
movl %eax, 0xc(%rsp)
movq 0x19e0(%r14), %rdx
movq %rbp, %rcx
testq %rdx, %rdx
je 0x9634f
movq %rbp, %rcx
xorl %esi, %esi
cmpl %eax, 0x20(%rdx)
setb %sil
cmovaeq %rdx, %rcx
movq 0x10(%rdx,%rsi,8), %rdx
testq %rdx, %rdx
jne 0x96338
movq %rbp, %rdx
cmpq %rbp, %rcx
je 0x96361
cmpl 0x20(%rcx), %eax
cmovbq %rbp, %rcx
movq %rcx, %rdx
cmpq %rbp, %rdx
jne 0x96373
movq %r13, %rdi
leaq 0xc(%rsp), %rsi
callq 0xb01ce
movq %r12, %rdi
callq 0x22ad0
movq %rax, %r12
cmpq %rbx, %rax
jne 0x96315
cmpq $0x0, 0x18b8(%r14)
je 0x966a8
movq 0x18a8(%r14), %r13
leaq 0x1898(%r14), %rbp
xorl %r12d, %r12d
cmpq %rbp, %r13
je 0x963f3
leaq 0x61eeb(%rip), %rbx     # 0xf8299
cmpl $0x3, 0x1614(%r14)
jb 0x963d8
movl 0x20(%r13), %esi
movq 0xdfbcd(%rip), %rdi     # 0x175f90
callq 0x22650
movl $0x2, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x22ab0
movl 0x20(%r13), %eax
cmpl %r12d, %eax
cmoval %eax, %r12d
movq %r13, %rdi
callq 0x22ad0
movq %rax, %r13
cmpq %rbp, %rax
jne 0x963ae
cmpl $-0x1, %r12d
je 0x96767
movl %r12d, %edi
movl %r15d, %esi
callq 0xbf2b8
movl %eax, 0x8(%rsp)
cmpl $0x3, 0x1614(%r14)
jb 0x9648a
movq 0xdfb73(%rip), %rdi     # 0x175f90
leaq 0x6b93a(%rip), %rsi     # 0x101d5e
movl $0x2e, %edx
callq 0x22ab0
movl %r12d, %esi
movq 0xdfb58(%rip), %rdi     # 0x175f90
callq 0x22650
movq %rax, %rbx
leaq 0x6b946(%rip), %rsi     # 0x101d8d
movl $0xf, %edx
movq %rax, %rdi
callq 0x22ab0
movl 0x8(%rsp), %esi
movq %rbx, %rdi
callq 0x22650
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq %rbx, %rdi
callq 0x22050
movq %rax, %rdi
callq 0x22660
movl $0x1, 0x4(%rsp)
cmpl $0x0, 0x8(%rsp)
je 0x966f8
leaq 0x18c0(%r14), %rax
movq %rax, 0x18(%rsp)
leaq 0x18c8(%r14), %r12
xorl %r13d, %r13d
movq %r12, 0x20(%rsp)
testl %r15d, %r15d
je 0x9652c
movb $0x1, %bl
xorl %r12d, %r12d
movl 0x4(%rsp), %edi
movl %r12d, %esi
movl %r15d, %edx
callq 0xbf2a3
movq 0x18a0(%r14), %rdx
movq %rbp, %rcx
testq %rdx, %rdx
je 0x964fa
movq %rbp, %rcx
xorl %esi, %esi
cmpl %eax, 0x20(%rdx)
setb %sil
cmovaeq %rdx, %rcx
movq 0x10(%rdx,%rsi,8), %rdx
testq %rdx, %rdx
jne 0x964e3
movq %rbp, %rdx
cmpq %rbp, %rcx
je 0x9650c
cmpl 0x20(%rcx), %eax
cmovbq %rbp, %rcx
movq %rcx, %rdx
cmpq %rbp, %rdx
movzbl %bl, %ebx
cmovel %r13d, %ebx
incl %r12d
cmpl %r15d, %r12d
jne 0x964c2
testb $0x1, %bl
movq 0x20(%rsp), %r12
je 0x96692
cmpl $0x3, 0x1614(%r14)
jb 0x9659c
movl $0xa, %edx
movq 0xdfa4e(%rip), %rdi     # 0x175f90
leaq 0x6b839(%rip), %rsi     # 0x101d82
callq 0x22ab0
movl 0x4(%rsp), %esi
movq 0xdfa37(%rip), %rdi     # 0x175f90
callq 0x22650
movq %rax, %rbx
movl $0x21, %edx
movq %rax, %rdi
leaq 0x6b82d(%rip), %rsi     # 0x101d9d
callq 0x22ab0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq %rbx, %rdi
callq 0x22050
movq %rax, %rdi
callq 0x22660
movq 0x18d0(%r14), %rcx
movq %r12, %rax
testq %rcx, %rcx
je 0x965c9
movl 0x4(%rsp), %edx
movq %r12, %rax
xorl %esi, %esi
cmpl %edx, 0x20(%rcx)
setb %sil
cmovaeq %rcx, %rax
movq 0x10(%rcx,%rsi,8), %rcx
testq %rcx, %rcx
jne 0x965b2
movq %r12, %rcx
cmpq %r12, %rax
je 0x965df
movl 0x4(%rsp), %ecx
cmpl 0x20(%rax), %ecx
cmovbq %r12, %rax
movq %rax, %rcx
cmpq %r12, %rcx
je 0x9665a
cmpl $0x3, 0x1614(%r14)
jb 0x96692
movl $0xa, %edx
movq 0xdf992(%rip), %rdi     # 0x175f90
leaq 0x6b77d(%rip), %rsi     # 0x101d82
callq 0x22ab0
movl 0x4(%rsp), %esi
movq 0xdf97b(%rip), %rdi     # 0x175f90
callq 0x22650
movq %rax, %rbx
movl $0x34, %edx
movq %rax, %rdi
leaq 0x6b793(%rip), %rsi     # 0x101dbf
callq 0x22ab0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq %rbx, %rdi
callq 0x22050
movq %rax, %rdi
callq 0x22660
jmp 0x96692
movq 0x18(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0xb01ce
movq 0x10(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x96688
movl 0x4(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x96692
leaq 0x4(%rsp), %rdx
callq 0x6b5ce
movl 0x4(%rsp), %eax
incl %eax
movl %eax, 0x4(%rsp)
cmpl 0x8(%rsp), %eax
jbe 0x964b8
jmp 0x966f8
cmpl $0x0, 0x1614(%r14)
je 0x966f8
movq 0xdf8d7(%rip), %rbx     # 0x175f90
leaq 0x6b639(%rip), %rsi     # 0x101cf9
movl $0x27, %edx
movq %rbx, %rdi
callq 0x22ab0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq 0xdf8a5(%rip), %rdi     # 0x175f90
callq 0x22050
movq %rax, %rdi
callq 0x22660
cmpl $0x3, 0x1614(%r14)
jb 0x967ad
movq 0xdf883(%rip), %rdi     # 0x175f90
leaq 0x6b6e0(%rip), %rsi     # 0x101df4
movl $0x1f, %edx
callq 0x22ab0
movq 0x18b8(%r14), %rsi
movq 0xdf864(%rip), %rdi     # 0x175f90
callq 0x22650
movq 0xdf858(%rip), %rdi     # 0x175f90
leaq 0x6b6d5(%rip), %rsi     # 0x101e14
movl $0x23, %edx
callq 0x22ab0
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rsi
subq (%rax), %rsi
sarq $0x2, %rsi
movq 0xdf830(%rip), %rdi     # 0x175f90
callq 0x22650
jmp 0x967ad
movq 0xdf822(%rip), %rbx     # 0x175f90
leaq 0x6b5ac(%rip), %rsi     # 0x101d21
movl $0x3c, %edx
movq %rbx, %rdi
callq 0x22ab0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq 0xdf7f0(%rip), %rdi     # 0x175f90
callq 0x22050
movq %rax, %rdi
callq 0x22660
movq 0x10(%rsp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x967cb
jmp 0x967cb
jmp 0x967cb
jmp 0x967cb
jmp 0x967cb
movq %rax, %rbx
movq 0x10(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x967e7
movq 0x10(%rax), %rsi
subq %rdi, %rsi
callq 0x229c0
movq %rbx, %rdi
callq 0x23240
nop