// File: /workspace/github_cpp_makefile_star2_O3/narges64[P]SIMBA/ftl.cpp
// Function: full_write_preconditioning(ssd_info*, bool)
void full_write_preconditioning(ssd_info * ssd, bool seq){
	unsigned int total_size = ssd->parameter->lun_num * ssd->parameter->plane_lun *
						ssd->parameter->block_plane * ssd->parameter->page_block;
	total_size = total_size * (1-ssd->parameter->overprovide);
	cerr << "full write for total size " << total_size << " page ";
	// add write to table
	int lpn = 0;
	int ppn = -1;
	local * location = new local(0,0,0,0,0);
	for (int i = 0; i <  total_size; i++){
		if (!seq){
			if ((invalid_old_page(ssd, lpn, location) != SUCCESS)){
				#if DEBUG
				cout << "fail in invalid old page" << endl;
				#endif 
			}
			ppn = get_new_ppn (ssd, lpn, location, true);
			if (ppn == -1) {
				cout << "fail in precondition " << endl;
			}
		}else {
			if ((invalid_old_page(ssd, lpn, location) == SUCCESS)){
				#if DEBUG 
				cout << "seqential should not see the old page " << endl;
				#endif 
			}
			ppn = get_new_ppn(ssd, lpn, NULL, true);
			if (ppn == -1)
				cout << "fail in precondition 2" << endl;
		}
		if (write_page(ssd, lpn, ppn) == FAIL)
			cout << "full write precondition fail in write_page " << endl;
		bool gc = check_need_gc(ssd, ppn);
		if (gc) {
			if (seq) cerr << "should not have GC in sequential preconditioning " << endl;
			local * location = new local(0,0,0);
			find_location(ssd, ppn, location);
			pre_process_gc(ssd, location);
			delete location;
 		}
		if(seq) {
			lpn++;
			lpn = lpn % total_size;
		}else
			lpn = rand() % total_size;
	}
	cerr << "is complete. erase count: " <<  ssd->stats->flash_erase_count
				<< ". move count: " << ssd->stats->gc_moved_page << endl;
	ssd->stats->flash_erase_count  = 0;
	ssd->stats->gc_moved_page = 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0x58(%rdi), %rax
movl 0x22c(%rax), %ecx
imull 0x88(%rax), %ecx
imull 0x230(%rax), %ecx
imull 0x234(%rax), %ecx
cvtsi2ss %rcx, %xmm0
movss 0x5b5f(%rip), %xmm1     # 0xa130
subss 0x25c(%rax), %xmm1
movl %esi, %ebp
mulss %xmm0, %xmm1
cvttss2si %xmm1, %r12
movq 0x9a05(%rip), %r14      # 0xdff0
leaq 0x5fc1(%rip), %rsi      # 0xa5b3
movl $0x1a, %edx
movq %r14, %rdi
callq 0x21e0
movl %r12d, %esi
movq %r14, %rdi
callq 0x20e0
leaq 0x6572(%rip), %rsi      # 0xab83
movl $0x6, %edx
movq %rax, %rdi
callq 0x21e0
movl $0x18, %edi
callq 0x2190
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movl $0x0, 0x10(%rax)
testl %r12d, %r12d
je 0x4829
movq %rax, %r14
xorl %r13d, %r13d
movl %r12d, %r15d
movq %rax, 0x8(%rsp)
movl %ebp, 0x4(%rsp)
movq %rbx, 0x10(%rsp)
movq %rbx, %rdi
movl %r13d, %esi
movq %r14, %rdx
callq 0x48db
movq %rbx, %rdi
testb %bpl, %bpl
je 0x4694
xorl %edx, %edx
movl $0x1, %ecx
callq 0x499c
cmpl $-0x1, %eax
jne 0x46a6
movl $0x16, %edx
movq 0x9948(%rip), %r14      # 0xdfd0
movq %r14, %rdi
leaq 0x5f52(%rip), %rsi      # 0xa5e4
jmp 0x46c1
movq %r14, %rdx
movl $0x1, %ecx
callq 0x499c
cmpl $-0x1, %eax
je 0x46ab
movl %eax, %r14d
jmp 0x46f3
movl $0x15, %edx
movq 0x9919(%rip), %r14      # 0xdfd0
movq %r14, %rdi
leaq 0x5f0d(%rip), %rsi      # 0xa5ce
callq 0x21e0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %r14, %rdi
callq 0x2050
movq %rax, %rdi
callq 0x20f0
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq %rbx, %rdi
movl %r13d, %esi
movl %r14d, %edx
callq 0x4a26
testl %eax, %eax
jne 0x4757
movl $0x2b, %edx
movl %ebp, %ebx
movq %r12, %rbp
movq 0x98ba(%rip), %r12      # 0xdfd0
movq %r12, %rdi
leaq 0x5edb(%rip), %rsi      # 0xa5fb
callq 0x21e0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %r12, %rdi
movq %rbp, %r12
movl %ebx, %ebp
movq 0x10(%rsp), %rbx
callq 0x2050
movq %rax, %rdi
callq 0x20f0
movq %rbx, %rdi
movl %r14d, %esi
callq 0x4a67
testb %al, %al
je 0x47fe
movl %ebp, %eax
movq %r12, %rbp
testb %al, %al
je 0x47b6
movl $0x31, %edx
movq 0x9871(%rip), %r12      # 0xdff0
movq %r12, %rdi
leaq 0x5e9e(%rip), %rsi      # 0xa627
callq 0x21e0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %r12, %rdi
callq 0x2050
movq %rax, %rdi
callq 0x20f0
movl $0x18, %edi
callq 0x2190
movq %rax, %r12
movq $0x0, (%rax)
movl $0x0, 0x8(%rax)
movq %rbx, %rdi
movl %r14d, %esi
movq %rax, %rdx
callq 0x4af9
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7c02
movl $0x18, %esi
movq %r12, %rdi
callq 0x21a0
movq %rbp, %r12
movl 0x4(%rsp), %ebp
testb %bpl, %bpl
je 0x4808
incl %r13d
jmp 0x4810
callq 0x20a0
movl %eax, %r13d
movq 0x8(%rsp), %r14
movl %r13d, %eax
xorl %edx, %edx
divl %r12d
movl %edx, %r13d
decl %r15d
jne 0x4655
movq 0x97c0(%rip), %r14      # 0xdff0
leaq 0x5e22(%rip), %rsi      # 0xa659
movl $0x1a, %edx
movq %r14, %rdi
callq 0x21e0
movq 0x98(%rbx), %rax
movq 0x98(%rax), %rsi
movq %r14, %rdi
callq 0x2140
movq %rax, %r14
leaq 0x5e10(%rip), %rsi      # 0xa674
movl $0xe, %edx
movq %rax, %rdi
callq 0x21e0
movq 0x98(%rbx), %rax
movl 0xc8(%rax), %esi
movq %r14, %rdi
callq 0x22d0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %r14, %rdi
callq 0x2050
movq %rax, %rdi
callq 0x20f0
movq 0x98(%rbx), %rax
movq $0x0, 0x98(%rax)
movl $0x0, 0xc8(%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq