// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movl 0x8(%rsi), %eax
xorl %ebp, %ebp
cmpq $0x6, %rax
ja 0x5a450
leaq 0x2c6f0(%rip), %rcx     # 0x869c4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x38(%rbx), %rdi
leaq 0x2c7ac(%rip), %rsi     # 0x86a94
callq 0x4ee50
cmpl $0x0, 0x60(%rbx)
jne 0x5a689
movl %eax, %r15d
movq %rbx, 0x98(%r14)
xorl %ebp, %ebp
jmp 0x5a453
leaq 0x38(%rbx), %rdi
leaq 0x2c815(%rip), %rsi     # 0x86b28
callq 0x4ee50
movl %eax, %r15d
cmpq $0x0, 0xb0(%r14)
setne %bpl
movq %rbx, 0xb0(%r14)
jmp 0x5a453
leaq 0x38(%rbx), %rdi
leaq 0x2c7f4(%rip), %rsi     # 0x86b32
callq 0x520f0
testb %al, %al
je 0x5a3e1
cmpq $0x0, 0xc0(%r14)
setne %bpl
movq %rbx, 0xc0(%r14)
jmp 0x5a3e3
leaq 0x38(%rbx), %rdi
leaq 0x2c486(%rip), %rsi     # 0x867f4
callq 0x4ee50
movl %eax, %r15d
cmpq $0x0, 0xc8(%r14)
setne %bpl
movq %rbx, 0xc8(%r14)
jmp 0x5a453
leaq 0x38(%rbx), %rdi
leaq 0x2c795(%rip), %rsi     # 0x86b2e
callq 0x4ee50
movl %eax, %r15d
cmpq $0x0, 0xa8(%r14)
setne %bpl
movq %rbx, 0xa8(%r14)
jmp 0x5a453
leaq 0x38(%rbx), %rdi
leaq 0x2c88f(%rip), %rsi     # 0x86c53
callq 0x4ee50
movl %eax, %r15d
cmpq $0x0, 0xb8(%r14)
setne %bpl
movq %rbx, 0xb8(%r14)
jmp 0x5a453
xorl %ebp, %ebp
movl 0x24(%rbx), %eax
testb $0x20, %al
jne 0x5a444
btl $0x9, %eax
jae 0x5a450
cmpl $0x1, 0x60(%rbx)
je 0x5a450
pushq $0x20
popq %rdi
callq 0x4e180
movq %rax, %r14
leaq 0x2c730(%rip), %rsi     # 0x86b38
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x515e0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x4ddf0
xorl %ebp, %ebp
movq 0x54a70(%rip), %rsi     # 0xaeea0
movq 0x54801(%rip), %rdx     # 0xaec38
movq %r14, %rdi
callq 0x51630
jmp 0x5a6d2
movq %rbx, %rdi
callq 0x4d9e0
orb $0x40, 0x24(%rax)
xorl %r15d, %r15d
leaq 0x8(%r14), %r12
movq 0x8(%r14), %rax
movq 0x10(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movslq 0x60(%rbx), %rcx
cmpq %rcx, %rdx
movq %r12, 0x50(%rsp)
ja 0x5a492
incl %ecx
movslq %ecx, %rsi
leaq 0x8(%rsp), %rdx
andq $0x0, (%rdx)
movq %r12, %rdi
callq 0x4d6e0
movslq 0x60(%rbx), %rcx
movq (%r12), %rax
movq (%rax,%rcx,8), %r12
movl %r15d, %eax
orb %bpl, %al
testb $0x1, %al
jne 0x5a4d9
testq %r12, %r12
jne 0x5a4d9
leaq 0x38(%r14), %r13
leaq 0x38(%rbx), %rsi
leaq 0x8(%rsp), %rbp
movq %rbp, %rdi
callq 0x50630
movq %rbx, 0x20(%rbp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x505e0
movl %edx, %ebp
xorb $0x1, %bpl
leaq 0x8(%rsp), %rdi
callq 0x4e020
movl %r15d, %eax
orb %bpl, %al
testb $0x1, %al
jne 0x5a4e8
testq %r12, %r12
je 0x5a4f9
cmpl $0x0, 0x20(%rbx)
jne 0x5a4f7
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
xorl %ebx, %ebx
testb %r15b, %r15b
jne 0x5a53a
testb $0x1, %bpl
jne 0x5a5a0
testq %r12, %r12
jne 0x5a606
movslq 0x60(%rbx), %rax
movq 0x8(%r14), %rcx
movq %rbx, (%rcx,%rax,8)
incl 0x20(%rbx)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4f0b0
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x20
popq %rdi
callq 0x4e180
movq %rax, %r14
addq $0x38, %rbx
leaq 0x2c60d(%rip), %rsi     # 0x86b5d
leaq 0x30(%rsp), %rdi
movq %rbx, %rdx
callq 0x4f1c0
leaq 0x2c600(%rip), %rdx     # 0x86b64
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x4d6c0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x4ddf0
xorl %ebp, %ebp
movq 0x54914(%rip), %rsi     # 0xaeea0
movq 0x546a5(%rip), %rdx     # 0xaec38
movq %r14, %rdi
callq 0x51630
jmp 0x5a6d2
pushq $0x20
popq %rdi
callq 0x4e180
movq %rax, %r14
addq $0x38, %rbx
leaq 0x2c5a7(%rip), %rsi     # 0x86b5d
leaq 0x30(%rsp), %rdi
movq %rbx, %rdx
callq 0x4f1c0
leaq 0x2c5bb(%rip), %rdx     # 0x86b85
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x4d6c0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x4ddf0
xorl %ebp, %ebp
movq 0x548ae(%rip), %rsi     # 0xaeea0
movq 0x5463f(%rip), %rdx     # 0xaec38
movq %r14, %rdi
callq 0x51630
jmp 0x5a6d2
pushq $0x20
popq %rdi
callq 0x4e180
movq %rax, %r14
leaq 0x38(%rbx), %rdx
leaq 0x2c541(%rip), %rsi     # 0x86b5d
leaq 0x58(%rsp), %rdi
callq 0x4f1c0
leaq 0x2c578(%rip), %rdx     # 0x86ba5
leaq 0x30(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x4d6c0
movslq 0x60(%rbx), %rax
movq 0x50(%rsp), %rcx
movq (%rcx), %rcx
movq (%rcx,%rax,8), %rdx
addq $0x38, %rdx
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x50bf0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x4ddf0
xorl %ebp, %ebp
movq 0x54828(%rip), %rsi     # 0xaeea0
movq 0x545b9(%rip), %rdx     # 0xaec38
movq %r14, %rdi
callq 0x51630
jmp 0x5a6d2
pushq $0x20
popq %rdi
callq 0x4e180
movq %rax, %r14
leaq 0x2c468(%rip), %rsi     # 0x86b03
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x515e0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x4ddf0
xorl %ebp, %ebp
movq 0x547dd(%rip), %rsi     # 0xaeea0
movq 0x5456e(%rip), %rdx     # 0xaec38
movq %r14, %rdi
callq 0x51630
jmp 0x5a6d6
jmp 0x5a73e
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
jmp 0x5a72e
jmp 0x5a73e
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x4e020
jmp 0x5a6f7
movq %rax, %rbx
movb $0x1, %bpl
leaq 0x30(%rsp), %rdi
callq 0x4e020
jmp 0x5a709
movq %rax, %rbx
movb $0x1, %bpl
leaq 0x58(%rsp), %rdi
jmp 0x5a72e
jmp 0x5a714
jmp 0x5a723
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x4e020
jmp 0x5a729
movq %rax, %rbx
movb $0x1, %bpl
leaq 0x30(%rsp), %rdi
callq 0x4e020
testb %bpl, %bpl
jne 0x5a741
jmp 0x5a749
jmp 0x5a73e
jmp 0x5a73e
movq %rax, %rbx
movq %r14, %rdi
callq 0x4ea60
movq %rbx, %rdi
callq 0x518c0
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x4e020
jmp 0x5a749