// File: /workspace/github_c_makefile_star2_O1/42Bastian[P]lyxass/lyxass.c
// Function: main
int main(int argc, char **argv)
{
  // init
  label_t * l;

  my_stderr = stdout; //stderr;
  chgPathToUpper = 0;

  InitLabels();
  InitTransASCII();

  InitParser();

  memset( (char *)&Current, 0, sizeof(struct current_s) );
  memset( (char *)&Global, 0, sizeof(struct global_s) );
  Global.run = -1;
  sourceMode = LYNX;
  jaguar_mode = -1;

  code.Mem = my_malloc(MAX_CODE_SIZE);
  code.Size = 12;
  code.Ptr = code.Mem+12;

  bll_root = getenv("BLL_ROOT");
  bjl_root = getenv("BJL_ROOT");

  CommandLine( &argc, argv );

  l = newSymbol("CYCLES", 0);
  l->type |= VARIABLE;
  p_cycles = (uint32_t *)&l->value;

  l = newSymbol("__LYXASS__", VERSION);

  /*
  if ( argc != 2 ) {
    printf("Aufruf : dump filename \n");
    return FALSE;
  }
  */
  if (LoadSource(argv[argc])){

    mainloop(0);

    if ( refFirst ){
      REFERENCE *ptr1,*ptr = refFirst;

      Error(UNSOLVED_ERR,"\b");

      while ( ptr ){
        printf("<%32s> [%5d %s]\n",ptr->unknown->name,
               ptr->line+1,file_list[ptr->file].name);
        ptr1 = ptr;
        ptr = ptr->up;
        free(ptr1);
      }
    }
    if ( cntError ){
      printf("Total Errors :%d\nNo file written !\n",cntError);
    } else {
      if ( Global.run != -1 ){
        if ( Global.mainMode == LYNX ){
          code.Mem += 2;
          code.Size -=2;

          code.Mem[0] = -0x80;
          code.Mem[1] = 0x08;

          code.Mem[2] = Global.run >> 8;
          code.Mem[3] = Global.run & 0xff;
          code.Mem[4] = (char)(code.Size >> 8);
          code.Mem[5] = (char)(code.Size & 0xff);

          code.Mem[6] = 'B';
          code.Mem[7] = 'S';
          code.Mem[8] = '9';
          code.Mem[9] = '3';
          /*
          code.Mem += 4;
          code.Size -= 4;
          code.Mem[0] = (char)0x81;
          code.Mem[1] = 'P';
          code.Mem[2] = Global.run >> 8;
          code.Mem[3] = Global.run & 0xff;
          code.Mem[4] = ((code.Size-6) >> 8) ^ 0xff;
          code.Mem[5] = ((code.Size-6) & 0xff) ^ 0xff;
          */
        } else {
          code.Mem[0] = 'B';
          code.Mem[1] = 'S';
          code.Mem[2] = '9';
          code.Mem[3] = '4';
          code.Mem[4] = Global.run >> 24;
          code.Mem[5] = (Global.run >> 16) & 255;
          code.Mem[6] = (Global.run >>  8) & 255;
          code.Mem[7] = Global.run & 255;
          code.Mem[8] = (code.Size-12)>> 24;
          code.Mem[9] = ((code.Size-12) >> 16) & 255;
          code.Mem[10] = ((code.Size-12) >>  8) & 255;
          code.Mem[11] = (code.Size-12) & 255;
        }
        if ( data ){
          if (Global.mainMode == LYNX ){
            code.Size -= 10;
            code.Mem += 10;
          } else {
            code.Size -= 12;
            code.Mem += 12;
          }
          writeFile(outfile,code.Mem,code.Size);
        } else {
          writeFile(outfile,code.Mem,code.Size);
        }
        if ( symbols ){
          writeSymbols(outfile, hexsymbols);
        }
        if ( verbose ){
          printf("\nCode-size : %ld\n"
                 "Lines : %d\n"
                 "Macros expanded : %d\n"
                 "Pass 2 runs : %d\n"
                 "Start-address : $%04x\n"
                 "Memory usage : %ld\n",
                 code.Size,Global.Lines,
                 cntMacroExpand,cntRef,Global.run,totalMemory);
        }
      }else{
        printf("No RUN statement ! No outputfile generated.\n");
      }
    }
    if ( dumpGlobals ){
      DumpGlobals();
    }
  }

  //  hashStatistics();
  return cntError;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
leaq 0x14(%rsp), %r14
movl %edi, (%r14)
movq 0xf0e0(%rip), %rax      # 0x12fd0
movq (%rax), %rax
movq %rax, 0x106fe(%rip)     # 0x145f8
movl $0x0, 0x106fc(%rip)     # 0x14600
xorl %eax, %eax
callq 0x5c24
callq 0x806f
xorl %eax, %eax
callq 0x5bc3
leaq 0x106ea(%rip), %rdi     # 0x14608
movl $0x1c0, %edx            # imm = 0x1C0
xorl %esi, %esi
callq 0x30d0
leaq 0x1047f(%rip), %rdi     # 0x143b0
movl $0x220, %edx            # imm = 0x220
xorl %esi, %esi
callq 0x30d0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0x10478(%rip)     # 0x143c0
movl $0x1, 0x1069e(%rip)     # 0x145f0
movl %eax, 0x1069c(%rip)     # 0x145f4
movl $0x200000, %edi         # imm = 0x200000
callq 0x331c
movq %rax, 0x10667(%rip)     # 0x145d0
movq $0xc, 0x10664(%rip) # 0x145d8
addq $0xc, %rax
movq %rax, 0x10661(%rip)     # 0x145e0
leaq 0x8fe7(%rip), %rdi      # 0xcf6d
callq 0x3040
movq %rax, 0x10836(%rip)     # 0x147c8
leaq 0x8fdd(%rip), %rdi      # 0xcf76
callq 0x3040
movq %rax, 0x1082b(%rip)     # 0x147d0
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3ae0
leaq 0x8fc8(%rip), %rdi      # 0xcf7f
xorl %esi, %esi
callq 0x6651
orb $0x10, 0x4(%rax)
addq $0x8, %rax
movq %rax, 0x1080b(%rip)     # 0x147d8
leaq 0x8fb2(%rip), %rdi      # 0xcf86
movl $0x11203, %esi          # imm = 0x11203
callq 0x6651
movslq (%r14), %rax
movq (%rbx,%rax,8), %rdi
callq 0x4858
testl %eax, %eax
je 0x4090
xorl %edi, %edi
callq 0x42cd
leaq 0x1eda0(%rip), %rax     # 0x22da0
movq (%rax), %rbx
testq %rbx, %rbx
je 0x4068
leaq 0x8f82(%rip), %rsi      # 0xcf91
movl $0x1d, %edi
callq 0xa2c8
leaq 0x107c0(%rip), %r15     # 0x147e0
leaq 0x8f6c(%rip), %r14      # 0xcf93
movq 0x38(%rbx), %rsi
addq $0x38, %rsi
movl 0x14(%rbx), %edx
incl %edx
movslq 0x18(%rbx), %rax
movq %rax, %rcx
shlq $0x9, %rcx
leaq (%rcx,%rax,4), %rax
leaq (%r15,%rax), %rcx
addq $0x4, %rcx
movq %r14, %rdi
xorl %eax, %eax
callq 0x30c0
movq (%rbx), %r12
movq %rbx, %rdi
callq 0x3050
movq %r12, %rbx
testq %r12, %r12
jne 0x4027
movl 0x10322(%rip), %esi     # 0x14390
testl %esi, %esi
je 0x40a2
leaq 0x8f2b(%rip), %rdi      # 0xcfa4
xorl %eax, %eax
callq 0x30c0
cmpl $0x0, 0x102fd(%rip)     # 0x14384
je 0x4090
xorl %eax, %eax
callq 0x6264
movl 0x102fa(%rip), %eax     # 0x14390
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
cmpl $-0x1, 0x10317(%rip)    # 0x143c0
je 0x414d
cmpl $0x1, 0x10316(%rip)     # 0x143cc
movq 0x10513(%rip), %rax     # 0x145d0
jne 0x415e
leaq 0x2(%rax), %rcx
movq %rcx, 0x10502(%rip)     # 0x145d0
addq $-0x2, 0x10502(%rip)    # 0x145d8
movb $-0x80, 0x2(%rax)
movq 0x104ef(%rip), %rax     # 0x145d0
movb $0x8, 0x1(%rax)
movb 0x102d6(%rip), %al      # 0x143c1
movq 0x104de(%rip), %rcx     # 0x145d0
movb %al, 0x2(%rcx)
movb 0x102c5(%rip), %al      # 0x143c0
movq 0x104ce(%rip), %rcx     # 0x145d0
movb %al, 0x3(%rcx)
movb 0x104ce(%rip), %al      # 0x145d9
movq 0x104be(%rip), %rcx     # 0x145d0
movb %al, 0x4(%rcx)
movb 0x104bd(%rip), %al      # 0x145d8
movq 0x104ae(%rip), %rcx     # 0x145d0
movb %al, 0x5(%rcx)
movq 0x104a4(%rip), %rax     # 0x145d0
movb $0x42, 0x6(%rax)
movq 0x10499(%rip), %rax     # 0x145d0
movb $0x53, 0x7(%rax)
movq 0x1048e(%rip), %rax     # 0x145d0
movw $0x3339, 0x8(%rax)      # imm = 0x3339
jmp 0x4203
leaq 0x8f5e(%rip), %rdi      # 0xd0b2
callq 0x3080
jmp 0x4080
movb $0x42, (%rax)
movq 0x10468(%rip), %rax     # 0x145d0
movb $0x53, 0x1(%rax)
movq 0x1045d(%rip), %rax     # 0x145d0
movb $0x39, 0x2(%rax)
movq 0x10452(%rip), %rax     # 0x145d0
movb $0x34, 0x3(%rax)
movb 0x1023b(%rip), %al      # 0x143c3
movq 0x10441(%rip), %rcx     # 0x145d0
movb %al, 0x4(%rcx)
movb 0x1022a(%rip), %al      # 0x143c2
movq 0x10431(%rip), %rcx     # 0x145d0
movb %al, 0x5(%rcx)
movb 0x10219(%rip), %al      # 0x143c1
movq 0x10421(%rip), %rcx     # 0x145d0
movb %al, 0x6(%rcx)
movb 0x10208(%rip), %al      # 0x143c0
movq 0x10411(%rip), %rcx     # 0x145d0
movb %al, 0x7(%rcx)
movl 0x10410(%rip), %ecx     # 0x145d8
addl $-0xc, %ecx
shrl $0x18, %ecx
movq 0x103fb(%rip), %rax     # 0x145d0
movb %cl, 0x8(%rax)
movl $0xfffff4, %ecx         # imm = 0xFFFFF4
addl 0x103f5(%rip), %ecx     # 0x145d8
shrl $0x10, %ecx
movb %cl, 0x9(%rax)
movl $0xfff4, %ecx           # imm = 0xFFF4
addl 0x103e4(%rip), %ecx     # 0x145d8
movb %ch, 0xa(%rax)
movb 0x103db(%rip), %cl      # 0x145d8
addb $-0xc, %cl
movb %cl, 0xb(%rax)
cmpl $0x0, 0x10176(%rip)     # 0x14380
movq 0x103c7(%rip), %rdx     # 0x145d8
je 0x4253
xorl %eax, %eax
xorl %ecx, %ecx
cmpl $0x1, 0x101ae(%rip)     # 0x143cc
setne %al
sete %cl
addl %ecx, %ecx
orq $-0xc, %rcx
addq %rcx, %rdx
movq %rdx, 0x103a4(%rip)     # 0x145d8
movq 0x10395(%rip), %rcx     # 0x145d0
leaq (%rcx,%rax,2), %rsi
addq $0xa, %rsi
movq %rsi, 0x10386(%rip)     # 0x145d0
movq 0x1011f(%rip), %rdi     # 0x14370
jmp 0x4261
movq 0x10116(%rip), %rdi     # 0x14370
movq 0x1036f(%rip), %rsi     # 0x145d0
callq 0x3a58
cmpl $0x0, 0x1011b(%rip)     # 0x14388
je 0x4281
movq 0x100fa(%rip), %rdi     # 0x14370
movl 0x10110(%rip), %esi     # 0x1438c
callq 0x6361
cmpl $0x0, 0x100f4(%rip)     # 0x1437c
je 0x4080
movq 0x10343(%rip), %rsi     # 0x145d8
movl 0x1011d(%rip), %edx     # 0x143b8
movl 0x100f7(%rip), %ecx     # 0x14398
movl 0x100f4(%rip), %r8d     # 0x1439c
movl 0x10111(%rip), %r9d     # 0x143c0
movq 0x100f2(%rip), %rax     # 0x143a8
movq %rax, (%rsp)
leaq 0x8d07(%rip), %rdi      # 0xcfc8
xorl %eax, %eax
callq 0x30c0
jmp 0x4080