// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movl %edi, -0x4(%rbp)
leaq 0x4295e(%rip), %rax     # 0x489c0
movl (%rax), %ecx
addl $0x1, %ecx
leaq 0x42952(%rip), %rax     # 0x489c0
movl %ecx, (%rax)
cmpl $0x0, 0x429a9(%rip)     # 0x48a20
je 0x60b7
movq 0x42968(%rip), %rax     # 0x489e8
movq %rax, 0x42989(%rip)     # 0x48a10
movq 0x42962(%rip), %rax     # 0x489f0
movq %rax, -0x10(%rbp)
movl $0x0, 0x42984(%rip)     # 0x48a20
movq 0x42935(%rip), %rax     # 0x489d8
movq %rax, 0x4297e(%rip)     # 0x48a28
movq 0x4292f(%rip), %rax     # 0x489e0
movq %rax, -0x18(%rbp)
jmp 0x60f3
movq 0x4291a(%rip), %rax     # 0x489d8
movq %rax, 0x4294b(%rip)     # 0x48a10
movq 0x42914(%rip), %rax     # 0x489e0
movq %rax, -0x10(%rbp)
movl $0x1, 0x42946(%rip)     # 0x48a20
movq 0x42907(%rip), %rax     # 0x489e8
movq %rax, 0x42940(%rip)     # 0x48a28
movq 0x42901(%rip), %rax     # 0x489f0
movq %rax, -0x18(%rbp)
movq 0x42916(%rip), %rax     # 0x48a10
movq -0x10(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, 0x42924(%rip)     # 0x48a30
movq %rax, 0x42905(%rip)     # 0x48a18
movq 0x4290e(%rip), %rax     # 0x48a28
movq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, 0x4290c(%rip)     # 0x48a38
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
cmpl 0x42894(%rip), %eax     # 0x489d0
jae 0x6171
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x428f6(%rip), %rax     # 0x48a40
movq (%rax,%rcx,8), %rdi
callq 0x6270
movq %rax, %rdx
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x428de(%rip), %rax     # 0x48a40
movq %rdx, (%rax,%rcx,8)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x6133
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
cmpl 0x42a4f(%rip), %eax     # 0x48bd0
jae 0x61bc
movl -0x8(%rbp), %eax
movl %eax, %ecx
leaq 0x42a51(%rip), %rax     # 0x48be0
movq (%rax,%rcx,8), %rax
movq (%rax), %rdi
callq 0x6270
movq %rax, %rcx
movl -0x8(%rbp), %eax
movl %eax, %edx
leaq 0x42a36(%rip), %rax     # 0x48be0
movq (%rax,%rdx,8), %rax
movq %rcx, (%rax)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x6178
callq 0x24a0
movq 0x42850(%rip), %rax     # 0x48a18
movl -0x4(%rbp), %edx
addl $0x2, %edx
xorl %ecx, %ecx
subl %edx, %ecx
shll $0x3, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x42836(%rip)     # 0x48a18
movq 0x4282f(%rip), %rax     # 0x48a18
cmpq 0x42820(%rip), %rax     # 0x48a10
jae 0x6201
movl $0x2, %edi
callq 0x5f70
jmp 0x605b
movq 0x42810(%rip), %rax     # 0x48a18
movq 0x42801(%rip), %rcx     # 0x48a10
movq -0x10(%rbp), %rdx
shrq %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0x622e
movl $0x2, %edi
callq 0x5f70
jmp 0x624a
movq 0x427ab(%rip), %rax     # 0x489e0
cmpq 0x427b4(%rip), %rax     # 0x489f0
je 0x6248
movl $0x1, %edi
callq 0x5f70
jmp 0x624a
jmp 0x624c
movl -0x4(%rbp), %ecx
shll $0x2, %ecx
movq 0x427bf(%rip), %rax     # 0x48a18
movl %ecx, (%rax)
movq 0x427b6(%rip), %rax     # 0x48a18
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)