// File: /workspace/github_cpp_makefile_star2_O1/narges64[P]SIMBA/ssd.cpp
// Function: print_statistics(ssd_info*, int)
void print_statistics(ssd_info *ssd, int app){

	fprintf(ssd->statisticfile, "======== Application %d , time %lld ============ \n", app, ssd->total_execution_time);

	fprintf(ssd->statisticfile, "request read RT avg %lld us , var %lld ms2 , count %lld , max %lld us\n", 
									ssd->stats->read_RT.get_average(), ssd->stats->read_RT.get_variance(), 
									ssd->stats->read_RT.get_count() , ssd->stats->read_RT.get_max());

	fprintf(ssd->statisticfile, "request write RT avg %lld us , var %lld ms2, count %lld , max %lld us \n", 
									ssd->stats->write_RT.get_average(), ssd->stats->write_RT.get_variance(), 
									ssd->stats->write_RT.get_count() , ssd->stats->write_RT.get_max());
	
	fprintf(ssd->statisticfile, "read IOPS and BW [%d]: %f , %f  \n", app, ssd->stats->read_throughput.get_IOPS() , ssd->stats->read_throughput.get_BW());
	fprintf(ssd->statisticfile, "write IOPS and BW [%d]: %f , %f  \n", app, ssd->stats->write_throughput.get_IOPS() , ssd->stats->write_throughput.get_BW());

	fprintf(ssd->statisticfile,"erase: ( %lld )\n", ssd->stats->total_flash_erase_count);
	fprintf(ssd->statisticfile,"total gc move count: %d \n", ssd->stats->gc_moved_page);
	fprintf(ssd->statisticfile, "buffer read hit %d , write hit %d , gc buffer read hit %d , write hit %d \n ", 
								ssd->dram->buffer->read_hit , ssd->dram->buffer->write_hit , 
								ssd->dram->gc_buffer->read_hit , ssd->dram->gc_buffer->write_hit); 

	fprintf(ssd->statisticfile, "flash program count %d , WAF %f\n" , ssd->stats->flash_prog_count , (ssd->stats->flash_prog_count)/(double)(ssd->stats->flash_prog_count - ssd->stats->gc_moved_page));  

	fprintf(ssd->statisticfile, "========================\n");

	ssd->stats->flash_erase_count = 0;

	// Print lun statistic output
	int chan,lun = 0;
	/*


	fprintf(ssd->statisticfile, "\nlun IOPS \n");
	for (chan = 0; chan < ssd->parameter->channel_number; chan++){
		for (lun = 0; lun < ssd->channel_head[chan]->lun_num; lun++){
			fprintf(ssd->statisticfile, "%d,", (int)ssd->channel_head[chan]->lun_head[lun]->stat_read_throughput.get_IOPS());
			fprintf(ssd->statisticfile, "%d,", (int)ssd->channel_head[chan]->lun_head[lun]->stat_write_throughput.get_IOPS());
			fprintf(ssd->statisticfile, "%d\t", (int)ssd->channel_head[chan]->lun_head[lun]->stat_rw_throughput.get_IOPS());
		}
		fprintf(ssd->statisticfile, "\n");
	}

	fprintf(ssd->statisticfile, "\nlun BW  (MB/s) \n");
	for (chan = 0; chan < ssd->parameter->channel_number; chan++){
		for (lun = 0; lun < ssd->channel_head[chan]->lun_num; lun++){
			fprintf(ssd->statisticfile, "%d,", (int)ssd->channel_head[chan]->lun_head[lun]->stat_read_throughput.get_BW());
			fprintf(ssd->statisticfile, "%d,", (int)ssd->channel_head[chan]->lun_head[lun]->stat_write_throughput.get_BW());
			fprintf(ssd->statisticfile, "%d\t", (int)ssd->channel_head[chan]->lun_head[lun]->stat_rw_throughput.get_BW());
		}
		fprintf(ssd->statisticfile, "\n");
	}

	fprintf(ssd->statisticfile, "\nlun noop IOPS \n");
	for (chan = 0; chan < ssd->parameter->channel_number; chan++){
		for (lun = 0; lun < ssd->channel_head[chan]->lun_num; lun++){
			fprintf(ssd->statisticfile, "%d,", (int)ssd->channel_head[chan]->lun_head[lun]->stat_read_throughput.get_noop_IOPS());
			fprintf(ssd->statisticfile, "%d,", (int)ssd->channel_head[chan]->lun_head[lun]->stat_write_throughput.get_noop_IOPS());
			fprintf(ssd->statisticfile, "%d\t", (int)ssd->channel_head[chan]->lun_head[lun]->stat_rw_throughput.get_noop_IOPS());
		}
		fprintf(ssd->statisticfile, "\n");
	}


	fprintf(ssd->statisticfile, "\nlun noop BW (MB/s) \n");
	for (chan = 0; chan < ssd->parameter->channel_number; chan++){
		for (lun = 0; lun < ssd->channel_head[chan]->lun_num; lun++){
			fprintf(ssd->statisticfile, "%d,", (int)ssd->channel_head[chan]->lun_head[lun]->stat_read_throughput.get_noop_BW());
			fprintf(ssd->statisticfile, "%d,", (int)ssd->channel_head[chan]->lun_head[lun]->stat_write_throughput.get_noop_BW());
			fprintf(ssd->statisticfile, "%d\t", (int)ssd->channel_head[chan]->lun_head[lun]->stat_rw_throughput.get_noop_BW());
		}
		fprintf(ssd->statisticfile, "\n");
	}
	*/

	fprintf(ssd->statisticfile, "\nlun erase count \n");
	for (chan = 0; chan < ssd->parameter->channel_number; chan++){
		for (lun = 0; lun < ssd->channel_head[chan]->lun_num; lun++){
			fprintf(ssd->statisticfile, "%d\t", ssd->channel_head[chan]->lun_head[lun]->erase_count);
		}
		fprintf(ssd->statisticfile, "\n");
	}

	fprintf(ssd->statisticfile, "\nplanes erase number: \n");
	for(int i=0;i<ssd->parameter->channel_number;i++){
		for (int j = 0; j < ssd->parameter->lun_channel[i]; j++){
			for(int l=0;l<ssd->parameter->plane_lun;l++)
			{
				int plane_erase = ssd->channel_head[i]->lun_head[j]->plane_head[l]->erase_count;
				fprintf(ssd->statisticfile,"(%d,%d)",l, plane_erase);
			}
			fprintf(ssd->statisticfile, "\t");
		}
		fprintf(ssd->statisticfile, "\n");
	}

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %rbx
movq 0x28(%rdi), %rcx
movq 0x50(%rdi), %rdi
leaq 0x2790(%rip), %rsi      # 0xae4e
xorl %r14d, %r14d
movl %ebp, %edx
xorl %eax, %eax
callq 0x2280
movq 0x50(%rbx), %rdi
movq 0x98(%rbx), %r9
movslq 0x8(%r9), %r8
testq %r8, %r8
je 0x86ea
movq 0x10(%r9), %rax
cqto
idivq %r8
movq %rax, %r14
movabsq $0x20c49ba5e353f7cf, %r12 # imm = 0x20C49BA5E353F7CF
testl %r8d, %r8d
je 0x8731
movq 0x10(%r9), %rax
movq 0x18(%r9), %rcx
cqto
idivq %r8
movq %rax, %rsi
movq %rcx, %rax
cqto
idivq %r8
movq %rax, %rcx
movq %rsi, %rax
imulq %r12
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
imulq %rdx, %rdx
subq %rdx, %rcx
jmp 0x8733
xorl %ecx, %ecx
movq 0x20(%r9), %r9
leaq 0x2743(%rip), %rsi      # 0xae81
xorl %r15d, %r15d
movq %r14, %rdx
xorl %eax, %eax
callq 0x2280
movq 0x50(%rbx), %rdi
movq 0x98(%rbx), %r9
movslq 0x30(%r9), %r8
testq %r8, %r8
je 0x876b
movq 0x38(%r9), %rax
cqto
idivq %r8
movq %rax, %r15
testl %r8d, %r8d
je 0x87a8
movq 0x38(%r9), %rax
movq 0x40(%r9), %rcx
cqto
idivq %r8
movq %rax, %rsi
movq %rcx, %rax
cqto
idivq %r8
movq %rax, %rcx
movq %rsi, %rax
imulq %r12
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
imulq %rdx, %rdx
subq %rdx, %rcx
jmp 0x87aa
xorl %ecx, %ecx
movq 0x48(%r9), %r9
leaq 0x2713(%rip), %rsi      # 0xaec8
movq %r15, %rdx
xorl %eax, %eax
callq 0x2280
movq 0x98(%rbx), %rcx
movq 0x190(%rcx), %rax
xorpd %xmm1, %xmm1
xorpd %xmm0, %xmm0
testq %rax, %rax
je 0x87f7
xorps %xmm0, %xmm0
cvtsi2sdq 0x1a0(%rcx), %xmm0
mulsd 0x23ea(%rip), %xmm0     # 0xabd8
cvtsi2sd %rax, %xmm2
divsd %xmm2, %xmm0
movq 0x50(%rbx), %rdi
testq %rax, %rax
je 0x8824
xorps %xmm1, %xmm1
cvtsi2sdq 0x198(%rcx), %xmm1
mulsd 0x23c4(%rip), %xmm1     # 0xabd8
shlq $0xb, %rax
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
divsd %xmm2, %xmm1
leaq 0x26e5(%rip), %rsi      # 0xaf10
movl %ebp, %edx
movb $0x2, %al
callq 0x2280
movq 0x98(%rbx), %rcx
movq 0x1b0(%rcx), %rax
xorpd %xmm1, %xmm1
xorpd %xmm0, %xmm0
testq %rax, %rax
je 0x886f
xorps %xmm0, %xmm0
cvtsi2sdq 0x1c0(%rcx), %xmm0
mulsd 0x2375(%rip), %xmm0     # 0xabd8
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
divsd %xmm2, %xmm0
movq 0x50(%rbx), %rdi
testq %rax, %rax
je 0x889c
xorps %xmm1, %xmm1
cvtsi2sdq 0x1b8(%rcx), %xmm1
mulsd 0x234c(%rip), %xmm1     # 0xabd8
shlq $0xb, %rax
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
divsd %xmm2, %xmm1
leaq 0x268f(%rip), %rsi      # 0xaf32
movl %ebp, %edx
movb $0x2, %al
callq 0x2280
movq 0x50(%rbx), %rdi
movq 0x98(%rbx), %rax
movq 0xa0(%rax), %rdx
leaq 0x2690(%rip), %rsi      # 0xaf55
xorl %eax, %eax
callq 0x2280
movq 0x50(%rbx), %rdi
movq 0x98(%rbx), %rax
movl 0xc8(%rax), %edx
leaq 0x2682(%rip), %rsi      # 0xaf66
xorl %eax, %eax
callq 0x2280
movq 0x50(%rbx), %rdi
movq 0x60(%rbx), %rax
movq 0x18(%rax), %rcx
movq 0x20(%rax), %rax
movl (%rcx), %edx
movl 0x4(%rcx), %ecx
movl (%rax), %r8d
movl 0x4(%rax), %r9d
leaq 0x2672(%rip), %rsi      # 0xaf80
xorl %eax, %eax
callq 0x2280
movq 0x50(%rbx), %rdi
movq 0x98(%rbx), %rax
movq 0x88(%rax), %rdx
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
movslq 0xc8(%rax), %rax
movq %rdx, %rcx
subq %rax, %rcx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
divsd %xmm1, %xmm0
leaq 0x267d(%rip), %rsi      # 0xafcc
movb $0x1, %al
callq 0x2280
movq 0x50(%rbx), %rcx
leaq 0x268c(%rip), %rdi      # 0xafed
movl $0x19, %esi
movl $0x1, %edx
callq 0x2310
movq 0x98(%rbx), %rax
movq $0x0, 0x98(%rax)
movq 0x50(%rbx), %rcx
leaq 0x267a(%rip), %rdi      # 0xb007
movl $0x12, %esi
movl $0x1, %edx
callq 0x2310
movq 0x58(%rbx), %rax
cmpl $0x0, 0x98(%rax)
je 0x8a15
leaq 0x266a(%rip), %r14      # 0xb01a
xorl %r15d, %r15d
movq 0x90(%rbx), %rax
movq (%rax,%r15,8), %rax
cmpl $0x0, (%rax)
jle 0x89f5
xorl %r12d, %r12d
movq 0x50(%rbx), %rdi
movq 0x50(%rax), %rax
movq (%rax,%r12,8), %rax
movl 0x8(%rax), %edx
movq %r14, %rsi
xorl %eax, %eax
callq 0x2280
incq %r12
movq 0x90(%rbx), %rax
movq (%rax,%r15,8), %rax
movslq (%rax), %rcx
cmpq %rcx, %r12
jl 0x89c6
movq 0x50(%rbx), %rsi
movl $0xa, %edi
callq 0x2220
incq %r15
movq 0x58(%rbx), %rax
movl 0x98(%rax), %eax
cmpq %rax, %r15
jb 0x89b3
movq 0x50(%rbx), %rcx
leaq 0x25fe(%rip), %rdi      # 0xb01e
movl $0x17, %esi
movl $0x1, %edx
callq 0x2310
movq 0x58(%rbx), %rax
cmpl $0x0, 0x98(%rax)
je 0x8af2
leaq 0x25ef(%rip), %r14      # 0xb036
xorl %r12d, %r12d
movq 0x58(%rbx), %rax
cmpl $0x0, 0x9c(%rax,%r12,4)
je 0x8ace
xorl %r13d, %r13d
movq 0x58(%rbx), %rax
cmpl $0x0, 0x22c(%rax)
je 0x8aac
xorl %r15d, %r15d
movq 0x50(%rbx), %rdi
movq 0x90(%rbx), %rax
movq (%rax,%r12,8), %rax
movq 0x50(%rax), %rax
movq (%rax,%r13,8), %rax
movq (%rax), %rax
movq (%rax,%r15,8), %rax
movl 0x30(%rax), %ecx
movq %r14, %rsi
movl %r15d, %edx
xorl %eax, %eax
callq 0x2280
incq %r15
movq 0x58(%rbx), %rax
movl 0x22c(%rax), %eax
cmpq %rax, %r15
jb 0x8a6c
movq 0x50(%rbx), %rsi
movl $0x9, %edi
callq 0x2220
incq %r13
movq 0x58(%rbx), %rax
movl 0x9c(%rax,%r12,4), %eax
cmpq %rax, %r13
jb 0x8a5c
movq 0x50(%rbx), %rsi
movl $0xa, %edi
callq 0x2220
incq %r12
movq 0x58(%rbx), %rax
movl 0x98(%rax), %eax
cmpq %rax, %r12
jb 0x8a4a
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq