// File: navrajsaini[P]PL_Compiler_design_project/interp.cpp
// Function: Interpreter::load_program(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void Interpreter::load_program( string name)
{
  int x = 0;
  int word;
  const char* tempname = name.c_str(); 
  ifstream program(tempname, ios::in);
  
  if (!program)
  {
    cerr << " Could not open program file" << endl;
    return;
  }

// read program into memory

  while (!program.eof())
  {
    program >> word;
//    cout << " Read word " << word << endl;
    store[x] = word;
    if ( word == -1) break;
    ++x;
//    cout << "x is " << x << endl;
    
    if ( x >= STORE_SIZE)
    {
      cerr << "program exceeded" << x << " words " << endl;
      cerr << "Not enough memory to load program " << endl;
      return;
     }
   }
  
   stack_bottom = x;

 //  cout << "stack_bottom = " << x << endl;
   
   // clear the rest of memory

   for (int i = stack_bottom; i <= STORE_SIZE; i++)
      store[i] = -1;
   program.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x280, %rsp            # imm = 0x280
movq %rsi, -0x250(%rbp)
movq %rdi, %rax
movq -0x250(%rbp), %rdi
movq %rax, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x248(%rbp)
movl $0x0, -0x14(%rbp)
callq 0x20c0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rsi
leaq -0x228(%rbp), %rdi
movl $0x8, %edx
callq 0x2370
movq -0x228(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x228(%rbp,%rax), %rdi
callq 0x20f0
movb %al, -0x23d(%rbp)
jmp 0x1d314
movb -0x23d(%rbp), %al
testb $0x1, %al
jne 0x1d320
jmp 0x1d383
movq 0x9cc9(%rip), %rdi      # 0x26ff0
leaq 0x287b(%rip), %rsi      # 0x1fba9
callq 0x21b0
movq %rax, -0x258(%rbp)
jmp 0x1d33c
movq -0x258(%rbp), %rdi
movq 0x9c6e(%rip), %rsi      # 0x26fb8
callq 0x21d0
jmp 0x1d351
movl $0x1, -0x238(%rbp)
jmp 0x1d507
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x2060
jmp 0x1d51c
jmp 0x1d385
movq -0x228(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x228(%rbp,%rax), %rdi
callq 0x2380
movb %al, -0x259(%rbp)
jmp 0x1d3a5
movb -0x259(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x1d3b6
jmp 0x1d4a1
leaq -0x228(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x2120
jmp 0x1d3c8
movq -0x248(%rbp), %rax
movl -0x18(%rbp), %edx
movslq -0x14(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
cmpl $-0x1, -0x18(%rbp)
jne 0x1d3e4
jmp 0x1d4a1
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
cmpl $0x3e8, -0x14(%rbp)     # imm = 0x3E8
jl 0x1d49c
movq 0x9bef(%rip), %rdi      # 0x26ff0
leaq 0x27be(%rip), %rsi      # 0x1fbc6
callq 0x21b0
movq %rax, -0x268(%rbp)
jmp 0x1d416
movq -0x268(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x2320
movq %rax, -0x270(%rbp)
jmp 0x1d42e
movq -0x270(%rbp), %rdi
leaq 0x279b(%rip), %rsi      # 0x1fbd7
callq 0x21b0
movq %rax, -0x278(%rbp)
jmp 0x1d44a
movq -0x278(%rbp), %rdi
movq 0x9b60(%rip), %rsi      # 0x26fb8
callq 0x21d0
jmp 0x1d45f
movq 0x9b8a(%rip), %rdi      # 0x26ff0
leaq 0x2772(%rip), %rsi      # 0x1fbdf
callq 0x21b0
movq %rax, -0x280(%rbp)
jmp 0x1d47b
movq -0x280(%rbp), %rdi
movq 0x9b2f(%rip), %rsi      # 0x26fb8
callq 0x21d0
jmp 0x1d490
movl $0x1, -0x238(%rbp)
jmp 0x1d507
jmp 0x1d385
movq -0x248(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, 0xfa4(%rax)
movl 0xfa4(%rax), %eax
movl %eax, -0x23c(%rbp)
cmpl $0x3e8, -0x23c(%rbp)    # imm = 0x3E8
jg 0x1d4ef
movq -0x248(%rbp), %rax
movslq -0x23c(%rbp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl -0x23c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x23c(%rbp)
jmp 0x1d4bd
leaq -0x228(%rbp), %rdi
callq 0x2050
jmp 0x1d4fd
movl $0x0, -0x238(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x2060
addq $0x280, %rsp            # imm = 0x280
popq %rbp
retq
movq -0x230(%rbp), %rdi
callq 0x2340
nopl (%rax,%rax)