// File: /workspace/github_cpp_makefile_star2_O1/nicklausw[P]snesasm/snesasm.cpp
// Function: parse_num(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
long parse_num(string num)
{
  unsigned int label_search;
  string without_sym = num; // declare without symbol
  
  // make 'without symbol' true
  if (!isdigit(without_sym[0])) {
    without_sym.erase(without_sym.begin());
  }
  
  if (isalpha(num[0])) {
    for (label_search = 0; label_search < labels.size(); label_search++) { // look for a label!
      if (labels[label_search].name == num) {
        return labels[label_search].val; // it's a match!
      }
    }
  }
  
  // check for invalid symbols
  for (unsigned int checkn = 0; checkn < without_sym.length(); checkn++) {
    if (isdigit(without_sym[checkn])) continue;
    
    // not a digit...
    if (num[0] != '$') {
      cerr << "error: invalid symbol in number\n";
      exit(fail);
    } else {
      switch (without_sym[checkn]) {
        case 'a': continue;
        case 'b': continue;
        case 'c': continue;
        case 'd': continue;
        case 'e': continue;
        case 'f': continue;
        default:
          // invalid symbol
          cerr << "error: invalid symbol in number\n";
          exit(fail);
      }
    }
  }
  
  
  char *chararray = const_cast<char*>(without_sym.c_str()); // turn without_sym into char array
  
  switch (num[0]) {
    case '%':
      // binary
      return strtol(chararray, &chararray, 2);
    case '$':
      // hex
      return strtol(chararray, &chararray, 16);
  }
  
  return strtol(chararray, &chararray, 10);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r14
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
movq (%rdi), %rsi
movq 0x8(%rdi), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x7be0
movq (%rbx), %rax
movsbl (%rax), %eax
addl $-0x30, %eax
cmpl $0xa, %eax
jb 0x773b
leaq 0x8(%rsp), %rdi
movl $0x1, %edx
xorl %esi, %esi
callq 0x21a0
movq (%r14), %rax
movq %rax, 0x28(%rsp)
movb (%rax), %bpl
movsbl %bpl, %edi
callq 0x2230
testl %eax, %eax
je 0x77bf
movq 0x4b1e(%rip), %rax      # 0xc278
movq 0x4b0f(%rip), %r12      # 0xc270
subq %r12, %rax
je 0x77bf
sarq $0x3, %rax
movabsq $-0x3333333333333333, %r13 # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %r13
movq 0x8(%r14), %r14
movl $0x1, %r15d
xorl %eax, %eax
leaq (%rax,%rax,4), %rax
movq 0x8(%r12,%rax,8), %rdx
cmpq %r14, %rdx
jne 0x77b4
leaq (%r12,%rax,8), %rbx
testq %rdx, %rdx
je 0x7856
movq (%rbx), %rdi
movq 0x28(%rsp), %rsi
callq 0x2170
testl %eax, %eax
je 0x7856
movl %r15d, %eax
incl %r15d
cmpq %rax, %r13
ja 0x7784
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x77fe
movl $0x1, %ecx
movq 0x8(%rsp), %rdx
xorl %esi, %esi
movsbl (%rdx,%rsi), %esi
leal -0x30(%rsi), %edi
cmpl $0xa, %edi
jb 0x77f5
cmpb $0x24, %bpl
jne 0x7871
addb $-0x61, %sil
cmpb $0x6, %sil
jae 0x785c
movl %ecx, %esi
incl %ecx
cmpq %rsi, %rax
ja 0x77d5
movq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movq %rdi, (%rsi)
cmpb $0x24, %bpl
movl $0x10, %eax
movl $0xa, %ecx
cmovel %eax, %ecx
cmpb $0x25, %bpl
movl $0x2, %edx
cmovnel %ecx, %edx
callq 0x21f0
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x7844
callq 0x2140
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%rbx), %rbx
jmp 0x7830
movq 0x478d(%rip), %rdi      # 0xbff0
leaq 0x1ee0(%rip), %rsi      # 0x974a
callq 0x2150
jmp 0x7884
movq 0x4778(%rip), %rdi      # 0xbff0
leaq 0x1ecb(%rip), %rsi      # 0x974a
callq 0x2150
movl $0x1, %edi
callq 0x21b0
jmp 0x7890
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x78a7
callq 0x2140
movq %rbx, %rdi
callq 0x2250