// File: /workspace/github_cpp_makefile_star2_O1/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 0x2a11(%rip), %rsi      # 0xad26
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 0x2a04(%rip), %rsi      # 0xad45
movq %rbx, (%rsp)
movl %ebx, %edx
xorl %eax, %eax
callq 0x2280
movq 0x50(%r14), %rdi
movq 0x98(%r14), %r9
movslq 0x8(%r9), %r8
testq %r8, %r8
je 0x836e
movq 0x10(%r9), %rax
cqto
idivq %r8
movq %rax, %r15
movabsq $0x20c49ba5e353f7cf, %rbx # imm = 0x20C49BA5E353F7CF
testl %r8d, %r8d
je 0x83b5
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 %rbx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
imulq %rdx, %rdx
subq %rdx, %rcx
jmp 0x83b7
xorl %ecx, %ecx
movq 0x20(%r9), %r9
leaq 0x2997(%rip), %rsi      # 0xad59
xorl %r12d, %r12d
movq %r15, %rdx
xorl %eax, %eax
callq 0x2280
movq 0x50(%r14), %rdi
movq 0x98(%r14), %r9
movslq 0x30(%r9), %r8
testq %r8, %r8
je 0x83ef
movq 0x38(%r9), %rax
cqto
idivq %r8
movq %rax, %r12
testl %r8d, %r8d
je 0x842c
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 %rbx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x7, %rdx
addq %rax, %rdx
imulq %rdx, %rdx
subq %rdx, %rcx
jmp 0x842e
xorl %ecx, %ecx
movq 0x48(%r9), %r9
leaq 0x2a97(%rip), %rsi      # 0xaed0
movq %r12, %rdx
xorl %eax, %eax
callq 0x2280
movq 0x50(%r14), %rdi
movq 0x98(%r14), %rax
movq 0x98(%rax), %rdx
movq 0xa0(%rax), %rcx
leaq 0x2934(%rip), %rsi      # 0xad97
xorl %eax, %eax
callq 0x2280
movq 0x50(%r14), %rdi
movq 0x98(%r14), %rax
movl 0xc8(%rax), %edx
leaq 0x2938(%rip), %rsi      # 0xadba
xorl %eax, %eax
callq 0x2280
movq 0x98(%r14), %rax
movq $0x0, 0x98(%rax)
movq 0x50(%r14), %rdi
leaq 0x2927(%rip), %rsi      # 0xadcd
movq (%rsp), %rdx
xorl %eax, %eax
callq 0x2280
leaq 0x292a(%rip), %rbx      # 0xade2
xorl %r15d, %r15d
movq 0x50(%r14), %rdi
movq 0x98(%r14), %rax
movq 0x188(%rax), %rax
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 0x84bb
movq 0x50(%r14), %rsi
movl $0xa, %edi
callq 0x2220
movq 0x58(%r14), %rcx
cmpl $0x0, 0x88(%rcx)
je 0x865f
leaq 0x28c2(%rip), %r12      # 0xade2
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 0x2894(%rip), %rsi      # 0xade8
movq (%rsp), %rdx
movq %rcx, 0x10(%rsp)
movl %ebp, %r8d
xorl %eax, %eax
callq 0x2280
xorl %r13d, %r13d
movq 0x50(%r14), %rdi
movq 0x90(%rbx), %rax
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 0x856a
movq 0x50(%r14), %rsi
movl $0xa, %edi
callq 0x2220
movq 0x58(%r14), %rax
cmpl $0x0, 0x22c(%rax)
je 0x8649
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 0x2817(%rip), %rsi      # 0xadfd
movq (%rsp), %rdx
movl %ebp, %r8d
movl %ebx, %r9d
xorl %eax, %eax
callq 0x2280
xorl %r15d, %r15d
movq 0x50(%r14), %rdi
movq 0x60(%r13), %rax
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 0x85fa
movq 0x50(%r14), %rsi
movl $0xa, %edi
callq 0x2220
incq %rbx
movq 0x58(%r14), %rax
movl 0x22c(%rax), %eax
cmpq %rax, %rbx
jb 0x85bc
movl 0xc(%rsp), %eax
incl %eax
movq 0x58(%r14), %rcx
cmpl 0x88(%rcx), %eax
jb 0x8522
movq 0x50(%r14), %rdi
movq 0x98(%r14), %rax
movq 0xe0(%rax), %rcx
movq 0xe8(%rax), %r8
movq 0xf0(%rax), %r9
leaq 0x2790(%rip), %rsi      # 0xae16
movq (%rsp), %rdx
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2280