// File: ColinHarker[P]ltsim/src/memory.cpp
// Function: RandomAccessMemory::parseMemInfo(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, flag::memType)
void RandomAccessMemory::parseMemInfo(const std::string& memInfoType,
                                      flag::memType      classVariable)
{
   std::string   token;
   std::ifstream file("/proc/meminfo");
   while(file >> token)
   {
      if(token == memInfoType + ":")
      {
         std::string mem;
         if(file >> mem)
         {
            if(classVariable == flag::memType::memTotal)
            {
               m_memTotal = std::stoul(mem);
            }
            else if(classVariable == flag::memType::memAvailable)
            {
               m_memAvailable = std::stoul(mem);
            }
            else if(classVariable == flag::memType::swapTotal)
            {
               m_swapTotal = std::stoul(mem);
            }
            else
            {
               m_swapFree = std::stoul(mem);
            }
         }
      }
      // ignore rest of the line
      file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2e0, %rsp            # imm = 0x2E0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x298(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x3430
leaq 0x6f2f(%rip), %rsi      # 0xe100
leaq -0x240(%rbp), %rdi
movl $0x8, %edx
callq 0x3540
jmp 0x71e4
jmp 0x71e6
leaq -0x240(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x33d0
movq %rax, -0x2a0(%rbp)
jmp 0x71ff
movq -0x2a0(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x33b0
movb %al, -0x2a1(%rbp)
jmp 0x721d
movb -0x2a1(%rbp), %al
testb $0x1, %al
jne 0x722c
jmp 0x7433
movq -0x10(%rbp), %rsi
leaq 0x6ed7(%rip), %rdx      # 0xe10e
leaq -0x270(%rbp), %rdi
callq 0x7620
jmp 0x7245
leaq -0x38(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x7590
movb %al, -0x2a2(%rbp)
leaq -0x270(%rbp), %rdi
callq 0x31d0
movb -0x2a2(%rbp), %al
testb $0x1, %al
jne 0x7276
jmp 0x7413
leaq -0x290(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
callq 0x3430
movq -0x2b8(%rbp), %rsi
leaq -0x240(%rbp), %rdi
callq 0x33d0
movq %rax, -0x2b0(%rbp)
jmp 0x72a5
movq -0x2b0(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x33b0
movb %al, -0x2b9(%rbp)
jmp 0x72c3
movb -0x2b9(%rbp), %al
testb $0x1, %al
jne 0x72d2
jmp 0x7407
cmpl $0x0, -0x14(%rbp)
jne 0x7361
xorl %eax, %eax
movl %eax, %esi
leaq -0x290(%rbp), %rdi
movl $0xa, %edx
callq 0x76a0
movq %rax, -0x2c8(%rbp)
jmp 0x72fa
movq -0x298(%rbp), %rax
movq -0x2c8(%rbp), %rcx
movq %rcx, (%rax)
jmp 0x7405
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
jmp 0x745d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
jmp 0x7451
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
leaq -0x290(%rbp), %rdi
callq 0x31d0
jmp 0x7451
cmpl $0x1, -0x14(%rbp)
jne 0x7399
xorl %eax, %eax
movl %eax, %esi
leaq -0x290(%rbp), %rdi
movl $0xa, %edx
callq 0x76a0
movq %rax, -0x2d0(%rbp)
jmp 0x7385
movq -0x298(%rbp), %rax
movq -0x2d0(%rbp), %rcx
movq %rcx, 0x8(%rax)
jmp 0x7403
cmpl $0x2, -0x14(%rbp)
jne 0x73d1
xorl %eax, %eax
movl %eax, %esi
leaq -0x290(%rbp), %rdi
movl $0xa, %edx
callq 0x76a0
movq %rax, -0x2d8(%rbp)
jmp 0x73bd
movq -0x298(%rbp), %rax
movq -0x2d8(%rbp), %rcx
movq %rcx, 0x10(%rax)
jmp 0x7401
xorl %eax, %eax
movl %eax, %esi
leaq -0x290(%rbp), %rdi
movl $0xa, %edx
callq 0x76a0
movq %rax, -0x2e0(%rbp)
jmp 0x73ef
movq -0x298(%rbp), %rax
movq -0x2e0(%rbp), %rcx
movq %rcx, 0x18(%rax)
jmp 0x7403
jmp 0x7405
jmp 0x7407
leaq -0x290(%rbp), %rdi
callq 0x31d0
callq 0x47c0
movq %rax, %rsi
leaq -0x240(%rbp), %rdi
movl $0xa, %edx
callq 0x31e0
jmp 0x742e
jmp 0x71e6
leaq -0x240(%rbp), %rdi
callq 0x30b0
leaq -0x38(%rbp), %rdi
callq 0x31d0
addq $0x2e0, %rsp            # imm = 0x2E0
popq %rbp
retq
leaq -0x240(%rbp), %rdi
callq 0x30b0
leaq -0x38(%rbp), %rdi
callq 0x31d0
movq -0x248(%rbp), %rdi
callq 0x3510
nopw %cs:(%rax,%rax)