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

{
  bool nameTypeMismatch = false;
  bool duplicateName = false;
  bool duplicateId = false;
  switch(spc->getType()) {
  case IPTR_CONSTANT:
    if (spc->getName() != "const")
      nameTypeMismatch = true;
    if (spc->index != AddrSpace::constant_space_index)
      throw LowlevelError("const space must be assigned index 0");
    constantspace = spc;
    break;
  case IPTR_INTERNAL:
    if (spc->getName() != "unique")
      nameTypeMismatch = true;
    if (uniqspace != (AddrSpace *)0)
      duplicateName = true;
    uniqspace = spc;
    break;
  case IPTR_FSPEC:
    if (spc->getName() != "fspec")
      nameTypeMismatch = true;
    if (fspecspace != (AddrSpace *)0)
      duplicateName = true;
    fspecspace = spc;
    break;
  case IPTR_JOIN:
    if (spc->getName() != "join")
      nameTypeMismatch = true;
    if (joinspace != (AddrSpace *)0)
      duplicateName = true;
    joinspace = spc;
    break;
  case IPTR_IOP:
    if (spc->getName() != "iop")
      nameTypeMismatch = true;
    if (iopspace != (AddrSpace *)0)
      duplicateName = true;
    iopspace = spc;
    break;
  case IPTR_SPACEBASE:
    if (spc->getName() == "stack") {
      if (stackspace != (AddrSpace *)0)
	duplicateName = true;
      stackspace = spc;
    }
    // fallthru
  case IPTR_PROCESSOR:
    if (spc->isOverlay()) {	// If this is a new overlay space
      OverlaySpace *ospc = (OverlaySpace *)spc;
      ospc->getBaseSpace()->setFlags(AddrSpace::overlaybase); // Mark the base as being overlayed
    }
    else if (spc->isOtherSpace()) {
      if (spc->index != AddrSpace::other_space_index)
        throw LowlevelError("OTHER space must be assigned index 1");
    }
    break;
  }

  if (baselist.size() <= spc->index)
    baselist.resize(spc->index+1, (AddrSpace *)0);

  duplicateId = baselist[spc->index] != (AddrSpace *)0;

  if (!nameTypeMismatch && !duplicateName && !duplicateId) {
    duplicateName = !name2Space.insert(pair<string,AddrSpace *>(spc->getName(),spc)).second;
  }

  if (nameTypeMismatch || duplicateName || duplicateId) {
    if (spc->refcount == 0)
      delete spc;
    spc = (AddrSpace *)0;
  }
  if (nameTypeMismatch)
    throw LowlevelError("Space "+spc->getName()+" was initialized with wrong type");
  if (duplicateName)
    throw LowlevelError("Space "+spc->getName()+" was initialized more than once");
  if (duplicateId)
    throw LowlevelError("Space "+spc->getName()+" was assigned as id duplicating: "+baselist[spc->index]->getName());
  baselist[spc->index] = spc;
  spc->refcount += 1;
  assignShortcut(spc);
}

