// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
cmpl $0x2710, 0x37cc8(%rip)  # imm = 0x2710
jle 0x48ac
movq 0x4767(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x1d7c(%rip), %rsi      # 0x6617
movb $0x0, %al
callq 0x10d0
movl $0x1, %edi
callq 0x1120
cmpq $0x0, 0x18(%rsp)
jne 0x48cc
leaq 0x1d77(%rip), %rdi      # 0x6632
leaq 0x1e89(%rip), %rsi      # 0x674b
callq 0x1250
jmp 0x4af6
movq 0x18(%rsp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x4914
movq 0x18(%rsp), %rax
sarq %rax
movl %eax, 0xc(%rsp)
movq 0x20(%rsp), %rsi
movl $0x2, %edi
callq 0x4800
movq 0x20(%rsp), %rcx
leaq 0xc(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x1130
jmp 0x4af6
movl $0x0, 0x14(%rsp)
movl 0x14(%rsp), %eax
cmpl 0x37c2a(%rip), %eax     # 0x3c550
jge 0x4988
movq 0x18(%rsp), %rax
movslq 0x14(%rsp), %rdx
leaq 0x37c27(%rip), %rcx     # 0x3c560
cmpq (%rcx,%rdx,8), %rax
jne 0x4979
cmpl $0x0, 0x14(%rsp)
jne 0x4957
movq 0x20(%rsp), %rsi
movl $0x5, %edi
callq 0x4800
jmp 0x4974
movq 0x20(%rsp), %rsi
movl $0x4, %edi
callq 0x4800
movl 0x14(%rsp), %edi
movq 0x20(%rsp), %rsi
callq 0x4800
jmp 0x4af6
jmp 0x497b
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x491c
movq 0x18(%rsp), %rdx
movl 0x37bbd(%rip), %eax     # 0x3c550
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0x37bb2(%rip)     # 0x3c550
movslq %eax, %rcx
leaq 0x37bb8(%rip), %rax     # 0x3c560
movq %rdx, (%rax,%rcx,8)
movq 0x18(%rsp), %rax
movl (%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x4a61
movq 0x18(%rsp), %rax
movq %rax, (%rsp)
movq 0x18(%rsp), %rax
movl (%rax), %eax
shrl $0x2, %eax
movl %eax, 0x10(%rsp)
movq 0x20(%rsp), %rsi
movl $0x3, %edi
callq 0x4800
movl 0x10(%rsp), %edi
movq 0x20(%rsp), %rsi
callq 0x4800
movl $0x0, 0x14(%rsp)
movl 0x14(%rsp), %eax
cmpl 0x10(%rsp), %eax
jge 0x4a2a
movq (%rsp), %rax
movslq 0x14(%rsp), %rcx
movzbl 0x10(%rax,%rcx), %edi
movq 0x20(%rsp), %rsi
callq 0x4800
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x49fb
movq 0x18(%rsp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x4a49
movq 0x18(%rsp), %rsi
leaq 0x1c08(%rip), %rdi      # 0x664a
movb $0x0, %al
callq 0x1080
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rsi
callq 0x4870
jmp 0x4af6
movq 0x18(%rsp), %rax
movl (%rax), %eax
shrl $0x2, %eax
movl %eax, 0x10(%rsp)
movq 0x20(%rsp), %rsi
movl $0x1, %edi
callq 0x4800
movl 0x10(%rsp), %edi
movq 0x20(%rsp), %rsi
callq 0x4800
movq 0x18(%rsp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x4aab
movq 0x18(%rsp), %rsi
leaq 0x1bab(%rip), %rdi      # 0x664f
movb $0x0, %al
callq 0x1080
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rsi
callq 0x4870
movl $0x0, 0x14(%rsp)
movl 0x14(%rsp), %eax
cmpl 0x10(%rsp), %eax
jge 0x4af6
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rax
movslq 0x14(%rsp), %rcx
movq 0x10(%rax,%rcx,8), %rsi
callq 0x4870
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x4ac6
addq $0x28, %rsp
retq
nopl (%rax,%rax)