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

	string line;
	vector<string> split_line;
			
	if(!getline(m_textTrace , line)){
		return false;
	}
	if(line.empty())
		return false;
	
	split_line = split(line , ' ');

	string addr = split_line[0];

	if(addr[0] != '#' || addr[1] != '!')
	{
		cout << "Line passed - Wrong Format" << endl;
		return false;
	}

	addr.erase( remove(addr.begin(), addr.end(), '#'), addr.end());
	addr.erase( remove(addr.begin(), addr.end(), '!'), addr.end());

	element.m_address = hexToInt(addr);
	int operation = atoi(split_line[1].c_str());		
	element.m_size = atoi(split_line[2].c_str());		
	element.m_idthread = atoi(split_line[3].c_str());
	element.m_pc = hexToInt(split_line[4]);


	switch(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 $0x228, %rsp            # imm = 0x228
movq %rdi, 0x218(%rsp)
movq %rsi, 0x210(%rsp)
movq 0x218(%rsp), %rax
movq %rax, 0xa0(%rsp)
testb $0x1, 0x28(%rax)
je 0x4773f
jmp 0x4775e
leaq 0x2b80a(%rip), %rdi     # 0x72f50
leaq 0x2b80c(%rip), %rsi     # 0x72f59
movl $0x6b, %edx
leaq 0x2b8a7(%rip), %rcx     # 0x73000
callq 0x5260
leaq 0x1f0(%rsp), %rdi
movq %rdi, 0x90(%rsp)
callq 0x5540
leaq 0x1d8(%rsp), %rdi
callq 0xe850
movq 0xa0(%rsp), %rdi
movq 0x90(%rsp), %rsi
addq $0x30, %rdi
callq 0x50c0
movq %rax, 0x98(%rsp)
jmp 0x477a3
movq 0x98(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x51d0
movb %al, 0x8f(%rsp)
jmp 0x477c3
movb 0x8f(%rsp), %al
testb $0x1, %al
jne 0x477d0
jmp 0x47801
movb $0x0, 0x227(%rsp)
movl $0x1, 0x1c8(%rsp)
jmp 0x47d50
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1d0(%rsp)
movl %eax, 0x1cc(%rsp)
jmp 0x47d7b
leaq 0x1f0(%rsp), %rdi
callq 0x5630
testb $0x1, %al
jne 0x47814
jmp 0x4782c
movb $0x0, 0x227(%rsp)
movl $0x1, 0x1c8(%rsp)
jmp 0x47d50
leaq 0x190(%rsp), %rdi
leaq 0x1f0(%rsp), %rsi
callq 0x51b0
jmp 0x47843
leaq 0x1b0(%rsp), %rdi
leaq 0x190(%rsp), %rsi
movl $0x20, %edx
callq 0x653b0
jmp 0x4785f
leaq 0x1d8(%rsp), %rdi
movq %rdi, 0x80(%rsp)
leaq 0x1b0(%rsp), %rsi
movq %rsi, 0x78(%rsp)
callq 0x481d0
movq 0x78(%rsp), %rdi
callq 0xf560
leaq 0x190(%rsp), %rdi
callq 0x5768
movq 0x80(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xfd00
movq %rax, %rsi
leaq 0x170(%rsp), %rdi
callq 0x51b0
jmp 0x478bb
xorl %eax, %eax
movl %eax, %esi
leaq 0x170(%rsp), %rdi
callq 0x5750
movq %rax, 0x70(%rsp)
jmp 0x478d3
movq 0x70(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x4790a
leaq 0x170(%rsp), %rdi
movl $0x1, %esi
callq 0x5750
movq %rax, 0x68(%rsp)
jmp 0x478f9
movq 0x68(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x21, %eax
je 0x4798e
movq 0x4b6bf(%rip), %rdi     # 0x92fd0
leaq 0x2b685(%rip), %rsi     # 0x72f9d
callq 0x5380
movq %rax, 0x60(%rsp)
jmp 0x47924
movq 0x60(%rsp), %rdi
movq 0x4b688(%rip), %rsi     # 0x92fb8
callq 0x53d0
jmp 0x47937
movb $0x0, 0x227(%rsp)
movl $0x1, 0x1c8(%rsp)
jmp 0x47d32
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1d0(%rsp)
movl %eax, 0x1cc(%rsp)
leaq 0x190(%rsp), %rdi
callq 0x5768
jmp 0x47d7b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1d0(%rsp)
movl %eax, 0x1cc(%rsp)
jmp 0x47d41
leaq 0x170(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x5310
movq 0x50(%rsp), %rdi
movq %rax, 0x158(%rsp)
callq 0x5230
movq %rax, 0x150(%rsp)
movb $0x23, 0x14f(%rsp)
movq 0x158(%rsp), %rdi
movq 0x150(%rsp), %rsi
leaq 0x14f(%rsp), %rdx
callq 0x48210
movq %rax, 0x58(%rsp)
jmp 0x479e6
movq 0x58(%rsp), %rax
movq %rax, 0x160(%rsp)
leaq 0x168(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x48150
leaq 0x170(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x5230
movq %rax, 0x138(%rsp)
leaq 0x140(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x48150
movq 0x40(%rsp), %rdi
movq 0x168(%rsp), %rsi
movq 0x140(%rsp), %rdx
callq 0x50e0
movq %rax, 0x48(%rsp)
jmp 0x47a58
movq 0x48(%rsp), %rax
movq %rax, 0x130(%rsp)
leaq 0x170(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x5310
movq 0x30(%rsp), %rdi
movq %rax, 0x118(%rsp)
callq 0x5230
movq %rax, 0x110(%rsp)
movb $0x21, 0x10f(%rsp)
movq 0x118(%rsp), %rdi
movq 0x110(%rsp), %rsi
leaq 0x10f(%rsp), %rdx
callq 0x48210
movq %rax, 0x38(%rsp)
jmp 0x47abd
movq 0x38(%rsp), %rax
movq %rax, 0x120(%rsp)
leaq 0x128(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x48150
leaq 0x170(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x5230
movq %rax, 0xf8(%rsp)
leaq 0x100(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x48150
movq 0x20(%rsp), %rdi
movq 0x128(%rsp), %rsi
movq 0x100(%rsp), %rdx
callq 0x50e0
movq %rax, 0x28(%rsp)
jmp 0x47b2f
movq 0x28(%rsp), %rax
movq %rax, 0xf0(%rsp)
leaq 0xd0(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0x51b0
jmp 0x47b53
leaq 0xd0(%rsp), %rdi
callq 0x656a0
movq %rax, 0x18(%rsp)
jmp 0x47b67
movq 0x18(%rsp), %rcx
movq 0x210(%rsp), %rax
movq %rcx, (%rax)
leaq 0xd0(%rsp), %rdi
callq 0x5768
leaq 0x1d8(%rsp), %rdi
movq %rdi, 0x10(%rsp)
movl $0x1, %esi
callq 0xfd00
movq %rax, %rdi
callq 0x51a0
movq %rax, %rdi
callq 0x55b0
movq 0x10(%rsp), %rdi
movl %eax, 0xcc(%rsp)
movl $0x2, %esi
callq 0xfd00
movq %rax, %rdi
callq 0x51a0
movq %rax, %rdi
callq 0x55b0
movq 0x10(%rsp), %rdi
movl %eax, %ecx
movq 0x210(%rsp), %rax
movl %ecx, 0x8(%rax)
movl $0x3, %esi
callq 0xfd00
movq %rax, %rdi
callq 0x51a0
movq %rax, %rdi
callq 0x55b0
movq 0x10(%rsp), %rdi
movl %eax, %ecx
movq 0x210(%rsp), %rax
movl %ecx, 0x20(%rax)
movl $0x4, %esi
callq 0xfd00
movq %rax, %rsi
leaq 0xa8(%rsp), %rdi
callq 0x51b0
jmp 0x47c2b
leaq 0xa8(%rsp), %rdi
callq 0x656a0
movq %rax, 0x8(%rsp)
jmp 0x47c3f
movq 0x8(%rsp), %rcx
movq 0x210(%rsp), %rax
movq %rcx, 0x10(%rax)
leaq 0xa8(%rsp), %rdi
callq 0x5768
movl 0xcc(%rsp), %eax
movl %eax, 0x4(%rsp)
testl %eax, %eax
je 0x47ccd
jmp 0x47c6e
movl 0x4(%rsp), %eax
subl $0x1, %eax
je 0x47cde
jmp 0x47c79
movl 0x4(%rsp), %eax
subl $0x2, %eax
je 0x47cef
jmp 0x47d00
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1d0(%rsp)
movl %eax, 0x1cc(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x5768
jmp 0x47d41
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1d0(%rsp)
movl %eax, 0x1cc(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x5768
jmp 0x47d41
movq 0x210(%rsp), %rax
movl $0x0, 0x1c(%rax)
jmp 0x47d1f
movq 0x210(%rsp), %rax
movl $0x2, 0x1c(%rax)
jmp 0x47d1f
movq 0x210(%rsp), %rax
movl $0x3, 0x1c(%rax)
jmp 0x47d1f
leaq 0x2b2b1(%rip), %rdi     # 0x72fb8
leaq 0x2b24b(%rip), %rsi     # 0x72f59
movl $0x8e, %edx
leaq 0x2b2e6(%rip), %rcx     # 0x73000
callq 0x5260
movb $0x1, 0x227(%rsp)
movl $0x1, 0x1c8(%rsp)
leaq 0x170(%rsp), %rdi
callq 0x5768
jmp 0x47d50
leaq 0x170(%rsp), %rdi
callq 0x5768
jmp 0x47d7b
leaq 0x1d8(%rsp), %rdi
callq 0xf560
leaq 0x1f0(%rsp), %rdi
callq 0x5768
movb 0x227(%rsp), %al
andb $0x1, %al
addq $0x228, %rsp            # imm = 0x228
retq
leaq 0x1d8(%rsp), %rdi
callq 0xf560
leaq 0x1f0(%rsp), %rdi
callq 0x5768
movq 0x1d0(%rsp), %rdi
callq 0x5690
nopw %cs:(%rax,%rax)