// File: /workspace/github_c_makefile_star2_O2/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 %rdi, %rbx
leaq 0x37236(%rip), %r13     # 0x3a570
pushq $0x3
popq %rbp
movslq 0x3721c(%rip), %rax     # 0x3a560
cmpq $0x2711, %rax           # imm = 0x2711
jge 0x34c1
movq %rsi, %r14
testq %rsi, %rsi
je 0x34e5
testb $0x1, %r14b
jne 0x3432
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
movq %r13, %rdx
xorl %r12d, %r12d
cmpq %r12, %rcx
je 0x338d
cmpq %r14, (%rdx)
je 0x3404
incq %r12
addq $0x8, %rdx
jmp 0x3376
leal 0x1(%rax), %ecx
movl %ecx, 0x371ca(%rip)     # 0x3a560
movq %r14, (%r13,%rax,8)
movl (%r14), %eax
movl %eax, %r12d
shrl $0x2, %r12d
testb $0x2, %al
je 0x3468
movl %ebp, %edi
movq %rbx, %rsi
callq 0x32d9
movl %r12d, %edi
movq %rbx, %rsi
callq 0x32d9
xorl %r15d, %r15d
cmpq %r15, %r12
je 0x33dd
movzbl 0x10(%r14,%r15), %edi
movq %rbx, %rsi
callq 0x32d9
incq %r15
jmp 0x33c5
movq 0x8(%r14), %rsi
testq %rsi, %rsi
jne 0x333d
leaq 0x1074(%rip), %rdi      # 0x4465
movq %r14, %rsi
xorl %eax, %eax
callq 0x10a0
movq 0x8(%r14), %rsi
jmp 0x333d
testq %r12, %r12
je 0x3419
pushq $0x4
popq %rdi
movq %rbx, %rsi
callq 0x32d9
movl %r12d, %edi
jmp 0x341c
pushq $0x5
popq %rdi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x32d9
shrq %r14
leaq 0x4(%rsp), %r15
movl %r14d, (%r15)
pushq $0x2
popq %rdi
movq %rbx, %rsi
callq 0x32d9
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rdi
movq %rbx, %rcx
callq 0x1150
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rdi
movq %rbx, %rsi
callq 0x32d9
movl %r12d, %edi
movq %rbx, %rsi
callq 0x32d9
movq 0x8(%r14), %rsi
testq %rsi, %rsi
jne 0x349c
leaq 0xfdc(%rip), %rdi       # 0x446a
movq %r14, %rsi
xorl %eax, %eax
callq 0x10a0
movq 0x8(%r14), %rsi
movq %rbx, %rdi
callq 0x3325
movl %r12d, %r15d
xorl %r12d, %r12d
cmpq %r12, %r15
je 0x3459
movq 0x10(%r14,%r12,8), %rsi
movq %rbx, %rdi
callq 0x3325
incq %r12
jmp 0x34aa
movq 0x3b30(%rip), %rax      # 0x6ff8
movq (%rax), %rcx
leaq 0xf60(%rip), %rdi       # 0x4432
pushq $0x1a
popq %rsi
pushq $0x1
popq %rdx
callq 0x1150
pushq $0x1
popq %rdi
callq 0x1140
leaq 0xf61(%rip), %rdi       # 0x444d
leaq 0x1043(%rip), %rsi      # 0x4536
callq 0x126c