// File: /workspace/github_c_makefile_star2_O2/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
pushq $-0x10
popq %rcx
subl %eax, %ecx
movslq %ecx, %r14
leaq 0x413c9(%rip), %r15     # 0x459e8
pushq $0x2
popq %rbp
leaq 0x41397(%rip), %rax     # 0x459c0
incl (%rax)
movb 0x413ef(%rip), %al      # 0x45a20
movq %r15, %rsi
leaq 0x4139d(%rip), %rcx     # 0x459d8
leaq 0x413ae(%rip), %rdi     # 0x459f0
leaq 0x41397(%rip), %rdx     # 0x459e0
testb %al, %al
jne 0x4665
leaq 0x41384(%rip), %rsi     # 0x459d8
movq %r15, %rcx
leaq 0x41382(%rip), %rdi     # 0x459e0
leaq 0x4138b(%rip), %rdx     # 0x459f0
movq (%rsi), %rsi
movq %rsi, 0x413a1(%rip)     # 0x45a10
movq (%rdi), %r12
xorb $0x1, %al
movb %al, 0x413a6(%rip)      # 0x45a20
movq (%rcx), %rax
movq %rax, 0x413a4(%rip)     # 0x45a28
movq (%rdx), %rcx
movq %r12, %rdx
shlq $0x4, %rdx
addq %rsi, %rdx
movq %rdx, 0x41398(%rip)     # 0x45a30
movq %rdx, 0x41379(%rip)     # 0x45a18
shlq $0x4, %rcx
addq %rax, %rcx
movq %rcx, 0x4138b(%rip)     # 0x45a38
leaq 0x4138c(%rip), %rbx     # 0x45a40
xorl %r13d, %r13d
movl 0x41313(%rip), %eax     # 0x459d0
cmpq %rax, %r13
jae 0x46d6
movq (%rbx), %rdi
callq 0x477a
movq %rax, (%rbx)
incq %r13
addq $0x8, %rbx
jmp 0x46b7
leaq 0x41503(%rip), %r13     # 0x45be0
xorl %ebx, %ebx
movl 0x414eb(%rip), %eax     # 0x45bd0
cmpq %rax, %rbx
jae 0x4706
movq (%r13), %rax
movq (%rax), %rdi
callq 0x477a
movq (%r13), %rcx
movq %rax, (%rcx)
incq %rbx
addq $0x8, %r13
jmp 0x46df
callq 0x248c
movq 0x41306(%rip), %rax     # 0x45a18
addq %r14, %rax
movq %rax, 0x412fc(%rip)     # 0x45a18
movq 0x412ed(%rip), %rcx     # 0x45a10
cmpq %rcx, %rax
jae 0x4734
movl %ebp, %edi
callq 0x455f
jmp 0x4622
andq $-0x2, %r12
leaq (%rcx,%r12,8), %rcx
cmpq %rcx, %rax
jb 0x4754
movq 0x41298(%rip), %rax     # 0x459e0
cmpq 0x412a1(%rip), %rax     # 0x459f0
je 0x475b
pushq $0x1
popq %rbp
movl %ebp, %edi
callq 0x455f
movq (%rsp), %rcx
shll $0x2, %ecx
movq 0x412af(%rip), %rax     # 0x45a18
movl %ecx, (%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq