// File: /workspace/github_c_makefile_star2_O1/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
subq $0x18, %rsp
movq %rdi, 0x8(%rsp)
leal (,%rdi,8), %eax
movl $0xfffffff0, %ecx       # imm = 0xFFFFFFF0
subl %eax, %ecx
movslq %ecx, %rax
movq %rax, 0x10(%rsp)
leaq 0x40f7f(%rip), %r13     # 0x459d8
leaq 0x40f90(%rip), %rbp     # 0x459f0
leaq 0x40f79(%rip), %rbx     # 0x459e0
leaq 0x40f52(%rip), %rax     # 0x459c0
incl (%rax)
movb 0x40faa(%rip), %al      # 0x45a20
movl %eax, %ecx
xorb $0x1, %cl
testb %al, %al
movq %r13, %rax
leaq 0x40f61(%rip), %rsi     # 0x459e8
cmovneq %rsi, %rax
movq (%rax), %rax
movq %rax, 0x40f7b(%rip)     # 0x45a10
movq %rbx, %rdx
cmovneq %rbp, %rdx
movq (%rdx), %r15
movb %cl, 0x40f7b(%rip)      # 0x45a20
movq %rsi, %rcx
cmovneq %r13, %rcx
movq (%rcx), %rcx
movq %rbp, %rdx
cmovneq %rbx, %rdx
movq %rcx, 0x40f6b(%rip)     # 0x45a28
movq (%rdx), %rdx
movq %r15, %rsi
shlq $0x4, %rsi
addq %rax, %rsi
movq %rsi, 0x40f5f(%rip)     # 0x45a30
movq %rsi, 0x40f40(%rip)     # 0x45a18
shlq $0x4, %rdx
addq %rcx, %rdx
movq %rdx, 0x40f52(%rip)     # 0x45a38
cmpl $0x0, 0x40ee3(%rip)     # 0x459d0
je 0x4b16
leaq 0x40f4a(%rip), %r14     # 0x45a40
xorl %r12d, %r12d
movq (%r14), %rdi
callq 0x4bcb
movq %rax, (%r14)
incq %r12
movl 0x40ec3(%rip), %eax     # 0x459d0
addq $0x8, %r14
cmpq %rax, %r12
jb 0x4af9
cmpl $0x0, 0x410b3(%rip)     # 0x45bd0
je 0x4b4c
leaq 0x410ba(%rip), %r14     # 0x45be0
xorl %r12d, %r12d
movq (%r14), %rax
movq (%rax), %rdi
callq 0x4bcb
movq (%r14), %rcx
movq %rax, (%rcx)
incq %r12
movl 0x4108d(%rip), %eax     # 0x45bd0
addq $0x8, %r14
cmpq %rax, %r12
jb 0x4b29
callq 0x24dc
movq 0x40ec0(%rip), %rax     # 0x45a18
addq 0x10(%rsp), %rax
movq %rax, 0x40eb4(%rip)     # 0x45a18
movq 0x40ea5(%rip), %rcx     # 0x45a10
cmpq %rcx, %rax
jae 0x4b7f
movl $0x2, %edi
callq 0x4992
jmp 0x4a67
andq $-0x2, %r15
leaq (%rcx,%r15,8), %rcx
movl $0x2, %edi
cmpq %rcx, %rax
jb 0x4ba6
movq 0x40e48(%rip), %rax     # 0x459e0
movl $0x1, %edi
cmpq 0x40e4c(%rip), %rax     # 0x459f0
je 0x4bab
callq 0x4992
movq 0x8(%rsp), %rcx
shll $0x2, %ecx
movq 0x40e5e(%rip), %rax     # 0x45a18
movl %ecx, (%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq