// File: narges64[P]SIMBA/ssd.cpp
// Function: collect_statistics(ssd_info*, request*)
void collect_statistics(ssd_info * ssd, request * req){

	sub_request * sub;
	sub = req->subs; //  critical_sub;

	while (sub != NULL)
	{
		if (sub->complete_time != req->response_time) { sub = sub->next_subs; continue;  }
	for (unsigned int i = 0; i < SR_MODE_NUM; i++){
			ssd->stats->subreq_state_time[i] += sub->state_time[i];
		}

		sub = sub->next_subs;

	}

	if(req->response_time-req->begin_time==0)
	{
		printf("1. the response time is 0?? %lld %lld \n", req->response_time, req->begin_time);
		getchar();
	}
	
	if (req->operation==READ)
	{
		ssd->stats->read_request_size[req->app_id] += req->size;
		ssd->stats->read_RT.update(req->response_time - req->begin_time); 
		ssd->stats->read_throughput.add_time(req->begin_time, req->response_time); // changed 
		ssd->stats->read_throughput.add_capacity(req->size);
		ssd->stats->read_throughput.add_count(1);
	}
	else
	{
		ssd->stats->write_request_size[req->app_id] += req->size; 
		ssd->stats->write_RT.update(req->response_time - req->begin_time); 
		ssd->stats->write_throughput.add_time(req->begin_time, req->response_time); 
		ssd->stats->write_throughput.add_capacity(req->size);
		ssd->stats->write_throughput.add_count(1);
	}

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xdbf8
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x28(%rcx), %rax
je 0xdba3
movq -0x18(%rbp), %rax
movq 0x68(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0xdb7c
movl $0x0, -0x1c(%rbp)
cmpl $0xa, -0x1c(%rbp)
jae 0xdbea
movq -0x18(%rbp), %rax
movq 0x80(%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rdx
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
movq 0x188(%rax), %rax
movl -0x1c(%rbp), %ecx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xdbaa
movq -0x18(%rbp), %rax
movq 0x68(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0xdb7c
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
subq 0x20(%rcx), %rax
cmpq $0x0, %rax
jne 0xdc31
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
leaq 0x20cf(%rip), %rdi      # 0xfcf4
movb $0x0, %al
callq 0x2050
callq 0x21d0
movq -0x10(%rbp), %rax
cmpl $0x1, 0x18(%rax)
jne 0xdcf1
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, %edx
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
movq 0x58(%rax), %rax
movq -0x10(%rbp), %rcx
movl (%rcx), %ecx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rdi
addq $0x8, %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0x10(%rbp), %rax
subq 0x20(%rax), %rsi
callq 0xe3c0
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rdi
addq $0x190, %rdi            # imm = 0x190
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdx
callq 0xe470
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rdi
addq $0x190, %rdi            # imm = 0x190
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, %esi
callq 0xe500
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rdi
addq $0x190, %rdi            # imm = 0x190
movl $0x1, %esi
callq 0xe520
jmp 0xdd9e
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, %edx
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
movq 0x68(%rax), %rax
movq -0x10(%rbp), %rcx
movl (%rcx), %ecx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rdi
addq $0x30, %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0x10(%rbp), %rax
subq 0x20(%rax), %rsi
callq 0xe3c0
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rdi
addq $0x1b0, %rdi            # imm = 0x1B0
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdx
callq 0xe470
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rdi
addq $0x1b0, %rdi            # imm = 0x1B0
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, %esi
callq 0xe500
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rdi
addq $0x1b0, %rdi            # imm = 0x1B0
movl $0x1, %esi
callq 0xe520
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)