// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq %rsp, %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x21d0
movq (%r14), %rsi
movsbl (%rsi), %eax
addl $-0x30, %eax
cmpl $0xa, %eax
jb 0x6732
movq %rsp, %rdi
callq 0x21b0
movq (%rbx), %rax
movsbl (%rax), %edi
callq 0x2240
testl %eax, %eax
je 0x678a
xorl %ecx, %ecx
pushq $0x28
popq %r14
movl %ecx, %r15d
movq 0x5b37(%rip), %rax      # 0xc288
movq 0x5b28(%rip), %rdi      # 0xc280
subq %rdi, %rax
cqto
idivq %r14
cmpq %r15, %rax
jbe 0x678a
imulq $0x28, %r15, %r12
addq %r12, %rdi
movq %rbx, %rsi
callq 0x6a58
leal 0x1(%r15), %ecx
testb %al, %al
je 0x6747
movq 0x5afd(%rip), %rax      # 0xc280
movq 0x20(%rax,%r12), %rbx
jmp 0x67e7
movq (%rsp), %rdi
movq 0x8(%rsp), %rax
xorl %ecx, %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jbe 0x67bc
movsbl (%rdi,%rcx), %edx
leal -0x30(%rdx), %esi
cmpl $0xa, %esi
jb 0x67b8
movq (%rbx), %rsi
cmpb $0x24, (%rsi)
jne 0x67fe
addb $-0x61, %dl
cmpb $0x6, %dl
jae 0x6813
incl %ecx
jmp 0x6795
leaq 0x20(%rsp), %rsi
movq %rdi, (%rsi)
movq (%rbx), %rax
movb (%rax), %al
cmpb $0x24, %al
pushq $0x10
popq %rcx
pushq $0xa
popq %r8
cmovel %ecx, %r8d
cmpb $0x25, %al
pushq $0x2
popq %rdx
cmovnel %r8d, %edx
callq 0x21f0
movq %rax, %rbx
movq %rsp, %rdi
callq 0x22c8
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0x57eb(%rip), %rdi      # 0xbff0
leaq 0x1f4e(%rip), %rsi      # 0x875a
callq 0x2140
jmp 0x6826
movq 0x57d6(%rip), %rdi      # 0xbff0
leaq 0x1f39(%rip), %rsi      # 0x875a
callq 0x2140
pushq $0x1
popq %rdi
callq 0x2180
jmp 0x6830
movq %rax, %rbx
movq %rsp, %rdi
callq 0x22c8
movq %rbx, %rdi
callq 0x2270