// File: /workspace/github_cpp_makefile_star2_O1/besm6[P]pascal-re/pascompl.cc
// Function: caseStatement()
void caseStatement()
{
    typedef struct CaseClause : public BESM6Obj {
        CaseClause * next;
        Word value;
        int64_t offset;
    } * CaseClausePtr;

    CaseClausePtr allClauses, curClause, clause, old = NULL;
    bool isIntCase;
    bool otherSeen;
    int64_t otherOffset = -1;
    bool itemsEnded, goodMode;
    TypesPtr firstType, itemtype, exprtype;
    Word itemvalue;
    int64_t itemSpan;
    Word expected;
    int64_t startLine, l4var17z, endOfStmt;
    Word minValue, maxValue;

    startLine = lineCnt;
    expression();
    exprtype = curExpr->typ;
    otherSeen = false;
    if (exprtype == AlfaType or
        (exprtype->k == kindScalar || exprtype->k == kindRange))
        (void) formOperator(LOAD);
    else
        error(25); /* errExprNotOfADiscreteType */
    disableNorm();
    l4var17z = 0;
    endOfStmt = 0;
    allClauses = NULL;
    formJump(l4var17z);
    checkSymAndRead(OFSY);
    firstType = NULL;
    goodMode = true;
    do {
        if (not (SY == SEMICOLON || SY == ENDSY)) {
            padToLeft();
            arithMode = 1;
            if (SY == OTHERSY) {
                if (otherSeen)
                    error(73); /* errCaseLabelsIdentical */
                inSymbol();
                otherSeen = true;
                otherOffset = moduleOffset;
            } else do {
                    parseLiteral(itemtype, itemvalue, true);
                    if (itemtype != NULL) {
                        if (firstType == NULL) {
                            firstType = itemtype;
                        } else {
                            if (not typeCheck(itemtype, firstType))
                                error(errConstOfOtherTypeNeeded);
                        } /* 15700 */
                        clause = new CaseClause;
                        clause->value = itemvalue;
                        clause->offset = moduleOffset;
                        curClause = allClauses;
                        while (curClause != NULL) {
                            if (itemvalue == curClause->value) {
                                error(73); /* errCaseLabelsIdentical */
                                break;
                            } else if (itemvalue.i < curClause->value.i) {
                                break;
                            } else {
                                old = curClause;
                                curClause = curClause->next;
                            }
                        } /* 15723 */
                        if (curClause == allClauses) {
                            clause->next = allClauses;
                            allClauses = clause;
                        } else {
                            clause->next = curClause;
                            old->next = clause;
                        }
                        inSymbol();
                    } /* 15735 */
                  itemsEnded = (SY != COMMA);
                  if (not itemsEnded)
                      inSymbol();
                } while (!itemsEnded);
            checkSymAndRead(COLON);
            Statement();
            goodMode = goodMode and (arithMode == 1);
            formJump(endOfStmt);
        } /* 15762 */
        itemsEnded = (SY == ENDSY);
        if (not itemsEnded)
            inSymbol();
    } while (!itemsEnded);
    if (SY != ENDSY) {
        requiredSymErr(ENDSY);
        stmtName = "CASE  ";
        reportStmtType(startLine);
    } else
        inSymbol();
    if (not typeCheck(firstType, exprtype)) {
        error(88); /* errDifferentTypesOfLabelsAndExpr */;
        return;
    }
    padToLeft();
    isIntCase = typeCheck(exprtype, IntegerType);
    if (allClauses != NULL) {
        expected = allClauses->value;
        minValue = expected;
        curClause = allClauses;
        while (curClause != NULL) {
            if (expected == curClause->value and
                exprtype->k == kindScalar) {
                maxValue = expected;
                if (isIntCase) {
                    expected.i = expected.i + 1; // Integers with exponent
                } else {
                    curVal = expected;
                    curVal.ii = curVal.ii + 1; // Integers without exponent
                    expected = curVal;
                }
                curClause = curClause->next;
            } else {
                itemSpan = 34000;
                P0715(0, l4var17z);
                if (firstType->k == kindRange) {
                    itemSpan = std::max(std::abs(firstType->cast<RangeT>().left),
                                        std::abs(firstType->cast<RangeT>().right));
                } else {
                    if (firstType->k == kindScalar)
                        itemSpan = firstType->cast<ScalarT>().numen;
                }
                itemsEnded = (itemSpan < 32000);
                if (itemsEnded) {
                    form1Insn(KATI+14);
                } else {
                    form1Insn(KATX+SP+1);
                }
                minValue.i = (minValue.i - minValue.i); /* WTF? */
                while (allClauses != NULL) {
                    if (itemsEnded) {
                        curVal.i = (minValue.i - allClauses->value.i);
                        curVal.i = curVal.ii;
                        form1Insn(getValueOrAllocSymtab(curVal.i) +
                                  (KUTM+I14));
                        form1Insn(KVZM+I14 + allClauses->offset);
                        minValue = allClauses->value;
                    } else {
                        form1Insn(KXTA+SP+1);
                        curVal = allClauses->value;
                        form2Insn(KAEX + I8 + getFCSToffset(),
                                  InsnTemp[UZA] + allClauses->offset);
                    }
                    allClauses = allClauses->next;
                }
                if (otherSeen)
                    form1Insn(InsnTemp[UJ] + otherOffset);
                goto L16211;
            } /* if 16141 */
        } /* while 16142 */
        if (not otherSeen) {
            otherOffset = moduleOffset;
            formJump(endOfStmt);
        }
        P0715(0, l4var17z);
        curVal = minValue;
        P0715(-(InsnTemp[U1A]+otherOffset), maxValue.i);
        curVal = minValue;
        curVal.i = curVal.ii;
        form1Insn(KATI+14);
        curVal.i = ((moduleOffset + (1)) - curVal.i);
        if (curVal.i < 040000) {
            curVal.i = (curVal.i - 040000);
            curVal.i = allocSymtab(041000000 | (curVal.ii & 077777));
        }
        form1Insn(KUJ+I14 + curVal.i);
        while (allClauses != NULL) {
            padToLeft();
            form1Insn(InsnTemp[UJ] + allClauses->offset);
            allClauses = allClauses->next;
        }
L16211:
        P0715(0, endOfStmt);
        if (not goodMode)
            disableNorm();
        /* 16217 */
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x888, %rsp            # imm = 0x888
callq 0xebcc
movq 0x54e6b(%rip), %rax     # 0x64ab0
movq (%rax), %rax
cmpq 0x54dc1(%rip), %rax     # 0x64a10
movq %rax, 0x8(%rsp)
je 0xfc60
movl 0x10(%rax), %eax
decl %eax
cmpl $0x1, %eax
ja 0xfc7c
leaq 0xf0(%rsp), %rdi
movl $0x2, %esi
callq 0xc044
addq $-0x8, 0xad756(%rip)    # 0xbd3d0
jmp 0xfc86
movl $0x19, %edi
callq 0x589e
cmpq $0x1, 0x54c5a(%rip)     # 0x648e8
je 0xfca7
movq 0x14601(%rip), %rdi     # 0x24298
callq 0x5941
movq $0x1, 0x54c41(%rip) # 0x648e8
movabsq $0x1ffffffffff, %rbp    # imm = 0x1FFFFFFFFFF
xorl %r14d, %r14d
leaq 0x30(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x20(%rsp), %rax
movq %r14, (%rax)
callq 0x5ac6
movl $0x2a, %edi
callq 0x82d3
movb $0x1, 0x7(%rsp)
movq $-0x1, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
xorl %r15d, %r15d
xorl %r12d, %r12d
movl 0x54b36(%rip), %eax     # 0x6482c
cmpl $0xf, %eax
je 0xfda9
cmpl $0x27, %eax
je 0xfda9
cmpb $0x0, 0x54c75(%rip)     # 0x64984
jne 0xfd1d
movq 0x597a0(%rip), %rdi     # 0x694b8
callq 0x5941
movq $0x0, 0x54c40(%rip) # 0x64968
movq $0x1, 0x54bb5(%rip) # 0x648e8
cmpl $0x31, 0x54af2(%rip)    # 0x6482c
jne 0xfdc8
testb $0x1, 0x10(%rsp)
je 0xfd51
movl $0x49, %edi
callq 0x589e
leaq 0x718(%rsp), %rdi
callq 0x6e26
movb $0x1, %al
movq %rax, 0x10(%rsp)
movq 0x54b2c(%rip), %rax     # 0x64898
movq %rax, 0x18(%rsp)
movl $0x12, %edi
callq 0x82d3
leaq 0x98(%rsp), %rdi
callq 0x10652
addq $-0x8, 0xad6a8(%rip)    # 0xbd438
cmpq $0x1, 0x54b50(%rip)     # 0x648e8
sete %al
andb %al, 0x7(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x5ac6
cmpl $0x27, 0x54a7c(%rip)    # 0x6482c
je 0xfec5
leaq 0x2c8(%rsp), %rdi
callq 0x6e26
jmp 0xfcf0
leaq 0x48(%rsp), %rdi
leaq 0x40(%rsp), %rsi
movl $0x1, %edx
callq 0x8027
movq 0x48(%rsp), %rsi
testq %rsi, %rsi
je 0xfea6
testq %r15, %r15
je 0xfe17
leaq 0x50(%rsp), %rdi
movq %r15, %rdx
callq 0x83b2
addq $-0x8, 0xad5b4(%rip)    # 0xbd3b8
cmpb $0x0, 0x50(%rsp)
jne 0xfe1a
movl $0x7, %edi
callq 0x589e
jmp 0xfe1a
movq %rsi, %r15
movl $0x18, %edi
callq 0x3d03
movq %rax, %r13
movq 0x40(%rsp), %rax
movq %rax, 0x8(%r13)
movq 0x54a61(%rip), %rcx     # 0x64898
movq %rcx, 0x10(%r13)
testq %r12, %r12
je 0xfe72
movq %rax, %rcx
shlq $0x17, %rcx
movq %r12, %rdx
movq %rdx, %rbx
movq 0x8(%rdx), %rdx
movq %rdx, %rsi
xorq %rax, %rsi
testq %rbp, %rsi
je 0xfe77
shlq $0x17, %rdx
cmpq %rdx, %rcx
jl 0xfe81
movq (%rbx), %rdx
movq %rbx, %r14
testq %rdx, %rdx
jne 0xfe4a
jmp 0xfe84
movq %r12, %rdx
jmp 0xfe84
movl $0x49, %edi
callq 0x589e
movq %rbx, %rdx
cmpq %r12, %rdx
je 0xfe92
movq %rdx, (%r13)
movq %r13, (%r14)
jmp 0xfe99
movq %r12, (%r13)
movq %r13, %r12
leaq 0x5a8(%rsp), %rdi
callq 0x6e26
cmpl $0xe, 0x5497f(%rip)     # 0x6482c
jne 0xfd71
leaq 0x438(%rsp), %rdi
callq 0x6e26
jmp 0xfdc8
leaq 0x158(%rsp), %rdi
callq 0x6e26
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movq 0x8(%rsp), %rdx
callq 0x83b2
addq $-0x8, 0xad4c9(%rip)    # 0xbd3b8
cmpb $0x0, (%rbx)
je 0x10107
cmpb $0x0, 0x54a85(%rip)     # 0x64984
jne 0xff0d
movq 0x595b0(%rip), %rdi     # 0x694b8
callq 0x5941
movq $0x0, 0x54a50(%rip) # 0x64968
movq 0x54ad9(%rip), %rdx     # 0x649f8
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0x83b2
movb (%rbx), %bl
addq $-0x8, 0xad47d(%rip)    # 0xbd3b8
testq %r12, %r12
je 0x1029f
movq 0x8(%r12), %rax
leaq 0x50(%rsp), %rcx
movq %rax, (%rcx)
movq %rax, 0x38(%rsp)
movq %rax, 0x28(%rsp)
movq %r12, %r13
movq 0x8(%rsp), %rcx
movq 0x50(%rsp), %r14
movq 0x8(%r13), %rax
xorq %r14, %rax
testq %rbp, %rax
jne 0x10116
cmpl $0x1, 0x10(%rcx)
jne 0x10116
testb %bl, %bl
je 0xffa5
movq %r14, %rsi
shlq $0x17, %rsi
sarq $0x17, %rsi
incq %rsi
leaq 0x50(%rsp), %rdi
callq 0x3bf2
movq 0x8(%rsp), %rcx
jmp 0xffb5
leaq 0x1(%r14), %rax
movq %rax, 0x54a90(%rip)     # 0x64a40
movq %rax, 0x50(%rsp)
movq (%r13), %r13
testq %r13, %r13
jne 0xff63
testb $0x1, 0x10(%rsp)
movq 0x18(%rsp), %rbx
jne 0xffdb
movq 0x548c7(%rip), %rbx     # 0x64898
leaq 0x20(%rsp), %rdi
callq 0x5ac6
movq 0x30(%rsp), %rsi
xorl %edi, %edi
callq 0x617f
movq 0x38(%rsp), %r13
movq %r13, 0x54a4d(%rip)     # 0x64a40
addq 0x594e6(%rip), %rbx     # 0x694e0
leaq 0x54a3f(%rip), %r15     # 0x64a40
negq %rbx
shlq $0x17, %r14
sarq $0x17, %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x617f
movq %r13, 0x54a22(%rip)     # 0x64a40
movq %r15, %rdi
movq %r13, %rsi
callq 0x3bf2
movl $0x2000e, %edi          # imm = 0x2000E
callq 0x5941
movq 0x5485e(%rip), %rax     # 0x64898
movq 0x549ff(%rip), %rcx     # 0x64a40
shlq $0x17, %rcx
sarq $0x17, %rcx
negq %rcx
leaq (%rax,%rcx), %rsi
incq %rsi
movq %r15, %rdi
callq 0x3bf2
movq 0x549de(%rip), %rsi     # 0x64a40
shlq $0x17, %rsi
sarq $0x17, %rsi
cmpq $0x3fff, %rsi           # imm = 0x3FFF
jg 0x100ad
addq $-0x4000, %rsi          # imm = 0xC000
leaq 0x549bf(%rip), %rbx     # 0x64a40
movq %rbx, %rdi
callq 0x3bf2
movq 0x549b0(%rip), %rdi     # 0x64a40
andl $0x7fff, %edi           # imm = 0x7FFF
orq $0x840000, %rdi         # imm = 0x840000
callq 0x5e79
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3bf2
movq 0x5498c(%rip), %rdi     # 0x64a40
shlq $0x17, %rdi
sarq $0x17, %rdi
addq $0xec0000, %rdi         # imm = 0xEC0000
callq 0x5941
cmpb $0x0, 0x548b5(%rip)     # 0x64984
jne 0x100dd
movq 0x593e0(%rip), %rdi     # 0x694b8
callq 0x5941
movq $0x0, 0x54880(%rip) # 0x64968
movq 0x10(%r12), %rdi
addq 0x593f4(%rip), %rdi     # 0x694e8
callq 0x5941
movq (%r12), %r12
testq %r12, %r12
jne 0x100c8
jmp 0x1026b
movl $0x58, %edi
callq 0x589e
jmp 0x1029f
movq 0x30(%rsp), %rsi
xorl %edi, %edi
callq 0x617f
movl 0x10(%r15), %eax
cmpl $0x1, %eax
je 0x1015b
movl $0x84d0, %r13d          # imm = 0x84D0
cmpl $0x2, %eax
jne 0x1015f
movq 0x28(%r15), %rax
movq 0x30(%r15), %rcx
movq %rax, %rdx
negq %rdx
cmovsq %rax, %rdx
movq %rcx, %r13
negq %r13
cmovsq %rcx, %r13
cmpq %r13, %rdx
cmovaq %rdx, %r13
jmp 0x1015f
movq 0x20(%r15), %r13
cmpq $0x7d00, %r13           # imm = 0x7D00
movl $0x2000e, %eax          # imm = 0x2000E
movl $0xf00001, %edi         # imm = 0xF00001
cmovlq %rax, %rdi
callq 0x5941
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3bf2
movq (%rbx), %r14
leaq 0x548ae(%rip), %rbx     # 0x64a40
movl $0xee0000, %ebp         # imm = 0xEE0000
cmpq $0x7cff, %r13           # imm = 0x7CFF
jg 0x1020b
shlq $0x17, %r14
sarq $0x17, %r14
movq 0x8(%r12), %rax
shlq $0x17, %rax
sarq $0x17, %rax
subq %rax, %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3bf2
movq 0x54876(%rip), %rsi     # 0x64a40
movq %rbx, %rdi
callq 0x3bf2
movq 0x54867(%rip), %rdi     # 0x64a40
shlq $0x17, %rdi
sarq $0x17, %rdi
callq 0x6128
leaq 0xea8000(%rax), %rdi
callq 0x5941
movq 0x10(%r12), %rdi
addq %rbp, %rdi
callq 0x5941
movq 0x8(%r12), %r14
movq %r14, 0x28(%rsp)
jmp 0x10246
movl $0xf08001, %edi         # imm = 0xF08001
callq 0x5941
movq 0x8(%r12), %rax
movq %rax, 0x5481f(%rip)     # 0x64a40
callq 0x5f9d
leaq 0x80a000(%rax), %rdi
movq 0x10(%r12), %r15
addq 0x5929f(%rip), %r15     # 0x694d8
callq 0x5941
movq %r15, %rdi
callq 0x5941
movq (%r12), %r12
testq %r12, %r12
jne 0x10197
testb $0x1, 0x10(%rsp)
je 0x1026b
movq 0x18(%rsp), %rdi
addq 0x59282(%rip), %rdi     # 0x694e8
callq 0x5941
movq 0x20(%rsp), %rsi
xorl %edi, %edi
callq 0x617f
testb $0x1, 0x7(%rsp)
jne 0x1029f
cmpq $0x1, 0x54662(%rip)     # 0x648e8
je 0x1029f
movq 0x14009(%rip), %rdi     # 0x24298
callq 0x5941
movq $0x1, 0x54649(%rip) # 0x648e8
addq $0x888, %rsp            # imm = 0x888
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq