// File: /workspace/github_cpp_makefile_star2_O2/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 $0x98, %rsp
movq %rsi, %r13
movq %rdi, %rbx
addq $0x80, %rdi
leaq 0x50(%rbx), %r14
movq %r14, %rsi
callq 0x4210
leaq 0x12daf(%rip), %rsi     # 0x1e9e6
movq %rax, %rdi
callq 0x4240
movq %rax, %rdi
movq %r13, %rsi
callq 0x4230
leaq 0x12daa(%rip), %rsi     # 0x1e9fb
movq %rax, %rdi
callq 0x4240
leaq 0x390(%rbx), %rdi
movq %r14, %rsi
callq 0x4210
leaq 0x12d7d(%rip), %rsi     # 0x1e9ec
movq %rax, %rdi
callq 0x4240
movq %rax, %rdi
movq %r13, %rsi
callq 0x4230
leaq 0x12d72(%rip), %rsi     # 0x1e9fb
movq %rax, %rdi
callq 0x4240
leaq 0x208(%rbx), %rdi
movq %r14, %rsi
callq 0x4210
leaq 0x12d4d(%rip), %rsi     # 0x1e9f4
movq %rax, %rdi
callq 0x4240
leaq 0x88(%rbx), %rsi
leaq 0x78(%rsp), %rdi
callq 0x4440
leaq 0x210(%rbx), %rsi
leaq 0x58(%rsp), %rdi
callq 0x4440
leaq 0x398(%rbx), %rsi
leaq 0x38(%rsp), %rdi
callq 0x4440
leaq 0x690(%rbx), %rdi
movq 0x78(%rsp), %rsi
pushq $0x10
popq %rdx
movq %rdi, 0x28(%rsp)
callq 0x4040
leaq 0xa90(%rbx), %rdi
movq 0x38(%rsp), %rsi
pushq $0x10
popq %rbp
movq %rdi, 0x20(%rsp)
movl %ebp, %edx
callq 0x4040
movq 0xa90(%rbx), %rax
movq -0x18(%rax), %rax
movq $0xa, 0xa98(%rbx,%rax)
leaq 0x890(%rbx), %r12
cmpq $0x1, %r13
movq 0x58(%rsp), %rsi
pushq $0xa
popq %rdx
cmovel %ebp, %edx
movq %r12, %rdi
callq 0x4040
leaq 0x12cac(%rip), %rsi     # 0x1e9fe
movq %r12, %rdi
callq 0x4240
movq %rax, %rdi
movq %r13, %rsi
callq 0x4230
leaq 0x12c9f(%rip), %rsi     # 0x1ea0b
movq %rax, %rdi
callq 0x4240
movq %rax, %rdi
callq 0x4100
movq 0x23245(%rip), %rdi     # 0x2efc8
leaq 0x12c89(%rip), %rsi     # 0x1ea13
callq 0x4240
movq %rax, %rdi
callq 0x4100
leaq 0x12c8c(%rip), %rsi     # 0x1ea2a
movq %r12, %rdi
callq 0x4240
movq %rax, %rdi
callq 0x4100
movq %rbx, %rdi
callq 0xc1c0
xorl %ebp, %ebp
xorl %edi, %edi
callq 0x4220
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x30(%rsp)
leaq 0xe90(%rbx), %r13
xorpd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
cmpq 0x10(%rbx), %rbp
jae 0xbe9d
movsd 0x28(%rbx), %xmm0
ucomisd 0x38(%rbx), %xmm0
jb 0xbe99
xorl %r14d, %r14d
movsd 0x12208(%rip), %xmm0    # 0x1e008
movapd %xmm0, (%rsp)
xorl %r15d, %r15d
movq 0xef0(%rbx), %rdi
movq 0x8(%rdi), %rax
subq (%rdi), %rax
sarq $0x3, %rax
cmpq %rax, %r15
jae 0xbe51
movq %r15, %rsi
callq 0x970e
movq (%rax), %rdi
movq (%rdi), %rax
movsd 0x18(%rsp), %xmm0
callq *0x10(%rax)
movapd (%rsp), %xmm1
ucomisd %xmm0, %xmm1
cmovaq %r15, %r14
minsd %xmm1, %xmm0
incq %r15
movapd %xmm0, (%rsp)
jmp 0xbe08
movupd 0x38(%rbx), %xmm0
movapd (%rsp), %xmm1
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
addpd %xmm0, %xmm1
movupd %xmm1, 0x38(%rbx)
movq 0xe90(%rbx), %rax
incq (%rax,%r14,8)
movq %r14, %rsi
callq 0x970e
movq (%rax), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movq %rbx, %rdi
callq 0xc362
incq %rbp
movapd (%rsp), %xmm0
jmp 0xbdd5
movq %rbp, 0x10(%rbx)
xorl %edi, %edi
callq 0x4220
movq %rax, %r14
movq 0x2311a(%rip), %rdi     # 0x2efc8
leaq 0x12b8e(%rip), %rsi     # 0x1ea43
callq 0x4240
leaq 0x12b82(%rip), %rsi     # 0x1ea43
movq %r12, %rdi
callq 0x4240
cvtsi2sd %r14, %xmm0
movsd %xmm0, (%rsp)
xorl %ebp, %ebp
movq 0x230ec(%rip), %r14     # 0x2efc8
leaq 0x12511(%rip), %r15     # 0x1e3f4
movq 0xe98(%rbx), %rax
subq 0xe90(%rbx), %rax
sarq $0x3, %rax
cmpq %rax, %rbp
jge 0xbf41
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4ae8
movq (%rax), %rsi
movq %r14, %rdi
callq 0x4230
movq %rax, %rdi
movq %r15, %rsi
callq 0x4240
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4ae8
movq (%rax), %rsi
movq %r12, %rdi
callq 0x4230
movq %rax, %rdi
movq %r15, %rsi
callq 0x4240
incq %rbp
jmp 0xbee3
movq 0x23080(%rip), %rdi     # 0x2efc8
callq 0x4100
movq %r12, %rdi
callq 0x4100
movq 0x2306c(%rip), %rdi     # 0x2efc8
leaq 0x12af5(%rip), %rsi     # 0x1ea58
callq 0x4240
movsd 0x38(%rbx), %xmm0
movq %rax, %rdi
callq 0x4460
leaq 0x12aee(%rip), %rsi     # 0x1ea6a
movq %rax, %rdi
callq 0x4240
movq %rax, %rdi
callq 0x4100
leaq 0x12ac5(%rip), %rsi     # 0x1ea58
movq %r12, %rdi
callq 0x4240
movsd 0x38(%rbx), %xmm0
movq %rax, %rdi
callq 0x4460
leaq 0x12abb(%rip), %rsi     # 0x1ea6a
movq %rax, %rdi
callq 0x4240
movq %rax, %rdi
callq 0x4100
movq 0x23002(%rip), %rdi     # 0x2efc8
leaq 0x12aa1(%rip), %rsi     # 0x1ea6e
callq 0x4240
movq 0x10(%rbx), %rsi
movq %rax, %rdi
callq 0x4160
movq %rax, %rdi
callq 0x4100
leaq 0x12a81(%rip), %rsi     # 0x1ea6e
movq %r12, %rdi
callq 0x4240
movq 0x10(%rbx), %rsi
movq %rax, %rdi
callq 0x4160
movq %rax, %rdi
callq 0x4100
movq 0x22fb8(%rip), %rdi     # 0x2efc8
leaq 0x12a6a(%rip), %rsi     # 0x1ea81
callq 0x4240
movsd (%rsp), %xmm0
subsd 0x30(%rsp), %xmm0
movq %rax, %rdi
movsd %xmm0, (%rsp)
callq 0x4460
leaq 0x1471d(%rip), %rsi     # 0x20758
movq %rax, %rdi
callq 0x4240
movq %rax, %rdi
callq 0x4100
leaq 0x12a2f(%rip), %rsi     # 0x1ea81
movq %r12, %rdi
callq 0x4240
movq %rax, %rdi
movsd (%rsp), %xmm0
callq 0x4460
leaq 0x146ea(%rip), %rsi     # 0x20758
movq %rax, %rdi
callq 0x4240
movq %rax, %rdi
callq 0x4100
movq %rbx, %rdi
callq 0xc1c0
movq 0x22f3b(%rip), %rdi     # 0x2efc8
leaq 0x12a00(%rip), %rsi     # 0x1ea94
callq 0x4240
movq %rax, %rdi
callq 0x4100
leaq 0x129ec(%rip), %rsi     # 0x1ea94
movq %r12, %rdi
callq 0x4240
movq %rax, %rdi
callq 0x4100
movq %rax, %rdi
callq 0x4100
movq %rax, %rdi
callq 0x4100
movq 0x28(%rsp), %rdi
callq 0x43b0
movq %r12, %rdi
callq 0x43b0
movq 0x20(%rsp), %rdi
callq 0x43b0
leaq 0x38(%rsp), %rdi
callq 0x4568
leaq 0x58(%rsp), %rdi
callq 0x4568
leaq 0x78(%rsp), %rdi
callq 0x4568
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r14
movq %rax, %rbx
jmp 0xc146
movq %rdx, %r14
movq %rax, %rbx
jmp 0xc150
jmp 0xc126
movq %rdx, %r14
movq %rax, %rbx
jmp 0xc15a
jmp 0xc136
jmp 0xc136
jmp 0xc136
jmp 0xc136
movq %rdx, %r14
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x4568
leaq 0x58(%rsp), %rdi
callq 0x4568
leaq 0x78(%rsp), %rdi
callq 0x4568
cmpl $0x1, %r14d
jne 0xc1af
movq %rbx, %rdi
callq 0x40e0
movq %rax, %rbx
movq 0x22e56(%rip), %rdi     # 0x2efc8
leaq 0x1292f(%rip), %rsi     # 0x1eaa8
callq 0x4240
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x4240
movq %rax, %rdi
callq 0x4100
callq 0x4480
jmp 0xc102
movq %rax, %rbx
callq 0x4480
movq %rbx, %rdi
callq 0x44f0
movq %rax, %rdi
callq 0x4b49
nop