// File: /workspace/github_cpp_makefile_star2_O3/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 %rdi, 0x18(%rsp)
movq $0x0, 0x10(%rdi)
movq 0x15c8(%rsi), %r15
subq 0x15c0(%rsi), %r15
shrq $0x3, %r15
cmpq $0x0, 0x1848(%rsi)
je 0x959a9
movq 0x1838(%r14), %r12
leaq 0x1828(%r14), %rbx
cmpq %rbx, %r12
je 0x959a9
leaq 0x1998(%r14), %r13
leaq 0x19a0(%r14), %rbp
movl 0x20(%r12), %edi
movl %r15d, %esi
callq 0xbe99e
movl %eax, 0x14(%rsp)
movq 0x19a8(%r14), %rcx
testq %rcx, %rcx
je 0x9598c
movq %rbp, %rdx
xorl %esi, %esi
cmpl %eax, 0x20(%rcx)
setb %sil
cmovaeq %rcx, %rdx
movq 0x10(%rcx,%rsi,8), %rcx
testq %rcx, %rcx
jne 0x9596b
cmpq %rbp, %rdx
je 0x9598c
cmpl 0x20(%rdx), %eax
jae 0x95999
movq %r13, %rdi
leaq 0x14(%rsp), %rsi
callq 0xaf99c
movq %r12, %rdi
callq 0x22ad0
movq %rax, %r12
cmpq %rbx, %rax
jne 0x9594b
cmpq $0x0, 0x1880(%r14)
je 0x95a32
movq 0x1870(%r14), %r12
leaq 0x1860(%r14), %rbx
cmpq %rbx, %r12
je 0x95a32
leaq 0x19d0(%r14), %r13
leaq 0x19d8(%r14), %rbp
movl 0x20(%r12), %edi
movl %r15d, %esi
callq 0xbe99e
movl %eax, 0x14(%rsp)
movq 0x19e0(%r14), %rcx
testq %rcx, %rcx
je 0x95a15
movq %rbp, %rdx
xorl %esi, %esi
cmpl %eax, 0x20(%rcx)
setb %sil
cmovaeq %rcx, %rdx
movq 0x10(%rcx,%rsi,8), %rcx
testq %rcx, %rcx
jne 0x959f4
cmpq %rbp, %rdx
je 0x95a15
cmpl 0x20(%rdx), %eax
jae 0x95a22
movq %r13, %rdi
leaq 0x14(%rsp), %rsi
callq 0xaf99c
movq %r12, %rdi
callq 0x22ad0
movq %rax, %r12
cmpq %rbx, %rax
jne 0x959d4
cmpq $0x0, 0x18b8(%r14)
je 0x95d2f
movq 0x18a8(%r14), %r13
leaq 0x1898(%r14), %rbp
xorl %r12d, %r12d
cmpq %rbp, %r13
je 0x95aac
leaq 0x627ec(%rip), %rbx     # 0xf8249
cmpl $0x3, 0x1614(%r14)
jb 0x95a87
movl 0x20(%r13), %esi
movq 0xe0536(%rip), %rdi     # 0x175fa8
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 0x95a5d
cmpl $-0x1, %r12d
je 0x95dee
movl %r12d, %edi
movl %r15d, %esi
callq 0xbe99e
movl %eax, 0x10(%rsp)
cmpl $0x3, 0x1614(%r14)
jb 0x95b39
movq 0xe04dc(%rip), %rdi     # 0x175fa8
leaq 0x6c272(%rip), %rsi     # 0x101d45
movl $0x2e, %edx
callq 0x22ab0
movl %r12d, %esi
movq 0xe04c1(%rip), %rdi     # 0x175fa8
callq 0x22650
movq %rax, %rbx
leaq 0x6c27e(%rip), %rsi     # 0x101d74
movl $0xf, %edx
movq %rax, %rdi
callq 0x22ab0
movl 0x10(%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, 0xc(%rsp)
cmpl $0x0, 0x10(%rsp)
je 0x95d7f
leaq 0x18c0(%r14), %rax
movq %rax, 0x20(%rsp)
leaq 0x18c8(%r14), %r12
testl %r15d, %r15d
je 0x95bcb
movb $0x1, %bl
xorl %r13d, %r13d
movl 0xc(%rsp), %edi
movl %r13d, %esi
movl %r15d, %edx
callq 0xbe989
movq 0x18a0(%r14), %rdx
movq %rbp, %rsi
testq %rdx, %rdx
je 0x95bb3
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 0x95b8a
movq %rbp, %rsi
cmpq %rbp, %rcx
je 0x95bb3
cmpl 0x20(%rcx), %eax
cmovbq %rbp, %rcx
movq %rcx, %rsi
cmpq %rbp, %rsi
setne %al
andb %al, %bl
incl %r13d
cmpl %r15d, %r13d
jne 0x95b69
testb %bl, %bl
je 0x95d19
cmpl $0x3, 0x1614(%r14)
jb 0x95c3b
movl $0xa, %edx
movq 0xe03c7(%rip), %rdi     # 0x175fa8
leaq 0x6c181(%rip), %rsi     # 0x101d69
callq 0x22ab0
movl 0xc(%rsp), %esi
movq 0xe03b0(%rip), %rdi     # 0x175fa8
callq 0x22650
movq %rax, %rbx
movl $0x21, %edx
movq %rax, %rdi
leaq 0x6c175(%rip), %rsi     # 0x101d84
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
testq %rcx, %rcx
je 0x95c6f
movl 0xc(%rsp), %eax
movq %r12, %rdx
xorl %esi, %esi
cmpl %eax, 0x20(%rcx)
setb %sil
cmovaeq %rcx, %rdx
movq 0x10(%rcx,%rsi,8), %rcx
testq %rcx, %rcx
jne 0x95c4e
cmpq %r12, %rdx
je 0x95c6f
cmpl 0x20(%rdx), %eax
jae 0x95ca9
movq 0x20(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0xaf99c
movq 0x18(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x95c9d
movl 0xc(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x95d19
leaq 0xc(%rsp), %rdx
callq 0x6b0da
jmp 0x95d19
cmpl $0x3, 0x1614(%r14)
jb 0x95d19
movl $0xa, %edx
movq 0xe02e9(%rip), %rdi     # 0x175fa8
leaq 0x6c0a3(%rip), %rsi     # 0x101d69
callq 0x22ab0
movl 0xc(%rsp), %esi
movq 0xe02d2(%rip), %rdi     # 0x175fa8
callq 0x22650
movq %rax, %rbx
movl $0x34, %edx
movq %rax, %rdi
leaq 0x6c0b9(%rip), %rsi     # 0x101da6
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
movl 0xc(%rsp), %eax
incl %eax
movl %eax, 0xc(%rsp)
cmpl 0x10(%rsp), %eax
jbe 0x95b5f
jmp 0x95d7f
cmpl $0x0, 0x1614(%r14)
je 0x95d7f
movq 0xe0268(%rip), %rbx     # 0x175fa8
leaq 0x6bf99(%rip), %rsi     # 0x101ce0
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 0xe0236(%rip), %rdi     # 0x175fa8
callq 0x22050
movq %rax, %rdi
callq 0x22660
cmpl $0x3, 0x1614(%r14)
jb 0x95e34
movq 0xe0214(%rip), %rdi     # 0x175fa8
leaq 0x6c040(%rip), %rsi     # 0x101ddb
movl $0x1f, %edx
callq 0x22ab0
movq 0x18b8(%r14), %rsi
movq 0xe01f5(%rip), %rdi     # 0x175fa8
callq 0x22650
movq 0xe01e9(%rip), %rdi     # 0x175fa8
leaq 0x6c035(%rip), %rsi     # 0x101dfb
movl $0x23, %edx
callq 0x22ab0
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rsi
subq (%rax), %rsi
sarq $0x2, %rsi
movq 0xe01c1(%rip), %rdi     # 0x175fa8
callq 0x22650
jmp 0x95e34
movq 0xe01b3(%rip), %rbx     # 0x175fa8
leaq 0x6bf0c(%rip), %rsi     # 0x101d08
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 0xe0181(%rip), %rdi     # 0x175fa8
callq 0x22050
movq %rax, %rdi
callq 0x22660
movq 0x18(%rsp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x95e52
jmp 0x95e52
jmp 0x95e52
jmp 0x95e52
jmp 0x95e52
movq %rax, %rbx
movq 0x18(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x95e6e
movq 0x10(%rax), %rsi
subq %rdi, %rsi
callq 0x229c0
movq %rbx, %rdi
callq 0x23240