LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: czmccrory[P]ManchesterBaby/baby.cpp
// Function: ManchesterBaby::add(int)
void ManchesterBaby::add(int operand) {
	presentMnemonic = "ADD " + to_string(operand);

  int accumulatorDec = accumulator.getDecVector(); 
  int storeDec = store.at(operand).getDecVector(); 

  int result = accumulatorDec + storeDec; //add the two values together

  accumulator.setDecVector(result);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0xc(%rbp), %esi
leaq -0x50(%rbp), %rdi
movq %rdi, -0x70(%rbp)
callq 0x5bf0
movq -0x70(%rbp), %rdx
leaq 0x6dd6(%rip), %rsi      # 0xb0bb
leaq -0x30(%rbp), %rdi
callq 0x5ba0
jmp 0x42f0
movq -0x78(%rbp), %rdi
addq $0x38, %rdi
leaq -0x30(%rbp), %rsi
callq 0x32d0
leaq -0x30(%rbp), %rdi
callq 0x3150
leaq -0x50(%rbp), %rdi
callq 0x3150
movq -0x78(%rbp), %rdi
addq $0x28, %rdi
callq 0x7f70
movq -0x78(%rbp), %rdi
movl %eax, -0x60(%rbp)
movslq -0xc(%rbp), %rsi
callq 0x5b60
movq %rax, %rdi
callq 0x7f70
movq -0x78(%rbp), %rdi
movl %eax, -0x64(%rbp)
movl -0x60(%rbp), %eax
addl -0x64(%rbp), %eax
movl %eax, -0x68(%rbp)
addq $0x28, %rdi
movl -0x68(%rbp), %esi
callq 0x7fe0
addq $0x80, %rsp
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x3150
movq -0x58(%rbp), %rdi
callq 0x33e0
nopl (%rax,%rax)
// File: czmccrory[P]ManchesterBaby/baby.cpp
// Function: ManchesterBaby::imadd(int)
void ManchesterBaby::imadd(int operand) {

	presentMnemonic = "IMADD " + to_string(operand);

  int accumulatorDec = accumulator.getDecVector();
  int result = accumulatorDec + operand; //add the two values

  accumulator.setDecVector(result); //save it to the accumulator
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0xc(%rbp), %esi
leaq -0x50(%rbp), %rdi
movq %rdi, -0x70(%rbp)
callq 0x5bf0
movq -0x70(%rbp), %rdx
leaq 0x6d04(%rip), %rsi      # 0xb0b9
leaq -0x30(%rbp), %rdi
callq 0x5ba0
jmp 0x43c0
movq -0x78(%rbp), %rdi
addq $0x38, %rdi
leaq -0x30(%rbp), %rsi
callq 0x32d0
leaq -0x30(%rbp), %rdi
callq 0x3150
leaq -0x50(%rbp), %rdi
callq 0x3150
movq -0x78(%rbp), %rdi
addq $0x28, %rdi
callq 0x7f70
movq -0x78(%rbp), %rdi
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
addl -0xc(%rbp), %eax
movl %eax, -0x64(%rbp)
addq $0x28, %rdi
movl -0x64(%rbp), %esi
callq 0x7fe0
addq $0x80, %rsp
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x3150
movq -0x58(%rbp), %rdi
callq 0x33e0
nopw %cs:(%rax,%rax)
// File: czmccrory[P]ManchesterBaby/baby.cpp
// Function: ManchesterBaby::negsto(int)
void ManchesterBaby::negsto(int operand) {

	presentMnemonic = "NEGSTO " + to_string(operand);
  int accumulatorValue = accumulator.getDecVector();
  //store the negative of the accumulator in the store
  store.at(operand).setDecVector(0-accumulatorValue);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
movl -0xc(%rbp), %esi
leaq -0x50(%rbp), %rdi
movq %rdi, -0x68(%rbp)
callq 0x5bf0
movq -0x68(%rbp), %rdx
leaq 0x6c50(%rip), %rsi      # 0xb0c2
leaq -0x30(%rbp), %rdi
callq 0x5ba0
jmp 0x447d
movq -0x70(%rbp), %rdi
addq $0x38, %rdi
leaq -0x30(%rbp), %rsi
callq 0x32d0
leaq -0x30(%rbp), %rdi
callq 0x3150
leaq -0x50(%rbp), %rdi
callq 0x3150
movq -0x70(%rbp), %rdi
addq $0x28, %rdi
callq 0x7f70
movq -0x70(%rbp), %rdi
movl %eax, -0x60(%rbp)
movslq -0xc(%rbp), %rsi
callq 0x5b60
movq %rax, %rdi
xorl %esi, %esi
subl -0x60(%rbp), %esi
callq 0x7fe0
addq $0x70, %rsp
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x3150
movq -0x58(%rbp), %rdi
callq 0x33e0
nop
// File: czmccrory[P]ManchesterBaby/baby.cpp
// Function: ManchesterBaby::execute(int, int)
void ManchesterBaby::execute(int opcode, int operand){
	clrscr();
  //Process the opcode
  switch(opcode){
    case 0: 
    //Set CI to content of Store location
      jmp(operand);
      break;
    case 1:
    //Add content of Store location to CI
      jrp(operand);
      break;
    case 2:
    //Load Accumulator with negative form of Store contents
      ldn(operand);
      break;
    case 3:
    //Copy Accumulator to Store location
      sto(operand);
      break;
    case 4:
    //Subtract content of Store location from Accumulator
      sub(operand);
      break;
    case 5:
    //Subtract content of Store location from Accumulator
      sub(operand);
      break;
    case 6:
    //Increment CI if Accumulator value negative, otherwise do nothing
      cmp();
      break;
    case 7:
    //Halt the Baby and light the 'stop lamp'
      stp();
      break;
    case 8:
    //Multiply content of Store and Accumulator
      mul(operand);
      break;
    case 9:
    //Load Accumulator with (positive form of) Store contents
      ldp(operand);
      break;
    case 10:
    //Add content of Store and Accumulator
      add(operand);
      break;
    case 11:
    //Copy negative form of Accumulator to Store location
      negsto(operand);
      break;
    case 12:
    	inc();
    	break;
    case 13:
    	dec();
    	break;
    default:
      break;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
callq 0x4770
movl -0xc(%rbp), %eax
movq %rax, -0x18(%rbp)
subq $0xd, %rax
ja 0x4768
movq -0x18(%rbp), %rax
leaq 0x6969(%rip), %rcx      # 0xb004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x20(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x37d0
jmp 0x476a
movq -0x20(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x3910
jmp 0x476a
movq -0x20(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x3a60
jmp 0x476a
movq -0x20(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x3bc0
jmp 0x476a
movq -0x20(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x3d10
jmp 0x476a
movq -0x20(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x3d10
jmp 0x476a
movq -0x20(%rbp), %rdi
callq 0x3f40
jmp 0x476a
movq -0x20(%rbp), %rdi
callq 0x3f90
jmp 0x476a
movq -0x20(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x3fd0
jmp 0x476a
movq -0x20(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x4160
jmp 0x476a
movq -0x20(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x42b0
jmp 0x476a
movq -0x20(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x4440
jmp 0x476a
movq -0x20(%rbp), %rdi
callq 0x3de0
jmp 0x476a
movq -0x20(%rbp), %rdi
callq 0x3e30
jmp 0x476a
jmp 0x476a
addq $0x20, %rsp
popq %rbp
retq
// File: czmccrory[P]ManchesterBaby/baby.cpp
// Function: ManchesterBaby::addressedExecute(int, int, bool)
void ManchesterBaby::addressedExecute(int opcode, int operand, bool immAddressing) {
	if (immAddressing){
    //if the addressing in the PI is immediate run this method
		immediateEx(opcode, operand);
	} else {
    //if it's absolute run this other method
		execute(opcode, operand);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movb %cl, %al
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
testb $0x1, -0x11(%rbp)
je 0x4a18
movq -0x20(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
callq 0x47a0
jmp 0x4a27
movq -0x20(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
callq 0x4660
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)
// File: czmccrory[P]ManchesterBaby/baby.cpp
// Function: ManchesterBaby::readFromFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void ManchesterBaby::readFromFile(string path){
  ifstream file (path); //open a file stream at path
  if(file){ //if opened successfully
    string l; 
    size_t i = 0;
    while (getline(file, l)) { //get a line to l
      Line myline(l); //call the line string constructor for this line
      store.at(i) = myline; //save this line to the store at i
      i++;
    }
  }
  else {
    cout << "Unable to open file" << endl;
  }

  file.close(); //close the file

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2b0, %rsp            # imm = 0x2B0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x288(%rbp)
leaq -0x218(%rbp), %rdi
movl $0x8, %edx
callq 0x3380
movq -0x218(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x218(%rbp,%rax), %rdi
callq 0x32f0
movb %al, -0x279(%rbp)
jmp 0x4a7f
movb -0x279(%rbp), %al
testb $0x1, %al
jne 0x4a8e
jmp 0x4bfb
leaq -0x248(%rbp), %rdi
callq 0x3330
movq $0x0, -0x250(%rbp)
leaq -0x218(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x3050
movq %rax, -0x290(%rbp)
jmp 0x4ac1
movq -0x290(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x32f0
movb %al, -0x291(%rbp)
jmp 0x4adf
movb -0x291(%rbp), %al
testb $0x1, %al
jne 0x4aee
jmp 0x4bdf
leaq -0x278(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x30e0
jmp 0x4b03
leaq -0x258(%rbp), %rdi
leaq -0x278(%rbp), %rsi
callq 0x7980
jmp 0x4b18
leaq -0x278(%rbp), %rdi
callq 0x3150
movq -0x288(%rbp), %rdi
movq -0x250(%rbp), %rsi
callq 0x5b60
movq %rax, -0x2a0(%rbp)
jmp 0x4b40
movq -0x2a0(%rbp), %rax
movq -0x258(%rbp), %rcx
movq %rcx, (%rax)
movq -0x250(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x250(%rbp)
leaq -0x258(%rbp), %rdi
callq 0x7ac0
jmp 0x4aa5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x4c51
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x4bed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x278(%rbp), %rdi
callq 0x3150
jmp 0x4bed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x258(%rbp), %rdi
callq 0x7ac0
jmp 0x4bed
leaq -0x248(%rbp), %rdi
callq 0x3150
jmp 0x4c2e
leaq -0x248(%rbp), %rdi
callq 0x3150
jmp 0x4c51
movq 0xb3be(%rip), %rdi      # 0xffc0
leaq 0x64c1(%rip), %rsi      # 0xb0ca
callq 0x3210
movq %rax, -0x2a8(%rbp)
jmp 0x4c17
movq -0x2a8(%rbp), %rdi
movq 0xb38b(%rip), %rsi      # 0xffb0
callq 0x3240
jmp 0x4c2c
jmp 0x4c2e
leaq -0x218(%rbp), %rdi
callq 0x3060
jmp 0x4c3c
leaq -0x218(%rbp), %rdi
callq 0x3090
addq $0x2b0, %rsp            # imm = 0x2B0
popq %rbp
retq
leaq -0x218(%rbp), %rdi
callq 0x3090
movq -0x220(%rbp), %rdi
callq 0x33e0
nopl (%rax)
// File: czmccrory[P]ManchesterBaby/baby.cpp
// Function: ManchesterBaby::runBaby(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void ManchesterBaby::runBaby(string filename) {
	readFromFile(filename); //read the file
  cin.ignore(); //clear the cin
  cin.clear();

  int instruction;
  char temp;
  do {
    incrementCI(); //increment program counter
    fetch(); //get next line and save it to the PI
    instruction = decodeInstruction(); //get the decimal opcode number
    int operand = decodeOperand();
	  bool immAddressing = decodeAddressingMode();
    addressedExecute(instruction, operand, immAddressing);
    output(); //display the store, PI, CI, acucmulator
    cin.get(temp);
  } while (instruction != 7 && temp == '\n'); //run until the decoded opcode is halt/stop

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0x58(%rbp)
callq 0x30e0
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x4a30
jmp 0x5054
leaq -0x30(%rbp), %rdi
callq 0x3150
movq 0xaf74(%rip), %rdi      # 0xffd8
callq 0x3420
movq 0xaf68(%rip), %rax      # 0xffd8
movq (%rax), %rax
movq 0xaf5e(%rip), %rdi      # 0xffd8
addq -0x18(%rax), %rdi
xorl %esi, %esi
callq 0x33b0
movq -0x60(%rbp), %rdi
callq 0x3770
movq -0x60(%rbp), %rdi
callq 0x3790
movq -0x60(%rbp), %rdi
callq 0x45f0
movq -0x60(%rbp), %rdi
movl %eax, -0x40(%rbp)
callq 0x4610
movq -0x60(%rbp), %rdi
movl %eax, -0x48(%rbp)
callq 0x4630
movq -0x60(%rbp), %rdi
andb $0x1, %al
movb %al, -0x49(%rbp)
movl -0x40(%rbp), %esi
movl -0x48(%rbp), %edx
movb -0x49(%rbp), %al
andb $0x1, %al
movzbl %al, %ecx
callq 0x49e0
movq -0x60(%rbp), %rdi
callq 0x4c70
movq 0xaef4(%rip), %rdi      # 0xffd8
leaq -0x41(%rbp), %rsi
callq 0x3320
xorl %eax, %eax
cmpl $0x7, -0x40(%rbp)
movb %al, -0x61(%rbp)
je 0x5105
movsbl -0x41(%rbp), %eax
cmpl $0xa, %eax
sete %al
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
testb $0x1, %al
jne 0x5085
addq $0x70, %rsp
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x3150
movq -0x38(%rbp), %rdi
callq 0x33e0
nopw %cs:(%rax,%rax)
// File: czmccrory[P]ManchesterBaby/baby.cpp
// Function: main
int main(int argc, char** argv) {
  ManchesterBaby mb;
  if(argc > 2) {
  	cerr<<"Invalid use of program. Run using either \"" << argv[0]
  		<<"\" or \"" <<argv[0]<<" "<< argv[1] << "\"." <<endl;
  		return 1;
  } else if (argc == 2) {
  	mb.setParamFile(argv[1]);
  	mb.menu();
  } else {
 	mb.menu();
  }
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x35d0
cmpl $0x2, -0x8(%rbp)
jle 0x58d6
movq 0xa81a(%rip), %rdi      # 0xfff0
leaq 0x5b08(%rip), %rsi      # 0xb2e5
callq 0x3210
movq %rax, -0xd0(%rbp)
jmp 0x57eb
movq -0xd0(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x3210
movq %rax, -0xd8(%rbp)
jmp 0x5807
movq -0xd8(%rbp), %rdi
leaq 0x5afb(%rip), %rsi      # 0xb310
callq 0x3210
movq %rax, -0xe0(%rbp)
jmp 0x5823
movq -0xe0(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x3210
movq %rax, -0xe8(%rbp)
jmp 0x583f
movq -0xe8(%rbp), %rdi
leaq 0x59a6(%rip), %rsi      # 0xb1f3
callq 0x3210
movq %rax, -0xf0(%rbp)
jmp 0x585b
movq -0xf0(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x3210
movq %rax, -0xf8(%rbp)
jmp 0x5878
movq -0xf8(%rbp), %rdi
leaq 0x5a91(%rip), %rsi      # 0xb317
callq 0x3210
movq %rax, -0x100(%rbp)
jmp 0x5894
movq -0x100(%rbp), %rdi
movq 0xa70e(%rip), %rsi      # 0xffb0
callq 0x3240
jmp 0x58a9
movl $0x1, -0x4(%rbp)
movl $0x1, -0xa0(%rbp)
jmp 0x59be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x59d6
cmpl $0x2, -0x8(%rbp)
jne 0x599b
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x110(%rbp)
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x33f0
movq -0x110(%rbp), %rsi
movq -0x108(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
callq 0x5dc0
jmp 0x591e
leaq -0x90(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x54e0
jmp 0x5933
leaq -0xc0(%rbp), %rdi
callq 0x3150
leaq -0xc1(%rbp), %rdi
callq 0x3260
leaq -0x90(%rbp), %rdi
callq 0x5510
jmp 0x5959
jmp 0x59ab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x598d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x3150
leaq -0xc1(%rbp), %rdi
callq 0x3260
jmp 0x59d6
leaq -0x90(%rbp), %rdi
callq 0x5510
jmp 0x59a9
jmp 0x59ab
jmp 0x59ad
movl $0x0, -0x4(%rbp)
movl $0x1, -0xa0(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x5e90
movl -0x4(%rbp), %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
leaq -0x90(%rbp), %rdi
callq 0x5e90
movq -0x98(%rbp), %rdi
callq 0x33e0
nop
// File: czmccrory[P]ManchesterBaby/line.cpp
// Function: binToDec(std::vector<bool, std::allocator<bool>>*)
int binToDec(vector<bool> * bin)
{
	bool negative = bin->back(); //1/true means negative, 0/false means positive
  int length = bin->size();
  int decimal = 0;

  for (int i = 0; i < length -1; i++)
  {
    if (bin->at(i) == 1) //add value of 2^(length - i - 1)(value of its position in the binary number)
    {
      decimal += (static_cast<int>(pow(2, i)));
    }
  }

  if (negative) {
  	return 0-decimal;
  } else {
	return decimal;
  }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x8060
movq %rax, -0x28(%rbp)
movq %rdx, -0x20(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x80d0
andb $0x1, %al
movb %al, -0x11(%rbp)
movq -0x10(%rbp), %rdi
callq 0x8100
movl %eax, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl -0x2c(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x752e
movq -0x10(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0x8180
movq %rax, -0x48(%rbp)
movq %rdx, -0x40(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x80d0
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x7521
movl -0x34(%rbp), %esi
movl $0x2, %edi
callq 0x81d0
cvttsd2si %xmm0, %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x7523
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x74d5
testb $0x1, -0x11(%rbp)
je 0x753e
xorl %eax, %eax
subl -0x30(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x7544
movl -0x30(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)
// File: czmccrory[P]ManchesterBaby/line.cpp
// Function: decToBin(int, int)
vector<bool>* decToBin(int dec, int numOfBits) 
{	
  vector<bool>* bin = new vector<bool>(numOfBits, 0); // vector to hold binary value (in this case size 8 for rule.)

  //const unsigned long long maxDec = pow(2,numOfBits)-1; //we are using operandWidth-bit numbers
   //with the last bit as the sign
  bool negative;
  if (dec < 0) {
  	negative = true;
	dec = 0 - dec;
  } else {
  	negative = false;
  }
  for (size_t i=numOfBits-1; dec>0; i--)
  {
    // take the remainder of the dec / 2 and save it to the vector
    // this value will always be 1 or 0
    (*bin).at(numOfBits-1-i) = dec%2;
    // update dec
    dec /= 2;
  }
  bin->at(numOfBits-1) = negative; //setting the 13th bit

  return bin;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl $0x28, %edi
callq 0x3220
movq %rax, -0x68(%rbp)
movq %rax, -0x70(%rbp)
movb $0x1, -0x25(%rbp)
movslq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movb $0x0, -0x11(%rbp)
leaq -0x12(%rbp), %rdi
movq %rdi, -0x58(%rbp)
callq 0x8480
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rcx
leaq -0x11(%rbp), %rdx
callq 0x84a0
jmp 0x7617
movb $0x0, -0x25(%rbp)
leaq -0x12(%rbp), %rdi
callq 0x8520
movq -0x70(%rbp), %rax
movq %rax, -0x10(%rbp)
cmpl $0x0, -0x4(%rbp)
jge 0x7670
movb $0x1, -0x26(%rbp)
xorl %eax, %eax
subl -0x4(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x7674
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x12(%rbp), %rdi
callq 0x8520
testb $0x1, -0x25(%rbp)
jne 0x765d
jmp 0x766b
movq -0x70(%rbp), %rdi
movl $0x28, %esi
callq 0x3230
jmp 0x772a
movb $0x0, -0x26(%rbp)
movl -0x8(%rbp), %eax
subl $0x1, %eax
cltq
movq %rax, -0x30(%rbp)
cmpl $0x0, -0x4(%rbp)
jle 0x76e9
movl -0x4(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
setne %al
movb %al, -0x71(%rbp)
movq -0x10(%rbp), %rdi
movl -0x8(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
subq -0x30(%rbp), %rsi
callq 0x8180
movq %rax, %rcx
movb -0x71(%rbp), %al
movq %rcx, -0x40(%rbp)
movq %rdx, -0x38(%rbp)
movzbl %al, %esi
andl $0x1, %esi
leaq -0x40(%rbp), %rdi
callq 0x8540
movl -0x4(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x4(%rbp)
movq -0x30(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x7680
movb -0x26(%rbp), %al
movb %al, -0x72(%rbp)
movq -0x10(%rbp), %rdi
movl -0x8(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x8180
movq %rax, %rcx
movb -0x72(%rbp), %al
movq %rcx, -0x50(%rbp)
movq %rdx, -0x48(%rbp)
leaq -0x50(%rbp), %rdi
andb $0x1, %al
movzbl %al, %esi
callq 0x8540
movq -0x10(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
movq -0x20(%rbp), %rdi
callq 0x33e0
nopw %cs:(%rax,%rax)
// File: czmccrory[P]ManchesterBaby/line.cpp
// Function: printVector(std::vector<bool, std::allocator<bool>>*)
void printVector(vector<bool> * v) {
	vector<bool>::iterator it;
	for (it=v->begin(); it != v->end(); ++it) {
		cout << *it << "" <<flush;
	}
	cout <<flush;
	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x85b0
movq -0x8(%rbp), %rdi
callq 0x85e0
movl %edx, -0x30(%rbp)
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x28(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x18(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0x8650
movl %edx, -0x50(%rbp)
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x40(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x8620
testb $0x1, %al
jne 0x77f2
jmp 0x784a
leaq -0x18(%rbp), %rdi
callq 0x8670
movq %rax, -0x68(%rbp)
movq %rdx, -0x60(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x80d0
movzbl %al, %esi
andl $0x1, %esi
movq 0x87a7(%rip), %rdi      # 0xffc0
callq 0x3400
movq %rax, %rdi
leaq 0x38de(%rip), %rsi      # 0xb106
callq 0x3210
movq %rax, %rdi
movq 0x8791(%rip), %rsi      # 0xffc8
callq 0x3240
leaq -0x18(%rbp), %rdi
callq 0x86b0
jmp 0x77c1
movq 0x876f(%rip), %rdi      # 0xffc0
movq 0x8770(%rip), %rsi      # 0xffc8
callq 0x3240
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: czmccrory[P]ManchesterBaby/line.cpp
// Function: Line::set(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void Line::set(string s) {
	//cout << "trying to set(string) " << endl;
	//delete line;
	line = new vector<bool>; //use something else to empty it
	for (char &c : s) {
		if (c == '0') {
			line->push_back(0);
		} else if (c == '1'){ //anything that's not 0
			line->push_back(1);
		}
		//cout << c;
		//cout << static_cast<int>(c);
	}

	//cout <<endl;// << "all set. " <<endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rsi, -0x38(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movl $0x28, %edi
callq 0x3220
movq %rax, %rdi
movq %rdi, -0x48(%rbp)
callq 0x87f0
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rsi
movq %rcx, (%rax)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x31e0
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3120
movq %rax, -0x28(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x8810
testb $0x1, %al
jne 0x7a62
jmp 0x7ab7
leaq -0x20(%rbp), %rdi
callq 0x8850
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x30, %eax
jne 0x7a8b
movq -0x40(%rbp), %rax
movq (%rax), %rdi
xorl %esi, %esi
callq 0x8390
jmp 0x7aaa
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x31, %eax
jne 0x7aa8
movq -0x40(%rbp), %rax
movq (%rax), %rdi
movl $0x1, %esi
callq 0x8390
jmp 0x7aaa
jmp 0x7aac
leaq -0x20(%rbp), %rdi
callq 0x8870
jmp 0x7a4f
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)
// File: nus-comparch[P]cs5222-lab-prefetcher/example_prefetchers/stream_prefetcher.cc
// Function: l2_prefetcher_initialize
void l2_prefetcher_initialize(int cpu_num)
{
  printf("Streaming Prefetcher\n");
  // you can inspect these knob values from your code to see which configuration you're runnig in
  printf("Knobs visible from prefetcher: %d %d %d\n", knob_scramble_loads, knob_small_llc, knob_low_bandwidth);

  int i;
  for(i=0; i<STREAM_DETECTOR_COUNT; i++)
    {
      detectors[i].page = 0;
      detectors[i].direction = 0;
      detectors[i].confidence = 0;
      detectors[i].pf_index = -1;
    }

  replacement_index = 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl %edi, -0x4(%rbp)
leaq 0x98b2(%rip), %rdi      # 0x40b004
movb $0x0, %al
callq 0x401030
movq $0x4ad2f0, %rax         # imm = 0x4AD2F0
movl (%rax), %esi
movq $0x411060, %rax         # imm = 0x411060
movl (%rax), %edx
movq $0x4ad2f4, %rax         # imm = 0x4AD2F4
movl (%rax), %ecx
leaq 0x989f(%rip), %rdi      # 0x40b01a
movb $0x0, %al
callq 0x401030
movl $0x0, -0x8(%rbp)
cmpl $0x40, -0x8(%rbp)
jge 0x4017fe
movslq -0x8(%rbp), %rcx
leaq 0xca46(%rip), %rax      # 0x40e1e0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq $0x0, (%rax)
movslq -0x8(%rbp), %rcx
leaq 0xca2d(%rip), %rax      # 0x40e1e0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x8(%rax)
movslq -0x8(%rbp), %rcx
leaq 0xca14(%rip), %rax      # 0x40e1e0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0xc(%rax)
movslq -0x8(%rbp), %rcx
leaq 0xc9fb(%rip), %rax      # 0x40e1e0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x10(%rax) # imm = 0xFFFFFFFF
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x401789
movl $0x0, 0xcfd8(%rip)      # 0x40e7e0
addq $0x10, %rsp
popq %rbp
retq
nop
// File: m8pple[P]arch2-2014-cw1/src/eie2ugs/test_mips.cpp
// Function: main
int main()
{
	mips_mem_h mem=mips_mem_create_ram(
		1<<20,
		4
		);

	mips_cpu_h cpu=mips_cpu_create(mem);

	mips_test_begin_suite();

	int testId=mips_test_begin_test("and");
	int passed=0;

	
	mips_error err = mips_cpu_set_register(cpu, 8, 0x0000FFFFul);
	if(err==0)
		err = mips_cpu_set_register(cpu, 9, 0x00FFFF00ul);

	// and $10, $8, $9

	// TODO : work out the bit-wise encoding for the instruction.

	// TODO : Write it into mempory at a known address

	// TODO : Make sure the program-counter is at that address

	if(err==0)
		err=mips_cpu_step(cpu);

	uint32_t got;
	if(err==0)
		err = (mips_error)(err | mips_cpu_get_register(cpu, 10, &got));

	passed = (err == mips_Success) && (got==0x0000FF00);

	mips_test_end_test(testId, passed, NULL);

	mips_test_end_suite();

	mips_cpu_free(cpu);
	mips_mem_free(mem);

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl $0x0, -0x4(%rbp)
movl $0x100000, %edi         # imm = 0x100000
movl $0x4, %esi
callq 0x6700
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6960
movq %rax, -0x18(%rbp)
callq 0x2550
leaq 0x5149(%rip), %rdi      # 0x75c4
callq 0x2660
movl %eax, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rdi
movl $0x8, %esi
movl $0xffff, %edx           # imm = 0xFFFF
callq 0x6a50
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x24bc
movq -0x18(%rbp), %rdi
movl $0x9, %esi
movl $0xffff00, %edx         # imm = 0xFFFF00
callq 0x6a50
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x24ce
movq -0x18(%rbp), %rdi
callq 0x6aa0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x24f6
movl -0x24(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rdi
movl $0xa, %esi
leaq -0x28(%rbp), %rdx
callq 0x69f0
movl %eax, %ecx
movl -0x2c(%rbp), %eax
orl %ecx, %eax
movl %eax, -0x24(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x24(%rbp)
movb %al, -0x2d(%rbp)
jne 0x250e
cmpl $0xff00, -0x28(%rbp)    # imm = 0xFF00
sete %al
movb %al, -0x2d(%rbp)
movb -0x2d(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %edi
movl -0x20(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x2880
callq 0x29f0
movq -0x18(%rbp), %rdi
callq 0x69d0
movq -0x10(%rbp), %rdi
callq 0x6920
xorl %eax, %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: m8pple[P]arch2-2014-cw1/src/shared/mips_mem_ram.cpp
// Function: mips_mem_create_ram
mips_mem_h mips_mem_create_ram(
	uint32_t cbMem,	//!< Total number of bytes of ram
	uint32_t blockSize	//!< Granularity in bytes
){
	uint8_t *data=(uint8_t*)malloc(cbMem);
	if(data==0)
		return 0;
	
	struct mips_mem_provider *mem=(struct mips_mem_provider*)malloc(sizeof(struct mips_mem_provider));
	if(mem==0){
		free(data);
		return 0;
	}
	
	mem->length=cbMem;
	mem->blockSize=blockSize;
	mem->data=data;
	
	return mem;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl %edi, -0xc(%rbp)
movl %esi, -0x10(%rbp)
movl -0xc(%rbp), %eax
movl %eax, %edi
callq 0x2230
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x672d
movq $0x0, -0x8(%rbp)
jmp 0x677c
movl $0x10, %edi
callq 0x2230
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x6755
movq -0x18(%rbp), %rdi
callq 0x2200
movq $0x0, -0x8(%rbp)
jmp 0x677c
movl -0xc(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x10(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: m8pple[P]arch2-2014-cw1/src/shared/mips_mem_ram.cpp
// Function: mips_mem_read
mips_error mips_mem_read(
    mips_mem_h mem,		//!< Handle to target memory
    uint32_t address,	//!< Byte address to start transaction at
    uint32_t length,	//!< Number of bytes to transfer
    uint8_t *dataOut	//!< Receives the target bytes
)
{	
	return mips_mem_read_write(
		false,	// we want to read
		mem,
		address,
		length,
		dataOut
	);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq -0x8(%rbp), %rsi
movl -0xc(%rbp), %edx
movl -0x10(%rbp), %ecx
movq -0x18(%rbp), %r8
xorl %edi, %edi
callq 0x67d0
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: m8pple[P]arch2-2014-cw1/src/shared/mips_mem_ram.cpp
// Function: mips_mem_read_write(bool, mips_mem_provider*, unsigned int, unsigned int, unsigned char*)
static mips_error mips_mem_read_write(
	bool write,
    mips_mem_h mem,
    uint32_t address,
    uint32_t length,
    uint8_t *dataOut
)
{	
	if(mem==0)
		return mips_ErrorInvalidHandle;
	
	if(0 != (address%mem->blockSize) ){
		return mips_ExceptionInvalidAlignment;
	}
	if(0 != ((address+length)%mem->blockSize)){
		return mips_ExceptionInvalidAlignment;
	}
	if((address+length) > mem->length){	// A subtle bug here, maybe?
		return mips_ExceptionInvalidAddress;
	}
	
	if(write){
		for(unsigned i=0; i<length; i++){
			mem->data[address+i]=dataOut[i];
		}
	}else{
		for(unsigned i=0; i<length; i++){
			dataOut[i]=mem->data[address+i];
		}
	}
	return mips_Success;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movb %dil, %al
andb $0x1, %al
movb %al, -0x5(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x67fd
movl $0x1002, -0x4(%rbp)     # imm = 0x1002
jmp 0x68d2
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
xorl %edx, %edx
divl 0x4(%rcx)
xorl %eax, %eax
cmpl %edx, %eax
je 0x681b
movl $0x2002, -0x4(%rbp)     # imm = 0x2002
jmp 0x68d2
movl -0x14(%rbp), %eax
addl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
xorl %edx, %edx
divl 0x4(%rcx)
xorl %eax, %eax
cmpl %edx, %eax
je 0x683c
movl $0x2002, -0x4(%rbp)     # imm = 0x2002
jmp 0x68d2
movl -0x14(%rbp), %eax
addl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jbe 0x6853
movl $0x2001, -0x4(%rbp)     # imm = 0x2001
jmp 0x68d2
testb $0x1, -0x5(%rbp)
je 0x6892
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x18(%rbp), %eax
jae 0x6890
movq -0x20(%rbp), %rax
movl -0x24(%rbp), %ecx
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x14(%rbp), %ecx
addl -0x24(%rbp), %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x6860
jmp 0x68cb
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x18(%rbp), %eax
jae 0x68c9
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x14(%rbp), %ecx
addl -0x28(%rbp), %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %dl
movq -0x20(%rbp), %rax
movl -0x28(%rbp), %ecx
movb %dl, (%rax,%rcx)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x6899
jmp 0x68cb
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopw (%rax,%rax)
// File: m8pple[P]arch2-2014-cw1/src/shared/mips_mem_ram.cpp
// Function: mips_mem_write
mips_error mips_mem_write(
	mips_mem_h mem,	//! Handle to target memory
	uint32_t address,		//! Byte address to start transaction at
	uint32_t length,			//! Number of bytes to transfer
	const uint8_t *dataIn	//! Receives the target bytes
)
{
	return mips_mem_read_write(
		true,	// we want to write
		mem,
		address,
		length,
		(uint8_t*)dataIn
	);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq -0x8(%rbp), %rsi
movl -0xc(%rbp), %edx
movl -0x10(%rbp), %ecx
movq -0x18(%rbp), %r8
movl $0x1, %edi
callq 0x67d0
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: m8pple[P]arch2-2014-cw1/src/eie2ugs/mips_cpu.c
// Function: mips_cpu_create
mips_cpu_h mips_cpu_create(mips_mem_h mem)
{
	unsigned i;
	mips_cpu_h res=(mips_cpu_h)malloc(sizeof(struct mips_cpu_impl));

	res->mem=mem;

	res->pc=0;
	res->pcN=4;	// NOTE: why does this make sense?

	for( i=0;i<32;i++){
		res->regs[i]=0;
	}

	return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl $0x90, %edi
callq 0x2230
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x88(%rax)
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movq -0x18(%rbp), %rax
movl $0x4, 0x4(%rax)
movl $0x0, -0xc(%rbp)
cmpl $0x20, -0xc(%rbp)
jae 0x69c5
movq -0x18(%rbp), %rax
movl -0xc(%rbp), %ecx
movl $0x0, 0x8(%rax,%rcx,4)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x69a5
movq -0x18(%rbp), %rax
addq $0x20, %rsp
popq %rbp
retq
nop
// File: m8pple[P]arch2-2014-cw1/src/eie2ugs/mips_cpu.c
// Function: mips_cpu_get_register
mips_error mips_cpu_get_register(
	mips_cpu_h state,	//!< Valid (non-empty) handle to a CPU
	unsigned index,		//!< Index from 0 to 31
	uint32_t *value		//!< Where to write the value to
)
{
	if(state==0)
		return mips_ErrorInvalidHandle;
	if(index>=32)
		return mips_ErrorInvalidArgument;
	if(value==0)
		return mips_ErrorInvalidArgument;

	*value = state->regs[index];
	return mips_Success;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x6a0f
movl $0x1002, -0x4(%rbp)     # imm = 0x1002
jmp 0x6a46
cmpl $0x20, -0x14(%rbp)
jb 0x6a1e
movl $0x1001, -0x4(%rbp)     # imm = 0x1001
jmp 0x6a46
cmpq $0x0, -0x20(%rbp)
jne 0x6a2e
movl $0x1001, -0x4(%rbp)     # imm = 0x1001
jmp 0x6a46
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl 0x8(%rax,%rcx,4), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax,%rax)
// File: m8pple[P]arch2-2014-cw1/src/eie2ugs/mips_cpu.c
// Function: mips_cpu_set_register
mips_error mips_cpu_set_register(
	mips_cpu_h state,	//!< Valid (non-empty) handle to a CPU
	unsigned index,		//!< Index from 0 to 31
	uint32_t value		//!< New value to write into register file
)
{
	if(state==0)
		return mips_ErrorInvalidHandle;
	if(index>=32)
		return mips_ErrorInvalidArgument;

	// TODO : What about register zero?
	state->regs[index]=value;

	return mips_Success;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x6a6e
movl $0x1002, -0x4(%rbp)     # imm = 0x1002
jmp 0x6a92
cmpl $0x20, -0x14(%rbp)
jb 0x6a7d
movl $0x1001, -0x4(%rbp)     # imm = 0x1001
jmp 0x6a92
movl -0x18(%rbp), %edx
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %edx, 0x8(%rax,%rcx,4)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopw (%rax,%rax)
// File: m8pple[P]arch2-2014-cw1/src/eie2ugs/mips_cpu.c
// Function: mips_cpu_step
mips_error mips_cpu_step(mips_cpu_h state)
{
	uint32_t pc=state->pc;

	if(state==0)
		return mips_ErrorInvalidHandle;

	//TODO: Here is where the magic happens
	// - Fetch the instruction from memory (mips_mem_read)
	// - Decode the instruction (is it R, I, J)?
	// - Execute the instruction (do maths, access memory, ...)
	// - Writeback the results (update registers, advance pc)

	return mips_ErrorNotImplemented;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x6ac1
movl $0x1002, -0x4(%rbp)     # imm = 0x1002
jmp 0x6ac8
movl $0x1000, -0x4(%rbp)     # imm = 0x1000
movl -0x4(%rbp), %eax
popq %rbp
retq
// File: isabellab3[P]OS-Simulation/./OS.h
// Function: OperatingSystem::Snapshot() const
void Snapshot() const {
            std::cout << "Process using CPU: " << CPU << std::endl;
            std::cout << "Ready Queue:  ";
            for (auto itr = ready_queue.begin(); itr != ready_queue.end(); ++itr) {
                std::cout <<  " <- " << *itr;
            }
            std::cout << std::endl;
        }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq 0x101f5(%rip), %rdi     # 0x12fd0
leaq 0x9308(%rip), %rsi      # 0xc0ea
callq 0x21d0
movq %rax, %rdi
movq -0x20(%rbp), %rax
movl (%rax), %esi
callq 0x2320
movq %rax, %rdi
movq 0x101c1(%rip), %rsi     # 0x12fc0
callq 0x2210
movq 0x101c5(%rip), %rdi     # 0x12fd0
leaq 0x92ec(%rip), %rsi      # 0xc0fe
callq 0x21d0
movq -0x20(%rbp), %rdi
addq $0x20, %rdi
callq 0x80c0
movq %rax, -0x10(%rbp)
movq -0x20(%rbp), %rdi
addq $0x20, %rdi
callq 0x8120
movq %rax, -0x18(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x80f0
testb $0x1, %al
jne 0x2e4c
jmp 0x2e82
movq 0x1017d(%rip), %rdi     # 0x12fd0
leaq 0x92b3(%rip), %rsi      # 0xc10d
callq 0x21d0
movq %rax, -0x28(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x8150
movq -0x28(%rbp), %rdi
movl (%rax), %esi
callq 0x2320
leaq -0x10(%rbp), %rdi
callq 0x8180
jmp 0x2e28
movq 0x10147(%rip), %rdi     # 0x12fd0
movq 0x10130(%rip), %rsi     # 0x12fc0
callq 0x2210
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: isabellab3[P]OS-Simulation/./OS.h
// Function: OperatingSystem::IOSnapshot() const
void IOSnapshot() const {
            for (int i = 0; i < number_of_hard_disks; i++) {
                std::cout << "Disk " << i << ": ";
                if (hard_disks[i]->DiskIsIdle()) {
                    std::cout << "idle" << std::endl;
                }
                else {
                    std::cout << "[" << hard_disks[i]->GetCurrentProcess() << " " << hard_disks[i]->GetCurrentFile() << "]" << std::endl;
                    std::cout << "Queue for disk " << i << ": ";
                    hard_disks[i]->PrintQueue();
                }
            }
        }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0xc(%rbp)
movq -0x48(%rbp), %rcx
movl -0xc(%rbp), %eax
cmpl 0xc(%rcx), %eax
jge 0x3063
movq 0x100fb(%rip), %rdi     # 0x12fd0
leaq 0x9236(%rip), %rsi      # 0xc112
callq 0x21d0
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x2320
movq %rax, %rdi
leaq 0x9205(%rip), %rsi      # 0xc0fb
callq 0x21d0
movq -0x48(%rbp), %rdi
addq $0x38, %rdi
movslq -0xc(%rbp), %rsi
callq 0x8210
movq (%rax), %rdi
callq 0x8230
testb $0x1, %al
jne 0x2f1a
jmp 0x2f41
movq 0x100af(%rip), %rdi     # 0x12fd0
leaq 0x91f0(%rip), %rsi      # 0xc118
callq 0x21d0
movq %rax, %rdi
movq 0x10089(%rip), %rsi     # 0x12fc0
callq 0x2210
jmp 0x3053
movq 0x10088(%rip), %rdi     # 0x12fd0
leaq 0x91e3(%rip), %rsi      # 0xc132
callq 0x21d0
movq -0x48(%rbp), %rdi
movq %rax, -0x70(%rbp)
addq $0x38, %rdi
movq %rdi, -0x68(%rbp)
movslq -0xc(%rbp), %rsi
callq 0x8210
movq (%rax), %rdi
callq 0x8250
movq -0x70(%rbp), %rdi
movl %eax, %esi
callq 0x2320
movq %rax, %rdi
leaq 0x91de(%rip), %rsi      # 0xc168
callq 0x21d0
movq -0x68(%rbp), %rdi
movq %rax, -0x60(%rbp)
movslq -0xc(%rbp), %rsi
callq 0x8210
movq (%rax), %rsi
leaq -0x30(%rbp), %rdi
movq %rdi, -0x58(%rbp)
callq 0x8260
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x21c0
movq %rax, -0x50(%rbp)
jmp 0x2fc3
movq -0x50(%rbp), %rdi
leaq 0x914f(%rip), %rsi      # 0xc11d
callq 0x21d0
movq %rax, -0x78(%rbp)
jmp 0x2fd9
movq -0x78(%rbp), %rdi
movq 0xffdc(%rip), %rsi      # 0x12fc0
callq 0x2210
jmp 0x2feb
leaq -0x30(%rbp), %rdi
callq 0x2130
movq 0xffd5(%rip), %rdi      # 0x12fd0
leaq 0x911d(%rip), %rsi      # 0xc11f
callq 0x21d0
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x2320
movq %rax, %rdi
leaq 0x90df(%rip), %rsi      # 0xc0fb
callq 0x21d0
movq -0x48(%rbp), %rdi
addq $0x38, %rdi
movslq -0xc(%rbp), %rsi
callq 0x8210
movq (%rax), %rdi
callq 0x8290
jmp 0x3053
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x2130
jmp 0x306c
jmp 0x3055
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x2ebe
addq $0x80, %rsp
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x2330
nopw %cs:(%rax,%rax)
nop
// File: isabellab3[P]OS-Simulation/./OS.h
// Function: OperatingSystem::MemorySnapshot()
void MemorySnapshot() {
            std::cout << "Frame   " << "Page Number     " << "pid       " << "ts" << std::endl;
            for (unsigned int i = 0; i < frames.size(); i++) {
                std::cout << "  " <<  i << "        ";
                if (frames[i]->pid_ != 0) {
                    std::cout << "   " << frames[i]->page_ << "          " << frames[i]->pid_ << "         " << frames[i]->timestamp_;
                }
                std::cout << std::endl;
            }
        }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
movq 0xff35(%rip), %rdi      # 0x12fd0
leaq 0x9095(%rip), %rsi      # 0xc137
callq 0x21d0
movq %rax, %rdi
leaq 0x908f(%rip), %rsi      # 0xc140
callq 0x21d0
movq %rax, %rdi
leaq 0x9091(%rip), %rsi      # 0xc151
callq 0x21d0
movq %rax, %rdi
leaq 0x908d(%rip), %rsi      # 0xc15c
callq 0x21d0
movq %rax, %rdi
movq 0xfee2(%rip), %rsi      # 0x12fc0
callq 0x2210
movl $0x0, -0xc(%rbp)
movq -0x18(%rbp), %rdi
movl -0xc(%rbp), %eax
movq %rax, -0x20(%rbp)
addq $0x80, %rdi
callq 0x84d0
movq %rax, %rcx
movq -0x20(%rbp), %rax
cmpq %rcx, %rax
jae 0x3229
movq 0xfeb8(%rip), %rdi      # 0x12fd0
leaq 0x9048(%rip), %rsi      # 0xc167
callq 0x21d0
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x2290
movq %rax, %rdi
leaq 0x9028(%rip), %rsi      # 0xc161
callq 0x21d0
movq -0x18(%rbp), %rdi
addq $0x80, %rdi
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0x84f0
movq (%rax), %rax
cmpl $0x0, 0x8(%rax)
je 0x3208
movq 0xfe69(%rip), %rdi      # 0x12fd0
leaq 0x8ff8(%rip), %rsi      # 0xc166
callq 0x21d0
movq -0x18(%rbp), %rdi
movq %rax, -0x38(%rbp)
addq $0x80, %rdi
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0x84f0
movq -0x38(%rbp), %rdi
movq (%rax), %rax
movl 0x4(%rax), %esi
callq 0x2320
movq %rax, %rdi
leaq 0x8fba(%rip), %rsi      # 0xc15f
callq 0x21d0
movq -0x18(%rbp), %rdi
movq %rax, -0x30(%rbp)
addq $0x80, %rdi
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0x84f0
movq -0x30(%rbp), %rdi
movq (%rax), %rax
movl 0x8(%rax), %esi
callq 0x2320
movq %rax, %rdi
leaq 0x8f84(%rip), %rsi      # 0xc160
callq 0x21d0
movq -0x18(%rbp), %rdi
movq %rax, -0x28(%rbp)
addq $0x80, %rdi
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0x84f0
movq -0x28(%rbp), %rdi
movq (%rax), %rax
movl (%rax), %esi
callq 0x2320
movq 0xfdc1(%rip), %rdi      # 0x12fd0
movq 0xfdaa(%rip), %rsi      # 0x12fc0
callq 0x2210
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x30ea
addq $0x40, %rsp
popq %rbp
retq
nop
// File: isabellab3[P]OS-Simulation/./OS.h
// Function: OperatingSystem::CreateProcess()
void CreateProcess() {
            PCB* new_process = new PCB{ ++number_of_processes };
            all_processes[number_of_processes] = new_process;
            
            // Parent process is 1
            all_processes[1]->AddChildProcess(new_process);
            new_process->SetParent(1);

            // Adds new process to ready queue
            AddToReadyQueue(number_of_processes);
        }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x28, %edi
callq 0x21e0
movq %rax, %rdi
movq -0x30(%rbp), %rax
movq %rdi, %rcx
movq %rcx, -0x28(%rbp)
movq %rax, %rsi
addq $0x4, %rsi
movl 0x4(%rax), %ecx
incl %ecx
movl %ecx, 0x4(%rax)
callq 0x3fa0
jmp 0x3272
movq -0x30(%rbp), %rsi
movq -0x28(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq %rsi, %rdi
addq $0x50, %rdi
addq $0x4, %rsi
callq 0x4050
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rdi
movq %rcx, (%rax)
addq $0x50, %rdi
movl $0x1, -0x20(%rbp)
leaq -0x20(%rbp), %rsi
callq 0x8510
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x85f0
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x4030
movq -0x30(%rbp), %rdi
movl 0x4(%rdi), %esi
callq 0x8620
addq $0x40, %rsp
popq %rbp
retq
movq -0x28(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x28, %esi
callq 0x21f0
movq -0x18(%rbp), %rdi
callq 0x2330
nopw %cs:(%rax,%rax)
nop
// File: isabellab3[P]OS-Simulation/./OS.h
// Function: OperatingSystem::Fork()
void Fork() {
            if (CPU == 1) { // If fork called with no process in CPU
                std::cout << "There is no process in the CPU to fork" << std::endl;
            }
            else {
                PCB* new_process = new PCB(++number_of_processes);

                // Parent process is the process in the CPU that called fork
                all_processes[CPU]->AddChildProcess(new_process); 
                new_process->SetParent(CPU);

                // Add new process to ready queue
                AddToReadyQueue(number_of_processes);

                all_processes[number_of_processes] = new_process;
            }
        }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpl $0x1, (%rax)
jne 0x33a0
movq 0xfc50(%rip), %rdi      # 0x12fd0
leaq 0x8dfd(%rip), %rsi      # 0xc184
callq 0x21d0
movq %rax, %rdi
movq 0xfc2a(%rip), %rsi      # 0x12fc0
callq 0x2210
jmp 0x344e
movl $0x28, %edi
callq 0x21e0
movq %rax, %rdi
movq -0x28(%rbp), %rax
movq %rdi, %rcx
movq %rcx, -0x30(%rbp)
movq %rax, %rsi
addq $0x4, %rsi
movl 0x4(%rax), %ecx
incl %ecx
movl %ecx, 0x4(%rax)
callq 0x3fa0
jmp 0x33ce
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rax
movq %rax, -0x10(%rbp)
movq %rsi, %rdi
addq $0x50, %rdi
callq 0x4050
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x85f0
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rdi
movl (%rax), %esi
callq 0x4030
movq -0x28(%rbp), %rdi
movl 0x4(%rdi), %esi
callq 0x8620
movq -0x28(%rbp), %rsi
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq %rsi, %rdi
addq $0x50, %rdi
addq $0x4, %rsi
callq 0x4050
movq -0x38(%rbp), %rcx
movq %rcx, (%rax)
jmp 0x344e
movq -0x30(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x28, %esi
callq 0x21f0
jmp 0x3454
addq $0x40, %rsp
popq %rbp
retq
movq -0x18(%rbp), %rdi
callq 0x2330
nopl (%rax)