// File: /workspace/github_c_makefile_star2_O3/GregorR[P]lstg/source/memory.c
// Function: gcollect
struct object  *gcollect(int sz)
{
  LstUInt       i;
  size_t        spaceSize, oldSize;

gcretry:
  gccount++;

  /*
     first change spaces 
   */
  if(inSpaceOne)
  {
    memoryBase = spaceTwo;
    spaceSize = spaceTwoSize;
    inSpaceOne = 0;
    oldBase = spaceOne;
    oldSize = spaceOneSize;
  }
  else
  {
    memoryBase = spaceOne;
    spaceSize = spaceOneSize;
    inSpaceOne = 1;
    oldBase = spaceTwo;
    oldSize = spaceTwoSize;
  }
  memoryPointer = memoryTop = memoryBase + spaceSize;
  oldTop = oldBase + oldSize;

  /*
     then do the collection 
   */
  for(i = 0; i < rootTop; i++)
  {
    rootStack[i] = gc_move((struct mobject *) rootStack[i]);
  }
  for(i = 0; i < staticRootTop; i++)
  {
    (*staticRoots[i]) = gc_move((struct mobject *) *staticRoots[i]);
  }

  flushCache();

  /*
     then see if there is room for allocation 
   */
  memoryPointer = WORDSDOWN(memoryPointer, sz + 2);
  if(memoryPointer < memoryBase)
  {
    /* need more space */
    gcexpand(2);
    goto gcretry;
  }
  else if (memoryPointer < memoryBase + (spaceSize >> 1))
  {
    /* we're not *out* of space, but to make GC's less frequent, we'll
     * pre-expand the other space */
    gcexpand(2);
  }
  else if (spaceOneSize != spaceTwoSize)
  {
    /* even them out */
    gcexpand(1);
  }
  SETSIZE(memoryPointer, sz);
  return (memoryPointer);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, (%rsp)
leal (,%rdi,8), %eax
movl $0xfffffff0, %ecx       # imm = 0xFFFFFFF0
subl %eax, %ecx
movslq %ecx, %r14
leaq 0x40eee(%rip), %rbp     # 0x459d8
leaq 0x40ef7(%rip), %rbx     # 0x459e8
leaq 0x40ec8(%rip), %rax     # 0x459c0
incl (%rax)
movb 0x40f20(%rip), %al      # 0x45a20
movq %rbx, %rsi
movq %rbp, %rcx
leaq 0x40ee3(%rip), %rdi     # 0x459f0
leaq 0x40ecc(%rip), %rdx     # 0x459e0
testb %al, %al
jne 0x4b2c
movq %rbp, %rsi
movq %rbx, %rcx
leaq 0x40ebb(%rip), %rdi     # 0x459e0
leaq 0x40ec4(%rip), %rdx     # 0x459f0
movq (%rsi), %rsi
movq %rsi, 0x40eda(%rip)     # 0x45a10
movq (%rdi), %r15
xorb $0x1, %al
movb %al, 0x40edf(%rip)      # 0x45a20
movq (%rcx), %rax
movq %rax, 0x40edd(%rip)     # 0x45a28
movq (%rdx), %rcx
movq %r15, %rdx
shlq $0x4, %rdx
addq %rsi, %rdx
movq %rdx, 0x40ed1(%rip)     # 0x45a30
movq %rdx, 0x40eb2(%rip)     # 0x45a18
shlq $0x4, %rcx
addq %rax, %rcx
movq %rcx, 0x40ec4(%rip)     # 0x45a38
cmpl $0x0, 0x40e55(%rip)     # 0x459d0
je 0x4ba6
leaq 0x40ebc(%rip), %r12     # 0x45a40
xorl %r13d, %r13d
movq (%r12), %rdi
callq 0x4c5a
movq %rax, (%r12)
incq %r13
movl 0x40e33(%rip), %eax     # 0x459d0
addq $0x8, %r12
cmpq %rax, %r13
jb 0x4b87
cmpl $0x0, 0x41023(%rip)     # 0x45bd0
je 0x4bde
leaq 0x4102a(%rip), %r12     # 0x45be0
xorl %r13d, %r13d
movq (%r12), %rax
movq (%rax), %rdi
callq 0x4c5a
movq (%r12), %rcx
movq %rax, (%rcx)
incq %r13
movl 0x40ffb(%rip), %eax     # 0x45bd0
addq $0x8, %r12
cmpq %rax, %r13
jb 0x4bb9
callq 0x24dc
movq 0x40e2e(%rip), %rax     # 0x45a18
addq %r14, %rax
movq %rax, 0x40e24(%rip)     # 0x45a18
movq 0x40e15(%rip), %rcx     # 0x45a10
cmpq %rcx, %rax
jae 0x4c0f
movl $0x2, %edi
callq 0x4a28
jmp 0x4af1
andq $-0x2, %r15
leaq (%rcx,%r15,8), %rcx
movl $0x2, %edi
cmpq %rcx, %rax
jb 0x4c36
movq 0x40db8(%rip), %rax     # 0x459e0
movl $0x1, %edi
cmpq 0x40dbc(%rip), %rax     # 0x459f0
je 0x4c3b
callq 0x4a28
movq (%rsp), %rcx
shll $0x2, %ecx
movq 0x40dcf(%rip), %rax     # 0x45a18
movl %ecx, (%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq