// File: /workspace/github_c_makefile_star2_O0/vtereshkov[P]umka-lang/src/umka_stmt.c
// Function: parseTypeCase
static void parseTypeCase(Compiler *comp, const char *concreteVarName, ConstArray *existingConcreteTypes)
{
    lexEat(&comp->lex, TOK_CASE);

    // type
    const Type *concreteType = parseType(comp, NULL);
    if (concreteType->kind == TYPE_INTERFACE)
        comp->error.handler(comp->error.context, "Non-interface type expected");

    Const concreteTypeAsConst = {.ptrVal = (Type *)concreteType};
    if (constArrayFindEquivalentType(&comp->consts, existingConcreteTypes, concreteTypeAsConst) >= 0)
        comp->error.handler(comp->error.context, "Duplicate case type");
    constArrayAppend(existingConcreteTypes, concreteTypeAsConst);

    const Type *concretePtrType = concreteType;
    if (concreteType->kind != TYPE_PTR)
        concretePtrType = typeAddPtrTo(&comp->types, &comp->blocks, concreteType);

    genDup(&comp->gen);                             // Duplicate interface expression
    genAssertType(&comp->gen, concretePtrType);

    genDup(&comp->gen);                             // Duplicate expression converted to the concrete type
    genPushGlobalPtr(&comp->gen, NULL);
    genBinary(&comp->gen, TOK_NOTEQ, TYPE_PTR, 0);

    genIfCondEpilog(&comp->gen);

    // ":" stmtList
    lexEat(&comp->lex, TOK_COLON);

    // Additional scope embracing stmtList
    blocksEnter(&comp->blocks);

    // Allocate and initialize concrete-type variable
    const Ident *concreteIdent = identAllocVar(&comp->idents, &comp->types, &comp->modules, &comp->blocks, concreteVarName, concreteType, false);
    identSetUsed(concreteIdent);                     // Do not warn about unused concrete variable
    doZeroVar(comp, concreteIdent);

    if (concreteType->kind != TYPE_PTR)
        genDeref(&comp->gen, concreteType->kind);

    doPushVarPtr(comp, concreteIdent);
    genSwapChangeRefCntAssign(&comp->gen, concreteType);

    parseStmtList(comp);

    // Additional scope embracing stmtList
    doGarbageCollection(comp);
    identWarnIfUnusedAll(&comp->idents, blocksCurrent(&comp->blocks));
    blocksLeave(&comp->blocks);

    genElseProlog(&comp->gen);

    genPop(&comp->gen);                 // Remove duplicate interface expression
}

// 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
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x9b80
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x17, (%rax)
jne 0x20064
movq -0x8(%rbp), %rax
movq 0x50f8(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x5118(%rax), %rdi
leaq 0x1b9ad5(%rip), %rsi    # 0x1d9b35
movb $0x0, %al
callq *%rcx
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
addq $0x4e68, %rdi           # imm = 0x4E68
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x9830
cmpl $0x0, %eax
jl 0x200aa
movq -0x8(%rbp), %rax
movq 0x50f8(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x5118(%rax), %rdi
leaq 0x1b9aab(%rip), %rsi    # 0x1d9b51
movb $0x0, %al
callq *%rcx
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x9720
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x10, (%rax)
je 0x200eb
movq -0x8(%rbp), %rdi
addq $0x4e18, %rdi           # imm = 0x4E18
movq -0x8(%rbp), %rsi
addq $0x4220, %rsi           # imm = 0x4220
movq -0x20(%rbp), %rdx
callq 0x21fa0
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
callq 0x16eb0
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movq -0x30(%rbp), %rsi
callq 0x17c70
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
callq 0x16eb0
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
xorl %eax, %eax
movl %eax, %esi
callq 0x16950
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movl $0x34, %esi
movl $0x10, %edx
xorl %ecx, %ecx
callq 0x17790
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
callq 0x18580
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
movl $0x41, %esi
callq 0x1b150
movq -0x8(%rbp), %rdi
addq $0x4220, %rdi           # imm = 0x4220
callq 0x5e60
movq -0x8(%rbp), %rdi
addq $0x4e38, %rdi           # imm = 0x4E38
movq -0x8(%rbp), %rsi
addq $0x4e18, %rsi           # imm = 0x4E18
movq -0x8(%rbp), %rdx
addq $0x100, %rdx            # imm = 0x100
movq -0x8(%rbp), %rcx
addq $0x4220, %rcx           # imm = 0x4220
movq -0x10(%rbp), %r8
movq -0x20(%rbp), %r9
xorl %eax, %eax
movl $0x0, (%rsp)
callq 0x1a450
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0x1ed60
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x1d5e0
movq -0x20(%rbp), %rax
cmpl $0x10, (%rax)
je 0x201ff
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movq -0x20(%rbp), %rax
movl (%rax), %esi
callq 0x16fa0
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xd010
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movq -0x20(%rbp), %rsi
callq 0x17500
movq -0x8(%rbp), %rdi
callq 0x1ec10
movq -0x8(%rbp), %rdi
callq 0x1d3a0
movq -0x8(%rbp), %rax
addq $0x4e38, %rax           # imm = 0x4E38
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
addq $0x4220, %rdi           # imm = 0x4220
callq 0x6020
movq -0x40(%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 0x18670
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
callq 0x16d30
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)