// File: narges64[P]SIMBA/ssd.cpp
// Function: main
int  main(int argc, char * argv[]){

	if (argc < 3) {
		printf("Not enough parameters: specify parameter file and statistic file! \n");
		return 0;
	}
	parameter_value * parameters = new parameter_value(argc, argv);
	ssd_info * ssd = new ssd_info(parameters, argv[2]); 

	ssd->tracefile = fopen(ssd->parameter->trace_filename, "r"); 
	if (ssd->tracefile == NULL){
		generate_trace_file(ssd, ssd->parameter->trace_filename); 
		ssd->tracefile = fopen(ssd->parameter->trace_filename, "r"); 
	}
	if (ssd->tracefile == NULL) {
		cout << "still trace file is null " << endl; 
		return 1; 
	}

	fseek(ssd->tracefile, 0 ,SEEK_SET);

	cerr << "start pre-conditioning " << endl;
	full_write_preconditioning(ssd, true);   // sequential 
	full_write_preconditioning(ssd, false);  // random 

	ssd->stats->print_all(); // does nothing now 
	ssd->stats->reset_all();
	
	ssd->reset_ssd_stats(); // reset read, write, erase number to zero 

	simulate(ssd);

	collect_gc_statistics(ssd, 0);
	print_epoch_statistics(ssd, 0);
	print_statistics(ssd, 0);

	close_files(ssd);
				
	delete ssd; 

	printf("\nthe simulation is completed!\n");

	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x3, -0x8(%rbp)
jge 0xbcb6
leaq 0x3f0d(%rip), %rdi      # 0xfbb0
movb $0x0, %al
callq 0x2050
movl $0x0, -0x4(%rbp)
jmp 0xbedb
movl $0x350, %edi            # imm = 0x350
callq 0x2130
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x38(%rbp)
movl -0x8(%rbp), %esi
movq -0x10(%rbp), %rdx
callq 0x24c0
jmp 0xbcd8
movq -0x38(%rbp), %rax
movq %rax, -0x18(%rbp)
movl $0xa0, %edi
callq 0x2130
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
callq 0x3df0
jmp 0xbd07
movq -0x40(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq 0x58(%rax), %rax
movq 0x340(%rax), %rdi
leaq 0x3427(%rip), %rsi      # 0xf14c
callq 0x2190
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x48(%rax)
jne 0xbdbe
movq -0x30(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x58(%rax), %rax
movq 0x340(%rax), %rsi
callq 0xbef0
movq -0x30(%rbp), %rax
movq 0x58(%rax), %rax
movq 0x340(%rax), %rdi
leaq 0x33de(%rip), %rsi      # 0xf14c
callq 0x2190
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x48(%rax)
jmp 0xbdbe
movq -0x38(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x350, %esi            # imm = 0x350
callq 0x2140
jmp 0xbee4
movq -0x40(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0xa0, %esi
callq 0x2140
jmp 0xbee4
movq -0x30(%rbp), %rax
cmpq $0x0, 0x48(%rax)
jne 0xbdf7
movq 0x8200(%rip), %rdi      # 0x13fd0
leaq 0x3e1d(%rip), %rsi      # 0xfbf4
callq 0x2110
movq %rax, %rdi
movq 0x81da(%rip), %rsi      # 0x13fc0
callq 0x2150
movl $0x1, -0x4(%rbp)
jmp 0xbedb
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x2170
movq 0x81df(%rip), %rdi      # 0x13ff0
leaq 0x3df6(%rip), %rsi      # 0xfc0e
callq 0x2110
movq %rax, %rdi
movq 0x8199(%rip), %rsi      # 0x13fc0
callq 0x2150
movq -0x30(%rbp), %rdi
movl $0x1, %esi
callq 0x5490
movq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x5490
movq -0x30(%rbp), %rax
movq 0x98(%rax), %rdi
callq 0xe140
movq -0x30(%rbp), %rax
movq 0x98(%rax), %rdi
callq 0x4290
movq -0x30(%rbp), %rdi
callq 0x4080
movq -0x30(%rbp), %rdi
callq 0xbfe0
movq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0xc110
movq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0xc120
movq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0xc640
movq -0x30(%rbp), %rdi
callq 0xcb70
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0xbec6
movq -0x48(%rbp), %rdi
callq 0xe150
movq -0x48(%rbp), %rdi
movl $0xa0, %esi
callq 0x2140
leaq 0x3d59(%rip), %rdi      # 0xfc26
movb $0x0, %al
callq 0x2050
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
movq -0x20(%rbp), %rdi
callq 0x2230
nopl (%rax)