// File: besm6[P]pascal-re/pascompl.cc
// Function: main
int main(int argc, char **argv)
{
    // Data Initializations moved here
    blockBegSys = Bits(LABELSY, CONSTSY, TYPESY, VARSY) + Bits(FUNCSY, PROCSY, BEGINSY);
    statBegSys = Bits(BEGINSY, IFSY, CASESY, REPEATSY) + Bits(WHILESY, FORSY, WITHSY) +
        Bits(GOTOSY, SELECTSY);
    statEndSys = Bits(SEMICOLON, ENDSY, ELSESY, UNTILSY);
    lvalOpSet = Bits(GETELT, GETVAR, op36, op37) + Bits(GETFIELD, DEREF, FILEPTR);

    funcInsn[fnABS] = KAMX;
    funcInsn[fnTRUNC] = KADD+ZERO;
    funcInsn[fnODD] = KAAX+E1;
    funcInsn[fnORD] = KAOX+ZERO;
    funcInsn[fnCHR] = KAAX+MANTISSA;
    funcInsn[fnSUCC] = KARX+E1;
    funcInsn[fnPRED] = KSUB+E1;
    funcInsn[fnSQR] = macro + mcSQRR;
    funcInsn[fnROUND] = macro + mcROUND;
    funcInsn[fnCARD] = macro + mcCARD;
    funcInsn[fnMINEL] = macro + mcMINEL;
    funcInsn[fnPTR] = KAAX+MANTISSA;
    funcInsn[fnABSI] = KAMX;
    funcInsn[fnSQRI] = macro + mcSQRI;

    for (int i = 0; i < 128; ++i) {
        charSymTabBase[i] = NOSY;
        chrClassTabBase[i] = NOOP;
    }
    for (int i = 0; i < 10; ++i) {
        charSymTabBase[i+'0'] = INTCONST;
        chrClassTabBase[i+'0'] = ALNUM;
    }
    for (int i = 0; i < 26; ++i) {
        charSymTabBase[i+'A'] = IDENT;
        chrClassTabBase[i+'A'] = ALNUM;
        charSymTabBase[i+'a'] = IDENT;
        chrClassTabBase[i+'a'] = ALNUM;
    }

    // Allow Cyrillics except Ъ which does not have a TEXT code
    for (int i = 0; i < 31; ++i) {
        charSymTabBase[i+0300] = IDENT;
        chrClassTabBase[i+0300] = ALNUM;
        charSymTabBase[i+0340] = IDENT;
        chrClassTabBase[i+0340] = ALNUM;
    }
    charSymTabBase['\''] = CHARCONST;
    charSymTabBase['_'] = REALCONST;
    charSymTabBase['<'] = LTSY;
    charSymTabBase['>'] = GTSY;
    chrClassTabBase['+'] = PLUSOP;
    chrClassTabBase['-'] = MINUSOP;
    chrClassTabBase['*'] = MUL;
    chrClassTabBase['/'] = RDIVOP;
    chrClassTabBase['='] = EQOP;
    chrClassTabBase['&'] = AMPERS;
    chrClassTabBase['>'] = GTOP;
    chrClassTabBase['<'] = LTOP;
    chrClassTabBase['#'] = NEOP;
    chrClassTabBase['='] = EQOP;
    charSymTabBase['+'] = ADDOP;
    charSymTabBase['-'] = ADDOP;
    charSymTabBase['*'] = MULOP;
    charSymTabBase['/'] = MULOP;
    charSymTabBase['&'] = MULOP;
    charSymTabBase[','] = COMMA;
    charSymTabBase['.'] = PERIOD;
    charSymTabBase['@'] = ARROW;
    charSymTabBase['^'] = ARROW;
    charSymTabBase['('] = LPAREN;
    charSymTabBase[')'] = RPAREN;
    charSymTabBase[';'] = SEMICOLON;
    charSymTabBase['['] = LBRACK;
    charSymTabBase[']'] = RBRACK;
    charSymTabBase['#'] = RELOP;
    charSymTabBase['='] = RELOP;
    charSymTabBase[':'] = COLON;
    charSymTabBase['~'] = NOTSY;
    charSymTabBase['{'] = LBRACE;
    charSymTabBase['}'] = RBRACE;

    iAddOpMap[PLUSOP] = INTPLUS;
    iAddOpMap[MINUSOP] = INTMINUS;
    setOpMap[PLUSOP] = SETOR;
    setOpMap[MINUSOP] = SETSUB;
    iMulOpMap[MUL] = IMULOP;
    iMulOpMap[RDIVOP] = IDIVROP;
    setOpMap[MUL] = SETAND;
    setOpMap[RDIVOP] = SETXOR;

    // Main program starts here

    // L0 by default: no listing, only errors
    PASINFOR.listMode = 0;
    initOptions(argc, argv);
    if (PASINFOR.listMode != 0)
        printf("%s\n", boilerplate);
    curInsnTemplate = 0;
    initTables();
    litExternal = toText("EXTERNAL");
    litForward = toText("FORWARD");
    litFortran = toText("FORTRAN");
    litOct = toText("OCT");
    PASINPUT = ugetc(pasinput);
    try {
        programme(curInsnTemplate, hashTravPtr);
    } catch (int foo) {
        if (foo == 9999) goto L9999;
    }
    if (errors) {
L9999:  printf(" IN %ld LINES %ld ERRORS\n", lineCnt-1, totalErrors);
        exit(1);
    } else {
        finalize();
        // Dump CHILD here
        FILE *f = fopen(outFileName, "w");
        if (f == NULL) {
            fprintf(stderr, "%s: Cannot open output file\n", progname);
            perror(outFileName);
            exit(-1);
        }
        if (stdArrayFmt) {
            int words = 0;
            for (int i = 1; i < entryPtCnt; ++i) {
                write_stdarray_word(f, words, entryPtTable[i]);
            }
            for (size_t i = 0; i < CHILD.size(); ++i) {
                write_stdarray_word(f, words, CHILD[i]);
            }
            while (words++ % 16 != 0)
                fprintf(f, "`%016lo\n", 0l);
        } else {
            fwrite("BESM6\0", 6, 1, f);
            for (size_t i = 7; i < CHILD.size(); ++i) {
                for (int j = 40; j >= 0; j -= 8)
                    fputc((CHILD[i] >> j) & 0xFF, f);
            }
        }
        fclose(f);
        exit(0);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x14, %edi
movl $0x15, %esi
movl $0x16, %edx
movl $0x17, %ecx
callq 0x4a00
movq %rax, -0x20(%rbp)
movl $0x18, %edi
movl $0x19, %esi
movl $0x1f, %edx
callq 0x4990
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x1db20
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, 0x62eae(%rip)     # 0x7fe98
movl $0x1f, %edi
movl $0x20, %esi
movl $0x21, %edx
movl $0x22, %ecx
callq 0x4a00
movq %rax, -0x40(%rbp)
movl $0x23, %edi
movl $0x24, %esi
movl $0x25, %edx
callq 0x4990
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x1db20
movq %rax, -0x38(%rbp)
movl $0x26, %edi
movl $0x2f, %esi
callq 0x4940
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x1db20
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, 0x62e41(%rip)     # 0x7fea0
movl $0xf, %edi
movl $0x27, %esi
movl $0x28, %edx
movl $0x29, %ecx
callq 0x4a00
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, 0x62e09(%rip)     # 0x7fe90
movl $0x1c, %edi
movl $0x1d, %esi
movl $0x1e, %edx
movl $0x1f, %ecx
callq 0x4a00
movq %rax, -0x68(%rbp)
movl $0x21, %edi
movl $0x22, %esi
movl $0x23, %edx
callq 0x4990
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x1db20
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, 0x62dd8(%rip)     # 0x7feb0
movq $0x7000, 0x678c5(%rip) # imm = 0x7000
movq $0x104009, 0x678c2(%rip) # imm = 0x104009
movq $0x109008, 0x678bf(%rip) # imm = 0x109008
movq $0x10d009, 0x678bc(%rip) # imm = 0x10D009
movq $0x10900c, 0x678b9(%rip) # imm = 0x10900C
movq $0x10b008, 0x678b6(%rip) # imm = 0x10B008
movq $0x105008, 0x678b3(%rip) # imm = 0x105008
movq $0x100000c, 0x678c8(%rip) # imm = 0x100000C
movq $0x100000b, 0x678c5(%rip) # imm = 0x100000B
movq $0x1000017, 0x678c2(%rip) # imm = 0x1000017
movq $0x100000f, 0x678bf(%rip) # imm = 0x100000F
movq $0x10900c, 0x678bc(%rip) # imm = 0x10900C
movq $0x7000, 0x678b9(%rip) # imm = 0x7000
movq $0x100000d, 0x678b6(%rip) # imm = 0x100000D
movl $0x0, -0x74(%rbp)
cmpl $0x80, -0x74(%rbp)
jge 0x1d1b1
movslq -0x74(%rbp), %rcx
leaq 0x68303(%rip), %rax     # 0x85490
movl $0x34, (%rax,%rcx,4)
movslq -0x74(%rbp), %rcx
leaq 0x67af1(%rip), %rax     # 0x84c90
movl $0x2e, (%rax,%rcx,4)
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x1d179
movl $0x0, -0x78(%rbp)
cmpl $0xa, -0x78(%rbp)
jge 0x1d1f7
movl -0x78(%rbp), %eax
addl $0x30, %eax
movslq %eax, %rcx
leaq 0x682c2(%rip), %rax     # 0x85490
movl $0x1, (%rax,%rcx,4)
movl -0x78(%rbp), %eax
addl $0x30, %eax
movslq %eax, %rcx
leaq 0x67aab(%rip), %rax     # 0x84c90
movl $0x25, (%rax,%rcx,4)
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x1d1b8
movl $0x0, -0x7c(%rbp)
cmpl $0x1a, -0x7c(%rbp)
jge 0x1d26b
movl -0x7c(%rbp), %eax
addl $0x41, %eax
movslq %eax, %rcx
leaq 0x6827c(%rip), %rax     # 0x85490
movl $0x0, (%rax,%rcx,4)
movl -0x7c(%rbp), %eax
addl $0x41, %eax
movslq %eax, %rcx
leaq 0x67a65(%rip), %rax     # 0x84c90
movl $0x25, (%rax,%rcx,4)
movl -0x7c(%rbp), %eax
addl $0x61, %eax
movslq %eax, %rcx
leaq 0x6824e(%rip), %rax     # 0x85490
movl $0x0, (%rax,%rcx,4)
movl -0x7c(%rbp), %eax
addl $0x61, %eax
movslq %eax, %rcx
leaq 0x67a37(%rip), %rax     # 0x84c90
movl $0x25, (%rax,%rcx,4)
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x1d1fe
movl $0x0, -0x80(%rbp)
cmpl $0x1f, -0x80(%rbp)
jge 0x1d2e7
movl -0x80(%rbp), %eax
addl $0xc0, %eax
movslq %eax, %rcx
leaq 0x68206(%rip), %rax     # 0x85490
movl $0x0, (%rax,%rcx,4)
movl -0x80(%rbp), %eax
addl $0xc0, %eax
movslq %eax, %rcx
leaq 0x679ed(%rip), %rax     # 0x84c90
movl $0x25, (%rax,%rcx,4)
movl -0x80(%rbp), %eax
addl $0xe0, %eax
movslq %eax, %rcx
leaq 0x681d4(%rip), %rax     # 0x85490
movl $0x0, (%rax,%rcx,4)
movl -0x80(%rbp), %eax
addl $0xe0, %eax
movslq %eax, %rcx
leaq 0x679bb(%rip), %rax     # 0x84c90
movl $0x25, (%rax,%rcx,4)
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x1d272
movl $0x3, 0x6823b(%rip)     # 0x8552c
movl $0x2, 0x68311(%rip)     # 0x8560c
movl $0x4, 0x6827b(%rip)     # 0x85580
movl $0x5, 0x68279(%rip)     # 0x85588
movl $0x5, 0x67a23(%rip)     # 0x84d3c
movl $0x6, 0x67a21(%rip)     # 0x84d44
movl $0x0, 0x67a0b(%rip)     # 0x84d38
movl $0x1, 0x67a15(%rip)     # 0x84d4c
movl $0x9, 0x67a43(%rip)     # 0x84d84
movl $0x2, 0x679dd(%rip)     # 0x84d28
movl $0xc, 0x67a33(%rip)     # 0x84d88
movl $0xa, 0x67a21(%rip)     # 0x84d80
movl $0x8, 0x679b3(%rip)     # 0x84d1c
movl $0x9, 0x67a11(%rip)     # 0x84d84
movl $0xa, 0x681bf(%rip)     # 0x8553c
movl $0xa, 0x681bd(%rip)     # 0x85544
movl $0x9, 0x681a7(%rip)     # 0x85538
movl $0x9, 0x681b1(%rip)     # 0x8554c
movl $0x9, 0x68183(%rip)     # 0x85528
movl $0xe, 0x68191(%rip)     # 0x85540
movl $0x10, 0x6818f(%rip)    # 0x85548
movl $0x11, 0x681cd(%rip)    # 0x85590
movl $0x11, 0x6823b(%rip)    # 0x85608
movl $0x7, 0x68159(%rip)     # 0x85530
movl $0xc, 0x68153(%rip)     # 0x85534
movl $0xf, 0x68191(%rip)     # 0x8557c
movl $0x8, 0x68207(%rip)     # 0x855fc
movl $0xd, 0x68205(%rip)     # 0x85604
movl $0xb, 0x68113(%rip)     # 0x8551c
movl $0xb, 0x68171(%rip)     # 0x85584
movl $0x12, 0x6815b(%rip)    # 0x85578
movl $0x6, 0x68261(%rip)     # 0x85688
movl $0x32, 0x6824b(%rip)    # 0x8567c
movl $0x33, 0x68249(%rip)    # 0x85684
movl $0x15, 0x66dbf(%rip)    # 0x84204
movl $0x16, 0x66db9(%rip)    # 0x84208
movl $0x13, 0x66ceb(%rip)    # 0x84144
movl $0x14, 0x66ce5(%rip)    # 0x84148
movl $0xf, 0x66c03(%rip)     # 0x84070
movl $0x10, 0x66bfd(%rip)    # 0x84074
movl $0x11, 0x66caf(%rip)    # 0x84130
movl $0x12, 0x66ca9(%rip)    # 0x84134
movq $0x0, 0xbb58a(%rip) # 0xd8a20
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x1c830
cmpq $0x0, 0xbb576(%rip)     # 0xd8a20
je 0x1d4c1
movq 0x21e25(%rip), %rsi     # 0x3f2d8
leaq 0x14e79(%rip), %rdi     # 0x32333
movb $0x0, %al
callq 0x4030
movq $0x0, 0x62a54(%rip) # 0x7ff20
leaq 0x62a4d(%rip), %rax     # 0x7ff20
movq %rax, -0x180(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x242d0
leaq 0x1597b(%rip), %rdi     # 0x32e68
callq 0x7860
movq %rax, 0x62c47(%rip)     # 0x80140
leaq 0x14ce4(%rip), %rdi     # 0x321e4
callq 0x7860
movq %rax, 0x62c3c(%rip)     # 0x80148
leaq 0x1595e(%rip), %rdi     # 0x32e71
callq 0x7860
movq %rax, 0x62c31(%rip)     # 0x80150
leaq 0x15953(%rip), %rdi     # 0x32e79
callq 0x7860
movq %rax, 0x62c06(%rip)     # 0x80138
movq 0x22937(%rip), %rdi     # 0x3fe70
callq 0x91c0
movq -0x180(%rbp), %rsi
movb %al, 0x2292d(%rip)      # 0x3fe78
movq 0x62b0e(%rip), %rdx     # 0x80060
leaq -0x138(%rbp), %rdi
callq 0x1a670
jmp 0x1d560
leaq -0x138(%rbp), %rdi
callq 0x24090
jmp 0x1d5de
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
movl -0x144(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x1d86d
movq -0x140(%rbp), %rdi
callq 0x40e0
movl (%rax), %eax
movl %eax, -0x148(%rbp)
cmpl $0x270f, -0x148(%rbp)   # imm = 0x270F
jne 0x1d5bf
movl $0xe, -0x14c(%rbp)
jmp 0x1d5c9
movl $0x0, -0x14c(%rbp)
callq 0x4480
movl -0x14c(%rbp), %eax
testl %eax, %eax
je 0x1d5dc
jmp 0x1d5da
jmp 0x1d5e9
jmp 0x1d5de
testb $0x1, 0x62a51(%rip)     # 0x80036
je 0x1d613
jmp 0x1d5e9
movq 0x62980(%rip), %rsi     # 0x7ff70
subq $0x1, %rsi
movq 0x6296d(%rip), %rdx     # 0x7ff68
leaq 0x1587b(%rip), %rdi     # 0x32e7d
movb $0x0, %al
callq 0x4030
movl $0x1, %edi
callq 0x43a0
callq 0x1c180
movq 0x21cb1(%rip), %rdi     # 0x3f2d0
leaq 0x14a83(%rip), %rsi     # 0x320a9
callq 0x4380
movq %rax, -0x158(%rbp)
cmpq $0x0, -0x158(%rbp)
jne 0x1d671
movq 0x21995(%rip), %rax     # 0x3efd8
movq (%rax), %rdi
movq 0xbb3fb(%rip), %rdx     # 0xd8a48
leaq 0x15843(%rip), %rsi     # 0x32e97
movb $0x0, %al
callq 0x4430
movq 0x21c6e(%rip), %rdi     # 0x3f2d0
callq 0x4240
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x43a0
testb $0x1, 0x629b8(%rip)     # 0x80030
je 0x1d797
movl $0x0, -0x15c(%rbp)
movl $0x1, -0x160(%rbp)
movslq -0x160(%rbp), %rax
cmpq 0x62860(%rip), %rax     # 0x7ff00
jge 0x1d6d8
movq -0x158(%rbp), %rdi
movslq -0x160(%rbp), %rcx
leaq 0x66bf9(%rip), %rax     # 0x842b0
movq (%rax,%rcx,8), %rdx
leaq -0x15c(%rbp), %rsi
callq 0x1c550
movl -0x160(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x160(%rbp)
jmp 0x1d692
movq $0x0, -0x168(%rbp)
movq -0x168(%rbp), %rax
movq %rax, -0x188(%rbp)
leaq 0xbb310(%rip), %rdi     # 0xd8a08
callq 0x24440
movq %rax, %rcx
movq -0x188(%rbp), %rax
cmpq %rcx, %rax
jae 0x1d757
movq -0x158(%rbp), %rax
movq %rax, -0x190(%rbp)
movq -0x168(%rbp), %rsi
leaq 0xbb2e0(%rip), %rdi     # 0xd8a08
callq 0x24160
movq -0x190(%rbp), %rdi
movq (%rax), %rdx
leaq -0x15c(%rbp), %rsi
callq 0x1c550
movq -0x168(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x168(%rbp)
jmp 0x1d6e3
jmp 0x1d759
movl -0x15c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x15c(%rbp)
movl $0x10, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x1d792
movq -0x158(%rbp), %rdi
leaq 0x14d13(%rip), %rsi     # 0x32498
xorl %eax, %eax
movl %eax, %edx
movb $0x0, %al
callq 0x4430
jmp 0x1d759
jmp 0x1d85a
movq -0x158(%rbp), %rcx
leaq 0x140d7(%rip), %rdi     # 0x3187c
movl $0x6, %esi
movl $0x1, %edx
callq 0x4560
movq $0x7, -0x170(%rbp)
movq -0x170(%rbp), %rax
movq %rax, -0x198(%rbp)
leaq 0xbb234(%rip), %rdi     # 0xd8a08
callq 0x24440
movq %rax, %rcx
movq -0x198(%rbp), %rax
cmpq %rcx, %rax
jae 0x1d858
movl $0x28, -0x174(%rbp)
cmpl $0x0, -0x174(%rbp)
jl 0x1d83f
movq -0x170(%rbp), %rsi
leaq 0xbb1ff(%rip), %rdi     # 0xd8a08
callq 0x24160
movq (%rax), %rax
movl -0x174(%rbp), %ecx
sarq %cl, %rax
andq $0xff, %rax
movl %eax, %edi
movq -0x158(%rbp), %rsi
callq 0x43d0
movl -0x174(%rbp), %eax
subl $0x8, %eax
movl %eax, -0x174(%rbp)
jmp 0x1d7f2
jmp 0x1d841
movq -0x170(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x170(%rbp)
jmp 0x1d7bf
jmp 0x1d85a
movq -0x158(%rbp), %rdi
callq 0x42a0
xorl %edi, %edi
callq 0x43a0
movq -0x140(%rbp), %rdi
callq 0x44c0
nopl (%rax)