// File: /workspace/github_c_makefile_star2_O0/GregorR[P]lstg/source/main.c
// Function: main
int main(int argc, char **argv)
{
  struct object  *aProcess,
                 *aContext,
                 *o;
  int             size,
                  i,
                  staticSize,
                  dynamicSize;
  FILE           *fp;
  char           *imageFileName = NULL,
                 *p;

#ifndef LITTLE_SMALLTALK_IMAGE
  imageFileName = "LittleSmalltalk.image";
#endif

  staticSize = DefaultStaticSize;
  dynamicSize = DefaultDynamicSize;
  lstDebugging = 0;

  /*
   * See if our environment tells us what TMPDIR to use
   */
  p = getenv("TMPDIR");
  if(p)
    lstTmpDir = strdup(p);

  /*
     first parse arguments 
   */
  for(i = 1; i < argc; i++)
  {
    if(strcmp(argv[i], "-i") == 0)
    {
      imageFileName = argv[++i];
    }
    else if(strcmp(argv[i], "-s") == 0)
    {
      staticSize = atoi(argv[++i]);
    }
    else if(strcmp(argv[i], "-d") == 0)
    {
      dynamicSize = atoi(argv[++i]);
    }
    else if(strcmp(argv[i], "-g") == 0)
    {
      lstDebugging = 1;
    }
    else if (argv[i][0] != '-')
    {
      break;
    }
  }
  lstArgv = argv;
  lstArgc = argc;

  gcinit(staticSize, dynamicSize);

  /*
     read in the method from the image file 
   */
#ifdef LITTLE_SMALLTALK_IMAGE
  if(imageFileName) {
#endif
    fp = fopen(imageFileName, "rb");
    if(!fp)
    {
      fprintf(stderr, "cannot open image file: %s\n", imageFileName);
      exit(1);
    }
#ifdef LITTLE_SMALLTALK_IMAGE
  }
  else
  {
    fp = fmemopen(LITTLE_SMALLTALK_IMAGE, LITTLE_SMALLTALK_IMAGE_LEN, "r");
  }
#endif
  if(lstDebugging)
    printf("%d objects in image\n", fileIn(fp));
  else
    fileIn(fp);
  fclose(fp);

  lstPrimitivesInit();

  /*
     build a context around it 
   */

  aProcess = staticAllocate(3);
  /*
     context should be dynamic 
   */
  aContext = gcalloc(contextSize);
  aContext->class = ContextClass;

  aProcess->data[contextInProcess] = aContext;
  size = integerValue(initialMethod->data[stackSizeInMethod]);
  aContext->data[stackInContext] = staticAllocate(size);
  aContext->data[argumentsInContext] = nilObject;

  aContext->data[temporariesInContext] = staticAllocate(19);
  aContext->data[bytePointerInContext] = newInteger(0);
  aContext->data[stackTopInContext] = newInteger(0);
  aContext->data[previousContextInContext] = nilObject;
  aContext->data[methodInContext] = initialMethod;

  /*
     now go do it 
   */
  rootStack[rootTop++] = aProcess;

  switch (execute(aProcess, 0))
  {
    case 2:
      if (lstDebugging) printf("User defined return\n");
      break;

    case 3:
      printf("can't find method in call\n");
      aProcess = rootStack[--rootTop];
      o = aProcess->data[resultInProcess];
      printf("Unknown method: %s\n", bytePtr(o));
      aContext = aProcess->data[contextInProcess];
      backTrace(aContext);
      break;

    case 4:
      if (lstDebugging) printf("\nnormal return\n");
      break;

    case 5:
      printf("time out\n");
      break;

    default:
      printf("unknown return code\n");
      break;
  }
  if (lstDebugging)
  {
    printf("cache hit %u miss %u", cacheHit, cacheMiss);
#define SCALE (1000)
    while((cacheHit > INT_MAX / SCALE) || (cacheMiss > INT_MAX / SCALE))
    {
      cacheHit /= 10;
      cacheMiss /= 10;
    }
    i = (SCALE * cacheHit) / (cacheHit + cacheMiss);
    printf(" ratio %u.%u%%\n", i / 10, i % 10);
    printf("%u garbage collections\n", gccount);
  }

  lstPrimitivesRelease();

  return (0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x9c40, -0x34(%rbp)    # imm = 0x9C40
movl $0x9c40, -0x38(%rbp)    # imm = 0x9C40
leaq 0x4450e(%rip), %rax     # 0x49c54
movl $0x0, (%rax)
leaq 0x4adb(%rip), %rdi      # 0xa22e
callq 0x2040
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x5773
movq -0x50(%rbp), %rdi
callq 0x2360
movq %rax, 0x3efbd(%rip)     # 0x44730
movl $0x1, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x5893
movq -0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x4a9c(%rip), %rsi      # 0xa235
callq 0x21a0
cmpl $0x0, %eax
jne 0x57c0
movq -0x10(%rbp), %rax
movl -0x30(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x30(%rbp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
jmp 0x5883
movq -0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x4a65(%rip), %rsi      # 0xa238
callq 0x21a0
cmpl $0x0, %eax
jne 0x57fe
movq -0x10(%rbp), %rax
movl -0x30(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x30(%rbp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2300
movl %eax, -0x34(%rbp)
jmp 0x5881
movq -0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x4a2a(%rip), %rsi      # 0xa23b
callq 0x21a0
cmpl $0x0, %eax
jne 0x5839
movq -0x10(%rbp), %rax
movl -0x30(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x30(%rbp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2300
movl %eax, -0x38(%rbp)
jmp 0x587f
movq -0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x49f2(%rip), %rsi      # 0xa23e
callq 0x21a0
cmpl $0x0, %eax
jne 0x5865
leaq 0x443f7(%rip), %rax     # 0x49c54
movl $0x1, (%rax)
jmp 0x587d
movq -0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0x587b
jmp 0x5893
jmp 0x587d
jmp 0x587f
jmp 0x5881
jmp 0x5883
jmp 0x5885
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x577a
movq -0x10(%rbp), %rcx
leaq 0x443aa(%rip), %rax     # 0x49c48
movq %rcx, (%rax)
movl -0x8(%rbp), %ecx
leaq 0x44395(%rip), %rax     # 0x49c40
movl %ecx, (%rax)
movl -0x34(%rbp), %edi
movl -0x38(%rbp), %esi
callq 0x5e30
cmpq $0x0, -0x48(%rbp)
je 0x5902
movq -0x48(%rbp), %rdi
leaq 0x4977(%rip), %rsi      # 0xa241
callq 0x22b0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x5900
movq 0x7717(%rip), %rax      # 0xcff8
movq (%rax), %rdi
movq -0x48(%rbp), %rdx
leaq 0x4955(%rip), %rsi      # 0xa244
movb $0x0, %al
callq 0x21e0
movl $0x1, %edi
callq 0x2330
jmp 0x5921
movl 0x3ee24(%rip), %eax     # 0x4472c
movl %eax, %esi
leaq 0x78cf(%rip), %rdi      # 0xd1e0
leaq 0x4948(%rip), %rdx      # 0xa260
callq 0x20a0
movq %rax, -0x40(%rbp)
leaq 0x4432c(%rip), %rax     # 0x49c54
cmpl $0x0, (%rax)
je 0x5948
movq -0x40(%rbp), %rdi
callq 0x67b0
movl %eax, %esi
leaq 0x4923(%rip), %rdi      # 0xa262
movb $0x0, %al
callq 0x2140
jmp 0x5951
movq -0x40(%rbp), %rdi
callq 0x67b0
movq -0x40(%rbp), %rdi
callq 0x20e0
movb $0x0, %al
callq 0x7430
movl $0x3, %edi
callq 0x6650
movq %rax, -0x18(%rbp)
leaq 0x430a2(%rip), %rax     # 0x48a18
movq (%rax), %rax
addq $-0x48, %rax
leaq 0x43094(%rip), %rcx     # 0x48a18
movq %rax, (%rcx)
leaq 0x43082(%rip), %rcx     # 0x48a10
cmpq (%rcx), %rax
jae 0x59a3
movl $0x7, %edi
callq 0x6050
movq %rax, -0x58(%rbp)
jmp 0x59c1
leaq 0x4306e(%rip), %rax     # 0x48a18
movq (%rax), %rax
movl $0x1c, (%rax)
leaq 0x4305e(%rip), %rax     # 0x48a18
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x20(%rbp)
leaq 0x42fa0(%rip), %rax     # 0x48970
movq (%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
leaq 0x42fc2(%rip), %rax     # 0x489b0
movq %rax, -0x68(%rbp)
movq (%rax), %rax
movq 0x28(%rax), %rax
shrq %rax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %edi
callq 0x6650
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x28(%rax)
leaq 0x42f1f(%rip), %rax     # 0x48938
movq %rax, -0x70(%rbp)
movq (%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x18(%rax)
movl $0x13, %edi
callq 0x6650
movq -0x70(%rbp), %rcx
movq %rax, %rsi
movq -0x68(%rbp), %rax
movq -0x20(%rbp), %rdx
movq %rsi, 0x20(%rdx)
movq -0x20(%rbp), %rdx
movq $0x1, 0x30(%rdx)
movq -0x20(%rbp), %rdx
movq $0x1, 0x38(%rdx)
movq (%rcx), %rdx
movq -0x20(%rbp), %rcx
movq %rdx, 0x40(%rcx)
movq (%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rdx
leaq 0x42f52(%rip), %rax     # 0x489d0
movl (%rax), %ecx
movl %ecx, %esi
incl %esi
movl %esi, (%rax)
leaq 0x42fb3(%rip), %rax     # 0x48a40
movq %rdx, (%rax,%rcx,8)
movq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0x24e0
addl $-0x2, %eax
movl %eax, %ecx
movq %rcx, -0x60(%rbp)
subl $0x3, %eax
ja 0x5b7c
movq -0x60(%rbp), %rax
leaq 0x473b(%rip), %rcx      # 0xa1f4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x4418b(%rip), %rax     # 0x49c54
cmpl $0x0, (%rax)
je 0x5adc
leaq 0x47a2(%rip), %rdi      # 0xa277
movb $0x0, %al
callq 0x2140
jmp 0x5b8a
leaq 0x47a4(%rip), %rdi      # 0xa28c
movb $0x0, %al
callq 0x2140
leaq 0x42eda(%rip), %rax     # 0x489d0
movl (%rax), %eax
addl $-0x1, %eax
leaq 0x42ece(%rip), %rcx     # 0x489d0
movl %eax, (%rcx)
movl %eax, %eax
movl %eax, %ecx
leaq 0x42f31(%rip), %rax     # 0x48a40
movq (%rax,%rcx,8), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rsi
addq $0x10, %rsi
leaq 0x4775(%rip), %rdi      # 0xa2a7
movb $0x0, %al
callq 0x2140
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x5c80
jmp 0x5b8a
leaq 0x440fd(%rip), %rax     # 0x49c54
cmpl $0x0, (%rax)
je 0x5b6a
leaq 0x4758(%rip), %rdi      # 0xa2bb
movb $0x0, %al
callq 0x2140
jmp 0x5b8a
leaq 0x4758(%rip), %rdi      # 0xa2cb
movb $0x0, %al
callq 0x2140
jmp 0x5b8a
leaq 0x4752(%rip), %rdi      # 0xa2d5
movb $0x0, %al
callq 0x2140
leaq 0x440c3(%rip), %rax     # 0x49c54
cmpl $0x0, (%rax)
je 0x5c61
movl 0x42e18(%rip), %esi     # 0x489b8
movl 0x42e16(%rip), %edx     # 0x489bc
leaq 0x473d(%rip), %rdi      # 0xa2ea
movb $0x0, %al
callq 0x2140
movb $0x1, %al
cmpl $0x20c49b, 0x42df8(%rip) # imm = 0x20C49B
movb %al, -0x71(%rbp)
ja 0x5bd5
cmpl $0x20c49b, 0x42ded(%rip) # imm = 0x20C49B
seta %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x5bde
jmp 0x5c0a
movl 0x42dd4(%rip), %eax     # 0x489b8
movl $0xa, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, 0x42dc5(%rip)     # 0x489b8
movl 0x42dc3(%rip), %eax     # 0x489bc
movl $0xa, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, 0x42db4(%rip)     # 0x489bc
jmp 0x5bb4
imull $0x3e8, 0x42da4(%rip), %eax # imm = 0x3E8
movl 0x42d9e(%rip), %ecx     # 0x489b8
addl 0x42d9c(%rip), %ecx     # 0x489bc
xorl %edx, %edx
divl %ecx
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl $0xa, %ecx
cltd
idivl %ecx
movl %eax, %esi
movl -0x30(%rbp), %eax
movl $0xa, %ecx
cltd
idivl %ecx
leaq 0x46b9(%rip), %rdi      # 0xa2ff
movb $0x0, %al
callq 0x2140
movl 0x42d6d(%rip), %esi     # 0x489c0
leaq 0x46b5(%rip), %rdi      # 0xa30f
movb $0x0, %al
callq 0x2140
movb $0x0, %al
callq 0x7440
xorl %eax, %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)