// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
movl 0x40(%rdi), %esi
leal -0x1(%rsi), %eax
movq 0xa8(%rdi), %rcx
movq 0x15c8(%rcx), %rdx
subq 0x15c0(%rcx), %rdx
shrq $0x3, %rdx
imull %edx, %eax
addl %r15d, %eax
incl %eax
movl %eax, 0x2c(%rsp)
movl %r15d, %r13d
cmpl %r15d, %edx
jbe 0x5e796
movq 0x48(%rbx), %rax
movq 0x50(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %r13, %rdx
jbe 0x5edab
cmpq $0x0, (%rax,%r13,8)
je 0x5e796
movq 0x78(%rbx), %rax
movq 0x80(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %r13, %rdx
jbe 0x5edab
cmpq $0x0, (%rax,%r13,8)
je 0x5e796
movq 0x90(%rbx), %rax
movq 0x98(%rbx), %rcx
subq %rax, %rcx
sarq $0x4, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
cmpq %r13, %rdx
jbe 0x5edab
leaq (,%r13,2), %rcx
addq %r13, %rcx
shlq $0x4, %rcx
cmpq $0x0, 0x28(%rax,%rcx)
jne 0x5ebd9
leaq 0x118(%rsp), %r12
movq %r12, %rdi
callq 0xc03b8
leaq 0x9afc6(%rip), %rcx     # 0xf9773
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 0x5e7ef
movq %rdx, 0xd8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xe8(%rsp)
jmp 0x5e7f6
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 0x9a4b3(%rip), %rsi     # 0xf8cd7
callq 0x233b0
leaq 0x80(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x5e856
movq %rdx, 0x70(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x80(%rsp)
jmp 0x5e85d
movups (%rcx), %xmm0
movups %xmm0, (%rbp)
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 0xc03b8
movq 0x70(%rsp), %rcx
movq 0x78(%rsp), %r8
movq 0xb8(%rsp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %esi
cmpq %rbp, %rcx
je 0x5e8ad
movq 0x80(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x5e8d2
leaq 0xc0(%rsp), %rdi
movl $0xf, %esi
cmpq %rdi, -0x10(%rdi)
je 0x5e8cd
movq 0xc0(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x5e8e6
movq 0xb0(%rsp), %rsi
leaq 0x70(%rsp), %rdi
callq 0x222b0
jmp 0x5e8f7
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 0x5e91b
movq %rsi, 0x30(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x40(%rsp)
jmp 0x5e921
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 0x99e3f(%rip), %rsi     # 0xf8784
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 0x5e977
movq %rdx, 0x50(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x60(%rsp)
jmp 0x5e97f
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 0xc03b8
movq 0x50(%rsp), %rcx
movq 0x58(%rsp), %r8
movq 0x98(%rsp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %esi
cmpq %r12, %rcx
je 0x5e9cd
movq 0x60(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x5e9f2
leaq 0xa0(%rsp), %rdi
movl $0xf, %esi
cmpq %rdi, -0x10(%rdi)
je 0x5e9ed
movq 0xa0(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x5ea06
movq 0x90(%rsp), %rsi
leaq 0x50(%rsp), %rdi
callq 0x222b0
jmp 0x5ea17
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 0x5ea3b
movq %rsi, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x5ea41
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 0x9a38a(%rip), %rsi     # 0xf8df2
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 0x5eaa2
movq %rdx, 0xf8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x108(%rsp)
jmp 0x5eaa9
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 0xc0396
movq 0xf8(%rsp), %rdi
cmpq %r14, %rdi
je 0x5eaea
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x229c0
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5eb05
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x229c0
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5eb26
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x229c0
movq 0x50(%rsp), %rdi
cmpq %r12, %rdi
je 0x5eb3d
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x229c0
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5eb58
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x229c0
leaq 0xc0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5eb79
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x229c0
movq 0x70(%rsp), %rdi
cmpq %rbp, %rdi
je 0x5eb93
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x229c0
movq 0xd8(%rsp), %rdi
cmpq %r13, %rdi
movq 0xd0(%rsp), %r13
je 0x5ebb8
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x229c0
leaq 0x128(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5ebd9
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x229c0
movq 0xa8(%rbx), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x5ec2c
movq 0x1173a0(%rip), %r12    # 0x175f90
leaq 0x9abab(%rip), %rsi     # 0xf97a2
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 %rbx, %rdi
xorl %esi, %esi
movl %r15d, %edx
callq 0x5aea6
movq 0x48(%rbx), %rax
movq 0x50(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %r13, %rdx
jbe 0x5edab
cmpq $0x0, (%rax,%r13,8)
je 0x5edbc
movq 0x18(%rbx), %rdi
movq 0x20(%rbx), %rdx
subq %rdi, %rdx
sarq $0x4, %rdx
movabsq $-0x5555555555555555, %rbp # imm = 0xAAAAAAAAAAAAAAAB
imulq %rbp, %rdx
cmpq %r13, %rdx
jbe 0x5edab
leaq (,%r13,2), %r14
addq %r13, %r14
shlq $0x4, %r14
cmpq $0x0, 0x28(%rdi,%r14)
je 0x5edbc
addq %r14, %rdi
movq 0xa8(%rbx), %rax
movq (%rax), %r15
movl 0xb0(%rbx), %eax
leaq 0x50(%rsp), %rsi
movl %eax, (%rsi)
callq 0x66830
movsd (%rax), %xmm0
leaq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0xc0446
movq %r15, %rdi
movq %r12, %rsi
callq 0x6a77e
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5ecf3
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x229c0
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
subq %rcx, %rdx
sarq $0x4, %rdx
imulq %rbp, %rdx
cmpq %r13, %rdx
jbe 0x5edab
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
imulq %rbp, %rdx
cmpq %r13, %rdx
jbe 0x5edab
movq 0x18(%rcx,%r14), %r12
leaq (%rax,%r14), %rcx
addq $0x8, %rcx
movq 0xa8(%rbx), %rax
cmpq %rcx, %r12
je 0x5edea
movq %r14, %r15
movq (%rax), %r14
movsd 0x40(%r12), %xmm0
leaq 0x8(%rsp), %rdi
callq 0xc0446
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0x6a77e
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x5ed86
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x229c0
movq %r12, %rdi
callq 0x22670
movq %rax, %r12
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
imulq %rbp, %rdx
cmpq %r13, %rdx
movq %r15, %r14
ja 0x5ed2e
leaq 0x94913(%rip), %rdi     # 0xf36c5
movq %r13, %rsi
xorl %eax, %eax
callq 0x22f40
movq 0x1171cd(%rip), %rbx    # 0x175f90
leaq 0x9a9f7(%rip), %rsi     # 0xf97c1
movl $0x3b, %edx
movq %rbx, %rdi
callq 0x22ab0
movq %rbx, %rdi
movq %r13, %rsi
callq 0x22650
movq %rax, %rbx
jmp 0x5ee99
cmpl $0x2, 0x1614(%rax)
jbe 0x5ee35
movq 0x117196(%rip), %r14    # 0x175f90
leaq 0x9a9fc(%rip), %rsi     # 0xf97fd
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(%rbx), %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 0x6bfb0
movq 0xa8(%rbx), %rax
movq (%rax), %rdi
movq (%rdi), %rsi
callq 0x6b3a4
movq 0xa8(%rbx), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x5eec0
movq 0x11710b(%rip), %rbx    # 0x175f90
leaq 0x9a99f(%rip), %rsi     # 0xf982b
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, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
jmp 0x5f02b
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
cmpq %r14, %rdi
je 0x5ef08
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0x5ef08
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5ef2b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0x5ef2b
movq %r14, %r13
movq %rax, %rbx
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5ef54
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0x5ef54
movq %r14, %r13
movq %rax, %rbx
movq 0x50(%rsp), %rdi
cmpq %r12, %rdi
je 0x5ef73
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0x5ef73
movq %r14, %r13
movq %rax, %rbx
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5ef96
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0x5ef96
movq %r14, %r13
movq %rax, %rbx
leaq 0xc0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5efbf
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0x5efbf
movq %r14, %r13
movq %rax, %rbx
movq 0x70(%rsp), %rdi
cmpq %rbp, %rdi
je 0x5efe1
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0x5efe1
movq %r14, %r13
movq %rax, %rbx
movq 0xd8(%rsp), %rdi
cmpq %r13, %rdi
je 0x5f003
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0x5f003
movq %rax, %rbx
leaq 0x128(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5f03d
movq 0x128(%rsp), %rsi
jmp 0x5f035
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x5f03d
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x229c0
movq %rbx, %rdi
callq 0x23240
nop