// File: /workspace/github_cpp_makefile_star2_O3/CMU-SAFARI[P]MQSim/src/ssd/Data_Cache_Manager_Flash_Simple.cpp
// Function: SSD_Components::Data_Cache_Manager_Flash_Simple::Execute_simulator_event(MQSimEngine::Sim_Event*)
void Data_Cache_Manager_Flash_Simple::Execute_simulator_event(MQSimEngine::Sim_Event* ev)
	{
		Data_Cache_Simulation_Event_Type eventType = (Data_Cache_Simulation_Event_Type)ev->Type;
		Memory_Transfer_Info* transfer_inf = (Memory_Transfer_Info*)ev->Parameters;

		switch (eventType)
			{
			case Data_Cache_Simulation_Event_Type::MEMORY_READ_FOR_USERIO_FINISHED://A user read is service from DRAM cache
			case Data_Cache_Simulation_Event_Type::MEMORY_WRITE_FOR_USERIO_FINISHED:
				((User_Request*)(transfer_inf)->Related_request)->Sectors_serviced_from_cache -= transfer_inf->Size_in_bytes / SECTOR_SIZE_IN_BYTE;
				if (is_user_request_finished((User_Request*)(transfer_inf)->Related_request)) {
					broadcast_user_request_serviced_signal(((User_Request*)(transfer_inf)->Related_request));
				}
				break;
			case Data_Cache_Simulation_Event_Type::MEMORY_READ_FOR_CACHE_EVICTION_FINISHED://Reading data from DRAM and writing it back to the flash storage
				static_cast<FTL*>(nvm_firmware)->Address_Mapping_Unit->Translate_lpa_to_ppa_and_dispatch(*((std::list<NVM_Transaction*>*)(transfer_inf->Related_request)));
				delete (std::list<NVM_Transaction*>*)transfer_inf->Related_request;
				break;
			case Data_Cache_Simulation_Event_Type::MEMORY_WRITE_FOR_CACHE_FINISHED://The recently read data from flash is written back to memory to support future user read requests
				break;
		}

		dram_execution_queue[transfer_inf->Stream_id].pop();
		if (dram_execution_queue[transfer_inf->Stream_id].size() > 0) {
			Memory_Transfer_Info* new_transfer_info = dram_execution_queue[transfer_inf->Stream_id].front();
			Simulator->Register_sim_event(Simulator->Time() + estimate_dram_access_time(new_transfer_info->Size_in_bytes, dram_row_size, dram_busrt_size,
				dram_burst_transfer_time_ddr, dram_tRCD, dram_tCL, dram_tRP),
				this, new_transfer_info, static_cast<int>(new_transfer_info->next_event_type));
		}

		delete transfer_inf;
	}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, %r14
