// File: MPSLab-ASU[P]DiRAC/./src/baseAccelSim.cc
// Function: baseAccelSim::read_file_DMAC_WB_management(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void baseAccelSim::read_file_DMAC_WB_management(string dmacWBManageFileName)
{
	uint8_t operand_number;	uint16_t SPM_pass_number;
	uint32_t offset_base_addr_SPM,	burst_width_bytes, offset_base_addr_DRAM;
	uint16_t it=0;

	ifstream inFile(dmacWBManageFileName.c_str());
	if(!inFile)
	{
		cout << "Cannot open and read file: " << dmacWBManageFileName.c_str() << endl;
		exit (EXIT_FAILURE);
	}

	string line;
 	while (getline(inFile, line)) {
		// skip reading first two lines of the file
		if(it < 2) {
			it++; continue;
		}
		istringstream tokenStream(line);
		string token1, token2, token3, token4, token5;
		tokenStream >> token1 >> token2 >> token3 >> token4 >> token5;
		SPM_pass_number = stoul(token1);
		operand_number = stoul(token2);
		offset_base_addr_SPM = stoul(token3);
		burst_width_bytes = stoul(token4);
		offset_base_addr_DRAM = stoul(token5);

		assert((operand_number >= 0 && operand_number < total_operands) && "invalid operand number!");
		assert((SPM_pass_number >= WB_delay_SPM_pass && SPM_pass_number < (SPM_passes+WB_delay_SPM_pass)) && "invalid number for an SPM pass!");
		assert(offset_base_addr_SPM >= 0 && offset_base_addr_SPM < SPM_size &&
			"invalid SPM address specified for setting offset for an operand for an SPM pass!");
		assert(burst_width_bytes > 0 && burst_width_bytes < SPM_size &&
			"invalid burst width specified for managing data in SPM!");
		assert(offset_base_addr_DRAM >= 0 && offset_base_addr_DRAM < SPM_size &&
			"invalid offset specified for accessing operand from DRAM in SPM pass!");

		write_operand_SPM_pass[SPM_pass_number][operand_number] = true;
		write_operand_offset_base_addr_SPM[SPM_pass_number][operand_number].push_back(offset_base_addr_SPM);
		write_operand_burst_width_bytes_SPM_pass[SPM_pass_number][operand_number].push_back(burst_width_bytes);
		write_operand_offset_base_addr_DRAM[SPM_pass_number][operand_number].push_back(offset_base_addr_DRAM);
		it++;
	}

	inFile.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x510, %rsp            # imm = 0x510
movq %rsi, -0x498(%rbp)
movq %rdi, %rax
movq -0x498(%rbp), %rdi
movq %rdi, -0x490(%rbp)
movq %rax, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movw $0x0, -0x22(%rbp)
callq 0x4a4170
movq %rax, %rsi
leaq -0x230(%rbp), %rdi
movl $0x8, %edx
callq 0x46e8c0
movq -0x230(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x230(%rbp,%rax), %rdi
callq 0x472d80
movb %al, -0x481(%rbp)
jmp 0x4089da
movb -0x481(%rbp), %al
testb $0x1, %al
jne 0x4089e6
jmp 0x408a5c
movq $0x61f900, %rdi         # imm = 0x61F900
leaq 0x19861c(%rip), %rsi    # 0x5a1010
callq 0x492450
movq %rax, -0x4a0(%rbp)
jmp 0x408a02
movq -0x490(%rbp), %rdi
callq 0x4a4170
movq -0x4a0(%rbp), %rdi
movq %rax, %rsi
callq 0x492450
movq %rax, -0x4a8(%rbp)
jmp 0x408a26
movq -0x4a8(%rbp), %rdi
movq $0x491d30, %rsi         # imm = 0x491D30
callq 0x490f40
jmp 0x408a3b
movl $0x1, %edi
callq 0x4ec1e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x408fcf
leaq -0x260(%rbp), %rdi
callq 0x4a2620
leaq -0x230(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x4a5170
movq %rax, -0x4b0(%rbp)
jmp 0x408a84
movq -0x4b0(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x472d70
movb %al, -0x4b1(%rbp)
jmp 0x408aa2
movb -0x4b1(%rbp), %al
testb $0x1, %al
jne 0x408ab1
jmp 0x408f94
movzwl -0x22(%rbp), %eax
cmpl $0x2, %eax
jge 0x408adf
movw -0x22(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x22(%rbp)
jmp 0x408a68
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x408fc3
leaq -0x3e0(%rbp), %rdi
leaq -0x260(%rbp), %rsi
movl $0x8, %edx
callq 0x49a120
jmp 0x408af9
leaq -0x400(%rbp), %rdi
movq %rdi, -0x4c8(%rbp)
callq 0x4a2620
leaq -0x420(%rbp), %rdi
callq 0x4a2620
leaq -0x440(%rbp), %rdi
callq 0x4a2620
leaq -0x460(%rbp), %rdi
callq 0x4a2620
leaq -0x480(%rbp), %rdi
callq 0x4a2620
movq -0x4c8(%rbp), %rsi
leaq -0x3e0(%rbp), %rdi
callq 0x4277f0
movq %rax, -0x4c0(%rbp)
jmp 0x408b58
movq -0x4c0(%rbp), %rdi
leaq -0x420(%rbp), %rsi
callq 0x4277f0
movq %rax, -0x4d0(%rbp)
jmp 0x408b74
movq -0x4d0(%rbp), %rdi
leaq -0x440(%rbp), %rsi
callq 0x4277f0
movq %rax, -0x4d8(%rbp)
jmp 0x408b90
movq -0x4d8(%rbp), %rdi
leaq -0x460(%rbp), %rsi
callq 0x4277f0
movq %rax, -0x4e0(%rbp)
jmp 0x408bac
movq -0x4e0(%rbp), %rdi
leaq -0x480(%rbp), %rsi
callq 0x4277f0
jmp 0x408bc1
xorl %eax, %eax
movl %eax, %esi
leaq -0x400(%rbp), %rdi
movl $0xa, %edx
callq 0x40f200
movq %rax, -0x4e8(%rbp)
jmp 0x408bdf
movq -0x4e8(%rbp), %rax
movw %ax, -0x14(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x420(%rbp), %rdi
movl $0xa, %edx
callq 0x40f200
movq %rax, -0x4f0(%rbp)
jmp 0x408c08
movq -0x4f0(%rbp), %rax
movb %al, -0x11(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x440(%rbp), %rdi
movl $0xa, %edx
callq 0x40f200
movq %rax, -0x4f8(%rbp)
jmp 0x408c30
movq -0x4f8(%rbp), %rax
movl %eax, -0x18(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x460(%rbp), %rdi
movl $0xa, %edx
callq 0x40f200
movq %rax, -0x500(%rbp)
jmp 0x408c58
movq -0x500(%rbp), %rax
movl %eax, -0x1c(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x480(%rbp), %rdi
movl $0xa, %edx
callq 0x40f200
movq %rax, -0x508(%rbp)
jmp 0x408c80
movq -0x508(%rbp), %rax
movl %eax, -0x20(%rbp)
movzbl -0x11(%rbp), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x509(%rbp)
jl 0x408cbc
movzbl -0x11(%rbp), %ecx
movzbl 0x2158b0(%rip), %edx    # 0x61e556
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x509(%rbp)
jge 0x408cbc
movb $0x1, %al
movb %al, -0x509(%rbp)
jmp 0x408cbc
movb -0x509(%rbp), %al
testb $0x1, %al
jne 0x408cc8
jmp 0x408cca
jmp 0x408d48
leaq 0x19931f(%rip), %rdi    # 0x5a1ff0
leaq 0x1983b6(%rip), %rsi    # 0x5a108e
movl $0x14e, %edx            # imm = 0x14E
leaq 0x199794(%rip), %rcx    # 0x5a2478
callq 0x4e53d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
leaq -0x480(%rbp), %rdi
callq 0x4a2730
leaq -0x460(%rbp), %rdi
callq 0x4a2730
leaq -0x440(%rbp), %rdi
callq 0x4a2730
leaq -0x420(%rbp), %rdi
callq 0x4a2730
leaq -0x400(%rbp), %rdi
callq 0x4a2730
leaq -0x3e0(%rbp), %rdi
callq 0x497a10
jmp 0x408fc3
movzwl -0x14(%rbp), %ecx
xorl %eax, %eax
cmpl $0x2, %ecx
movb %al, -0x50a(%rbp)
jl 0x408d7d
movzwl -0x14(%rbp), %ecx
movzwl 0x2157f0(%rip), %edx    # 0x61e554
addl $0x2, %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x50a(%rbp)
jge 0x408d7d
movb $0x1, %al
movb %al, -0x50a(%rbp)
jmp 0x408d7d
movb -0x50a(%rbp), %al
testb $0x1, %al
jne 0x408d89
jmp 0x408d8b
jmp 0x408daa
leaq 0x19971e(%rip), %rdi    # 0x5a24b0
leaq 0x1982f5(%rip), %rsi    # 0x5a108e
movl $0x14f, %edx            # imm = 0x14F
leaq 0x1996d3(%rip), %rcx    # 0x5a2478
callq 0x4e53d0
xorl %eax, %eax
cmpl $0x0, -0x18(%rbp)
movb %al, -0x50b(%rbp)
jb 0x408dd5
movl -0x18(%rbp), %ecx
xorl %eax, %eax
cmpl 0x2157f1(%rip), %ecx    # 0x61e5b4
movb %al, -0x50b(%rbp)
jae 0x408dd5
movb $0x1, %al
movb %al, -0x50b(%rbp)
jmp 0x408dd5
movb -0x50b(%rbp), %al
testb $0x1, %al
jne 0x408de1
jmp 0x408de3
jmp 0x408e02
leaq 0x199480(%rip), %rdi    # 0x5a226a
leaq 0x19829d(%rip), %rsi    # 0x5a108e
movl $0x151, %edx            # imm = 0x151
leaq 0x19967b(%rip), %rcx    # 0x5a2478
callq 0x4e53d0
xorl %eax, %eax
cmpl $0x0, -0x1c(%rbp)
movb %al, -0x50c(%rbp)
jbe 0x408e2d
movl -0x1c(%rbp), %ecx
xorl %eax, %eax
cmpl 0x215799(%rip), %ecx    # 0x61e5b4
movb %al, -0x50c(%rbp)
jae 0x408e2d
movb $0x1, %al
movb %al, -0x50c(%rbp)
jmp 0x408e2d
movb -0x50c(%rbp), %al
testb $0x1, %al
jne 0x408e39
jmp 0x408e3b
jmp 0x408e5a
leaq 0x1994f3(%rip), %rdi    # 0x5a2335
leaq 0x198245(%rip), %rsi    # 0x5a108e
movl $0x153, %edx            # imm = 0x153
leaq 0x199623(%rip), %rcx    # 0x5a2478
callq 0x4e53d0
xorl %eax, %eax
cmpl $0x0, -0x20(%rbp)
movb %al, -0x50d(%rbp)
jb 0x408e85
movl -0x20(%rbp), %ecx
xorl %eax, %eax
cmpl 0x215741(%rip), %ecx    # 0x61e5b4
movb %al, -0x50d(%rbp)
jae 0x408e85
movb $0x1, %al
movb %al, -0x50d(%rbp)
jmp 0x408e85
movb -0x50d(%rbp), %al
testb $0x1, %al
jne 0x408e91
jmp 0x408e93
jmp 0x408eb2
leaq 0x199554(%rip), %rdi    # 0x5a23ee
leaq 0x1981ed(%rip), %rsi    # 0x5a108e
movl $0x155, %edx            # imm = 0x155
leaq 0x1995cb(%rip), %rcx    # 0x5a2478
callq 0x4e53d0
movq 0x2157af(%rip), %rax    # 0x61e668
movzwl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movzbl -0x11(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movq 0x2157a0(%rip), %rax    # 0x61e670
movzwl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movzbl -0x11(%rbp), %ecx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
leaq -0x18(%rbp), %rsi
callq 0x40f240
jmp 0x408eef
movq 0x215782(%rip), %rax    # 0x61e678
movzwl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movzbl -0x11(%rbp), %ecx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
leaq -0x1c(%rbp), %rsi
callq 0x40f240
jmp 0x408f15
movq 0x215764(%rip), %rax    # 0x61e680
movzwl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movzbl -0x11(%rbp), %ecx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
leaq -0x20(%rbp), %rsi
callq 0x40f240
jmp 0x408f3b
movw -0x22(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x22(%rbp)
leaq -0x480(%rbp), %rdi
callq 0x4a2730
leaq -0x460(%rbp), %rdi
callq 0x4a2730
leaq -0x440(%rbp), %rdi
callq 0x4a2730
leaq -0x420(%rbp), %rdi
callq 0x4a2730
leaq -0x400(%rbp), %rdi
callq 0x4a2730
leaq -0x3e0(%rbp), %rdi
callq 0x497a10
jmp 0x408a68
leaq -0x230(%rbp), %rdi
callq 0x46ee70
jmp 0x408fa2
leaq -0x260(%rbp), %rdi
callq 0x4a2730
leaq -0x230(%rbp), %rdi
callq 0x46f220
addq $0x510, %rsp            # imm = 0x510
popq %rbp
retq
leaq -0x260(%rbp), %rdi
callq 0x4a2730
leaq -0x230(%rbp), %rdi
callq 0x46f220
movq -0x238(%rbp), %rdi
callq 0x4d0770
nopw (%rax,%rax)