// File: jstaursky[P]hutch/src/Sleigh/translate.cc
// Function: AddrSpaceManager::assignShortcut(AddrSpace*)
void AddrSpaceManager::assignShortcut(AddrSpace *spc)

{
  if (spc->shortcut != ' ') {	// If the shortcut is already assigned
    shortcut2Space.insert(pair<int4,AddrSpace *>(spc->shortcut,spc));
    return;
  }
  char shortcut;
  switch(spc->getType()) {
  case IPTR_CONSTANT:
    shortcut = '#';
    break;
  case IPTR_PROCESSOR:
    if (spc->getName() == "register")
      shortcut = '%';
    else
      shortcut = spc->getName()[0];
    break;
  case IPTR_SPACEBASE:
    shortcut = 's';
    break;
  case IPTR_INTERNAL:
    shortcut = 'u';
    break;
  case IPTR_FSPEC:
    shortcut = 'f';
    break;
  case IPTR_JOIN:
    shortcut = 'j';
    break;
  case IPTR_IOP:
    shortcut = 'i';
    break;
  default:
    shortcut = 'x';
    break;
  }

  if (shortcut >= 'A' && shortcut <= 'Z')
    shortcut += 0x20;

  int4 collisionCount = 0;
  while(!shortcut2Space.insert(pair<int4,AddrSpace *>(shortcut,spc)).second) {
    collisionCount += 1;
    if (collisionCount >26) {
      // Could not find a unique shortcut, but we just re-use 'z' as we
      // can always use the long form to specify the address if there are really so many
      // spaces that need to be distinguishable (in the console mode)
      spc->shortcut = 'z';
      return;
    }
    shortcut += 1;
    if (shortcut < 'a' || shortcut > 'z')
      shortcut = 'a';
  }
  spc->shortcut = (char)shortcut;
}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x90(%rsp)
movq %rsi, 0x88(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x88(%rsp), %rax
movsbl 0x30(%rax), %eax
cmpl $0x20, %eax
je 0xfc96e
movq 0x28(%rsp), %rax
addq $0x68, %rax
movq %rax, 0x20(%rsp)
movq 0x88(%rsp), %rsi
addq $0x30, %rsi
leaq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0xd9410
movq 0x20(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0xdee00
movq %rax, 0x68(%rsp)
movb %dl, 0x70(%rsp)
jmp 0xfcafa
movq 0x88(%rsp), %rdi
callq 0xcfb80
movl %eax, %ecx
movq %rcx, 0x18(%rsp)
subl $0x6, %eax
ja 0xfca14
movq 0x18(%rsp), %rax
leaq 0x8b065(%rip), %rcx     # 0x1879fc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $0x23, 0x67(%rsp)
jmp 0xfca19
movq 0x88(%rsp), %rdi
callq 0xd06f0
movq %rax, %rdi
leaq 0x8a6f9(%rip), %rsi     # 0x1870b7
callq 0xe30f0
testb $0x1, %al
jne 0xfc9c9
jmp 0xfc9d0
movb $0x25, 0x67(%rsp)
jmp 0xfc9ef
movq 0x88(%rsp), %rdi
callq 0xd06f0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xd9290
movb (%rax), %al
movb %al, 0x67(%rsp)
jmp 0xfca19
movb $0x73, 0x67(%rsp)
jmp 0xfca19
movb $0x75, 0x67(%rsp)
jmp 0xfca19
movb $0x66, 0x67(%rsp)
jmp 0xfca19
movb $0x6a, 0x67(%rsp)
jmp 0xfca19
movb $0x69, 0x67(%rsp)
jmp 0xfca19
movb $0x78, 0x67(%rsp)
movsbl 0x67(%rsp), %eax
cmpl $0x41, %eax
jl 0xfca39
movsbl 0x67(%rsp), %eax
cmpl $0x5a, %eax
jg 0xfca39
movsbl 0x67(%rsp), %eax
addl $0x20, %eax
movb %al, 0x67(%rsp)
movl $0x0, 0x60(%rsp)
movq 0x28(%rsp), %rax
addq $0x68, %rax
movq %rax, 0x8(%rsp)
leaq 0x40(%rsp), %rdi
movq %rdi, 0x10(%rsp)
leaq 0x67(%rsp), %rsi
leaq 0x88(%rsp), %rdx
callq 0xd9410
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0xdee00
movb %dl, 0x38(%rsp)
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x50(%rsp)
movb 0x38(%rsp), %al
movb %al, 0x58(%rsp)
movb 0x58(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xfcaa1
jmp 0xfcaeb
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
cmpl $0x1a, 0x60(%rsp)
jle 0xfcac1
movq 0x88(%rsp), %rax
movb $0x7a, 0x30(%rax)
jmp 0xfcafa
movsbl 0x67(%rsp), %eax
addl $0x1, %eax
movb %al, 0x67(%rsp)
movsbl 0x67(%rsp), %eax
cmpl $0x61, %eax
jl 0xfcae1
movsbl 0x67(%rsp), %eax
cmpl $0x7a, %eax
jle 0xfcae6
movb $0x61, 0x67(%rsp)
jmp 0xfca41
movb 0x67(%rsp), %cl
movq 0x88(%rsp), %rax
movb %cl, 0x30(%rax)
addq $0x98, %rsp
retq
nopw %cs:(%rax,%rax)