// File: /workspace/github_c_makefile_star2_O0/vtereshkov[P]umka-lang/src/umka_stmt.c
// Function: parseExprCase
static void parseExprCase(Compiler *comp, const Type *selectorType, ConstArray *existingConstants)
{
    lexEat(&comp->lex, TOK_CASE);

    // expr {"," expr}
    int numCaseConstants = 0;

    while (1)
    {
        Const constant;
        const Type *type = selectorType;
        parseExpr(comp, &type, &constant);
        doAssertImplicitTypeConv(comp, selectorType, &type, &constant);

        if (typeOverflow(selectorType->kind, constant))
            comp->error.handler(comp->error.context, "Overflow of %s", typeKindSpelling(selectorType->kind));

        if (constArrayFind(&comp->consts, existingConstants, constant) >= 0)
            comp->error.handler(comp->error.context, "Duplicate case constant");
        constArrayAppend(existingConstants, constant);

        genCaseConstantCheck(&comp->gen, &constant);
        numCaseConstants++;

        if (comp->lex.tok.kind != TOK_COMMA)
            break;
        lexNext(&comp->lex);
    }

    // ":" stmtList
    lexEat(&comp->lex, TOK_COLON);

    genCaseBlockProlog(&comp->gen, numCaseConstants);

    // Additional scope embracing stmtList
    blocksEnter(&comp->blocks);

    parseStmtList(comp);

    // Additional scope embracing stmtList
    doGarbageCollection(comp);
    identWarnIfUnusedAll(&comp->idents, blocksCurrent(&comp->blocks));
    blocksLeave(&comp->blocks);

    genCaseBlockEpilog(&comp->gen);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
movl $0x2, %esi
callq 0x1b150
movl $0x0, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x28(%rbp), %rdx
callq 0xe8c0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x30(%rbp), %rdx
leaq -0x28(%rbp), %rcx
callq 0xd6e0
movq -0x10(%rbp), %rax
movl (%rax), %edi
movq -0x28(%rbp), %rsi
callq 0x205f0
testb $0x1, %al
jne 0x203d3
jmp 0x20412
movq -0x8(%rbp), %rax
movq 0x50f8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x5118(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %edi
callq 0x23b40
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rcx
movq %rax, %rdx
leaq 0x1b7e72(%rip), %rsi    # 0x1d8280
movb $0x0, %al
callq *%rcx
movq -0x8(%rbp), %rdi
addq $0x4e68, %rdi           # imm = 0x4E68
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x97a0
cmpl $0x0, %eax
jl 0x20450
movq -0x8(%rbp), %rax
movq 0x50f8(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x5118(%rax), %rdi
leaq 0x1b972f(%rip), %rsi    # 0x1d9b7b
movb $0x0, %al
callq *%rcx
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x9720
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
leaq -0x28(%rbp), %rsi
callq 0x18720
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x3f, 0x4bd0(%rax)
je 0x20489
jmp 0x2049e
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
callq 0x1ad90
jmp 0x20390
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
movl $0x41, %esi
callq 0x1b150
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movl -0x1c(%rbp), %esi
callq 0x18780
movq -0x8(%rbp), %rdi
addq $0x4220, %rdi           # imm = 0x4220
callq 0x5e60
movq -0x8(%rbp), %rdi
callq 0x1ec10
movq -0x8(%rbp), %rdi
callq 0x1d3a0
movq -0x8(%rbp), %rax
addq $0x4e38, %rax           # imm = 0x4E38
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
addq $0x4220, %rdi           # imm = 0x4220
callq 0x6020
movq -0x48(%rbp), %rdi
movl %eax, %esi
callq 0x1a7e0
movq -0x8(%rbp), %rdi
addq $0x4220, %rdi           # imm = 0x4220
callq 0x5fa0
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
callq 0x187f0
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)