// File: CMU-SAFARI[P]MQSim/src/host/IO_Flow_Synthetic.cpp
// Function: Host_Components::IO_Flow_Synthetic::IO_Flow_Synthetic(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned short, unsigned long, unsigned long, double, unsigned short, unsigned short, unsigned short, IO_Flow_Priority_Class::Priority, double, Utils::Address_Distribution_Type, double, Utils::Request_Size_Distribution_Type, unsigned int, unsigned int, Utils::Request_Generator_Type, unsigned long, unsigned int, bool, unsigned int, int, unsigned long, double, unsigned int, HostInterface_Types, Host_Components::PCIe_Root_Complex*, Host_Components::SATA_HBA*, bool, unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
IO_Flow_Synthetic::IO_Flow_Synthetic(const sim_object_id_type &name, uint16_t flow_id,
									 LHA_type start_lsa_on_device, LHA_type end_lsa_on_device, double working_set_ratio, uint16_t io_queue_id,
									 uint16_t nvme_submission_queue_size, uint16_t nvme_completion_queue_size, IO_Flow_Priority_Class::Priority priority_class,
									 double read_ratio, Utils::Address_Distribution_Type address_distribution, double hot_region_ratio,
									 Utils::Request_Size_Distribution_Type request_size_distribution, unsigned int average_request_size, unsigned int variance_request_size,
									 Utils::Request_Generator_Type generator_type, sim_time_type Average_inter_arrival_time_nano_sec, unsigned int average_number_of_enqueued_requests,
									 bool generate_aligned_addresses, unsigned int alignment_value,
									 int seed, sim_time_type stop_time, double initial_occupancy_ratio, unsigned int total_req_count, HostInterface_Types SSD_device_type, PCIe_Root_Complex *pcie_root_complex, SATA_HBA *sata_hba,
									 bool enabled_logging, sim_time_type logging_period, std::string logging_file_path) : IO_Flow_Base(name, flow_id, start_lsa_on_device, LHA_type(start_lsa_on_device + (end_lsa_on_device - start_lsa_on_device) * working_set_ratio), io_queue_id, nvme_submission_queue_size, nvme_completion_queue_size, priority_class, stop_time, initial_occupancy_ratio, total_req_count, SSD_device_type, pcie_root_complex, sata_hba, enabled_logging, logging_period, logging_file_path),
																														  read_ratio(read_ratio), address_distribution(address_distribution),
																														  working_set_ratio(working_set_ratio), hot_region_ratio(hot_region_ratio),
																														  request_size_distribution(request_size_distribution), average_request_size(average_request_size), variance_request_size(variance_request_size),
																														  generator_type(generator_type), Average_inter_arrival_time_nano_sec(Average_inter_arrival_time_nano_sec), average_number_of_enqueued_requests(average_number_of_enqueued_requests),
																														  seed(seed), generate_aligned_addresses(generate_aligned_addresses), alignment_value(alignment_value)
{
	//If read ratio is 0, then we change its value to a negative one so that in request generation we never generate a read request
	if (read_ratio == 0.0)
	{
		read_ratio = -1.0;
	}
	random_request_type_generator_seed = seed++;
	random_request_type_generator = new Utils::RandomGenerator(random_request_type_generator_seed);
	random_address_generator_seed = seed++;
	random_address_generator = new Utils::RandomGenerator(random_address_generator_seed);
	if (this->start_lsa_on_device > this->end_lsa_on_device)
	{
		throw std::logic_error("Problem in IO Flow Synthetic, the start LBA address is greater than the end LBA address");
	}

	if (address_distribution == Utils::Address_Distribution_Type::RANDOM_HOTCOLD)
	{
		random_hot_address_generator_seed = seed++;
		random_hot_address_generator = new Utils::RandomGenerator(random_hot_address_generator_seed);
		random_hot_cold_generator_seed = seed++;
		random_hot_cold_generator = new Utils::RandomGenerator(random_hot_cold_generator_seed);
		hot_region_end_lsa = this->start_lsa_on_device + (LHA_type)((double)(this->end_lsa_on_device - this->start_lsa_on_device) * hot_region_ratio);
	}

	if (request_size_distribution == Utils::Request_Size_Distribution_Type::NORMAL)
	{
		random_request_size_generator_seed = seed++;
		random_request_size_generator = new Utils::RandomGenerator(random_request_size_generator_seed);
	}

	if (generator_type == Utils::Request_Generator_Type::BANDWIDTH)
	{
		random_time_interval_generator_seed = seed++;
		random_time_interval_generator = new Utils::RandomGenerator(random_time_interval_generator_seed);
	}

	if (this->working_set_ratio == 0)
	{
		PRINT_ERROR("The working set ratio is set to zero for workload " << name)
	}
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %rcx, 0xa0(%rsp)
movl %edx, %eax
movq %rsi, %r10
movq %rdi, %r11
movq 0xa0(%rsp), %rdi
movw %r9w, %dx
movw %ax, %r9w
movq 0x270(%rsp), %rsi
movq 0x268(%rsp), %rax
movb 0x260(%rsp), %al
movq 0x258(%rsp), %rcx
movq 0x250(%rsp), %rcx
movl 0x248(%rsp), %ecx
movl 0x240(%rsp), %ecx
movq 0x238(%rsp), %rcx
movl 0x230(%rsp), %ecx
movl 0x228(%rsp), %ecx
movb 0x220(%rsp), %cl
movl 0x218(%rsp), %ebx
movq 0x210(%rsp), %rbx
movl 0x208(%rsp), %ebx
movl 0x200(%rsp), %ebx
movl 0x1f8(%rsp), %ebx
movl 0x1f0(%rsp), %ebx
movl 0x1e8(%rsp), %ebx
movl 0x1e0(%rsp), %ebx
movw 0x1d8(%rsp), %bx
movw 0x1d0(%rsp), %bx
movq %r11, 0x190(%rsp)
movq %r10, 0x188(%rsp)
movw %r9w, 0x186(%rsp)
movq %rdi, 0x178(%rsp)
movq %r8, 0x170(%rsp)
movsd %xmm0, 0x168(%rsp)
movw %dx, 0x166(%rsp)
movsd %xmm1, 0x158(%rsp)
movsd %xmm2, 0x150(%rsp)
andb $0x1, %cl
movb %cl, 0x14f(%rsp)
movsd %xmm3, 0x140(%rsp)
andb $0x1, %al
movb %al, 0x13f(%rsp)
movq 0x190(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x188(%rsp), %rax
movq %rax, 0xc0(%rsp)
movzwl 0x186(%rsp), %eax
movl %eax, 0xcc(%rsp)
movq 0x178(%rsp), %rcx
movq %rcx, 0xf8(%rsp)
movq %rcx, %xmm1
movaps 0x73cf1(%rip), %xmm3    # 0xab9b0
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
movapd 0x73cf5(%rip), %xmm2    # 0xab9c0
subpd %xmm2, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movq 0x170(%rsp), %rax
subq %rcx, %rax
movq %rax, %xmm0
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
subpd %xmm2, %xmm0
movaps %xmm0, %xmm2
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm2, %xmm0
movsd 0x168(%rsp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x712e3(%rip), %xmm1    # 0xa9008
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, 0xd0(%rsp)
movzwl 0x166(%rsp), %eax
movl %eax, 0xdc(%rsp)
movzwl 0x1d0(%rsp), %eax
movl %eax, 0xbc(%rsp)
movzwl 0x1d8(%rsp), %eax
movl %eax, 0xb8(%rsp)
movl 0x1e0(%rsp), %ebx
movq 0x238(%rsp), %r14
movsd 0x140(%rsp), %xmm0
movsd %xmm0, 0xe0(%rsp)
movl 0x240(%rsp), %ebp
movl 0x248(%rsp), %r15d
movq 0x250(%rsp), %r12
movq 0x258(%rsp), %r13
movq 0x268(%rsp), %rax
movq %rax, 0xf0(%rsp)
movzbl 0x13f(%rsp), %eax
movl %eax, 0xb4(%rsp)
leaq 0x118(%rsp), %rdi
movq %rdi, 0xa8(%rsp)
callq 0x81a0
movq 0xa8(%rsp), %rcx
movl 0xb4(%rsp), %edi
movl 0xb8(%rsp), %r11d
movl 0xbc(%rsp), %r10d
movq 0xc0(%rsp), %rsi
movl 0xcc(%rsp), %edx
movq 0xd0(%rsp), %r8
movl 0xdc(%rsp), %r9d
movsd 0xe0(%rsp), %xmm0
movq %rsp, %rax
movq %rax, 0xe8(%rsp)
movq %rcx, 0x50(%rax)
movq 0xf0(%rsp), %rcx
movq %rcx, 0x48(%rax)
movq 0xf8(%rsp), %rcx
andl $0x1, %edi
movl %edi, 0x40(%rax)
movq 0x100(%rsp), %rdi
movq %r13, 0x38(%rax)
movq %r12, 0x30(%rax)
movl %r15d, 0x28(%rax)
movl %ebp, 0x20(%rax)
movq %r14, 0x18(%rax)
movl %ebx, 0x10(%rax)
movl %r11d, 0x8(%rax)
movl %r10d, (%rax)
callq 0x2fdf0
jmp 0x37e79
leaq 0x118(%rsp), %rdi
callq 0x8848
movq 0x100(%rsp), %rax
leaq 0xa0d9b(%rip), %rcx     # 0xd8c30
addq $0x10, %rcx
movq %rcx, (%rax)
leaq 0xa0d8d(%rip), %rcx     # 0xd8c30
addq $0x68, %rcx
movq %rcx, 0x30(%rax)
movsd 0x158(%rsp), %xmm0
movsd %xmm0, 0x470(%rax)
movsd 0x168(%rsp), %xmm0
movsd %xmm0, 0x478(%rax)
movl 0x1e8(%rsp), %ecx
movl %ecx, 0x48c(%rax)
movsd 0x150(%rsp), %xmm0
movsd %xmm0, 0x490(%rax)
movl 0x1f0(%rsp), %ecx
movl %ecx, 0x4d8(%rax)
movl 0x1f8(%rsp), %ecx
movl %ecx, 0x4dc(%rax)
movl 0x200(%rsp), %ecx
movl %ecx, 0x4e0(%rax)
movl 0x208(%rsp), %ecx
movl %ecx, 0x4f4(%rax)
movq 0x210(%rsp), %rcx
movq %rcx, 0x508(%rax)
movl 0x218(%rsp), %ecx
movl %ecx, 0x510(%rax)
movb 0x14f(%rsp), %cl
andb $0x1, %cl
movb %cl, 0x514(%rax)
movl 0x228(%rsp), %ecx
movl %ecx, 0x518(%rax)
movl 0x230(%rsp), %ecx
movl %ecx, 0x51c(%rax)
movsd 0x158(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x37fb2
jp 0x37fb2
movsd 0x73d37(%rip), %xmm0    # 0xabcb8
movsd %xmm0, 0x158(%rsp)
jmp 0x37fb2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
leaq 0x118(%rsp), %rdi
callq 0x8848
jmp 0x384b1
movq 0x100(%rsp), %rax
movl 0x230(%rsp), %ecx
movl %ecx, %edx
incl %edx
movl %edx, 0x230(%rsp)
movl %ecx, 0x488(%rax)
movl $0x18, %edi
callq 0x8450
movq %rax, 0x98(%rsp)
jmp 0x37fe6
movq 0x98(%rsp), %rdi
movq 0x100(%rsp), %rax
movl 0x488(%rax), %esi
callq 0xa6e40
jmp 0x38003
movq 0x100(%rsp), %rax
movq 0x98(%rsp), %rcx
movq %rcx, 0x480(%rax)
movl 0x230(%rsp), %ecx
movl %ecx, %edx
incl %edx
movl %edx, 0x230(%rsp)
movl %ecx, 0x4a0(%rax)
movl $0x18, %edi
callq 0x8450
movq %rax, 0x90(%rsp)
jmp 0x38046
movq 0x90(%rsp), %rdi
movq 0x100(%rsp), %rax
movl 0x4a0(%rax), %esi
callq 0xa6e40
jmp 0x38063
movq 0x100(%rsp), %rcx
movq 0x90(%rsp), %rax
movq %rax, 0x498(%rcx)
movq 0x68(%rcx), %rax
cmpq 0x70(%rcx), %rax
jbe 0x38159
movl $0x10, %edi
callq 0x8200
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x88(%rsp)
leaq 0x73c21(%rip), %rsi     # 0xabcc8
callq 0x8610
jmp 0x380ae
movq 0x88(%rsp), %rdi
movq 0xa1f03(%rip), %rsi     # 0xd9fc0
movq 0xa1ecc(%rip), %rdx     # 0xd9f90
callq 0x8710
jmp 0x384be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
jmp 0x384a4
movq 0x98(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
callq 0x8410
jmp 0x384a4
movq 0x90(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
callq 0x8410
jmp 0x384a4
movq 0x88(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
callq 0x8330
jmp 0x384a4
cmpl $0x3, 0x1e8(%rsp)
jne 0x382e0
movq 0x100(%rsp), %rax
movl 0x230(%rsp), %ecx
movl %ecx, %edx
incl %edx
movl %edx, 0x230(%rsp)
movl %ecx, 0x4c0(%rax)
movl $0x18, %edi
callq 0x8450
movq %rax, 0x80(%rsp)
jmp 0x3819b
movq 0x80(%rsp), %rdi
movq 0x100(%rsp), %rax
movl 0x4c0(%rax), %esi
callq 0xa6e40
jmp 0x381b8
movq 0x100(%rsp), %rax
movq 0x80(%rsp), %rcx
movq %rcx, 0x4b8(%rax)
movl 0x230(%rsp), %ecx
movl %ecx, %edx
incl %edx
movl %edx, 0x230(%rsp)
movl %ecx, 0x4b0(%rax)
movl $0x18, %edi
callq 0x8450
movq %rax, 0x78(%rsp)
jmp 0x381f8
movq 0x78(%rsp), %rdi
movq 0x100(%rsp), %rax
movl 0x4b0(%rax), %esi
callq 0xa6e40
jmp 0x38212
movq 0x100(%rsp), %rax
movq 0x78(%rsp), %rcx
movq %rcx, 0x4a8(%rax)
movq 0x68(%rax), %rcx
movq 0x70(%rax), %rdx
subq %rcx, %rdx
movq %rdx, %xmm0
movaps 0x73773(%rip), %xmm1    # 0xab9b0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x73777(%rip), %xmm1    # 0xab9c0
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x150(%rsp), %xmm1
mulsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rdx
movq %rdx, %rdi
sarq $0x3f, %rdi
movsd 0x70d8c(%rip), %xmm1    # 0xa9008
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rsi
andq %rdi, %rsi
orq %rsi, %rdx
addq %rdx, %rcx
movq %rcx, 0x4c8(%rax)
jmp 0x382e0
movq 0x80(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
callq 0x8410
jmp 0x384a4
movq 0x78(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
callq 0x8410
jmp 0x384a4
cmpl $0x1, 0x1f0(%rsp)
jne 0x38372
movq 0x100(%rsp), %rax
movl 0x230(%rsp), %ecx
movl %ecx, %edx
incl %edx
movl %edx, 0x230(%rsp)
movl %ecx, 0x4f0(%rax)
movl $0x18, %edi
callq 0x8450
movq %rax, 0x70(%rsp)
jmp 0x3831f
movq 0x70(%rsp), %rdi
movq 0x100(%rsp), %rax
movl 0x4f0(%rax), %esi
callq 0xa6e40
jmp 0x38339
movq 0x100(%rsp), %rax
movq 0x70(%rsp), %rcx
movq %rcx, 0x4e8(%rax)
jmp 0x38372
movq 0x70(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
callq 0x8410
jmp 0x384a4
cmpl $0x0, 0x208(%rsp)
jne 0x38404
movq 0x100(%rsp), %rax
movl 0x230(%rsp), %ecx
movl %ecx, %edx
incl %edx
movl %edx, 0x230(%rsp)
movl %ecx, 0x500(%rax)
movl $0x18, %edi
callq 0x8450
movq %rax, 0x68(%rsp)
jmp 0x383b1
movq 0x68(%rsp), %rdi
movq 0x100(%rsp), %rax
movl 0x500(%rax), %esi
callq 0xa6e40
jmp 0x383cb
movq 0x100(%rsp), %rax
movq 0x68(%rsp), %rcx
movq %rcx, 0x4f8(%rax)
jmp 0x38404
movq 0x68(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
callq 0x8410
jmp 0x384a4
movq 0x100(%rsp), %rax
movsd 0x478(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x38492
jp 0x38492
movq 0xa1bca(%rip), %rdi     # 0xd9ff0
leaq 0x724bb(%rip), %rsi     # 0xaa8e8
callq 0x8440
jmp 0x38434
movq 0xa1bb5(%rip), %rdi     # 0xd9ff0
leaq 0x738de(%rip), %rsi     # 0xabd20
callq 0x8440
movq %rax, 0x60(%rsp)
jmp 0x3844e
movq 0x60(%rsp), %rdi
movq 0x188(%rsp), %rsi
callq 0x83e0
movq %rax, 0x58(%rsp)
jmp 0x38467
movq 0x58(%rsp), %rdi
movq 0xa1ae5(%rip), %rsi     # 0xd9f58
callq 0x8480
jmp 0x3847a
movq 0xa1b4f(%rip), %rdi     # 0xd9fd0
callq 0x84f0
jmp 0x38488
movl $0x1, %edi
callq 0x8500
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x100(%rsp), %rdi
callq 0x305d0
movq 0x110(%rsp), %rdi
callq 0x8770
nop