// File: /workspace/github_cpp_makefile_star2_O1/nwieder[P]SSTS/src/System/Gillespie_Sys.cpp
// Function: nw::Gillespie_Sys::go(long)
void Gillespie_Sys::go(long n_it)
{
	try{

// 		build path to output files. n_it represents the current simulation run.

//		data files containing molecular numbers
		data_path << output_dir_path << "data_" << n_it << ".e";
// 		open/close log for channel dynamics
		oc_path << output_dir_path << "oc_log_" << n_it << ".e";
//		independent result log of every simulation run
		info_path << output_dir_path << "sim_res.e";

		const string &tmp_data = data_path.str();
		const string &tmp_info = info_path.str();
		const string &tmp_oclog = oc_path.str();

//		connect streams to output file
		data_output_file.open(tmp_data.c_str());
		oc_log_file.open(tmp_oclog.c_str());
		oc_log_file << std::setprecision(10);

//		reconnect to existing file (adding text)
		if (n_it == 1){
			info_output_file.open(tmp_info.c_str());
		}else{
			info_output_file.open(tmp_info.c_str(), ios::in | ios::ate);
		}

//		console output: indicate simulation start
		info_output_file<< "###### Run: " << n_it << " ######" << endl;
		cout << "--SIMULATION BEGIN-- \n" << endl;
		info_output_file << "--SIMULATION RESULTS-- \n" << endl;

//		print the initial system state
		print_system_state();

//		###############################
//		## START THE SIMULATION LOOP ##
//		###############################

//		set times
		double tau = 0, begin, end;
		begin = time(0);

//		check exit conditions
		for (size_t i = 0; i < n_steps; ++i) {
			if (curr_time <= max_Sim_Time) {

				long nextIndex = 0;
				double minTau = INFINITY;

//				event update procedure
				for (size_t j = 0; j < evt_vec->size(); ++j) {
					double actTau = evt_vec->at(j)->update(tau);
//					determine next Event Index
					if (actTau < minTau) {
						minTau = actTau;
						nextIndex = j;
					}
				}

//				update system times
				tau = minTau;
				rec_time += tau;
				curr_time += tau;

//				update event counter
				evt_cntr[nextIndex]++;

//				execute next Event
				evt_vec->at(nextIndex)->execute();

//				print system state if necessary
				system_output();

			} else{
				n_steps = i;
				break;
			}
		}

//		############################
//		## END OF SIMULATION LOOP ##
//		############################

		end = time(0);

//		output of event distribution in info_output_file
		cout << "Event distribution:\t";
		info_output_file << "Event distribution:\t";
		for (long p = 0; p < (long)evt_cntr.size(); p++){
			cout << evt_cntr.at(p) << ",";
			info_output_file << evt_cntr.at(p) << ",";
		}
		cout << endl;
		info_output_file << endl;

//		system information output to info_output_file.
		cout << "Simulated time:\t\t" << curr_time << " ms" << endl;
		info_output_file << "Simulated time:\t\t" << curr_time << " ms" << endl;
		cout << "Number of steps: \t" << n_steps << endl;
		info_output_file << "Number of steps: \t" << n_steps << endl;
		cout << "Computation time:\t" << end - begin << " s" << endl;
		info_output_file << "Computation time:\t" << end - begin << " s" << endl;

//		console output: indicate simulation end
		print_system_state();
		cout << "\n--SIMULATION END--" << endl;
		info_output_file << "\n--SIMULATION END--" << endl << endl << endl;

// 		disconnect stream from output file
		data_output_file.close();
		info_output_file.close();
		oc_log_file.close();
	}

	catch(exception& e){
		cout << "System::go(): " << e.what() << endl;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rsi, %r13
movq %rdi, %r15
addq $0x80, %rdi
movq 0x50(%r15), %rsi
movq 0x58(%r15), %rdx
callq 0x42f0
movq %rax, %rbx
leaq 0x15d15(%rip), %rsi     # 0x249e6
movl $0x5, %edx
movq %rax, %rdi
callq 0x42f0
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4270
leaq 0x15d0b(%rip), %rsi     # 0x249fb
movl $0x2, %edx
movq %rax, %rdi
callq 0x42f0
leaq 0x390(%r15), %rdi
movq 0x50(%r15), %rsi
movq 0x58(%r15), %rdx
callq 0x42f0
movq %rax, %rbx
leaq 0x15cd1(%rip), %rsi     # 0x249ec
movl $0x7, %edx
movq %rax, %rdi
callq 0x42f0
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4270
leaq 0x15cc1(%rip), %rsi     # 0x249fb
movl $0x2, %edx
movq %rax, %rdi
callq 0x42f0
leaq 0x208(%r15), %rdi
movq 0x50(%r15), %rsi
movq 0x58(%r15), %rdx
callq 0x42f0
leaq 0x15c92(%rip), %rsi     # 0x249f4
movl $0x9, %edx
movq %rax, %rdi
callq 0x42f0
leaq 0x88(%r15), %rsi
leaq 0x68(%rsp), %rdi
callq 0x4460
leaq 0x210(%r15), %rsi
leaq 0x48(%rsp), %rdi
callq 0x4460
leaq 0x398(%r15), %rsi
leaq 0x28(%rsp), %rdi
callq 0x4460
leaq 0x690(%r15), %rdi
movq 0x68(%rsp), %rsi
movq %rdi, 0x18(%rsp)
movl $0x10, %edx
callq 0x4050
leaq 0xa90(%r15), %rbp
movq 0x28(%rsp), %rsi
movl $0x10, %ebx
movq %rbp, %rdi
movl $0x10, %edx
callq 0x4050
movq 0xa90(%r15), %rax
movq -0x18(%rax), %rax
movq $0xa, 0xa98(%r15,%rax)
leaq 0x890(%r15), %r12
cmpq $0x1, %r13
movq 0x48(%rsp), %rsi
movl $0xa, %edx
cmovel %ebx, %edx
movq %r12, %rdi
callq 0x4050
leaq 0x15be5(%rip), %rsi     # 0x249fe
movl $0xc, %edx
movq %r12, %rdi
callq 0x42f0
movq %r12, %rdi
movq %r13, %rsi
callq 0x4270
movq %rax, %rbx
leaq 0x15bd0(%rip), %rsi     # 0x24a0b
movl $0x7, %edx
movq %rax, %rdi
callq 0x42f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4190
movq 0x24152(%rip), %rbx     # 0x32fc8
leaq 0x15b96(%rip), %rsi     # 0x24a13
movl $0x16, %edx
movq %rbx, %rdi
callq 0x42f0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x4280
movsbl %al, %esi
movq 0x24120(%rip), %rdi     # 0x32fc8
callq 0x4040
movq %rax, %rdi
callq 0x4190
leaq 0x15b6e(%rip), %rsi     # 0x24a2a
movl $0x18, %edx
movq %r12, %rdi
callq 0x42f0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x4280
movsbl %al, %esi
movq %r12, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4190
movq %r15, %rdi
callq 0xf5fe
xorl %edi, %edi
callq 0x4260
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x10(%r15)
je 0xf009
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %r14d, %r14d
movsd 0x28(%r15), %xmm0
ucomisd 0x38(%r15), %xmm0
jb 0xf00f
movq 0xef0(%r15), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
je 0xef98
xorl %r13d, %r13d
movsd 0x150bb(%rip), %xmm1    # 0x24008
xorl %ebx, %ebx
movsd %xmm1, (%rsp)
movq (%rax,%r13,8), %rdi
movq (%rdi), %rax
movsd 0x8(%rsp), %xmm0
callq *0x10(%rax)
movsd (%rsp), %xmm1
ucomisd %xmm0, %xmm1
cmovaq %r13, %rbx
minsd %xmm1, %xmm0
incq %r13
movq 0xef0(%r15), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movapd %xmm0, %xmm1
cmpq %rdx, %r13
jb 0xef4f
jmp 0xefa6
sarq $0x3, %rdx
xorl %ebx, %ebx
movsd 0x15062(%rip), %xmm0    # 0x24008
movsd 0x40(%r15), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x40(%r15)
movsd 0x38(%r15), %xmm1
movsd %xmm0, (%rsp)
addsd %xmm0, %xmm1
movsd %xmm1, 0x38(%r15)
movq 0xe90(%r15), %rcx
incq (%rcx,%rbx,8)
cmpq %rbx, %rdx
jbe 0xf505
movq (%rax,%rbx,8), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movq %r15, %rdi
callq 0xf87a
incq %r14
movsd (%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
cmpq 0x10(%r15), %r14
jb 0xef1d
leaq 0x10(%r15), %r13
jmp 0xf017
leaq 0x10(%r15), %r13
movq %r14, 0x10(%r15)
movq %rbp, 0x10(%rsp)
xorl %edi, %edi
callq 0x4260
movq %rax, 0x8(%rsp)
movq 0x23f99(%rip), %rbx     # 0x32fc8
leaq 0x15a0d(%rip), %rsi     # 0x24a43
movl $0x14, %edx
movq %rbx, %rdi
callq 0x42f0
leaq 0x159f9(%rip), %rsi     # 0x24a43
movl $0x14, %edx
movq %r12, %rdi
callq 0x42f0
movq %r13, (%rsp)
movq 0xe90(%r15), %rax
movq 0xe98(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
testq %rdx, %rdx
jle 0xf106
xorl %r14d, %r14d
movq 0x23f45(%rip), %r13     # 0x32fc8
leaq 0x1536a(%rip), %rbp     # 0x243f4
cmpq %r14, %rdx
jbe 0xf4f4
movq (%rax,%r14,8), %rsi
movq %r13, %rdi
callq 0x4270
movl $0x1, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x42f0
movq 0xe90(%r15), %rax
movq 0xe98(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %r14, %rdx
jbe 0xf4f4
movq (%rax,%r14,8), %rsi
movq %r12, %rdi
callq 0x4270
movl $0x1, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x42f0
incq %r14
movq 0xe90(%r15), %rax
movq 0xe98(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rdx, %r14
jl 0xf08a
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x4280
movq (%rsp), %r14
movsbl %al, %esi
movq 0x23ea0(%rip), %rdi     # 0x32fc8
callq 0x4040
movq %rax, %rdi
callq 0x4190
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x4280
movsbl %al, %esi
movq %r12, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4190
movq 0x23e64(%rip), %rdi     # 0x32fc8
leaq 0x158ed(%rip), %rsi     # 0x24a58
movl $0x11, %edx
callq 0x42f0
movsd 0x38(%r15), %xmm0
movq 0x23e46(%rip), %rdi     # 0x32fc8
callq 0x4480
movq %rax, %rbx
leaq 0x158d9(%rip), %rsi     # 0x24a6a
movl $0x3, %edx
movq %rax, %rdi
callq 0x42f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4190
leaq 0x1588c(%rip), %rsi     # 0x24a58
movl $0x11, %edx
movq %r12, %rdi
callq 0x42f0
movsd 0x38(%r15), %xmm0
movq %r12, %rdi
callq 0x4480
movq %rax, %rbx
leaq 0x15879(%rip), %rsi     # 0x24a6a
movl $0x3, %edx
movq %rax, %rdi
callq 0x42f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4190
movq 0x23d9c(%rip), %rdi     # 0x32fc8
leaq 0x1583b(%rip), %rsi     # 0x24a6e
movl $0x12, %edx
callq 0x42f0
movq (%r14), %rsi
movq 0x23d81(%rip), %rdi     # 0x32fc8
callq 0x4180
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4190
leaq 0x157f1(%rip), %rsi     # 0x24a6e
movl $0x12, %edx
movq %r12, %rdi
callq 0x42f0
movq (%r14), %rsi
movq %r12, %rdi
callq 0x4180
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4190
movq 0x23d02(%rip), %rdi     # 0x32fc8
leaq 0x157b4(%rip), %rsi     # 0x24a81
movl $0x12, %edx
callq 0x42f0
cvtsi2sdq 0x20(%rsp), %xmm1
cvtsi2sdq 0x8(%rsp), %xmm0
subsd %xmm1, %xmm0
movq 0x23cd8(%rip), %rdi     # 0x32fc8
movsd %xmm0, (%rsp)
callq 0x4480
movq %rax, %rbx
leaq 0x17424(%rip), %rsi     # 0x26728
movl $0x2, %edx
movq %rax, %rdi
callq 0x42f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4190
leaq 0x15742(%rip), %rsi     # 0x24a81
movl $0x12, %edx
movq %r12, %rdi
callq 0x42f0
movq %r12, %rdi
movsd (%rsp), %xmm0
callq 0x4480
movq %rax, %rbx
leaq 0x173c5(%rip), %rsi     # 0x26728
movl $0x2, %edx
movq %rax, %rdi
callq 0x42f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4190
movq %r15, %rdi
callq 0xf5fe
movq 0x23c22(%rip), %rbx     # 0x32fc8
leaq 0x156e7(%rip), %rsi     # 0x24a94
movl $0x13, %edx
movq %rbx, %rdi
callq 0x42f0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x4280
movsbl %al, %esi
movq 0x23bf0(%rip), %rdi     # 0x32fc8
callq 0x4040
movq %rax, %rdi
callq 0x4190
leaq 0x156a8(%rip), %rsi     # 0x24a94
movl $0x13, %edx
movq %r12, %rdi
callq 0x42f0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x4280
movsbl %al, %esi
movq %r12, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4190
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4190
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4190
movq 0x18(%rsp), %rdi
callq 0x43e0
movq %r12, %rdi
callq 0x43e0
movq 0x10(%rsp), %rdi
callq 0x43e0
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xf4ac
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42c0
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xf4c7
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42c0
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xf4e2
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x42c0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x14b48(%rip), %rdi     # 0x24043
movq %r14, %rsi
xorl %eax, %eax
callq 0x4430
leaq 0x14b37(%rip), %rdi     # 0x24043
movq %rbx, %rsi
xorl %eax, %eax
callq 0x4430
movq %rdx, %r14
movq %rax, %rbx
jmp 0xf55d
movq %rdx, %r14
movq %rax, %rbx
jmp 0xf578
jmp 0xf52a
jmp 0xf53c
movq %rdx, %r14
movq %rax, %rbx
jmp 0xf593
jmp 0xf53c
jmp 0xf53c
jmp 0xf53c
jmp 0xf53c
jmp 0xf53c
movq %rdx, %r14
movq %rax, %rbx
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xf55d
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42c0
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xf578
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42c0
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xf593
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x42c0
cmpl $0x1, %r14d
jne 0xf5ee
movq %rbx, %rdi
callq 0x4100
movq %rax, %rbx
movq 0x23a1d(%rip), %rdi     # 0x32fc8
leaq 0x154f6(%rip), %rsi     # 0x24aa8
movl $0xe, %edx
callq 0x42f0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0x239fc(%rip), %rdi     # 0x32fc8
movq %rax, %rsi
callq 0x4290
movq %rax, %rdi
callq 0x4120
callq 0x44a0
jmp 0xf4e2
movq %rax, %rbx
callq 0x44a0
movq %rbx, %rdi
callq 0x4510
movq %rax, %rdi
callq 0x6d6b