// Assembly:
subq $0x268, %rsp            # imm = 0x268
movq %rdi, 0x260(%rsp)
movq %rsi, 0x258(%rsp)
movq 0x260(%rsp), %rax
movq %rax, 0x90(%rsp)
movb $0x0, 0x257(%rsp)
movb $0x0, 0x256(%rsp)
movb $0x0, 0x255(%rsp)
movq 0x258(%rsp), %rdi
callq 0xcfb80
movl %eax, %ecx
movq %rcx, 0x98(%rsp)
subl $0x6, %eax
ja 0xfc09e
movq 0x98(%rsp), %rax
leaq 0x8bdb2(%rip), %rcx     # 0x1879e0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x258(%rsp), %rdi
callq 0xd06f0
movq %rax, %rdi
leaq 0x8be62(%rip), %rsi     # 0x187ab0
callq 0xd6530
testb $0x1, %al
jne 0xfbc59
jmp 0xfbc61
movb $0x1, 0x257(%rsp)
movq 0x258(%rsp), %rax
cmpl $0x0, 0x60(%rax)
je 0xfbd61
movb $0x1, 0x21b(%rsp)
movl $0x20, %edi
callq 0xd2b40
movq %rax, 0x80(%rsp)
leaq 0x22f(%rsp), %rdi
movq %rdi, 0x88(%rsp)
callq 0xe0c80
movq 0x88(%rsp), %rdx
leaq 0x8be6e(%rip), %rsi     # 0x187b1f
leaq 0x230(%rsp), %rdi
callq 0xe00a0
jmp 0xfbcc0
movq 0x80(%rsp), %rdi
leaq 0x230(%rsp), %rsi
callq 0xd1ae0
jmp 0xfbcd7
movq 0x80(%rsp), %rdi
movb $0x0, 0x21b(%rsp)
movq 0xcc1a2(%rip), %rsi     # 0x1c7e90
movq 0xcbedb(%rip), %rdx     # 0x1c7bd0
callq 0xe01f0
jmp 0xfc6ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x220(%rsp)
movl %eax, 0x21c(%rsp)
jmp 0xfbd36
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x220(%rsp)
movl %eax, 0x21c(%rsp)
leaq 0x230(%rsp), %rdi
callq 0xd4550
leaq 0x22f(%rsp), %rdi
callq 0xd8ec0
testb $0x1, 0x21b(%rsp)
jne 0xfbd4f
jmp 0xfbd5c
movq 0x80(%rsp), %rdi
callq 0xd5400
jmp 0xfc69f
movq 0x90(%rsp), %rax
movq 0x258(%rsp), %rcx
movq %rcx, 0x98(%rax)
jmp 0xfc09e
movq 0x258(%rsp), %rdi
callq 0xd06f0
movq %rax, %rdi
leaq 0x8bae0(%rip), %rsi     # 0x187874
callq 0xd6530
testb $0x1, %al
jne 0xfbd9f
jmp 0xfbda7
movb $0x1, 0x257(%rsp)
movq 0x90(%rsp), %rax
cmpq $0x0, 0xc8(%rax)
je 0xfbdc1
movb $0x1, 0x256(%rsp)
movq 0x90(%rsp), %rax
movq 0x258(%rsp), %rcx
movq %rcx, 0xc8(%rax)
jmp 0xfc09e
movq 0x258(%rsp), %rdi
callq 0xd06f0
movq %rax, %rdi
leaq 0x8bd50(%rip), %rsi     # 0x187b44
callq 0xd6530
testb $0x1, %al
jne 0xfbdff
jmp 0xfbe07
movb $0x1, 0x257(%rsp)
movq 0x90(%rsp), %rax
cmpq $0x0, 0xb0(%rax)
je 0xfbe21
movb $0x1, 0x256(%rsp)
movq 0x90(%rsp), %rax
movq 0x258(%rsp), %rcx
movq %rcx, 0xb0(%rax)
jmp 0xfc09e
movq 0x258(%rsp), %rdi
callq 0xd06f0
movq %rax, %rdi
leaq 0x8be1b(%rip), %rsi     # 0x187c6f
callq 0xd6530
testb $0x1, %al
jne 0xfbe5f
jmp 0xfbe67
movb $0x1, 0x257(%rsp)
movq 0x90(%rsp), %rax
cmpq $0x0, 0xb8(%rax)
je 0xfbe81
movb $0x1, 0x256(%rsp)
movq 0x90(%rsp), %rax
movq 0x258(%rsp), %rcx
movq %rcx, 0xb8(%rax)
jmp 0xfc09e
movq 0x258(%rsp), %rdi
callq 0xd06f0
movq %rax, %rdi
leaq 0x8bc96(%rip), %rsi     # 0x187b4a
callq 0xd6530
testb $0x1, %al
jne 0xfbebf
jmp 0xfbec7
movb $0x1, 0x257(%rsp)
movq 0x90(%rsp), %rax
cmpq $0x0, 0xa8(%rax)
je 0xfbee1
movb $0x1, 0x256(%rsp)
movq 0x90(%rsp), %rax
movq 0x258(%rsp), %rcx
movq %rcx, 0xa8(%rax)
jmp 0xfc09e
movq 0x258(%rsp), %rdi
callq 0xd06f0
movq %rax, %rdi
leaq 0x8bc3a(%rip), %rsi     # 0x187b4e
callq 0xe30f0
testb $0x1, %al
jne 0xfbf1f
jmp 0xfbf50
movq 0x90(%rsp), %rax
cmpq $0x0, 0xc0(%rax)
je 0xfbf39
movb $0x1, 0x256(%rsp)
movq 0x90(%rsp), %rax
movq 0x258(%rsp), %rcx
movq %rcx, 0xc0(%rax)
jmp 0xfbf52
movq 0x258(%rsp), %rdi
callq 0xd52e0
testb $0x1, %al
jne 0xfbf65
jmp 0xfbf94
movq 0x258(%rsp), %rax
movq %rax, 0x210(%rsp)
movq 0x210(%rsp), %rdi
callq 0xd09a0
movq %rax, %rdi
movl $0x40, %esi
callq 0xd7ff0
jmp 0xfc09c
movq 0x258(%rsp), %rdi
callq 0xde780
testb $0x1, %al
jne 0xfbfaa
jmp 0xfc09a
movq 0x258(%rsp), %rax
cmpl $0x1, 0x60(%rax)
je 0xfc098
movb $0x1, 0x1ee(%rsp)
movl $0x20, %edi
callq 0xd2b40
movq %rax, 0x70(%rsp)
leaq 0x1ef(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0xe0c80
movq 0x78(%rsp), %rdx
leaq 0x8bb63(%rip), %rsi     # 0x187b54
leaq 0x1f0(%rsp), %rdi
callq 0xe00a0
jmp 0xfc000
movq 0x70(%rsp), %rdi
leaq 0x1f0(%rsp), %rsi
callq 0xd1ae0
jmp 0xfc014
movq 0x70(%rsp), %rdi
movb $0x0, 0x1ee(%rsp)
movq 0xcbe68(%rip), %rsi     # 0x1c7e90
movq 0xcbba1(%rip), %rdx     # 0x1c7bd0
callq 0xe01f0
jmp 0xfc6ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x220(%rsp)
movl %eax, 0x21c(%rsp)
jmp 0xfc070
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x220(%rsp)
movl %eax, 0x21c(%rsp)
leaq 0x1f0(%rsp), %rdi
callq 0xd4550
leaq 0x1ef(%rsp), %rdi
callq 0xd8ec0
testb $0x1, 0x1ee(%rsp)
jne 0xfc089
jmp 0xfc093
movq 0x70(%rsp), %rdi
callq 0xd5400
jmp 0xfc69f
jmp 0xfc09a
jmp 0xfc09c
jmp 0xfc09e
movq 0x90(%rsp), %rdi
addq $0x8, %rdi
callq 0xd1e70
movq 0x258(%rsp), %rcx
movslq 0x60(%rcx), %rcx
cmpq %rcx, %rax
ja 0xfc0f6
movq 0x90(%rsp), %rdi
addq $0x8, %rdi
movq 0x258(%rsp), %rax
movl 0x60(%rax), %eax
addl $0x1, %eax
movslq %eax, %rsi
movq $0x0, 0x1e0(%rsp)
leaq 0x1e0(%rsp), %rdx
callq 0xcfdc0
movq 0x90(%rsp), %rdi
addq $0x8, %rdi
movq 0x258(%rsp), %rax
movslq 0x60(%rax), %rsi
callq 0xd1c20
cmpq $0x0, (%rax)
setne %al
andb $0x1, %al
movb %al, 0x255(%rsp)
testb $0x1, 0x257(%rsp)
jne 0xfc21f
testb $0x1, 0x256(%rsp)
jne 0xfc21f
testb $0x1, 0x255(%rsp)
jne 0xfc21f
movq 0x90(%rsp), %rax
addq $0x38, %rax
movq %rax, 0x50(%rsp)
movq 0x258(%rsp), %rdi
callq 0xd06f0
movq %rax, %rsi
leaq 0x1a8(%rsp), %rdi
movq %rdi, 0x58(%rsp)
leaq 0x258(%rsp), %rdx
callq 0xd5230
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0xd4b30
movb %dl, 0x67(%rsp)
movq %rax, 0x68(%rsp)
jmp 0xfc1a2
movb 0x67(%rsp), %al
movq 0x68(%rsp), %rcx
movq %rcx, 0x198(%rsp)
movb %al, 0x1a0(%rsp)
movq 0x198(%rsp), %rax
movq %rax, 0x1d0(%rsp)
movb 0x1a0(%rsp), %al
movb %al, 0x1d8(%rsp)
movb 0x1d8(%rsp), %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, 0x256(%rsp)
leaq 0x1a8(%rsp), %rdi
callq 0xd0cf0
jmp 0xfc21f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x220(%rsp)
movl %eax, 0x21c(%rsp)
leaq 0x1a8(%rsp), %rdi
callq 0xd0cf0
jmp 0xfc69f
testb $0x1, 0x257(%rsp)
jne 0xfc23d
testb $0x1, 0x256(%rsp)
jne 0xfc23d
testb $0x1, 0x255(%rsp)
je 0xfc277
movq 0x258(%rsp), %rax
cmpl $0x0, 0x20(%rax)
jne 0xfc26b
movq 0x258(%rsp), %rax
movq %rax, 0x48(%rsp)
cmpq $0x0, %rax
je 0xfc269
movq 0x48(%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0xfc26b
movq $0x0, 0x258(%rsp)
testb $0x1, 0x257(%rsp)
je 0xfc397
movb $0x1, 0x157(%rsp)
movl $0x20, %edi
callq 0xd2b40
movq %rax, 0x38(%rsp)
movq 0x258(%rsp), %rdi
callq 0xd06f0
movq %rax, 0x40(%rsp)
jmp 0xfc2b0
movq 0x40(%rsp), %rdx
leaq 0x8b8bd(%rip), %rsi     # 0x187b79
leaq 0x158(%rsp), %rdi
callq 0xd7370
jmp 0xfc2cb
leaq 0x8b8ae(%rip), %rdx     # 0x187b80
leaq 0x178(%rsp), %rdi
leaq 0x158(%rsp), %rsi
callq 0xcfd20
jmp 0xfc2e9
movq 0x38(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0xd1ae0
jmp 0xfc2fd
movq 0x38(%rsp), %rdi
movb $0x0, 0x157(%rsp)
movq 0xcbb7f(%rip), %rsi     # 0x1c7e90
movq 0xcb8b8(%rip), %rdx     # 0x1c7bd0
callq 0xe01f0
jmp 0xfc6ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x220(%rsp)
movl %eax, 0x21c(%rsp)
jmp 0xfc37c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x220(%rsp)
movl %eax, 0x21c(%rsp)
jmp 0xfc36f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x220(%rsp)
movl %eax, 0x21c(%rsp)
leaq 0x178(%rsp), %rdi
callq 0xd4550
leaq 0x158(%rsp), %rdi
callq 0xd4550
testb $0x1, 0x157(%rsp)
jne 0xfc388
jmp 0xfc392
movq 0x38(%rsp), %rdi
callq 0xd5400
jmp 0xfc69f
testb $0x1, 0x256(%rsp)
je 0xfc4b7
movb $0x1, 0x10f(%rsp)
movl $0x20, %edi
callq 0xd2b40
movq %rax, 0x28(%rsp)
movq 0x258(%rsp), %rdi
callq 0xd06f0
movq %rax, 0x30(%rsp)
jmp 0xfc3d0
movq 0x30(%rsp), %rdx
leaq 0x8b79d(%rip), %rsi     # 0x187b79
leaq 0x110(%rsp), %rdi
callq 0xd7370
jmp 0xfc3eb
leaq 0x8b7af(%rip), %rdx     # 0x187ba1
leaq 0x130(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0xcfd20
jmp 0xfc409
movq 0x28(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0xd1ae0
jmp 0xfc41d
movq 0x28(%rsp), %rdi
movb $0x0, 0x10f(%rsp)
movq 0xcba5f(%rip), %rsi     # 0x1c7e90
movq 0xcb798(%rip), %rdx     # 0x1c7bd0
callq 0xe01f0
jmp 0xfc6ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x220(%rsp)
movl %eax, 0x21c(%rsp)
jmp 0xfc49c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x220(%rsp)
movl %eax, 0x21c(%rsp)
jmp 0xfc48f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x220(%rsp)
movl %eax, 0x21c(%rsp)
leaq 0x130(%rsp), %rdi
callq 0xd4550
leaq 0x110(%rsp), %rdi
callq 0xd4550
testb $0x1, 0x10f(%rsp)
jne 0xfc4a8
jmp 0xfc4b2
movq 0x28(%rsp), %rdi
callq 0xd5400
jmp 0xfc69f
testb $0x1, 0x255(%rsp)
je 0xfc63f
movb $0x1, 0xa7(%rsp)
movl $0x20, %edi
callq 0xd2b40
movq %rax, 0x18(%rsp)
movq 0x258(%rsp), %rdi
callq 0xd06f0
movq %rax, 0x20(%rsp)
jmp 0xfc4f0
movq 0x20(%rsp), %rdx
leaq 0x8b67d(%rip), %rsi     # 0x187b79
leaq 0xa8(%rsp), %rdi
callq 0xd7370
jmp 0xfc50b
leaq 0x8b6af(%rip), %rdx     # 0x187bc1
leaq 0xc8(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0xcfd20
jmp 0xfc529
movq 0x90(%rsp), %rdi
addq $0x8, %rdi
movq 0x258(%rsp), %rax
movslq 0x60(%rax), %rsi
callq 0xd1c20
movq (%rax), %rdi
callq 0xd06f0
movq %rax, 0x10(%rsp)
jmp 0xfc555
movq 0x10(%rsp), %rdx
leaq 0xe8(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0xddae0
jmp 0xfc571
movq 0x18(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0xd1ae0
jmp 0xfc585
movq 0x18(%rsp), %rdi
movb $0x0, 0xa7(%rsp)
movq 0xcb8f7(%rip), %rsi     # 0x1c7e90
movq 0xcb630(%rip), %rdx     # 0x1c7bd0
callq 0xe01f0
jmp 0xfc6ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x220(%rsp)
movl %eax, 0x21c(%rsp)
jmp 0xfc627
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x220(%rsp)
movl %eax, 0x21c(%rsp)
jmp 0xfc61a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x220(%rsp)
movl %eax, 0x21c(%rsp)
jmp 0xfc60d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x220(%rsp)
movl %eax, 0x21c(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0xd4550
leaq 0xc8(%rsp), %rdi
callq 0xd4550
leaq 0xa8(%rsp), %rdi
callq 0xd4550
testb $0x1, 0xa7(%rsp)
jne 0xfc633
jmp 0xfc63d
movq 0x18(%rsp), %rdi
callq 0xd5400
jmp 0xfc69f
movq 0x90(%rsp), %rdi
movq 0x258(%rsp), %rax
movq %rax, 0x8(%rsp)
addq $0x8, %rdi
movq 0x258(%rsp), %rax
movslq 0x60(%rax), %rsi
callq 0xd1c20
movq 0x8(%rsp), %rcx
movq 0x90(%rsp), %rdi
movq %rcx, (%rax)
movq 0x258(%rsp), %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
movq 0x258(%rsp), %rsi
callq 0xd6da0
addq $0x268, %rsp            # imm = 0x268
retq
movq 0x220(%rsp), %rdi
callq 0xe0be0
nopl (%rax)