// File: /workspace/github_c_makefile_star2_O1/GregorR[P]lstg/ImageBuilder/imageBuilder.c
// Function: imageOut
void imageOut(FILE * fp, struct object *obj)
{
  int             i,
                  size;

  if(imageTop > imageMaxNumberOfObjects)
  {
    fprintf(stderr, "too many indirect objects\n");
    exit(1);
  }

  /*
     printf("writing out object %d\n", obj);
   */

  if(obj == 0)
  {
    sysError("writing out null object", "");
    return;
  }

  /*
     Integer objects are simply encoded as the binary value 
   */
  if(IS_SMALLINT(obj))
  {
    int             val = HTONL(integerValue(obj));

    writeWord(2, fp);
    fwrite(&val, sizeof(val), 1, fp);
    return;
  }

  /*
     see if already written 
   */
  for(i = 0; i < imageTop; i++)
  {
    if(obj == writtenObjects[i])
    {
      if(i == 0)
        writeWord(5, fp);
      else
      {
        writeWord(4, fp);
        writeWord(i, fp);
      }
      return;
    }
  }

  /*
     not written, do it now 
   */
  writtenObjects[imageTop++] = obj;

  if(obj->size & FLAG_BIN)
  {                             /* byte objects */
    struct byteObject *bobj = (struct byteObject *) obj;

    size = SIZE(obj);
    writeWord(3, fp);
    writeWord(size, fp);
    /* fprintf(fp, "3 %d \n", size); */
    for(i = 0; i < size; i++)
    {
      /* fprintf(fp," %d ", bobj->bytes[i]); */
      writeWord(bobj->bytes[i], fp);
      /* fprintf(fp,"\n"); */
    }
    if(obj->class == 0)
    {
      printf("byte object 0x%p has null class\n", obj);
    }
    imageOut(fp, obj->class);
    return;
  }

  /*
     ordinary objects 
   */
  size = SIZE(obj);
  /*
     fprintf(fp,"1 %d ", size);
   */
  writeWord(1, fp);
  writeWord(size, fp);
  if(obj->class == 0)
  {
    printf("object 0x%p has null class\n", obj);
  }
  imageOut(fp, obj->class);
  for(i = 0; i < size; i++)
  {
    imageOut(fp, obj->data[i]);
  }
  /*
     fprintf(fp,"\n");
   */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x37c2b(%rip), %r13     # 0x3b570
leaq 0x1b55(%rip), %r15      # 0x54a1
movslq 0x37c0d(%rip), %rax     # 0x3b560
cmpq $0x2711, %rax           # imm = 0x2711
jge 0x3ae5
testq %r14, %r14
je 0x3aea
testb $0x1, %r14b
jne 0x3a4b
testl %eax, %eax
jle 0x3991
movq %r13, %rcx
xorl %r12d, %r12d
cmpq %r14, (%rcx)
je 0x3a05
incq %r12
addq $0x8, %rcx
cmpq %r12, %rax
jne 0x397c
leal 0x1(%rax), %ecx
movl %ecx, 0x37bc6(%rip)     # 0x3b560
movq %r14, (%r13,%rax,8)
movl (%r14), %ebp
movl %ebp, %r12d
shrl $0x2, %r12d
testb $0x2, %bpl
je 0x3a7a
movl $0x3, %edi
movq %rbx, %rsi
callq 0x10c0
movl %r12d, %edi
movq %rbx, %rsi
callq 0x38ce
cmpl $0x4, %ebp
jb 0x39e8
xorl %ebp, %ebp
movzbl 0x10(%r14,%rbp), %edi
movq %rbx, %rsi
callq 0x38ce
incq %rbp
cmpq %rbp, %r12
jne 0x39d2
cmpq $0x0, 0x8(%r14)
jne 0x39fc
movq %r15, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x10a0
movq 0x8(%r14), %r14
jmp 0x394c
testq %r12, %r12
je 0x3a30
movl $0x4, %edi
movq %rbx, %rsi
callq 0x10c0
movl %r12d, %edi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x38ce
movl $0x5, %edi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10c0
shrq %r14
leaq 0x4(%rsp), %r15
movl %r14d, (%r15)
movl $0x2, %edi
movq %rbx, %rsi
callq 0x10c0
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %rbx, %rcx
callq 0x1150
jmp 0x3ad6
movl $0x1, %edi
movq %rbx, %rsi
callq 0x10c0
movl %r12d, %edi
movq %rbx, %rsi
callq 0x38ce
cmpq $0x0, 0x8(%r14)
jne 0x3aaa
leaq 0x1a06(%rip), %rdi      # 0x54a6
movq %r14, %rsi
xorl %eax, %eax
callq 0x10a0
movq 0x8(%r14), %rsi
movq %rbx, %rdi
callq 0x392d
cmpl $0x4, %ebp
jb 0x3ad6
movl %r12d, %r15d
xorl %r12d, %r12d
movq 0x10(%r14,%r12,8), %rsi
movq %rbx, %rdi
callq 0x392d
incq %r12
cmpq %r12, %r15
jne 0x3ac1
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1180
leaq 0x154f(%rip), %rdi      # 0x5040
leaq 0x1991(%rip), %rsi      # 0x5489
leaq 0x1a73(%rip), %rdx      # 0x5572
xorl %eax, %eax
callq 0x10a0
movl $0x1, %edi
callq 0x1140