// File: gvaumour[P]cache-simulator/src/MemoryTrace.cc
// Function: CompressedTrace::readNext(Access&)
bool 
CompressedTrace::readNext(Access& element)
{
	assert(m_isOpen);	

	if(!gzread(m_compressedTrace, mybuffer_dummy, TRACE_BUFFER_SIZE))
		return false;
	

	readNext_addr = string(strtok(mybuffer_dummy, " "));

	
	if(readNext_addr[0] != '#' || readNext_addr[1] != '!')
	{
		cout << "Line passed - Wrong Format" << endl;
		return true;
	}
	readNext_addr.erase( readNext_addr.begin(), readNext_addr.begin()+2);
	
	element.m_address = hexToInt1(readNext_addr.c_str());
	readNext_operation = atoi(strtok(NULL, " ") );		
	element.m_size = atoi(strtok(NULL, " ")); 		
	element.m_idthread = atoi( strtok(NULL, " ") );
	element.m_pc = hexToInt1(strtok(NULL, " "));

	switch(readNext_operation){
		case 0 : element.m_type = MemCmd::INST_READ;break;
		case 1 : element.m_type = MemCmd::DATA_READ;break;
		case 2 : element.m_type = MemCmd::DATA_WRITE;break;
		default: assert(false && "operation not recognized \n");
	}

	return true;
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0xa8(%rsp)
movq %rsi, 0xa0(%rsp)
movq 0xa8(%rsp), %rax
movq %rax, 0x30(%rsp)
testb $0x1, 0x28(%rax)
je 0x4734c
jmp 0x4736b
leaq 0x2bbfd(%rip), %rdi     # 0x72f50
leaq 0x2bbff(%rip), %rsi     # 0x72f59
movl $0x33, %edx
leaq 0x2bc06(%rip), %rcx     # 0x72f6c
callq 0x5260
movq 0x30(%rsp), %rax
movq 0x30(%rax), %rdi
leaq 0x4c7f5(%rip), %rsi     # 0x93b70
movl $0x32, %edx
callq 0x56e0
cmpl $0x0, %eax
jne 0x47397
movb $0x0, 0xb7(%rsp)
jmp 0x47621
leaq 0x4c7d2(%rip), %rdi     # 0x93b70
leaq 0x2a430(%rip), %rsi     # 0x717d5
callq 0x55c0
movq %rax, 0x20(%rsp)
leaq 0x7f(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x56a0
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
leaq 0x80(%rsp), %rdi
callq 0x5530
jmp 0x473d7
leaq 0x4c76a(%rip), %rdi     # 0x93b48
leaq 0x80(%rsp), %rsi
callq 0x54a0
leaq 0x80(%rsp), %rdi
callq 0x5768
leaq 0x7f(%rsp), %rdi
callq 0x53e0
leaq 0x4c73f(%rip), %rdi     # 0x93b48
xorl %eax, %eax
movl %eax, %esi
callq 0x5750
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x47433
leaq 0x4c727(%rip), %rdi     # 0x93b48
movl $0x1, %esi
callq 0x5750
movsbl (%rax), %eax
cmpl $0x21, %eax
je 0x4747f
movq 0x4bb96(%rip), %rdi     # 0x92fd0
leaq 0x2bb5c(%rip), %rsi     # 0x72f9d
callq 0x5380
movq %rax, %rdi
movq 0x4bb68(%rip), %rsi     # 0x92fb8
callq 0x53d0
movb $0x1, 0xb7(%rsp)
jmp 0x47621
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
leaq 0x7f(%rsp), %rdi
callq 0x53e0
jmp 0x47632
leaq 0x4c6c2(%rip), %rdi     # 0x93b48
movq %rdi, (%rsp)
callq 0x5310
movq %rax, 0x58(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x48150
movq (%rsp), %rdi
callq 0x5310
movq %rax, 0x40(%rsp)
leaq 0x40(%rsp), %rdi
movl $0x2, %esi
callq 0x48190
movq %rax, 0x48(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x48150
movq (%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x50(%rsp), %rdx
callq 0x50e0
movq (%rsp), %rdi
movq %rax, 0x38(%rsp)
callq 0x51a0
movq %rax, %rdi
callq 0x65720
movq %rax, %rcx
movq 0xa0(%rsp), %rax
movq %rcx, (%rax)
leaq 0x2a2c3(%rip), %rsi     # 0x717d5
movq %rsi, 0x10(%rsp)
xorl %eax, %eax
movl %eax, %edi
movq %rdi, 0x8(%rsp)
callq 0x55c0
movq %rax, %rdi
callq 0x55b0
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl %eax, 0x4c667(%rip)     # 0x93ba4
callq 0x55c0
movq %rax, %rdi
callq 0x55b0
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl %eax, %ecx
movq 0xa0(%rsp), %rax
movl %ecx, 0x8(%rax)
callq 0x55c0
movq %rax, %rdi
callq 0x55b0
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl %eax, %ecx
movq 0xa0(%rsp), %rax
movl %ecx, 0x20(%rax)
callq 0x55c0
movq %rax, %rdi
callq 0x65720
movq %rax, %rcx
movq 0xa0(%rsp), %rax
movq %rcx, 0x10(%rax)
movl 0x4c5fd(%rip), %eax     # 0x93ba4
movl %eax, 0x1c(%rsp)
testl %eax, %eax
je 0x475c7
jmp 0x475b1
movl 0x1c(%rsp), %eax
subl $0x1, %eax
je 0x475d8
jmp 0x475bc
movl 0x1c(%rsp), %eax
subl $0x2, %eax
je 0x475e9
jmp 0x475fa
movq 0xa0(%rsp), %rax
movl $0x0, 0x1c(%rax)
jmp 0x47619
movq 0xa0(%rsp), %rax
movl $0x2, 0x1c(%rax)
jmp 0x47619
movq 0xa0(%rsp), %rax
movl $0x3, 0x1c(%rax)
jmp 0x47619
leaq 0x2b9b7(%rip), %rdi     # 0x72fb8
leaq 0x2b951(%rip), %rsi     # 0x72f59
movl $0x4d, %edx
leaq 0x2b958(%rip), %rcx     # 0x72f6c
callq 0x5260
movb $0x1, 0xb7(%rsp)
movb 0xb7(%rsp), %al
andb $0x1, %al
addq $0xb8, %rsp
retq
movq 0x70(%rsp), %rdi
callq 0x5690
nopl (%rax)