// File: CMU-SAFARI[P]MQSim/src/sim/Engine.cpp
// Function: MQSimEngine::Engine::Start_simulation()
void Engine::Start_simulation()
	{
		started = true;

		for(std::unordered_map<sim_object_id_type, Sim_Object*>::iterator obj = _ObjectList.begin();
			obj != _ObjectList.end();
			++obj) {
			if (!obj->second->IsTriggersSetUp()) {
				obj->second->Setup_triggers();
			}
		}

		for (std::unordered_map<sim_object_id_type, Sim_Object*>::iterator obj = _ObjectList.begin();
			obj != _ObjectList.end();
			++obj) {
			obj->second->Validate_simulation_config();
		}
		
		for (std::unordered_map<sim_object_id_type, Sim_Object*>::iterator obj = _ObjectList.begin();
			obj != _ObjectList.end();
			++obj) {
			obj->second->Start_simulation();
		}
		
		Sim_Event* ev = NULL;
		while (true) {
			if (_EventList->Count == 0 || stop) {
				break;
			}

			EventTreeNode* minNode = _EventList->Get_min_node();
			ev = minNode->FirstSimEvent;

			_sim_time = ev->Fire_time;

			while (ev != NULL) {
				if(!ev->Ignore) {
					ev->Target_sim_object->Execute_simulator_event(ev);
				}
				Sim_Event* consumed_event = ev;
				ev = ev->Next_event;
				delete consumed_event;
			}
			_EventList->Remove(minNode);
		}
	}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq 0x60(%rsp), %rdi
movq %rdi, 0x10(%rsp)
movb $0x1, 0x49(%rdi)
addq $0x10, %rdi
callq 0x46f80
movq %rax, 0x58(%rsp)
movq 0x10(%rsp), %rdi
addq $0x10, %rdi
callq 0x46e30
movq %rax, 0x50(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x46de0
testb $0x1, %al
jne 0x46a6d
jmp 0x46aa6
leaq 0x58(%rsp), %rdi
callq 0x46fb0
movq 0x20(%rax), %rdi
callq 0x46fd0
testb $0x1, %al
jne 0x46a98
leaq 0x58(%rsp), %rdi
callq 0x46fb0
movq 0x20(%rax), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
jmp 0x46a9a
leaq 0x58(%rsp), %rdi
callq 0x46fe0
jmp 0x46a45
movq 0x10(%rsp), %rdi
addq $0x10, %rdi
callq 0x46f80
movq %rax, 0x48(%rsp)
movq 0x10(%rsp), %rdi
addq $0x10, %rdi
callq 0x46e30
movq %rax, 0x40(%rsp)
leaq 0x48(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x46de0
testb $0x1, %al
jne 0x46ae1
jmp 0x46b01
leaq 0x48(%rsp), %rdi
callq 0x46fb0
movq 0x20(%rax), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
leaq 0x48(%rsp), %rdi
callq 0x46fe0
jmp 0x46ab9
movq 0x10(%rsp), %rdi
addq $0x10, %rdi
callq 0x46f80
movq %rax, 0x38(%rsp)
movq 0x10(%rsp), %rdi
addq $0x10, %rdi
callq 0x46e30
movq %rax, 0x30(%rsp)
leaq 0x38(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x46de0
testb $0x1, %al
jne 0x46b3c
jmp 0x46b5b
leaq 0x38(%rsp), %rdi
callq 0x46fb0
movq 0x20(%rax), %rdi
movq (%rdi), %rax
callq *(%rax)
leaq 0x38(%rsp), %rdi
callq 0x46fe0
jmp 0x46b14
movq $0x0, 0x28(%rsp)
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
cmpl $0x0, (%rax)
je 0x46b7d
movq 0x10(%rsp), %rax
testb $0x1, 0x48(%rax)
je 0x46b82
jmp 0x46c29
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x49420
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x20(%rsp)
movq 0x20(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, 0x28(%rsp)
movq 0x28(%rsp), %rcx
movq (%rcx), %rcx
movq %rcx, (%rax)
cmpq $0x0, 0x28(%rsp)
je 0x46c11
movq 0x28(%rsp), %rax
testb $0x1, 0x28(%rax)
jne 0x46bdd
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x28(%rsp), %rsi
movq (%rdi), %rax
callq *0x18(%rax)
movq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x28(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x46c0f
movq 0x8(%rsp), %rdi
callq 0x8410
jmp 0x46bb6
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x20(%rsp), %rsi
callq 0x49700
jmp 0x46b64
addq $0x68, %rsp
retq
nop