// File: /workspace/github_cpp_makefile_star2_O3/CMU-SAFARI[P]MQSim/src/ssd/Address_Mapping_Unit_Page_Level.cpp
// Function: SSD_Components::Address_Mapping_Unit_Page_Level::Allocate_address_for_preconditioning(unsigned short, std::map<unsigned long, unsigned long, std::less<unsigned long>, std::allocator<std::pair<unsigned long const, unsigned long>>>&, std::vector<double, std::allocator<double>>&)
void Address_Mapping_Unit_Page_Level::Allocate_address_for_preconditioning(const stream_id_type stream_id, std::map<LPA_type, page_status_type>& lpa_list, std::vector<double>& steady_state_distribution)
	{
		int idx = 0;
		std::vector<LPA_type>**** assigned_lpas = new std::vector<LPA_type>***[channel_count];
		for (unsigned int channel_cntr = 0; channel_cntr < channel_count; channel_cntr++) {
			assigned_lpas[channel_cntr] = new std::vector<LPA_type>**[chip_no_per_channel];
			for (unsigned int chip_cntr = 0; chip_cntr < chip_no_per_channel; chip_cntr++) {
				assigned_lpas[channel_cntr][chip_cntr] = new std::vector<LPA_type>*[die_no_per_chip];
				for (unsigned int die_cntr = 0; die_cntr < die_no_per_chip; die_cntr++) {
					assigned_lpas[channel_cntr][chip_cntr][die_cntr] = new std::vector<LPA_type>[plane_no_per_die];
				}
			}
		}

		//First: distribute LPAs to planes
		NVM::FlashMemory::Physical_Page_Address plane_address;
		for (auto lpa = lpa_list.begin(); lpa != lpa_list.end();) {
			if ((*lpa).first >= domains[stream_id]->Total_logical_pages_no) {
				PRINT_ERROR("Out of range LPA specified for preconditioning! LPA shoud be smaller than " << domains[stream_id]->Total_logical_pages_no << ", but it is " << (*lpa).first)
			}
			PPA_type ppa = domains[stream_id]->Get_ppa_for_preconditioning(stream_id, (*lpa).first);
			if (ppa != NO_LPA) {
				PRINT_ERROR("Calling address allocation for a previously allocated LPA during preconditioning!")
			}
			allocate_plane_for_preconditioning(stream_id, (*lpa).first, plane_address);
			if (LPA_type(Utils::Logical_Address_Partitioning_Unit::Get_share_of_physcial_pages_in_plane(plane_address.ChannelID, plane_address.ChipID, plane_address.DieID, plane_address.PlaneID) * page_no_per_plane)
				> assigned_lpas[plane_address.ChannelID][plane_address.ChipID][plane_address.DieID][plane_address.PlaneID].size()) {
				assigned_lpas[plane_address.ChannelID][plane_address.ChipID][plane_address.DieID][plane_address.PlaneID].push_back((*lpa).first);
				lpa++;
			} else {
				lpa_list.erase(lpa++);
			}
		}

		//Second: distribute LPAs within planes based on the steady-state status of blocks
		//unsigned int safe_guard_band = ftl->GC_and_WL_Unit->Get_minimum_number_of_free_pages_before_GC();
		for (unsigned int channel_cntr = 0; channel_cntr < domains[stream_id]->Channel_no; channel_cntr++) {
			for (unsigned int chip_cntr = 0; chip_cntr < domains[stream_id]->Chip_no; chip_cntr++) {
				for (unsigned int die_cntr = 0; die_cntr < domains[stream_id]->Die_no; die_cntr++) {
					for (unsigned int plane_cntr = 0; plane_cntr < domains[stream_id]->Plane_no; plane_cntr++) {
						plane_address.ChannelID = domains[stream_id]->Channel_ids[channel_cntr];
						plane_address.ChipID = domains[stream_id]->Chip_ids[chip_cntr];
						plane_address.DieID = domains[stream_id]->Die_ids[die_cntr];
						plane_address.PlaneID = domains[stream_id]->Plane_ids[plane_cntr];

						unsigned int physical_block_consumption_goal = (unsigned int)(double(block_no_per_plane - ftl->GC_and_WL_Unit->Get_minimum_number_of_free_pages_before_GC() / 2)
							* Utils::Logical_Address_Partitioning_Unit::Get_share_of_physcial_pages_in_plane(plane_address.ChannelID, plane_address.ChipID, plane_address.DieID, plane_address.PlaneID));

						//Adjust the average
						double model_average = 0;
						std::vector<double> adjusted_steady_state_distribution;
						//Check if probability distribution is correct 
						for (unsigned int i = 0; i <= pages_no_per_block; i++) {
							model_average += steady_state_distribution[i] * double(i) / double(pages_no_per_block);
							adjusted_steady_state_distribution.push_back(steady_state_distribution[i]);
						}
						double real_average = double(assigned_lpas[plane_address.ChannelID][plane_address.ChipID][plane_address.DieID][plane_address.PlaneID].size()) / (physical_block_consumption_goal * pages_no_per_block);
						if (std::abs(model_average - real_average) * pages_no_per_block > 0.9999) {
							int displacement_index = int((real_average - model_average) * pages_no_per_block);
							if (displacement_index > 0) {
								for (int i = 0; i < displacement_index; i++) {
									adjusted_steady_state_distribution[i] = 0;
								}
								for (int i = displacement_index; i < int(pages_no_per_block); i++) {
									adjusted_steady_state_distribution[i] = steady_state_distribution[i - displacement_index];
								}
							} else {
								displacement_index *= -1;
								for (int i = 0; i < int(pages_no_per_block) - displacement_index; i++) {
									adjusted_steady_state_distribution[i] = steady_state_distribution[i + displacement_index];
								}
								for (int i = int(pages_no_per_block) - displacement_index; i < int(pages_no_per_block); i++) {
									adjusted_steady_state_distribution[i] = 0;
								}
							}
						}

						//Check if it is possible to find a PPA for each LPA with current proability assignments 
						unsigned int total_valid_pages = 0;
						for (int valid_pages_in_block = pages_no_per_block; valid_pages_in_block >= 0; valid_pages_in_block--) {
							total_valid_pages += valid_pages_in_block * (unsigned int)(adjusted_steady_state_distribution[valid_pages_in_block] * physical_block_consumption_goal);
						}
						unsigned int pages_need_PPA = 0;//The number of LPAs that remain unassigned due to imperfect probability assignments
						if (total_valid_pages < assigned_lpas[plane_address.ChannelID][plane_address.ChipID][plane_address.DieID][plane_address.PlaneID].size()) {
							pages_need_PPA = (unsigned int)(assigned_lpas[plane_address.ChannelID][plane_address.ChipID][plane_address.DieID][plane_address.PlaneID].size()) - total_valid_pages;
						}
						
						unsigned int remaining_blocks_to_consume = physical_block_consumption_goal;
						for (int valid_pages_in_block = pages_no_per_block; valid_pages_in_block >= 0; valid_pages_in_block--) {
							unsigned int block_no_with_x_valid_page = (unsigned int)(adjusted_steady_state_distribution[valid_pages_in_block] * physical_block_consumption_goal);
							if (block_no_with_x_valid_page > 0 && pages_need_PPA > 0) {
								block_no_with_x_valid_page += (pages_need_PPA / valid_pages_in_block) + (pages_need_PPA % valid_pages_in_block == 0 ? 0 : 1);
								pages_need_PPA = 0;
							}

							if (block_no_with_x_valid_page <= remaining_blocks_to_consume) {
								remaining_blocks_to_consume -= block_no_with_x_valid_page;
							} else {
								block_no_with_x_valid_page = remaining_blocks_to_consume;
								remaining_blocks_to_consume = 0;
							}

							for (unsigned int block_cntr = 0; block_cntr < block_no_with_x_valid_page; block_cntr++) {
								//Assign physical addresses
								std::vector<NVM::FlashMemory::Physical_Page_Address> addresses;
								if (assigned_lpas[plane_address.ChannelID][plane_address.ChipID][plane_address.DieID][plane_address.PlaneID].size() < valid_pages_in_block) {
									valid_pages_in_block = int(assigned_lpas[plane_address.ChannelID][plane_address.ChipID][plane_address.DieID][plane_address.PlaneID].size());
								}
								for (int page_cntr = 0; page_cntr < valid_pages_in_block; page_cntr++) {
									NVM::FlashMemory::Physical_Page_Address addr(plane_address.ChannelID, plane_address.ChipID, plane_address.DieID, plane_address.PlaneID, 0, 0);
									addresses.push_back(addr);
								}
								block_manager->Allocate_Pages_in_block_and_invalidate_remaining_for_preconditioning(stream_id, plane_address, addresses);

								//Update mapping table
								for (auto const &address : addresses) {
									LPA_type lpa = assigned_lpas[plane_address.ChannelID][plane_address.ChipID][plane_address.DieID][plane_address.PlaneID].back();
									assigned_lpas[plane_address.ChannelID][plane_address.ChipID][plane_address.DieID][plane_address.PlaneID].pop_back();
									PPA_type ppa = Convert_address_to_ppa(address);
									flash_controller->Change_memory_status_preconditioning(&address, &lpa);
									domains[stream_id]->GlobalMappingTable[lpa].PPA = ppa;
									domains[stream_id]->GlobalMappingTable[lpa].WrittenStateBitmap = (*lpa_list.find(lpa)).second;
									domains[stream_id]->GlobalMappingTable[lpa].TimeStamp = 0;
								}
							}
						}
						if (assigned_lpas[plane_address.ChannelID][plane_address.ChipID][plane_address.DieID][plane_address.PlaneID].size() > 0) {
							PRINT_ERROR("It is not possible to assign PPA to all LPAs in Allocate_address_for_preconditioning! It is not safe to continue preconditioning." << assigned_lpas[plane_address.ChannelID][plane_address.ChipID][plane_address.DieID][plane_address.PlaneID].size())
						}
					}
				}
			}
		}

		for (unsigned int channel_cntr = 0; channel_cntr < channel_count; channel_cntr++) {
			for (unsigned int chip_cntr = 0; chip_cntr < chip_no_per_channel; chip_cntr++) {
				for (unsigned int die_cntr = 0; die_cntr < die_no_per_chip; die_cntr++) {
					delete[] assigned_lpas[channel_cntr][chip_cntr][die_cntr];
				}
				delete[] assigned_lpas[channel_cntr][chip_cntr];
			}
			delete[] assigned_lpas[channel_cntr];
		}
		delete[] assigned_lpas;
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rcx, 0x48(%rsp)
movq %rdx, 0x98(%rsp)
movl %esi, 0x58(%rsp)
movq %rdi, %r14
movl 0x64(%rdi), %ebx
leaq (,%rbx,8), %rdi
callq 0x7030
movq %rax, 0x38(%rsp)
movq %rbx, 0x90(%rsp)
testq %rbx, %rbx
je 0x2c445
movl 0x68(%r14), %eax
movl 0x6c(%r14), %ecx
movq %rax, 0x30(%rsp)
leaq (,%rax,8), %rax
movq %rax, 0x60(%rsp)
movq %rcx, 0x28(%rsp)
leaq (,%rcx,8), %rax
movq %rax, 0x50(%rsp)
xorl %ebx, %ebx
movq 0x60(%rsp), %rdi
callq 0x7030
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq %rbx, 0x68(%rsp)
movq %rcx, 0x8(%rsp)
movq %rcx, (%rax,%rbx,8)
cmpq $0x0, 0x30(%rsp)
je 0x2c42f
movl 0x70(%r14), %r13d
leaq (,%r13,8), %rax
leaq (%rax,%rax,2), %r15
addq $0x8, %r15
leaq (%rax,%rax,2), %rax
addq $-0x18, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
mulq %rcx
shrq $0x4, %rdx
leaq (%rdx,%rdx,2), %rax
leaq 0x18(,%rax,8), %rax
movq %rax, 0x40(%rsp)
xorl %r12d, %r12d
movq 0x50(%rsp), %rdi
callq 0x7030
movq 0x8(%rsp), %rcx
movq %rax, (%rcx,%r12,8)
cmpq $0x0, 0x28(%rsp)
je 0x2c425
xorl %ebp, %ebp
movq %r15, %rdi
callq 0x7030
leaq 0x8(%rax), %rbx
movq %r13, (%rax)
testq %r13, %r13
je 0x2c40e
movq %rbx, %rdi
xorl %esi, %esi
movq 0x40(%rsp), %rdx
callq 0x7230
movq 0x8(%rsp), %rax
movq (%rax,%r12,8), %rax
movq %rbx, (%rax,%rbp,8)
incq %rbp
cmpq %rbp, 0x28(%rsp)
jne 0x2c3eb
incq %r12
cmpq 0x30(%rsp), %r12
jne 0x2c3ce
movq 0x68(%rsp), %rbx
incq %rbx
cmpq 0x90(%rsp), %rbx
jne 0x2c361
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x98(%rsp), %rax
movq 0x18(%rax), %r15
leaq 0x8(%rax), %r12
movzwl 0x58(%rsp), %eax
movq %rax, 0x8(%rsp)
cmpq %r12, %r15
je 0x2c5ad
leaq 0x10(%rsp), %rbx
movq 0x48(%rsp), %r13
leaq 0x20(%r15), %rbp
movq 0x20(%r15), %rdx
movq 0xa8(%r14), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
cmpq 0x258(%rax), %rdx
jae 0x2ce2e
movq 0x20(%rax), %rax
leaq (%rdx,%rdx,2), %rcx
cmpq $-0x1, (%rax,%rcx,8)
jne 0x2ce8f
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rcx
callq 0x2cf0a
movl 0x10(%rsp), %edi
movl 0x14(%rsp), %esi
movl 0x18(%rsp), %edx
movl 0x1c(%rsp), %ecx
callq 0x52f26
movl 0x94(%r14), %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x28b47(%rip), %xmm1    # 0x55050
cvttsd2si %xmm1, %rdx
andq %rcx, %rdx
orq %rax, %rdx
movl 0x10(%rsp), %eax
movl 0x14(%rsp), %ecx
movq 0x38(%rsp), %rsi
movq (%rsi,%rax,8), %rax
movq (%rax,%rcx,8), %rax
movl 0x18(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movl 0x1c(%rsp), %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x8(%rax,%rcx,8), %rsi
movq %rsi, %rdi
subq (%rax,%rcx,8), %rdi
sarq $0x3, %rdi
cmpq %rdx, %rdi
jae 0x2c569
leaq (%rax,%rcx,8), %rdi
cmpq 0x10(%rdi), %rsi
je 0x2c58f
movq (%rbp), %rax
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x2c597
movq %r15, %rdi
callq 0x72a0
movq %rbx, %rbp
movq %rax, %rbx
movq 0x98(%rsp), %rdi
movq %r15, %rsi
callq 0x30f24
movq %rbx, %r15
movq %rbp, %rbx
jmp 0x2c5a2
movq %rbp, %rdx
callq 0x30e4e
movq %r15, %rdi
callq 0x72a0
movq %rax, %r15
cmpq %r12, %r15
jne 0x2c485
jmp 0x2c5b2
movq 0x48(%rsp), %r13
movq 0xa8(%r14), %rcx
movq 0x8(%rsp), %rax
movq (%rcx,%rax,8), %rax
cmpl $0x0, 0x218(%rax)
je 0x2ccd0
movq $0x0, 0x88(%rsp)
cmpl $0x0, 0x228(%rax)
je 0x2ccae
movq $0x0, 0x58(%rsp)
cmpl $0x0, 0x238(%rax)
je 0x2cc89
movq $0x0, 0x60(%rsp)
cmpl $0x0, 0x248(%rax)
je 0x2cc64
xorl %esi, %esi
movq 0x210(%rax), %rcx
movq 0x88(%rsp), %rdx
movl (%rcx,%rdx,4), %ecx
movl %ecx, 0x10(%rsp)
movq 0x220(%rax), %rcx
movq 0x58(%rsp), %rdx
movl (%rcx,%rdx,4), %ecx
movl %ecx, 0x14(%rsp)
movq 0x230(%rax), %rcx
movq 0x60(%rsp), %rdx
movl (%rcx,%rdx,4), %ecx
movl %ecx, 0x18(%rsp)
movq 0x240(%rax), %rax
movq %rsi, 0x90(%rsp)
movl (%rax,%rsi,4), %eax
movl %eax, 0x1c(%rsp)
movl 0x74(%r14), %ebx
movq 0x30(%r14), %rax
movq 0x48(%rax), %rdi
callq 0x3f9a4
shrl %eax
subl %eax, %ebx
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
movsd %xmm0, 0x28(%rsp)
movl 0x10(%rsp), %edi
movl 0x14(%rsp), %esi
movl 0x18(%rsp), %edx
movl 0x1c(%rsp), %ecx
callq 0x52f26
mulsd 0x28(%rsp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, 0x40(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x70(%rsp)
movq $0x0, 0x80(%rsp)
movl 0x78(%r14), %ebp
xorpd %xmm0, %xmm0
movsd %xmm0, 0x28(%rsp)
xorl %ebx, %ebx
movl %ebx, %r15d
movq (%r13), %rax
movsd (%rax,%r15,8), %xmm1
movq 0x78(%rsp), %rsi
cmpq 0x80(%rsp), %rsi
je 0x2c704
movsd %xmm1, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x78(%rsp)
movl %ebp, %r10d
jmp 0x2c722
movsd %xmm1, 0x30(%rsp)
leaq (%rax,%r15,8), %rdx
leaq 0x70(%rsp), %rdi
callq 0x30f5c
movl 0x78(%r14), %r10d
movsd 0x30(%rsp), %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
mulsd %xmm0, %xmm1
movl %ebp, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd %xmm0, %xmm1
movsd 0x28(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
incl %ebx
movl %r10d, %ebp
cmpl %r10d, %ebx
jbe 0x2c6d6
movl 0x10(%rsp), %eax
movl 0x14(%rsp), %ecx
movq 0x38(%rsp), %rdx
movq (%rdx,%rax,8), %rax
movq (%rax,%rcx,8), %rax
movl 0x18(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movl 0x1c(%rsp), %ecx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %r11
movq 0x8(%rax,%rcx,8), %rbx
movq %rbx, %rbp
subq %r11, %rbp
sarq $0x3, %rbp
movq %rbp, %xmm1
punpckldq 0x2b125(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x2b12d(%rip), %xmm1    # 0x578d0
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movl %r10d, %eax
imull 0x40(%rsp), %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movsd 0x28(%rsp), %xmm3
movapd %xmm3, %xmm2
subsd %xmm0, %xmm2
movl %r10d, %r13d
xorps %xmm1, %xmm1
cvtsi2sd %r13, %xmm1
andpd 0x2bd4c(%rip), %xmm2    # 0x58530
mulsd %xmm1, %xmm2
ucomisd 0x2bba0(%rip), %xmm2    # 0x58390
jbe 0x2c908
subsd %xmm3, %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %r15d
testl %r15d, %r15d
jle 0x2c881
movq 0x70(%rsp), %rdi
movl %r15d, %eax
movq %rax, 0x50(%rsp)
leaq (,%rax,8), %rdx
movq %rdi, 0x68(%rsp)
xorl %esi, %esi
movq %r10, 0x28(%rsp)
movq %rbx, 0x30(%rsp)
movq %r11, %rbx
callq 0x7230
movq %rbx, %r11
movq 0x30(%rsp), %rbx
movq 0x28(%rsp), %r10
cmpl %r15d, %r10d
jle 0x2c908
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq 0x50(%rsp), %rsi
movq 0x68(%rsp), %rcx
leaq (%rcx,%rsi,8), %rcx
movq %r13, %rdx
subq %rsi, %rdx
xorl %esi, %esi
movsd (%rax,%rsi,8), %xmm0
movsd %xmm0, (%rcx,%rsi,8)
incq %rsi
cmpq %rsi, %rdx
jne 0x2c86a
jmp 0x2c908
movl %r10d, %eax
addl %r15d, %eax
jle 0x2c8bb
movq 0x48(%rsp), %rcx
movq (%rcx), %rcx
movq 0x70(%rsp), %rdx
movl %eax, %esi
movl %r15d, %edi
negl %edi
xorl %r8d, %r8d
leal (%rdi,%r8), %r9d
movslq %r9d, %r9
movsd (%rcx,%r9,8), %xmm0
movsd %xmm0, (%rdx,%r8,8)
incq %r8
cmpq %r8, %rsi
jne 0x2c8a0
testl %r15d, %r15d
jns 0x2c908
movslq %eax, %rdi
shlq $0x3, %rdi
addq 0x70(%rsp), %rdi
movl %r15d, %eax
leal (%r15,%r10), %ecx
incl %ecx
cmpl %ecx, %r10d
cmovgl %r10d, %ecx
notl %eax
addl %eax, %ecx
subl %r10d, %ecx
leaq 0x8(,%rcx,8), %rdx
xorl %esi, %esi
movq %rbx, 0x30(%rsp)
movq %r10, %rbx
movq %r11, %r15
callq 0x7230
movq %r15, %r11
movq %rbx, %r10
movq 0x30(%rsp), %rbx
testl %r10d, %r10d
js 0x2cc1d
movq 0x70(%rsp), %rdx
movl 0x40(%rsp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
xorl %ecx, %ecx
leaq 0xc0(%rsp), %r15
movsd (%rdx,%r13,8), %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %rsi
imull %r13d, %esi
addl %esi, %ecx
addq $-0x1, %r13
jb 0x2c92c
testl %r10d, %r10d
movq 0x48(%rsp), %r13
js 0x2cc22
movl %ecx, %edx
movl %ebp, %esi
subl %ecx, %esi
cmpq %rdx, %rbp
movl $0x0, %ecx
cmovbel %ecx, %esi
movl %esi, 0x50(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x68(%rsp)
movl %r10d, %eax
movq 0x70(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm0
mulsd 0x68(%rsp), %xmm0
cvttsd2si %xmm0, %rcx
testl %ecx, %ecx
je 0x2c9b3
movl 0x50(%rsp), %eax
testl %eax, %eax
je 0x2c9b3
xorl %edx, %edx
divl %r10d
addl %ecx, %eax
cmpl $0x1, %edx
sbbl $-0x1, %eax
movl $0x0, 0x50(%rsp)
movl %eax, %ecx
movq 0x40(%rsp), %rdx
movl %edx, %esi
subl %ecx, %esi
movl $0x0, %eax
cmovbl %eax, %esi
movl %esi, 0x30(%rsp)
cmoval %ecx, %edx
movq %rdx, 0x40(%rsp)
testl %edx, %edx
je 0x2cbcf
xorl %r13d, %r13d
xorpd %xmm0, %xmm0
movapd %xmm0, 0xc0(%rsp)
movq $0x0, 0xd0(%rsp)
movl 0x10(%rsp), %eax
movl 0x14(%rsp), %ecx
movq 0x38(%rsp), %rdx
movq (%rdx,%rax,8), %rax
movq (%rax,%rcx,8), %rax
movl 0x18(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movl 0x1c(%rsp), %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x8(%rax,%rcx,8), %rdx
subq (%rax,%rcx,8), %rdx
sarq $0x3, %rdx
movslq %r10d, %r10
cmpq %r10, %rdx
cmovbl %edx, %r10d
movl %r10d, %ebx
movq %r10, 0x28(%rsp)
testl %r10d, %r10d
jle 0x2ca6c
movapd 0x10(%rsp), %xmm0
movapd %xmm0, 0xa0(%rsp)
movq $0x0, 0xb0(%rsp)
movq %r15, %rdi
leaq 0xa0(%rsp), %rsi
callq 0x2f7b8
decl %ebx
jne 0x2ca3d
movq 0x40(%r14), %rdi
movq (%rdi), %rax
movq 0x8(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movq %r15, %rcx
callq *0x28(%rax)
movq 0xc0(%rsp), %rbp
movq 0xc8(%rsp), %r15
cmpq %r15, %rbp
je 0x2cba7
movl 0x10(%rsp), %eax
movl 0x14(%rsp), %ecx
movq 0x38(%rsp), %rdx
movq (%rdx,%rax,8), %rax
movq (%rax,%rcx,8), %rax
movl 0x18(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movl 0x1c(%rsp), %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x8(%rax,%rcx,8), %rdx
movq -0x8(%rdx), %rsi
addq $-0x8, %rdx
movq %rsi, 0xa0(%rsp)
movq %rdx, 0x8(%rax,%rcx,8)
movq (%r14), %rax
movq %r14, %rdi
movq %rbp, %rsi
callq *0x90(%rax)
movq %rax, %rbx
movq 0x38(%r14), %rdi
movq (%rdi), %rax
movq %rbp, %rsi
leaq 0xa0(%rsp), %rdx
callq *0x20(%rax)
movq 0xa8(%r14), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x20(%rax), %rax
movq 0xa0(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq %rbx, (%rax,%rcx,8)
movq 0x98(%rsp), %rcx
movq 0x10(%rcx), %rsi
movq 0xa0(%rsp), %rcx
movq %r12, %rdi
testq %rsi, %rsi
je 0x2cb70
movq %r12, %rdx
xorl %edi, %edi
cmpq %rcx, 0x20(%rsi)
setb %dil
cmovaeq %rsi, %rdx
movq 0x10(%rsi,%rdi,8), %rsi
testq %rsi, %rsi
jne 0x2cb45
movq %r12, %rdi
cmpq %r12, %rdx
je 0x2cb70
cmpq 0x20(%rdx), %rcx
cmovbq %r12, %rdx
movq %rdx, %rdi
movq 0x28(%rdi), %rdx
leaq (%rcx,%rcx,2), %rcx
movq %rdx, 0x8(%rax,%rcx,8)
movq 0xa0(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq $0x0, 0x10(%rax,%rcx,8)
addq $0x18, %rbp
cmpq %r15, %rbp
jne 0x2ca9c
movq 0xc0(%rsp), %rbp
testq %rbp, %rbp
je 0x2cbb4
movq %rbp, %rdi
callq 0x7370
incl %r13d
cmpl 0x40(%rsp), %r13d
leaq 0xc0(%rsp), %r15
movq 0x28(%rsp), %r10
jne 0x2c9db
leal -0x1(%r10), %eax
movl 0x30(%rsp), %ecx
movq %rcx, 0x40(%rsp)
testl %r10d, %r10d
movl %eax, %r10d
movq 0x48(%rsp), %r13
jg 0x2c978
movl 0x10(%rsp), %eax
movl 0x14(%rsp), %ecx
movq 0x38(%rsp), %rdx
movq (%rdx,%rax,8), %rax
movq (%rax,%rcx,8), %rax
movl 0x18(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movl 0x1c(%rsp), %ecx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %r11
movq 0x8(%rax,%rcx,8), %rbx
jmp 0x2cc22
movq 0x48(%rsp), %r13
cmpq %r11, %rbx
jne 0x2cda7
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x2cc3a
callq 0x7370
movq 0x90(%rsp), %rsi
incq %rsi
movq 0xa8(%r14), %rcx
movq 0x8(%rsp), %rax
movq (%rcx,%rax,8), %rax
movl 0x248(%rax), %edx
cmpq %rdx, %rsi
jb 0x2c616
movq 0x60(%rsp), %rdi
incq %rdi
movl 0x238(%rax), %edx
movq %rdi, 0x60(%rsp)
cmpq %rdx, %rdi
jb 0x2c607
movq 0x8(%rsp), %rax
movq (%rcx,%rax,8), %rax
movq 0x58(%rsp), %rdi
incq %rdi
movl 0x228(%rax), %edx
movq %rdi, 0x58(%rsp)
cmpq %rdx, %rdi
jb 0x2c5f1
movq 0x8(%rsp), %rax
movq (%rcx,%rax,8), %rax
movq 0x88(%rsp), %rdi
incq %rdi
movl 0x218(%rax), %edx
movq %rdi, 0x88(%rsp)
cmpq %rdx, %rdi
jb 0x2c5db
cmpl $0x0, 0x64(%r14)
je 0x2cd8b
xorl %ecx, %ecx
cmpl $0x0, 0x68(%r14)
movq 0x38(%rsp), %rax
movq %rcx, 0x8(%rsp)
movq (%rax,%rcx,8), %r15
je 0x2cd69
xorl %r13d, %r13d
movl 0x6c(%r14), %eax
testl %eax, %eax
je 0x2cd4d
xorl %ebp, %ebp
movq (%r15,%r13,8), %rcx
movq (%rcx,%rbp,8), %r12
testq %r12, %r12
je 0x2cd43
movq -0x8(%r12), %rax
testq %rax, %rax
je 0x2cd33
shlq $0x3, %rax
leaq (%rax,%rax,2), %rbx
movq -0x18(%r12,%rbx), %rdi
testq %rdi, %rdi
je 0x2cd2d
callq 0x7370
addq $-0x18, %rbx
jne 0x2cd1e
addq $-0x8, %r12
movq %r12, %rdi
callq 0x7480
movl 0x6c(%r14), %eax
incq %rbp
movl %eax, %ecx
cmpq %rcx, %rbp
jb 0x2ccff
movq (%r15,%r13,8), %rdi
testq %rdi, %rdi
je 0x2cd5b
callq 0x7480
incq %r13
movl 0x68(%r14), %eax
cmpq %rax, %r13
jb 0x2ccf5
jmp 0x2cd6e
testq %r15, %r15
je 0x2cd76
movq %r15, %rdi
callq 0x7480
movq 0x8(%rsp), %rcx
incq %rcx
movl 0x64(%r14), %eax
cmpq %rax, %rcx
jb 0x2ccdd
movq 0x38(%rsp), %rdi
callq 0x7480
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x42242(%rip), %rdi     # 0x6eff0
leaq 0x297f3(%rip), %rsi     # 0x565a8
movl $0x6, %edx
callq 0x7400
movq 0x4222a(%rip), %rdi     # 0x6eff0
leaq 0x2bba7(%rip), %rsi     # 0x58974
movl $0x81, %edx
callq 0x7400
movl 0x10(%rsp), %eax
movl 0x14(%rsp), %ecx
movq 0x38(%rsp), %rdx
movq (%rdx,%rax,8), %rax
movq (%rax,%rcx,8), %rax
movl 0x18(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movl 0x1c(%rsp), %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x8(%rax,%rcx,8), %rsi
subq (%rax,%rcx,8), %rsi
sarq $0x3, %rsi
movq 0x421e0(%rip), %rdi     # 0x6eff0
callq 0x7280
movq %rax, %rdi
callq 0x71c0
movq 0x421ac(%rip), %rdi     # 0x6efd0
callq 0x7430
jmp 0x2cec8
movq 0x421bb(%rip), %rbx     # 0x6eff0
leaq 0x2976c(%rip), %rsi     # 0x565a8
movq %rbx, %rdi
callq 0x7390
leaq 0x2ba7f(%rip), %rsi     # 0x588ca
movq %rbx, %rdi
callq 0x7390
movq 0xa8(%r14), %rcx
movq 0x8(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x258(%rcx), %rsi
movq %rax, %rdi
callq 0x70f0
leaq 0x2ba9c(%rip), %rsi     # 0x58915
movq %rax, %rdi
callq 0x7390
movq (%rbp), %rsi
movq %rax, %rdi
callq 0x70f0
jmp 0x2ceb4
movq 0x4215a(%rip), %rbx     # 0x6eff0
leaq 0x2970b(%rip), %rsi     # 0x565a8
movq %rbx, %rdi
callq 0x7390
leaq 0x2ba76(%rip), %rsi     # 0x58922
movq %rbx, %rdi
callq 0x7390
movq %rax, %rdi
callq 0x71c0
movq 0x4210d(%rip), %rdi     # 0x6efd0
callq 0x7430
movl $0x1, %edi
callq 0x7440
jmp 0x2ced4
movq %rax, %rbx
jmp 0x2cef2
jmp 0x2cedd
jmp 0x2cedd
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x2cef2
callq 0x7370
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x2cf01
callq 0x7370
movq %rbx, %rdi
callq 0x7620
nop