// File: CMU-SAFARI[P]ramulator/src/Config.cpp
// Function: ramulator::Config::parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void Config::parse(const string& fname)
{
    ifstream file(fname);
    assert(file.good() && "Bad config file");
    string line;
    while (getline(file, line)) {
        char delim[] = " \t=";
        vector<string> tokens;

        while (true) {
            size_t start = line.find_first_not_of(delim);
            if (start == string::npos) 
                break;

            size_t end = line.find_first_of(delim, start);
            if (end == string::npos) {
                tokens.push_back(line.substr(start));
                break;
            }

            tokens.push_back(line.substr(start, end - start));
            line = line.substr(end);
        }

        // empty line
        if (!tokens.size())
            continue;

        // comment line
        if (tokens[0][0] == '#')
            continue;

        // parameter line
        assert(tokens.size() == 2 && "Only allow two tokens in one line");

        options[tokens[0]] = tokens[1];

        if (tokens[0] == "channels") {
          channels = atoi(tokens[1].c_str());
        } else if (tokens[0] == "ranks") {
          ranks = atoi(tokens[1].c_str());
        } else if (tokens[0] == "subarrays") {
          subarrays = atoi(tokens[1].c_str());
        } else if (tokens[0] == "cpu_tick") {
          cpu_tick = atoi(tokens[1].c_str());
        } else if (tokens[0] == "mem_tick") {
          mem_tick = atoi(tokens[1].c_str());
        } else if (tokens[0] == "expected_limit_insts") {
          expected_limit_insts = atoi(tokens[1].c_str());
        } else if (tokens[0] == "warmup_insts") {
          warmup_insts = atoi(tokens[1].c_str());
        }
    }
    file.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x340, %rsp            # imm = 0x340
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x2e8(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x218(%rbp), %rdi
movl $0x8, %edx
callq 0xc530
movq -0x218(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x218(%rbp,%rax), %rdi
callq 0xc590
movb %al, -0x2dd(%rbp)
jmp 0x185643
movb -0x2dd(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x2e9(%rbp)
jne 0x185658
jmp 0x185662
movb $0x1, %al
movb %al, -0x2e9(%rbp)
jmp 0x185662
movb -0x2e9(%rbp), %al
testb $0x1, %al
jne 0x18566e
jmp 0x185670
jmp 0x1856a6
leaq 0xd5ba1(%rip), %rdi     # 0x25b218
leaq 0xd5bbb(%rip), %rsi     # 0x25b239
movl $0xd, %edx
leaq 0xd5bbe(%rip), %rcx     # 0x25b248
callq 0xc280
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x185d1e
leaq -0x248(%rbp), %rdi
callq 0xc480
leaq -0x218(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0xc0e0
movq %rax, -0x2f8(%rbp)
jmp 0x1856ce
movq -0x2f8(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0xc440
movb %al, -0x2f9(%rbp)
jmp 0x1856ec
movb -0x2f9(%rbp), %al
testb $0x1, %al
jne 0x1856fb
jmp 0x185ce3
movl 0xd5b75(%rip), %eax     # 0x25b276
movl %eax, -0x24c(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x185d60
jmp 0x185715
leaq -0x24c(%rbp), %rsi
leaq -0x248(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
callq 0xc240
movq %rax, -0x270(%rbp)
cmpq $-0x1, -0x270(%rbp)
jne 0x185759
jmp 0x1858bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x185d12
leaq -0x24c(%rbp), %rsi
movq -0x270(%rbp), %rdx
leaq -0x248(%rbp), %rdi
callq 0xc200
movq %rax, -0x278(%rbp)
cmpq $-0x1, -0x278(%rbp)
jne 0x18580b
movq -0x270(%rbp), %rdx
leaq -0x298(%rbp), %rdi
leaq -0x248(%rbp), %rsi
movq $-0x1, %rcx
callq 0xc380
jmp 0x1857ab
leaq -0x268(%rbp), %rdi
leaq -0x298(%rbp), %rsi
callq 0x185d80
jmp 0x1857c0
leaq -0x298(%rbp), %rdi
callq 0xc6b8
jmp 0x1858bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x185cd5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x298(%rbp), %rdi
callq 0xc6b8
jmp 0x185cd5
movq -0x270(%rbp), %rdx
movq -0x278(%rbp), %rcx
subq %rdx, %rcx
leaq -0x2b8(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0xc380
jmp 0x185831
leaq -0x268(%rbp), %rdi
leaq -0x2b8(%rbp), %rsi
callq 0x185d80
jmp 0x185846
leaq -0x2b8(%rbp), %rdi
callq 0xc6b8
movq -0x278(%rbp), %rdx
leaq -0x2d8(%rbp), %rdi
leaq -0x248(%rbp), %rsi
movq $-0x1, %rcx
callq 0xc380
jmp 0x185875
leaq -0x248(%rbp), %rdi
leaq -0x2d8(%rbp), %rsi
callq 0xc420
leaq -0x2d8(%rbp), %rdi
callq 0xc6b8
jmp 0x185713
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x2b8(%rbp), %rdi
callq 0xc6b8
jmp 0x185cd5
leaq -0x268(%rbp), %rdi
callq 0x185db0
cmpq $0x0, %rax
jne 0x1858dd
movl $0x2, -0x2dc(%rbp)
jmp 0x185cb3
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x310(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x185dd0
movq -0x310(%rbp), %rsi
movq %rax, %rdi
callq 0xc690
movq %rax, -0x308(%rbp)
jmp 0x18590c
movq -0x308(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x18592a
movl $0x2, -0x2dc(%rbp)
jmp 0x185cb3
leaq -0x268(%rbp), %rdi
callq 0x185db0
movq %rax, %rcx
xorl %eax, %eax
cmpq $0x2, %rcx
movb %al, -0x311(%rbp)
jne 0x185951
movb $0x1, %al
movb %al, -0x311(%rbp)
jmp 0x185951
movb -0x311(%rbp), %al
testb $0x1, %al
jne 0x18595d
jmp 0x18595f
jmp 0x18597e
leaq 0xd5936(%rip), %rdi     # 0x25b29c
leaq 0xd58cc(%rip), %rsi     # 0x25b239
movl $0x2b, %edx
leaq 0xd58cf(%rip), %rcx     # 0x25b248
callq 0xc280
leaq -0x268(%rbp), %rdi
movq %rdi, -0x330(%rbp)
movl $0x1, %esi
callq 0x185dd0
movq -0x330(%rbp), %rdi
movq %rax, -0x328(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x185dd0
movq -0x2e8(%rbp), %rdi
movq %rax, %rsi
callq 0x185df0
movq %rax, -0x320(%rbp)
jmp 0x1859c5
movq -0x328(%rbp), %rsi
movq -0x320(%rbp), %rdi
callq 0xc050
jmp 0x1859da
xorl %eax, %eax
movl %eax, %esi
leaq -0x268(%rbp), %rdi
callq 0x185dd0
movq %rax, %rdi
leaq 0xda698(%rip), %rsi     # 0x26008c
callq 0x17f10
movb %al, -0x331(%rbp)
jmp 0x185a01
movb -0x331(%rbp), %al
testb $0x1, %al
jne 0x185a0d
jmp 0x185a3f
leaq -0x268(%rbp), %rdi
movl $0x1, %esi
callq 0x185dd0
movq %rax, %rdi
callq 0xc1b0
movq %rax, %rdi
callq 0xc500
movl %eax, %ecx
movq -0x2e8(%rbp), %rax
movl %ecx, 0x30(%rax)
jmp 0x185ca9
xorl %eax, %eax
movl %eax, %esi
leaq -0x268(%rbp), %rdi
callq 0x185dd0
movq %rax, %rdi
leaq 0xda8bb(%rip), %rsi     # 0x260314
callq 0x17f10
movb %al, -0x332(%rbp)
jmp 0x185a66
movb -0x332(%rbp), %al
testb $0x1, %al
jne 0x185a72
jmp 0x185aa4
leaq -0x268(%rbp), %rdi
movl $0x1, %esi
callq 0x185dd0
movq %rax, %rdi
callq 0xc1b0
movq %rax, %rdi
callq 0xc500
movl %eax, %ecx
movq -0x2e8(%rbp), %rax
movl %ecx, 0x34(%rax)
jmp 0x185ca7
xorl %eax, %eax
movl %eax, %esi
leaq -0x268(%rbp), %rdi
callq 0x185dd0
movq %rax, %rdi
leaq 0xd5818(%rip), %rsi     # 0x25b2d6
callq 0x17f10
movb %al, -0x333(%rbp)
jmp 0x185acb
movb -0x333(%rbp), %al
testb $0x1, %al
jne 0x185ad7
jmp 0x185b09
leaq -0x268(%rbp), %rdi
movl $0x1, %esi
callq 0x185dd0
movq %rax, %rdi
callq 0xc1b0
movq %rax, %rdi
callq 0xc500
movl %eax, %ecx
movq -0x2e8(%rbp), %rax
movl %ecx, 0x38(%rax)
jmp 0x185ca5
xorl %eax, %eax
movl %eax, %esi
leaq -0x268(%rbp), %rdi
callq 0x185dd0
movq %rax, %rdi
leaq 0xd57bd(%rip), %rsi     # 0x25b2e0
callq 0x17f10
movb %al, -0x334(%rbp)
jmp 0x185b30
movb -0x334(%rbp), %al
testb $0x1, %al
jne 0x185b3c
jmp 0x185b6e
leaq -0x268(%rbp), %rdi
movl $0x1, %esi
callq 0x185dd0
movq %rax, %rdi
callq 0xc1b0
movq %rax, %rdi
callq 0xc500
movl %eax, %ecx
movq -0x2e8(%rbp), %rax
movl %ecx, 0x3c(%rax)
jmp 0x185ca3
xorl %eax, %eax
movl %eax, %esi
leaq -0x268(%rbp), %rdi
callq 0x185dd0
movq %rax, %rdi
leaq 0xd5761(%rip), %rsi     # 0x25b2e9
callq 0x17f10
movb %al, -0x335(%rbp)
jmp 0x185b95
movb -0x335(%rbp), %al
testb $0x1, %al
jne 0x185ba1
jmp 0x185bd3
leaq -0x268(%rbp), %rdi
movl $0x1, %esi
callq 0x185dd0
movq %rax, %rdi
callq 0xc1b0
movq %rax, %rdi
callq 0xc500
movl %eax, %ecx
movq -0x2e8(%rbp), %rax
movl %ecx, 0x40(%rax)
jmp 0x185ca1
xorl %eax, %eax
movl %eax, %esi
leaq -0x268(%rbp), %rdi
callq 0x185dd0
movq %rax, %rdi
leaq 0xd5705(%rip), %rsi     # 0x25b2f2
callq 0x17f10
movb %al, -0x336(%rbp)
jmp 0x185bfa
movb -0x336(%rbp), %al
testb $0x1, %al
jne 0x185c06
jmp 0x185c39
leaq -0x268(%rbp), %rdi
movl $0x1, %esi
callq 0x185dd0
movq %rax, %rdi
callq 0xc1b0
movq %rax, %rdi
callq 0xc500
movl %eax, %ecx
movq -0x2e8(%rbp), %rax
movslq %ecx, %rcx
movq %rcx, 0x48(%rax)
jmp 0x185c9f
xorl %eax, %eax
movl %eax, %esi
leaq -0x268(%rbp), %rdi
callq 0x185dd0
movq %rax, %rdi
leaq 0xd56b4(%rip), %rsi     # 0x25b307
callq 0x17f10
movb %al, -0x337(%rbp)
jmp 0x185c60
movb -0x337(%rbp), %al
testb $0x1, %al
jne 0x185c6c
jmp 0x185c9d
leaq -0x268(%rbp), %rdi
movl $0x1, %esi
callq 0x185dd0
movq %rax, %rdi
callq 0xc1b0
movq %rax, %rdi
callq 0xc500
movl %eax, %ecx
movq -0x2e8(%rbp), %rax
movslq %ecx, %rcx
movq %rcx, 0x50(%rax)
jmp 0x185c9f
jmp 0x185ca1
jmp 0x185ca3
jmp 0x185ca5
jmp 0x185ca7
jmp 0x185ca9
movl $0x0, -0x2dc(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x185ed0
movl -0x2dc(%rbp), %eax
testl %eax, %eax
je 0x185cd0
jmp 0x185ccb
jmp 0x1856b2
jmp 0x1856b2
leaq -0x268(%rbp), %rdi
callq 0x185ed0
jmp 0x185d12
leaq -0x218(%rbp), %rdi
callq 0xc0f0
jmp 0x185cf1
leaq -0x248(%rbp), %rdi
callq 0xc6b8
leaq -0x218(%rbp), %rdi
callq 0xc120
addq $0x340, %rsp            # imm = 0x340
popq %rbp
retq
leaq -0x248(%rbp), %rdi
callq 0xc6b8
leaq -0x218(%rbp), %rdi
callq 0xc120
movq -0x220(%rbp), %rdi
callq 0xc5d0
nopw %cs:(%rax,%rax)