movl 0x18(%rsi), %eax
movq 0x10(%rsi), %rbx
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
jae 0x35ea7
movl (%rbx), %eax
shrl $0x9, %eax
movq 0x8(%rbx), %rsi
movl 0x58(%rsi), %ecx
cmpq $0x0, 0x50(%rsi)
sete %dl
subl %eax, %ecx
movl %ecx, 0x58(%rsi)
sete %al
andb %dl, %al
cmpb $0x1, %al
jne 0x35ee6
movq %r14, %rdi
callq 0x321ee
jmp 0x35ee6
testl %eax, %eax
jne 0x35ee6
movq 0x38(%r14), %rax
movq 0x38(%rax), %rdi
movq 0x8(%rbx), %rsi
movq (%rdi), %rax
callq *0x60(%rax)
movq 0x8(%rbx), %r15
testq %r15, %r15
je 0x35ede
movq (%r15), %rdi
cmpq %r15, %rdi
je 0x35ede
movq (%rdi), %r12
callq 0x7370
movq %r12, %rdi
cmpq %r15, %r12
jne 0x35ece
movq %r15, %rdi
callq 0x7370
movzwl 0x14(%rbx), %eax
leaq (%rax,%rax,4), %rdi
shll $0x4, %edi
addq 0xc8(%r14), %rdi
callq 0x3470a
movq 0xc8(%r14), %rcx
movzwl 0x14(%rbx), %eax
leaq (%rax,%rax,4), %rdx
shll $0x4, %edx
movq 0x48(%rcx,%rdx), %rax
movq %rax, %rsi
subq 0x28(%rcx,%rdx), %rsi
shrq $0x3, %rsi
cmpq $0x1, %rax
adcq $-0x1, %rsi
movq 0x30(%rcx,%rdx), %rdi
subq 0x38(%rcx,%rdx), %rdi
shlq $0x6, %rsi
sarq $0x3, %rdi
addq %rsi, %rdi
movq 0x10(%rcx,%rdx), %rax
movq 0x20(%rcx,%rdx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
addq %rdi, %rcx
je 0x3613f
movq (%rax), %r15
callq 0x28018
movq %rax, %r12
callq 0x28018
movq %rax, %rdi
callq 0x2841a
movq %rax, %rcx
movl (%r15), %edi
movl 0x40(%r14), %r8d
movl 0x48(%r14), %r10d
movsd 0x50(%r14), %xmm0
movq 0x58(%r14), %r13
movq 0x60(%r14), %r11
leaq (%r11,%r13), %rsi
cmpl %r8d, %edi
jbe 0x360f7
movl %r8d, %eax
xorl %edx, %edx
divl %r10d
movl %eax, %r9d
movq 0x68(%r14), %xmm3
movl %edi, %eax
xorl %edx, %edx
divl %r8d
movq %rsi, %xmm5
movq 0x21903(%rip), %xmm1    # 0x578c0
punpckldq %xmm1, %xmm5    # xmm5 = xmm5[0],xmm1[0],xmm5[1],xmm1[1]
movapd 0x21907(%rip), %xmm2    # 0x578d0
subpd %xmm2, %xmm5
movapd %xmm5, %xmm4
unpckhpd %xmm5, %xmm4            # xmm4 = xmm4[1],xmm5[1]
addsd %xmm5, %xmm4
shrl %r9d
xorps %xmm5, %xmm5
cvtsi2sd %r9d, %xmm5
punpckldq %xmm1, %xmm3    # xmm3 = xmm3[0],xmm1[0],xmm3[1],xmm1[1]
subpd %xmm2, %xmm3
movapd %xmm3, %xmm6
unpckhpd %xmm3, %xmm6            # xmm6 = xmm6[1],xmm3[1]
addsd %xmm3, %xmm6
mulsd %xmm0, %xmm5
addsd %xmm6, %xmm5
cvttsd2si %xmm5, %rsi
movq %rsi, %rdi
sarq $0x3f, %rdi
movsd 0x1f03c(%rip), %xmm3    # 0x55050
subsd %xmm3, %xmm5
cvttsd2si %xmm5, %r8
andq %rdi, %r8
orq %rsi, %r8
movq %r8, %xmm5
punpckldq %xmm1, %xmm5    # xmm5 = xmm5[0],xmm1[0],xmm5[1],xmm1[1]
subpd %xmm2, %xmm5
movapd %xmm5, %xmm6
unpckhpd %xmm5, %xmm6            # xmm6 = xmm6[1],xmm5[1]
addsd %xmm5, %xmm6
shrl %eax
xorps %xmm5, %xmm5
cvtsi2sd %eax, %xmm5
mulsd %xmm6, %xmm5
addsd %xmm4, %xmm5
movq %r13, %xmm4
punpckldq %xmm1, %xmm4    # xmm4 = xmm4[0],xmm1[0],xmm4[1],xmm1[1]
subpd %xmm2, %xmm4
movapd %xmm4, %xmm6
unpckhpd %xmm4, %xmm6            # xmm6 = xmm6[1],xmm4[1]
addsd %xmm4, %xmm6
addsd %xmm5, %xmm6
movq %r11, %xmm5
punpckldq %xmm1, %xmm5    # xmm5 = xmm5[0],xmm1[0],xmm5[1],xmm1[1]
subpd %xmm2, %xmm5
movapd %xmm5, %xmm4
unpckhpd %xmm5, %xmm4            # xmm4 = xmm4[1],xmm5[1]
addsd %xmm5, %xmm4
xorps %xmm5, %xmm5
cvtsi2sd %rdx, %xmm5
addsd %xmm6, %xmm4
movl %r10d, %eax
xorps %xmm6, %xmm6
cvtsi2sd %rax, %xmm6
mulsd %xmm0, %xmm6
divsd %xmm6, %xmm5
cvttsd2si %xmm5, %rax
movq %rax, %rdx
subsd %xmm3, %xmm5
cvttsd2si %xmm5, %rsi
sarq $0x3f, %rdx
andq %rdx, %rsi
orq %rax, %rsi
movq %rsi, %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
subpd %xmm2, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
addsd %xmm4, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
subsd %xmm3, %xmm1
cvttsd2si %xmm1, %rsi
andq %rdx, %rsi
orq %rax, %rsi
jmp 0x3612a
movl %edi, %eax
xorl %edx, %edx
divl %r10d
shrl %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rdx
subsd 0x1ef38(%rip), %xmm0    # 0x55050
cvttsd2si %xmm0, %rdi
sarq $0x3f, %rdx
andq %rdx, %rdi
orq %rax, %rdi
addq %rdi, %rsi
addq %rcx, %rsi
movl 0x10(%r15), %r8d
movq %r12, %rdi
movq %r14, %rdx
movq %r15, %rcx
callq 0x2841e
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x7370