// File: /workspace/github_cpp_makefile_star2_O3/narges64[P]SIMBA/ssd.cpp
// Function: print_epoch_statistics(ssd_info*, int)
void print_epoch_statistics(ssd_info * ssd, int app_id){
	int epoch_num = ssd->current_time / EPOCH_LENGTH;
	fprintf(ssd->statisticfile, "epoch %d , current_time %lld \n", epoch_num, ssd->current_time);
	// =================== LATENCY ================================================================
	ssd->stats->total_flash_erase_count += ssd->stats->flash_erase_count;

	fprintf(ssd->statisticfile, "Latency epoch: %d \n", epoch_num);
	fprintf(ssd->statisticfile, "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, "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, "erase(gc) count %lld , total %lld\n", ssd->stats->flash_erase_count, ssd->stats->total_flash_erase_count);
	fprintf(ssd->statisticfile, "GC move count %d \n" , ssd->stats->gc_moved_page);
	ssd->stats->flash_erase_count = 0;

	// =================== SUBREQ STATES ===========================================================
	fprintf(ssd->statisticfile, "SUBREQ ep: %d time:\t", epoch_num);
	for (int i = 0; i < SR_MODE_NUM; i++){
		fprintf(ssd->statisticfile, "%lld\t",ssd->stats->subreq_state_time[i]);
		ssd->stats->subreq_state_time[i] = 0;
	}
	fprintf(ssd->statisticfile, "\n");

	// =================== LUN STATES ============================================================
	for (int i = 0; i < ssd->parameter->lun_num; i++){
		int channel_num = i % ssd->parameter->channel_number;
		int lun_num = (i / ssd->parameter->channel_number) % ssd->channel_head[channel_num]->lun_num;
		lun_info * the_lun = ssd->channel_head[channel_num]->lun_head[lun_num];
		fprintf(ssd->statisticfile, "lun ep: %d (%d,%d): ",epoch_num , channel_num, lun_num);
		for (int i = 0; i < LUN_MODE_NUM; i++){
			fprintf(ssd->statisticfile, "%lld\t", the_lun->state_time[i]);
			the_lun->state_time[i] = 0;
		}
		fprintf(ssd->statisticfile, "\n");
		for (int j = 0; j < ssd->parameter->plane_lun; j++){
			int plane_num = j;
			plane_info * the_plane = ssd->channel_head[channel_num]->lun_head[lun_num]->plane_head[plane_num];
			fprintf(ssd->statisticfile, "plane ep: %d (%d,%d,%d) ", epoch_num, channel_num, lun_num, plane_num);
			for (int i = 0; i < PLANE_MODE_NUM; i++){
				fprintf(ssd->statisticfile, "%lld\t",the_plane->state_time[i]);
				the_plane->state_time[i] = 0;
			}
			fprintf(ssd->statisticfile, "\n");
		}

	}
	// ==================== OTHER STATS ===================================
	fprintf(ssd->statisticfile, "Multiplane ep: %d read %lld , write %lld , erase %lld \n", epoch_num, ssd->stats->read_multiplane_count , ssd->stats->write_multiplane_count , ssd->stats->erase_multiplane_count);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
movq (%rdi), %rcx
movq 0x50(%rdi), %rdi
movabsq $0x36f9bfb3af7b757, %rdx # imm = 0x36F9BFB3AF7B757
movq %rcx, %rax
imulq %rdx
movq %rdx, %rbx
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x1b, %rbx
addl %eax, %ebx
leaq 0x2aba(%rip), %rsi      # 0xad3e
xorl %r15d, %r15d
movl %ebx, %edx
xorl %eax, %eax
callq 0x2280
movq 0x98(%r14), %rax
movq 0x98(%rax), %rcx
addq %rcx, 0xa0(%rax)
movq 0x50(%r14), %rdi
leaq 0x2aad(%rip), %rsi      # 0xad5d
movq %rbx, (%rsp)
movl %ebx, %edx
xorl %eax, %eax
callq 0x2280
movq 0x50(%r14), %rdi
movq 0x98(%r14), %rsi
movslq 0x8(%rsi), %r8
movabsq $0x20c49ba5e353f7cf, %r12 # imm = 0x20C49BA5E353F7CF
testq %r8, %r8
je 0x8313
movq 0x10(%rsi), %rax
movq 0x18(%rsi), %rcx
cqto
idivq %r8
movq %rax, %r15
movq %rcx, %rax
cqto
idivq %r8
movq %rax, %rcx
movq %r15, %rax
imulq %r12
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
imulq %rdx, %rdx
subq %rdx, %rcx
jmp 0x8315
xorl %ecx, %ecx
movq 0x20(%rsi), %r9
leaq 0x2a51(%rip), %rsi      # 0xad71
xorl %ebx, %ebx
movq %r15, %rdx
xorl %eax, %eax
callq 0x2280
movq 0x50(%r14), %rdi
movq 0x98(%r14), %rsi
movslq 0x30(%rsi), %r8
testq %r8, %r8
je 0x8378
movq 0x38(%rsi), %rax
movq 0x40(%rsi), %rcx
cqto
idivq %r8
movq %rax, %rbx
movq %rcx, %rax
cqto
idivq %r8
movq %rax, %rcx
movq %rbx, %rax
imulq %r12
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
imulq %rdx, %rdx
subq %rdx, %rcx
jmp 0x837a
xorl %ecx, %ecx
movq 0x48(%rsi), %r9
leaq 0x2b63(%rip), %rsi      # 0xaee8
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2280
movq 0x50(%r14), %rdi
movq 0x98(%r14), %rax
movq 0x98(%rax), %rdx
movq 0xa0(%rax), %rcx
leaq 0x2a00(%rip), %rsi      # 0xadaf
xorl %eax, %eax
callq 0x2280
movq 0x50(%r14), %rdi
movq 0x98(%r14), %rax
movl 0xc8(%rax), %edx
leaq 0x2a04(%rip), %rsi      # 0xadd2
xorl %eax, %eax
callq 0x2280
movq 0x98(%r14), %rax
movq $0x0, 0x98(%rax)
movq 0x50(%r14), %rdi
leaq 0x29f3(%rip), %rsi      # 0xade5
movq (%rsp), %rdx
xorl %eax, %eax
callq 0x2280
movq 0x98(%r14), %rax
movq 0x188(%rax), %rax
leaq 0x29e8(%rip), %rbx      # 0xadfa
xorl %r15d, %r15d
movq 0x50(%r14), %rdi
movq (%rax,%r15,8), %rdx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2280
movq 0x98(%r14), %rax
movq 0x188(%rax), %rax
movq $0x0, (%rax,%r15,8)
incq %r15
cmpq $0xa, %r15
jne 0x8415
movq 0x50(%r14), %rsi
movl $0xa, %edi
callq 0x2220
movq 0x58(%r14), %rcx
cmpl $0x0, 0x88(%rcx)
je 0x85a7
leaq 0x298e(%rip), %r12      # 0xadfa
xorl %eax, %eax
movl %eax, 0xc(%rsp)
xorl %edx, %edx
divl 0x98(%rcx)
movl %edx, %ecx
movq 0x50(%r14), %rdi
movq 0x90(%r14), %rdx
movq (%rdx,%rcx,8), %rsi
xorl %edx, %edx
divl (%rsi)
movl %edx, %ebp
movq 0x50(%rsi), %rax
movq (%rax,%rbp,8), %rbx
leaq 0x2960(%rip), %rsi      # 0xae00
movq (%rsp), %rdx
movq %rcx, 0x10(%rsp)
movl %ebp, %r8d
xorl %eax, %eax
callq 0x2280
movq 0x90(%rbx), %rax
xorl %r13d, %r13d
movq 0x50(%r14), %rdi
movq (%rax,%r13,8), %rdx
movq %r12, %rsi
xorl %eax, %eax
callq 0x2280
movq 0x90(%rbx), %rax
movq $0x0, (%rax,%r13,8)
incq %r13
cmpq $0x3, %r13
jne 0x84bd
movq 0x50(%r14), %rsi
movl $0xa, %edi
callq 0x2220
movq 0x58(%r14), %rcx
cmpl $0x0, 0x22c(%rcx)
je 0x8595
xorl %ebx, %ebx
movq 0x50(%r14), %rdi
movq 0x90(%r14), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x50(%rax), %rax
movq (%rax,%rbp,8), %rax
movq (%rax), %rax
movq (%rax,%rbx,8), %r13
leaq 0x28e3(%rip), %rsi      # 0xae15
movq (%rsp), %rdx
movl %ebp, %r8d
movl %ebx, %r9d
xorl %eax, %eax
callq 0x2280
movq 0x60(%r13), %rax
xorl %r15d, %r15d
movq 0x50(%r14), %rdi
movq (%rax,%r15,8), %rdx
movq %r12, %rsi
xorl %eax, %eax
callq 0x2280
movq 0x60(%r13), %rax
movq $0x0, (%rax,%r15,8)
incq %r15
cmpq $0x3, %r15
jne 0x854a
movq 0x50(%r14), %rsi
movl $0xa, %edi
callq 0x2220
incq %rbx
movq 0x58(%r14), %rcx
movl 0x22c(%rcx), %eax
cmpq %rax, %rbx
jb 0x8508
movl 0xc(%rsp), %eax
incl %eax
cmpl 0x88(%rcx), %eax
jb 0x846e
movq 0x50(%r14), %rdi
movq 0x98(%r14), %rax
movq 0xe0(%rax), %rcx
movq 0xe8(%rax), %r8
movq 0xf0(%rax), %r9
leaq 0x2860(%rip), %rsi      # 0xae2e
movq (%rsp), %rdx
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2280