// File: nicklausw[P]snesasm/snesasm.cpp
// Function: directive_arg(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int)
void directive_arg(string str, int range)
{
  unsigned int label_search;
  int label_count = 0;
  
  pass_counter++;
  
  if (tokens[pass_counter].token_type == tkOP) { // if it's not number
    for (label_search = 0; label_search < labels.size(); label_search++) { // look for a label!
      if (labels[label_search].name == tokens[pass_counter].token_i) {
        tr = labels[label_search].val; // it's a match!
        label_count++; // no need for unsolved.
        break;
      }
    }
    
    if (!label_count) { // if no match was found
      // time for an unsolved!
      new_unsolved(tokens[pass_counter].token_i, org, range-1);
      return;
    }
  } else if (tokens[pass_counter].token_type == tkNUM) {
    tr = parse_num(tokens[pass_counter].token_i);
  } else {
    cerr << "error: " << str << " expects args\n";
    exit(fail);
  }
   
 
  if (range == r8) {
    if (tr > 0xFF) {
      cerr << "error: " << str << " requires 8-bit args\n";
      exit(fail);
    }
  } else if (range == r16) {
    if (tr > 0xFFFF) {
      cerr << "error: " << str << " requires 16-bit args\n";
      exit(fail);
    }
  }
}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x28(%rsp)
movq %rdi, 0x90(%rsp)
movl %esi, 0x8c(%rsp)
movl $0x0, 0x84(%rsp)
movq 0xa093(%rip), %rax      # 0x16330
addq $0x1, %rax
movq %rax, 0xa088(%rip)      # 0x16330
movq 0xa081(%rip), %rsi      # 0x16330
leaq 0x9f92(%rip), %rdi      # 0x16248
callq 0xd300
movl (%rax), %eax
cmpl 0x9f25(%rip), %eax      # 0x161e8
jne 0xc40c
movl $0x0, 0x88(%rsp)
movl 0x88(%rsp), %eax
movq %rax, 0x20(%rsp)
leaq 0xa009(%rip), %rdi      # 0x162f0
callq 0xd510
movq %rax, %rcx
movq 0x20(%rsp), %rax
cmpq %rcx, %rax
jae 0xc38c
movl 0x88(%rsp), %eax
movl %eax, %esi
leaq 0x9fe3(%rip), %rdi      # 0x162f0
callq 0xd530
movq %rax, 0x18(%rsp)
movq 0xa012(%rip), %rsi      # 0x16330
leaq 0x9f23(%rip), %rdi      # 0x16248
callq 0xd300
movq 0x18(%rsp), %rdi
movq %rax, %rsi
addq $0x8, %rsi
callq 0xd430
testb $0x1, %al
jne 0xc341
jmp 0xc374
movl 0x88(%rsp), %eax
movl %eax, %esi
leaq 0x9f9f(%rip), %rdi      # 0x162f0
callq 0xd530
movq 0x20(%rax), %rax
movq %rax, 0x9f6f(%rip)      # 0x162d0
movl 0x84(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x84(%rsp)
jmp 0xc38c
jmp 0xc376
movl 0x88(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x88(%rsp)
jmp 0xc2d4
cmpl $0x0, 0x84(%rsp)
jne 0xc407
movq 0x9f93(%rip), %rsi      # 0x16330
leaq 0x9ea4(%rip), %rdi      # 0x16248
callq 0xd300
movq %rax, %rsi
addq $0x8, %rsi
leaq 0x60(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x20d0
movq 0x10(%rsp), %rdi
movq 0x9e4d(%rip), %rsi      # 0x16218
movl 0x8c(%rsp), %edx
decl %edx
callq 0xcda0
jmp 0xc3db
leaq 0x60(%rsp), %rdi
callq 0x23a8
jmp 0xc581
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x23a8
jmp 0xc589
jmp 0xc4d1
movq 0x9f1d(%rip), %rsi      # 0x16330
leaq 0x9e2e(%rip), %rdi      # 0x16248
callq 0xd300
movl (%rax), %eax
cmpl 0x9db9(%rip), %eax      # 0x161e0
jne 0xc496
movq 0x9f00(%rip), %rsi      # 0x16330
leaq 0x9e11(%rip), %rdi      # 0x16248
callq 0xd300
movq %rax, %rsi
addq $0x8, %rsi
leaq 0x30(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x20d0
movq (%rsp), %rdi
callq 0xc960
movq %rax, 0x8(%rsp)
jmp 0xc461
movq 0x8(%rsp), %rax
movq %rax, 0x9e63(%rip)      # 0x162d0
leaq 0x30(%rsp), %rdi
callq 0x23a8
jmp 0xc4cf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x23a8
jmp 0xc589
movq 0x9b53(%rip), %rdi      # 0x15ff0
leaq 0x503a(%rip), %rsi      # 0x114de
callq 0x21b0
movq 0x28(%rsp), %rsi
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
leaq 0x4f3e(%rip), %rsi      # 0x113fe
callq 0x21b0
movl $0x1, %edi
callq 0x21f0
jmp 0xc4d1
movl 0x8c(%rsp), %eax
cmpl 0x9d22(%rip), %eax      # 0x16200
jne 0xc528
cmpq $0xff, 0x9de5(%rip) # 0x162d0
jle 0xc526
movq 0x9afc(%rip), %rdi      # 0x15ff0
leaq 0x4fe3(%rip), %rsi      # 0x114de
callq 0x21b0
movq 0x28(%rsp), %rsi
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
leaq 0x505a(%rip), %rsi      # 0x11571
callq 0x21b0
movl $0x1, %edi
callq 0x21f0
jmp 0xc581
movl 0x8c(%rsp), %eax
cmpl 0x9ccf(%rip), %eax      # 0x16204
jne 0xc57f
cmpq $0xffff, 0x9d8e(%rip) # imm = 0xFFFF
jle 0xc57d
movq 0x9aa5(%rip), %rdi      # 0x15ff0
leaq 0x4f8c(%rip), %rsi      # 0x114de
callq 0x21b0
movq 0x28(%rsp), %rsi
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
leaq 0x5022(%rip), %rsi      # 0x11590
callq 0x21b0
movl $0x1, %edi
callq 0x21f0
jmp 0xc57f
jmp 0xc581
addq $0x98, %rsp
retq
movq 0x58(%rsp), %rdi
callq 0x2320
nopw %cs:(%rax,%rax)