// File: /workspace/github_cpp_makefile_star2_O3/richardposner[P]BioNetFit2/src/code/Particle.cpp
// Function: Particle::finalizeSim(unsigned int)
void Particle::finalizeSim(unsigned int mid) {
	unsigned int subParID = calcsubParID(mid);
	if ((mid<0)|| (mid >= swarm_->getNumModels()) || (!getSubParticle(mid)) || (!models.at(mid)) || (dataFiles_.at(mid).empty())){
		outputError("finalizeSim Failed. Invalid SubParticle.  PID:"+ toString(id_) + "  model id:" + toString(mid)+ "  subParID:" + toString(subParID)+". Quitting !!!");
	}
	if (swarm_->options.verbosity >= 3) {cout << "Finalizing simulation. Started" << endl;}

	// Calculate our fit
	calculateFit(false, mid);  //razi: was calculateFit(), check if local should be false


	// Put our simulation params into the message vector
	if ((!this->getSubParticle(mid)) || (fitCalcs.at(mid).empty())){
		cout<<"can  not finalize simulation for subParticle with model id:"<<mid<<endl;
		return;
	}

		// Put our fit calc into the message vector
	swarm_->swarmComm->univMessageSender.push_back(toString(fitCalcs.at(mid).at(currentGeneration_)));
		//cout << "stored fit calc of " << fitCalcs.at(currentGeneration_) << " as " << swarm_->swarmComm->univMessageSender[0] << endl;


	//razi: here the slave fills in the values for free parameters [the list and order may be different for each model, should be taken care of by Master]
	for (map<string,double>::iterator i = simParams_.at(mid).begin(); i != simParams_.at(mid).end(); ++i){
		//cout << "stored param of " << i->second << endl;
		swarm_->swarmComm->univMessageSender.push_back(toString(i->second));
	}

	// Tell the swarm master that we're finished
	if (swarm_->options.verbosity >= 3) {
		cout << "Telling master that my simulation is finished" << endl;
	}

	swarm_->swarmComm->sendToSwarm(subParID, 0, SIMULATION_END, false, swarm_->swarmComm->univMessageSender);
	// Reset the message vector
	swarm_->swarmComm->univMessageSender.clear();
	if (swarm_->options.verbosity >= 3) {cout << "Finalizing simulation. Completed" << endl;}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movl %esi, %r15d
movq %rdi, %r13
movl 0x40(%rdi), %esi
leal -0x1(%rsi), %ecx
movq 0xa8(%rdi), %rax
movq 0x15c8(%rax), %rdx
subq 0x15c0(%rax), %rdx
shrq $0x3, %rdx
imull %edx, %ecx
addl %r15d, %ecx
incl %ecx
movl %ecx, 0x2c(%rsp)
movl %r15d, %ebp
cmpl %r15d, %edx
jbe 0x5e480
movq 0x48(%r13), %rcx
movq 0x50(%r13), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %rbp, %rdx
jbe 0x5ea89
cmpq $0x0, (%rcx,%rbp,8)
je 0x5e480
movq 0x78(%r13), %rcx
movq 0x80(%r13), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %rbp, %rdx
jbe 0x5ea89
cmpq $0x0, (%rcx,%rbp,8)
je 0x5e480
movq 0x90(%r13), %rcx
movq 0x98(%r13), %rdi
subq %rcx, %rdi
sarq $0x4, %rdi
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdi, %rdx
cmpq %rbp, %rdx
jbe 0x5ea89
leaq (,%rbp,2), %rdx
addq %rbp, %rdx
shlq $0x4, %rdx
cmpq $0x0, 0x28(%rcx,%rdx)
jne 0x5e8c7
leaq 0x118(%rsp), %r12
movq %r12, %rdi
callq 0xbfa49
leaq 0x9b2bc(%rip), %rcx     # 0xf9753
movl $0x2e, %r8d
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x22a80
leaq 0xe8(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x5e4d9
movq %rdx, 0xd8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xe8(%rsp)
jmp 0x5e4e0
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq %r13, 0xd0(%rsp)
movq 0x8(%rax), %rdx
leaq 0xd8(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x9a7a9(%rip), %rsi     # 0xf8cb7
callq 0x233b0
leaq 0x80(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x5e540
movq %rdx, 0x70(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x80(%rsp)
jmp 0x5e546
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq 0x8(%rax), %rdx
movq %rdx, 0x78(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0xb0(%rsp), %rdi
movl %r15d, %esi
callq 0xbfa49
movq 0x70(%rsp), %rcx
movq 0x78(%rsp), %r8
movq 0xb8(%rsp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %edi
cmpq %rbx, %rcx
je 0x5e596
movq 0x80(%rsp), %rdi
movq 0xb0(%rsp), %rsi
cmpq %rdi, %rax
jbe 0x5e5c2
leaq 0xc0(%rsp), %r9
movl $0xf, %edi
cmpq %r9, %rsi
je 0x5e5bd
movq 0xc0(%rsp), %rdi
cmpq %rdi, %rax
jbe 0x5e5ce
leaq 0x70(%rsp), %rdi
callq 0x222b0
jmp 0x5e5df
leaq 0xb0(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x22a80
leaq 0x40(%rsp), %rdx
movq %rdx, -0x10(%rdx)
movq (%rax), %rsi
leaq 0x10(%rax), %rcx
cmpq %rcx, %rsi
je 0x5e603
movq %rsi, 0x30(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x40(%rsp)
jmp 0x5e609
movups (%rcx), %xmm0
movups %xmm0, (%rdx)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x38(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0x9a137(%rip), %rsi     # 0xf8764
leaq 0x30(%rsp), %rdi
callq 0x233b0
leaq 0x60(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x5e65f
movq %rdx, 0x50(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x60(%rsp)
jmp 0x5e667
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
movq %rdx, 0x58(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x90(%rsp), %rdi
movl 0x2c(%rsp), %esi
callq 0xbfa49
movq 0x50(%rsp), %rcx
movq 0x58(%rsp), %r8
movq 0x98(%rsp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %edi
cmpq %r12, %rcx
je 0x5e6b5
movq 0x60(%rsp), %rdi
movq 0x90(%rsp), %rsi
cmpq %rdi, %rax
jbe 0x5e6e1
leaq 0xa0(%rsp), %r9
movl $0xf, %edi
cmpq %r9, %rsi
je 0x5e6dc
movq 0xa0(%rsp), %rdi
cmpq %rdi, %rax
jbe 0x5e6ed
leaq 0x50(%rsp), %rdi
callq 0x222b0
jmp 0x5e6fe
leaq 0x90(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x22a80
leaq 0x18(%rsp), %rdx
movq %rdx, -0x10(%rdx)
movq (%rax), %rsi
leaq 0x10(%rax), %rcx
cmpq %rcx, %rsi
je 0x5e722
movq %rsi, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x5e728
movups (%rcx), %xmm0
movups %xmm0, (%rdx)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x10(%rsp)
movq %rcx, (%rax)
movq %r14, %r13
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0x9a683(%rip), %rsi     # 0xf8dd2
leaq 0x8(%rsp), %rdi
callq 0x233b0
leaq 0x108(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x5e789
movq %rdx, 0xf8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x108(%rsp)
jmp 0x5e790
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
leaq 0xf8(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
callq 0xbfa27
movq 0xf8(%rsp), %rdi
cmpq %r14, %rdi
je 0x5e7d1
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x229c0
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5e7ec
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x229c0
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5e80d
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x229c0
movq 0x50(%rsp), %rdi
cmpq %r12, %rdi
je 0x5e824
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x229c0
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5e83f
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x229c0
leaq 0xc0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5e860
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x229c0
movq 0x70(%rsp), %rdi
cmpq %rbx, %rdi
je 0x5e87a
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x229c0
movq 0xd8(%rsp), %rdi
cmpq %r13, %rdi
movq 0xd0(%rsp), %r13
je 0x5e89f
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x229c0
leaq 0x128(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5e8c0
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x229c0
movq 0xa8(%r13), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x5e913
movq 0x1176d1(%rip), %r12    # 0x175fa8
leaq 0x9aea4(%rip), %rsi     # 0xf9782
movl $0x1e, %edx
movq %r12, %rdi
callq 0x22ab0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq %r12, %rdi
callq 0x22050
movq %rax, %rdi
callq 0x22660
movq %r13, %rdi
xorl %esi, %esi
movl %r15d, %edx
callq 0x5aae4
movq 0x48(%r13), %rax
movq 0x50(%r13), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rbp, %rdx
jbe 0x5ea89
cmpq $0x0, (%rax,%rbp,8)
je 0x5ea9a
movq 0x18(%r13), %rdi
movq 0x20(%r13), %rdx
subq %rdi, %rdx
sarq $0x4, %rdx
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rdx
cmpq %rbp, %rdx
jbe 0x5ea89
leaq (,%rbp,2), %r14
addq %rbp, %r14
shlq $0x4, %r14
cmpq $0x0, 0x28(%rdi,%r14)
je 0x5ea9a
addq %r14, %rdi
movq 0xa8(%r13), %rax
movq (%rax), %r15
movl 0xb0(%r13), %eax
leaq 0x50(%rsp), %rsi
movl %eax, (%rsi)
callq 0x66368
movsd (%rax), %xmm0
leaq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0xbfad7
movq %r15, %rdi
movq %r12, %rsi
callq 0x6a2a2
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5e9db
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x229c0
movq (%r13), %rax
movq 0x8(%r13), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
cmpq %rbp, %rdx
jbe 0x5ea89
movq 0x18(%rax,%r14), %r12
leaq 0x8(%rsp), %r15
leaq (%rax,%r14), %rcx
addq $0x8, %rcx
movq 0xa8(%r13), %rax
cmpq %rcx, %r12
je 0x5eac8
movq (%rax), %rbx
movsd 0x40(%r12), %xmm0
movq %r15, %rdi
callq 0xbfad7
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6a2a2
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x5ea5c
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x229c0
movq %r12, %rdi
callq 0x22670
movq %rax, %r12
movq (%r13), %rax
movq 0x8(%r13), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
cmpq %rbp, %rdx
ja 0x5ea0b
leaq 0x94be9(%rip), %rdi     # 0xf3679
movq %rbp, %rsi
xorl %eax, %eax
callq 0x22f40
movq 0x117507(%rip), %rbx    # 0x175fa8
leaq 0x9acf9(%rip), %rsi     # 0xf97a1
movl $0x3b, %edx
movq %rbx, %rdi
callq 0x22ab0
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x22650
movq %rax, %rbx
jmp 0x5eb77
cmpl $0x2, 0x1614(%rax)
jbe 0x5eb1a
movq 0x1174d0(%rip), %r14    # 0x175fa8
leaq 0x9acfe(%rip), %rsi     # 0xf97dd
movl $0x2d, %edx
movq %r14, %rdi
callq 0x22ab0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq %r14, %rdi
callq 0x22050
movq %rax, %rdi
callq 0x22660
movq 0xa8(%r13), %rax
movq (%rax), %rdi
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
movl 0x2c(%rsp), %esi
xorl %edx, %edx
movl $0xd, %ecx
xorl %r8d, %r8d
movq %rdi, %r9
callq 0x6bac2
movq 0xa8(%r13), %rax
movq (%rax), %rdi
movq (%rdi), %rsi
callq 0x6aebc
movq 0xa8(%r13), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x5eb9e
movq 0x117445(%rip), %rbx    # 0x175fa8
leaq 0x9aca1(%rip), %rsi     # 0xf980b
movl $0x20, %edx
movq %rbx, %rdi
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
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
jmp 0x5ed09
movq %rax, %r15
movq 0xf8(%rsp), %rdi
cmpq %r14, %rdi
je 0x5ebe6
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0x5ebe6
movq %rax, %r15
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5ec09
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0x5ec09
movq %r14, %r13
movq %rax, %r15
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5ec32
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0x5ec32
movq %r14, %r13
movq %rax, %r15
movq 0x50(%rsp), %rdi
cmpq %r12, %rdi
je 0x5ec51
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0x5ec51
movq %r14, %r13
movq %rax, %r15
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5ec74
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0x5ec74
movq %r14, %r13
movq %rax, %r15
leaq 0xc0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5ec9d
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0x5ec9d
movq %r14, %r13
movq %rax, %r15
movq 0x70(%rsp), %rdi
cmpq %rbx, %rdi
je 0x5ecbf
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0x5ecbf
movq %r14, %r13
movq %rax, %r15
movq 0xd8(%rsp), %rdi
cmpq %r13, %rdi
je 0x5ece1
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0x5ece1
movq %rax, %r15
leaq 0x128(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5ed1b
movq 0x128(%rsp), %rsi
jmp 0x5ed13
movq %rax, %r15
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x5ed1b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x229c0
movq %r15, %rdi
callq 0x23240
nop