// File: nicklausw[P]snesasm/snesasm.cpp
// Function: file_to_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void file_to_string(string file)
{
  ifstream in(file.c_str()); // file stream
  string str; // temporary build-up string
  char in_c; // char for comparison
  unsigned int counter = 0; // basic counter

  // clear ins
  ins.clear();
  
  // read into new_str converting tabs to spaces
  while (!in.eof()) {
    in.get(in_c);
    if (in_c == '\t') {
      ins.append(" ");
    } else {
      ins.append(string(1, in_c));
    }
  }
  
  str = ins;
  
  // prevent bug with last line being screwed up
  // by erasing very last character (copied twice)
  str.pop_back();
  
  // simplify multiple spaces to one space
  ins.clear();
  
  while (counter <= str.length()) {
    // don't touch inside quotes
    if (str[counter] == '\"') {
      ins.append("\"");
      while (str[counter] != '\"') {
        counter++;
        if (counter == str.length())
          break;
      }
    } else {
      ins.append(string(1, str[counter]));
      counter++;
    }
    
    if (str[counter] == ' ') {
      ins.append(" ");
      while (str[counter] == ' ') {
        counter++;
        if (counter == str.length())
          break;
      }
    } else {
      ins.append(string(1, str[counter]));
      counter++;
    }
  }
  
  // do same to remove comments
  ins.clear();
  counter = 0;
  
  while (counter <= str.length()) {
    if (str[counter] == ';') {
      ins.append("\n");
      while (str[counter] != '\n') {
        counter++;
        if (counter == str.length())
          break;
      }
    } else {
      ins.append(string(1, str[counter]));
      counter++;
    }
  }
}

