// File: /workspace/github_c_makefile_star2_O2/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 0xf193(%rip), %rax      # 0x12fc0
movq (%rax), %rax
movq %rax, 0x107c1(%rip)     # 0x145f8
andl $0x0, 0x107c2(%rip)     # 0x14600
xorl %eax, %eax
callq 0x54e4
callq 0x76f8
xorl %eax, %eax
callq 0x5488
leaq 0x107b0(%rip), %rdi     # 0x14608
movl $0x1c0, %edx            # imm = 0x1C0
xorl %esi, %esi
callq 0x30d0
leaq 0x10545(%rip), %rdi     # 0x143b0
movl $0x220, %edx            # imm = 0x220
xorl %esi, %esi
callq 0x30d0
orl $-0x1, 0x10542(%rip)    # 0x143c0
movl $0x1, 0x10768(%rip)     # 0x145f0
orl $-0x1, 0x10765(%rip)    # 0x145f4
movl $0x200000, %edi         # imm = 0x200000
callq 0x32ec
movq %rax, 0x10730(%rip)     # 0x145d0
movq $0xc, 0x1072d(%rip) # 0x145d8
addq $0xc, %rax
movq %rax, 0x1072a(%rip)     # 0x145e0
leaq 0x80b0(%rip), %rdi      # 0xbf6d
callq 0x3040
movq %rax, 0x108ff(%rip)     # 0x147c8
leaq 0x80a6(%rip), %rdi      # 0xbf76
callq 0x3040
movq %rax, 0x108f4(%rip)     # 0x147d0
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3a68
leaq 0x8091(%rip), %rdi      # 0xbf7f
xorl %esi, %esi
callq 0x5e64
orb $0x10, 0x4(%rax)
addq $0x8, %rax
movq %rax, 0x108d4(%rip)     # 0x147d8
leaq 0x807b(%rip), %rdi      # 0xbf86
movl $0x11203, %esi          # imm = 0x11203
callq 0x5e64
movslq (%r14), %rax
movq (%rbx,%rax,8), %rdi
callq 0x4750
testl %eax, %eax
je 0x3fc3
xorl %edi, %edi
callq 0x41f5
leaq 0x1ee69(%rip), %rax     # 0x22da0
movq (%rax), %rbx
testq %rbx, %rbx
je 0x3f9b
leaq 0x804b(%rip), %rsi      # 0xbf91
pushq $0x1d
popq %rdi
callq 0x96cc
leaq 0x1088b(%rip), %r15     # 0x147e0
leaq 0x8037(%rip), %r14      # 0xbf93
testq %rbx, %rbx
je 0x3f9b
movq 0x38(%rbx), %rsi
addq $0x38, %rsi
movl 0x14(%rbx), %edx
incl %edx
movslq 0x18(%rbx), %rax
imulq $0x204, %rax, %rax      # imm = 0x204
leaq (%rax,%r15), %rcx
addq $0x4, %rcx
movq %r14, %rdi
xorl %eax, %eax
callq 0x30c0
movq (%rbx), %r12
movq %rbx, %rdi
callq 0x3050
movq %r12, %rbx
jmp 0x3f5c
movl 0x103ef(%rip), %esi     # 0x14390
testl %esi, %esi
je 0x3fd5
leaq 0x7ff8(%rip), %rdi      # 0xbfa4
xorl %eax, %eax
callq 0x30c0
cmpl $0x0, 0x103ca(%rip)     # 0x14384
je 0x3fc3
xorl %eax, %eax
callq 0x5a99
movl 0x103c7(%rip), %eax     # 0x14390
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
cmpl $-0x1, 0x103e4(%rip)    # 0x143c0
je 0x4080
cmpl $0x1, 0x103e3(%rip)     # 0x143cc
movq 0x105e0(%rip), %rax     # 0x145d0
jne 0x4091
leaq 0x2(%rax), %rcx
movq %rcx, 0x105cf(%rip)     # 0x145d0
addq $-0x2, 0x105cf(%rip)    # 0x145d8
movb $-0x80, 0x2(%rax)
movq 0x105bc(%rip), %rax     # 0x145d0
movb $0x8, 0x1(%rax)
movb 0x103a3(%rip), %al      # 0x143c1
movq 0x105ab(%rip), %rcx     # 0x145d0
movb %al, 0x2(%rcx)
movb 0x10392(%rip), %al      # 0x143c0
movq 0x1059b(%rip), %rcx     # 0x145d0
movb %al, 0x3(%rcx)
movb 0x1059b(%rip), %al      # 0x145d9
movq 0x1058b(%rip), %rcx     # 0x145d0
movb %al, 0x4(%rcx)
movb 0x1058a(%rip), %al      # 0x145d8
movq 0x1057b(%rip), %rcx     # 0x145d0
movb %al, 0x5(%rcx)
movq 0x10571(%rip), %rax     # 0x145d0
movb $0x42, 0x6(%rax)
movq 0x10566(%rip), %rax     # 0x145d0
movb $0x53, 0x7(%rax)
movq 0x1055b(%rip), %rsi     # 0x145d0
movw $0x3339, 0x8(%rsi)      # imm = 0x3339
jmp 0x4135
leaq 0x802b(%rip), %rdi      # 0xc0b2
callq 0x3080
jmp 0x3fb3
movb $0x42, (%rax)
movq 0x10535(%rip), %rax     # 0x145d0
movb $0x53, 0x1(%rax)
movq 0x1052a(%rip), %rax     # 0x145d0
movb $0x39, 0x2(%rax)
movq 0x1051f(%rip), %rax     # 0x145d0
movb $0x34, 0x3(%rax)
movb 0x10308(%rip), %al      # 0x143c3
movq 0x1050e(%rip), %rcx     # 0x145d0
movb %al, 0x4(%rcx)
movb 0x102f7(%rip), %al      # 0x143c2
movq 0x104fe(%rip), %rcx     # 0x145d0
movb %al, 0x5(%rcx)
movb 0x102e6(%rip), %al      # 0x143c1
movq 0x104ee(%rip), %rcx     # 0x145d0
movb %al, 0x6(%rcx)
movb 0x102d5(%rip), %al      # 0x143c0
movq 0x104de(%rip), %rcx     # 0x145d0
movb %al, 0x7(%rcx)
movl 0x104dd(%rip), %eax     # 0x145d8
addl $-0xc, %eax
shrl $0x18, %eax
movq 0x104c8(%rip), %rsi     # 0x145d0
movb %al, 0x8(%rsi)
movl $0xfffff4, %eax         # imm = 0xFFFFF4
addl 0x104c2(%rip), %eax     # 0x145d8
shrl $0x10, %eax
movb %al, 0x9(%rsi)
movl $0xfff4, %eax           # imm = 0xFFF4
addl 0x104b1(%rip), %eax     # 0x145d8
movb %ah, 0xa(%rsi)
movb 0x104a8(%rip), %al      # 0x145d8
addb $-0xc, %al
movb %al, 0xb(%rsi)
cmpl $0x0, 0x10244(%rip)     # 0x14380
je 0x417b
xorl %eax, %eax
xorl %edx, %edx
cmpl $0x1, 0x10283(%rip)     # 0x143cc
setne %al
sete %dl
addl %edx, %edx
orq $-0xc, %rdx
addq 0x1047c(%rip), %rdx     # 0x145d8
leaq (%rsi,%rax,2), %rsi
addq $0xa, %rsi
movq %rdx, 0x1046d(%rip)     # 0x145d8
movq %rsi, 0x1045e(%rip)     # 0x145d0
movq 0x101f7(%rip), %rdi     # 0x14370
jmp 0x4189
movq 0x101ee(%rip), %rdi     # 0x14370
movq 0x1044f(%rip), %rdx     # 0x145d8
callq 0x39e4
cmpl $0x0, 0x101f3(%rip)     # 0x14388
je 0x41a9
movq 0x101d2(%rip), %rdi     # 0x14370
movl 0x101e8(%rip), %esi     # 0x1438c
callq 0x5b8e
cmpl $0x0, 0x101cc(%rip)     # 0x1437c
je 0x3fb3
movq 0x1041b(%rip), %rsi     # 0x145d8
movl 0x101f5(%rip), %edx     # 0x143b8
movl 0x101cf(%rip), %ecx     # 0x14398
movl 0x101cc(%rip), %r8d     # 0x1439c
movl 0x101e9(%rip), %r9d     # 0x143c0
movq 0x101ca(%rip), %rax     # 0x143a8
movq %rax, (%rsp)
leaq 0x7ddf(%rip), %rdi      # 0xbfc8
xorl %eax, %eax
callq 0x30c0
jmp 0x3fb3