// File: /workspace/github_c_makefile_star2_O3/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 0xf0e5(%rip), %rax      # 0x12fd0
movq (%rax), %rax
movq %rax, 0x10703(%rip)     # 0x145f8
movl $0x0, 0x10701(%rip)     # 0x14600
xorl %eax, %eax
callq 0x5b14
callq 0x7fae
xorl %eax, %eax
callq 0x5ab3
leaq 0x106ef(%rip), %rdi     # 0x14608
movl $0x1c0, %edx            # imm = 0x1C0
xorl %esi, %esi
callq 0x30d0
leaq 0x10484(%rip), %rdi     # 0x143b0
movl $0x220, %edx            # imm = 0x220
xorl %esi, %esi
callq 0x30d0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0x1047d(%rip)     # 0x143c0
movl $0x1, 0x106a3(%rip)     # 0x145f0
movl %eax, 0x106a1(%rip)     # 0x145f4
movl $0x200000, %edi         # imm = 0x200000
callq 0x331c
movq %rax, 0x1066c(%rip)     # 0x145d0
movq $0xc, 0x10669(%rip) # 0x145d8
addq $0xc, %rax
movq %rax, 0x10666(%rip)     # 0x145e0
leaq 0x8fec(%rip), %rdi      # 0xcf6d
callq 0x3040
movq %rax, 0x1083b(%rip)     # 0x147c8
leaq 0x8fe2(%rip), %rdi      # 0xcf76
callq 0x3040
movq %rax, 0x10830(%rip)     # 0x147d0
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3b01
leaq 0x8fcd(%rip), %rdi      # 0xcf7f
xorl %esi, %esi
callq 0x65ea
orb $0x10, 0x4(%rax)
addq $0x8, %rax
movq %rax, 0x10810(%rip)     # 0x147d8
leaq 0x8fb7(%rip), %rdi      # 0xcf86
movl $0x11203, %esi          # imm = 0x11203
callq 0x65ea
movslq (%r14), %rax
movq (%rbx,%rax,8), %rdi
callq 0x4820
testl %eax, %eax
je 0x408b
xorl %edi, %edi
callq 0x42bd
leaq 0x1eda5(%rip), %rax     # 0x22da0
movq (%rax), %rbx
testq %rbx, %rbx
je 0x4063
leaq 0x8f87(%rip), %rsi      # 0xcf91
movl $0x1d, %edi
callq 0xa1d8
leaq 0x107c5(%rip), %r15     # 0x147e0
leaq 0x8f71(%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 0x4022
movl 0x10327(%rip), %esi     # 0x14390
testl %esi, %esi
je 0x409d
leaq 0x8f30(%rip), %rdi      # 0xcfa4
xorl %eax, %eax
callq 0x30c0
cmpl $0x0, 0x10302(%rip)     # 0x14384
je 0x408b
xorl %eax, %eax
callq 0x61fd
movl 0x102ff(%rip), %eax     # 0x14390
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
cmpl $-0x1, 0x1031c(%rip)    # 0x143c0
je 0x4148
cmpl $0x1, 0x1031b(%rip)     # 0x143cc
movq 0x10518(%rip), %rax     # 0x145d0
jne 0x4159
leaq 0x2(%rax), %rcx
movq %rcx, 0x10507(%rip)     # 0x145d0
addq $-0x2, 0x10507(%rip)    # 0x145d8
movb $-0x80, 0x2(%rax)
movq 0x104f4(%rip), %rax     # 0x145d0
movb $0x8, 0x1(%rax)
movb 0x102db(%rip), %al      # 0x143c1
movq 0x104e3(%rip), %rcx     # 0x145d0
movb %al, 0x2(%rcx)
movb 0x102ca(%rip), %al      # 0x143c0
movq 0x104d3(%rip), %rcx     # 0x145d0
movb %al, 0x3(%rcx)
movb 0x104d3(%rip), %al      # 0x145d9
movq 0x104c3(%rip), %rcx     # 0x145d0
movb %al, 0x4(%rcx)
movb 0x104c2(%rip), %al      # 0x145d8
movq 0x104b3(%rip), %rcx     # 0x145d0
movb %al, 0x5(%rcx)
movq 0x104a9(%rip), %rax     # 0x145d0
movb $0x42, 0x6(%rax)
movq 0x1049e(%rip), %rax     # 0x145d0
movb $0x53, 0x7(%rax)
movq 0x10493(%rip), %rsi     # 0x145d0
movw $0x3339, 0x8(%rsi)      # imm = 0x3339
jmp 0x41fd
leaq 0x8f63(%rip), %rdi      # 0xd0b2
callq 0x3080
jmp 0x407b
movb $0x42, (%rax)
movq 0x1046d(%rip), %rax     # 0x145d0
movb $0x53, 0x1(%rax)
movq 0x10462(%rip), %rax     # 0x145d0
movb $0x39, 0x2(%rax)
movq 0x10457(%rip), %rax     # 0x145d0
movb $0x34, 0x3(%rax)
movb 0x10240(%rip), %al      # 0x143c3
movq 0x10446(%rip), %rcx     # 0x145d0
movb %al, 0x4(%rcx)
movb 0x1022f(%rip), %al      # 0x143c2
movq 0x10436(%rip), %rcx     # 0x145d0
movb %al, 0x5(%rcx)
movb 0x1021e(%rip), %al      # 0x143c1
movq 0x10426(%rip), %rcx     # 0x145d0
movb %al, 0x6(%rcx)
movb 0x1020d(%rip), %al      # 0x143c0
movq 0x10416(%rip), %rcx     # 0x145d0
movb %al, 0x7(%rcx)
movl 0x10415(%rip), %eax     # 0x145d8
addl $-0xc, %eax
shrl $0x18, %eax
movq 0x10400(%rip), %rsi     # 0x145d0
movb %al, 0x8(%rsi)
movl $0xfffff4, %eax         # imm = 0xFFFFF4
addl 0x103fa(%rip), %eax     # 0x145d8
shrl $0x10, %eax
movb %al, 0x9(%rsi)
movl $0xfff4, %eax           # imm = 0xFFF4
addl 0x103e9(%rip), %eax     # 0x145d8
movb %ah, 0xa(%rsi)
movb 0x103e0(%rip), %al      # 0x145d8
addb $-0xc, %al
movb %al, 0xb(%rsi)
cmpl $0x0, 0x1017c(%rip)     # 0x14380
je 0x4243
xorl %eax, %eax
xorl %edx, %edx
cmpl $0x1, 0x101bb(%rip)     # 0x143cc
setne %al
sete %dl
addl %edx, %edx
orq $-0xc, %rdx
addq 0x103b4(%rip), %rdx     # 0x145d8
leaq (%rsi,%rax,2), %rsi
addq $0xa, %rsi
movq %rdx, 0x103a5(%rip)     # 0x145d8
movq %rsi, 0x10396(%rip)     # 0x145d0
movq 0x1012f(%rip), %rdi     # 0x14370
jmp 0x4251
movq 0x10126(%rip), %rdi     # 0x14370
movq 0x10387(%rip), %rdx     # 0x145d8
callq 0x3a79
cmpl $0x0, 0x1012b(%rip)     # 0x14388
je 0x4271
movq 0x1010a(%rip), %rdi     # 0x14370
movl 0x10120(%rip), %esi     # 0x1438c
callq 0x62fa
cmpl $0x0, 0x10104(%rip)     # 0x1437c
je 0x407b
movq 0x10353(%rip), %rsi     # 0x145d8
movl 0x1012d(%rip), %edx     # 0x143b8
movl 0x10107(%rip), %ecx     # 0x14398
movl 0x10104(%rip), %r8d     # 0x1439c
movl 0x10121(%rip), %r9d     # 0x143c0
movq 0x10102(%rip), %rax     # 0x143a8
movq %rax, (%rsp)
leaq 0x8d17(%rip), %rdi      # 0xcfc8
xorl %eax, %eax
callq 0x30c0
jmp 0x407b