// Assembly:
subq $0x398, %rsp            # imm = 0x398
movq %rdi, 0x390(%rsp)
callq 0x20c0
movq %rax, %rsi
leaq 0x188(%rsp), %rdi
movl $0x8, %edx
callq 0x2340
leaq 0x168(%rsp), %rdi
callq 0x2270
movl $0x0, 0x160(%rsp)
leaq 0xe4e0(%rip), %rdi      # 0x16268
callq 0x2240
movq 0x188(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x188(%rsp,%rax), %rdi
callq 0x2350
movb %al, 0xb6(%rsp)
jmp 0x7daf
movb 0xb6(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x7dc1
jmp 0x7edf
leaq 0x188(%rsp), %rdi
leaq 0x167(%rsp), %rsi
callq 0x2260
jmp 0x7dd8
movsbl 0x167(%rsp), %eax
cmpl $0x9, %eax
jne 0x7e18
leaq 0xe47c(%rip), %rdi      # 0x16268
leaq 0x9767(%rip), %rsi      # 0x1155a
callq 0x2360
jmp 0x7dfa
jmp 0x7eda
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
jmp 0x8473
movsbl 0x167(%rsp), %eax
movl %eax, 0xa4(%rsp)
leaq 0x12f(%rsp), %rdi
movq %rdi, 0xa8(%rsp)
callq 0x2330
movl 0xa4(%rsp), %edx
movq 0xa8(%rsp), %rcx
leaq 0x130(%rsp), %rdi
movl $0x1, %esi
callq 0x2130
jmp 0x7e5f
leaq 0xe402(%rip), %rdi      # 0x16268
leaq 0x130(%rsp), %rsi
callq 0x2380
jmp 0x7e75
leaq 0x130(%rsp), %rdi
callq 0x23a8
leaq 0x12f(%rsp), %rdi
callq 0x21d0
jmp 0x7eda
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
jmp 0x7ec8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
leaq 0x130(%rsp), %rdi
callq 0x23a8
leaq 0x12f(%rsp), %rdi
callq 0x21d0
jmp 0x8473
jmp 0x7d8d
leaq 0xe382(%rip), %rsi      # 0x16268
leaq 0x168(%rsp), %rdi
callq 0x2030
jmp 0x7ef5
leaq 0x168(%rsp), %rdi
callq 0x2200
leaq 0xe35f(%rip), %rdi      # 0x16268
callq 0x2240
movl 0x160(%rsp), %eax
movq %rax, 0x98(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x22c0
movq %rax, %rcx
movq 0x98(%rsp), %rax
cmpq %rcx, %rax
ja 0x827b
movl 0x160(%rsp), %eax
movl %eax, %esi
leaq 0x168(%rsp), %rdi
callq 0x2390
movq %rax, 0x90(%rsp)
jmp 0x7f5e
movq 0x90(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x22, %eax
jne 0x7fff
leaq 0xe2ef(%rip), %rdi      # 0x16268
leaq 0x924d(%rip), %rsi      # 0x111cd
callq 0x2360
jmp 0x7f87
jmp 0x7f89
movl 0x160(%rsp), %eax
movl %eax, %esi
leaq 0x168(%rsp), %rdi
callq 0x2390
movq %rax, 0x88(%rsp)
jmp 0x7fa9
movq 0x88(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x22, %eax
je 0x7ffa
movl 0x160(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x160(%rsp)
movl 0x160(%rsp), %eax
movq %rax, 0x80(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x22c0
movq %rax, %rcx
movq 0x80(%rsp), %rax
cmpq %rcx, %rax
jne 0x7ff8
jmp 0x7ffa
jmp 0x7f89
jmp 0x80e3
movl 0x160(%rsp), %eax
movl %eax, %esi
leaq 0x168(%rsp), %rdi
callq 0x2390
movq %rax, 0x78(%rsp)
jmp 0x801c
movq 0x78(%rsp), %rax
movsbl (%rax), %eax
movl %eax, 0x6c(%rsp)
leaq 0x107(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0x2330
movl 0x6c(%rsp), %edx
movq 0x70(%rsp), %rcx
leaq 0x108(%rsp), %rdi
movl $0x1, %esi
callq 0x2130
jmp 0x8057
leaq 0xe20a(%rip), %rdi      # 0x16268
leaq 0x108(%rsp), %rsi
callq 0x2380
jmp 0x806d
leaq 0x108(%rsp), %rdi
callq 0x23a8
leaq 0x107(%rsp), %rdi
callq 0x21d0
movl 0x160(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x160(%rsp)
jmp 0x80e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
jmp 0x80d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
leaq 0x108(%rsp), %rdi
callq 0x23a8
leaq 0x107(%rsp), %rdi
callq 0x21d0
jmp 0x8473
movl 0x160(%rsp), %eax
movl %eax, %esi
leaq 0x168(%rsp), %rdi
callq 0x2390
movq %rax, 0x60(%rsp)
jmp 0x8100
movq 0x60(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x8192
leaq 0xe150(%rip), %rdi      # 0x16268
leaq 0x943b(%rip), %rsi      # 0x1155a
callq 0x2360
jmp 0x8126
jmp 0x8128
movl 0x160(%rsp), %eax
movl %eax, %esi
leaq 0x168(%rsp), %rdi
callq 0x2390
movq %rax, 0x58(%rsp)
jmp 0x8145
movq 0x58(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x818d
movl 0x160(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x160(%rsp)
movl 0x160(%rsp), %eax
movq %rax, 0x50(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x22c0
movq %rax, %rcx
movq 0x50(%rsp), %rax
cmpq %rcx, %rax
jne 0x818b
jmp 0x818d
jmp 0x8128
jmp 0x8276
movl 0x160(%rsp), %eax
movl %eax, %esi
leaq 0x168(%rsp), %rdi
callq 0x2390
movq %rax, 0x48(%rsp)
jmp 0x81af
movq 0x48(%rsp), %rax
movsbl (%rax), %eax
movl %eax, 0x3c(%rsp)
leaq 0xdf(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x2330
movl 0x3c(%rsp), %edx
movq 0x40(%rsp), %rcx
leaq 0xe0(%rsp), %rdi
movl $0x1, %esi
callq 0x2130
jmp 0x81ea
leaq 0xe077(%rip), %rdi      # 0x16268
leaq 0xe0(%rsp), %rsi
callq 0x2380
jmp 0x8200
leaq 0xe0(%rsp), %rdi
callq 0x23a8
leaq 0xdf(%rsp), %rdi
callq 0x21d0
movl 0x160(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x160(%rsp)
jmp 0x8276
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
jmp 0x8264
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x23a8
leaq 0xdf(%rsp), %rdi
callq 0x21d0
jmp 0x8473
jmp 0x7f0e
leaq 0xdfe6(%rip), %rdi      # 0x16268
callq 0x2240
movl $0x0, 0x160(%rsp)
movl 0x160(%rsp), %eax
movq %rax, 0x30(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x22c0
movq %rax, %rcx
movq 0x30(%rsp), %rax
cmpq %rcx, %rax
ja 0x8451
movl 0x160(%rsp), %eax
movl %eax, %esi
leaq 0x168(%rsp), %rdi
callq 0x2390
movq %rax, 0x28(%rsp)
jmp 0x82d9
movq 0x28(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x3b, %eax
jne 0x836b
leaq 0xdf77(%rip), %rdi      # 0x16268
leaq 0x8eb6(%rip), %rsi      # 0x111ae
callq 0x2360
jmp 0x82ff
jmp 0x8301
movl 0x160(%rsp), %eax
movl %eax, %esi
leaq 0x168(%rsp), %rdi
callq 0x2390
movq %rax, 0x20(%rsp)
jmp 0x831e
movq 0x20(%rsp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
je 0x8366
movl 0x160(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x160(%rsp)
movl 0x160(%rsp), %eax
movq %rax, 0x18(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x22c0
movq %rax, %rcx
movq 0x18(%rsp), %rax
cmpq %rcx, %rax
jne 0x8364
jmp 0x8366
jmp 0x8301
jmp 0x844c
movl 0x160(%rsp), %eax
movl %eax, %esi
leaq 0x168(%rsp), %rdi
callq 0x2390
movq %rax, 0x10(%rsp)
jmp 0x8388
movq 0x10(%rsp), %rax
movsbl (%rax), %eax
movl %eax, 0x4(%rsp)
leaq 0xb7(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x2330
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %rcx
leaq 0xb8(%rsp), %rdi
movl $0x1, %esi
callq 0x2130
jmp 0x83c3
leaq 0xde9e(%rip), %rdi      # 0x16268
leaq 0xb8(%rsp), %rsi
callq 0x2380
jmp 0x83d9
leaq 0xb8(%rsp), %rdi
callq 0x23a8
leaq 0xb7(%rsp), %rdi
callq 0x21d0
movl 0x160(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x160(%rsp)
jmp 0x844c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
jmp 0x843d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x23a8
leaq 0xb7(%rsp), %rdi
callq 0x21d0
jmp 0x8473
jmp 0x8292
leaq 0x168(%rsp), %rdi
callq 0x23a8
leaq 0x188(%rsp), %rdi
callq 0x2060
addq $0x398, %rsp            # imm = 0x398
retq
leaq 0x168(%rsp), %rdi
callq 0x23a8
leaq 0x188(%rsp), %rdi
callq 0x2060
movq 0x158(%rsp), %rdi
callq 0x2320
nopw (%rax,%rax)