// File: /workspace/github_cpp_makefile_star2_O3/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 0x7ace
movq (%rbx), %rax
movsbl (%rax), %eax
addl $-0x30, %eax
cmpl $0xa, %eax
jb 0x7622
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 0x76a6
movq 0x4c37(%rip), %rax      # 0xc278
movq 0x4c28(%rip), %r12      # 0xc270
subq %r12, %rax
je 0x76a6
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
cmpq %r14, 0x8(%r12,%rax,8)
jne 0x769b
leaq (%r12,%rax,8), %rbx
testq %r14, %r14
je 0x7732
movq (%rbx), %rdi
movq 0x28(%rsp), %rsi
movq %r14, %rdx
callq 0x2170
testl %eax, %eax
je 0x7732
movl %r15d, %eax
incl %r15d
cmpq %rax, %r13
ja 0x766b
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x76df
movl $0x1, %ecx
xorl %edx, %edx
movsbl (%rdi,%rdx), %edx
leal -0x30(%rdx), %esi
cmpl $0xa, %esi
jb 0x76d6
cmpb $0x24, %bpl
jne 0x774d
addb $-0x61, %dl
cmpb $0x6, %dl
jae 0x7738
movl %ecx, %edx
incl %ecx
cmpq %rdx, %rax
ja 0x76bc
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 0x7720
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 0x770c
movq 0x48b1(%rip), %rdi      # 0xbff0
leaq 0x2004(%rip), %rsi      # 0x974a
callq 0x2150
jmp 0x7760
movq 0x489c(%rip), %rdi      # 0xbff0
leaq 0x1fef(%rip), %rsi      # 0x974a
callq 0x2150
movl $0x1, %edi
callq 0x21b0
jmp 0x776c
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x7783
callq 0x2140
movq %rbx, %rdi
callq 0x2250