// File: /workspace/github_c_makefile_star2_O2/vtereshkov[P]umka-lang/src/umka_decl.c
// Function: parseVarDeclItem
static void parseVarDeclItem(Compiler *comp)
{
    IdentName varNames[MAX_IDENTS_IN_LIST];
    bool varExported[MAX_IDENTS_IN_LIST];
    int numVars = 0;
    const Type *varType = NULL;
    parseTypedIdentList(comp, varNames, varExported, MAX_IDENTS_IN_LIST, &numVars, &varType, false);

    Ident *var[MAX_IDENTS_IN_LIST];
    for (int i = 0; i < numVars; i++)
    {
        var[i] = identAllocVar(&comp->idents, &comp->types, &comp->modules, &comp->blocks, varNames[i], varType, varExported[i]);
        doZeroVar(comp, var[i]);
    }

    // Initializer
    if (comp->lex.tok.kind == TOK_EQ)
    {
        const Type *designatorType = NULL;
        if (typeStructured(var[0]->type))
            designatorType = var[0]->type;
        else
            designatorType = typeAddPtrTo(&comp->types, &comp->blocks, var[0]->type);

        if (numVars != 1)
        {
            // Designator list (types formally encoded as structure field types - not a real structure)
            Type *designatorListType = typeAdd(&comp->types, &comp->blocks, TYPE_STRUCT);
            designatorListType->isExprList = true;

            for (int i = 0; i < numVars; i++)
                typeAddField(&comp->types, designatorListType, designatorType, NULL);

            designatorType = designatorListType;
        }

        Const varPtrConstList[MAX_IDENTS_IN_LIST] = {0};

        for (int i = 0; i < numVars; i++)
        {
            if (comp->blocks.top == 0)          // Globals are initialized with constant expressions
                varPtrConstList[i].ptrVal = var[i]->ptr;
            else                                // Locals are assigned to
                doPushVarPtr(comp, var[i]);
        }

        lexNext(&comp->lex);
        parseAssignmentStmt(comp, designatorType, (comp->blocks.top == 0) ? varPtrConstList : NULL);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x11148, %rsp          # imm = 0x11148
movq %rdi, %r12
leaq 0x3c(%rsp), %r15
andl $0x0, (%r15)
leaq 0x30(%rsp), %rax
andq $0x0, (%rax)
movq %rax, %r9
andl $0x0, (%rsp)
leaq 0x1140(%rsp), %r14
leaq 0x40(%rsp), %rdx
movq %r14, %rsi
movl $0x100, %ecx            # imm = 0x100
movq %r15, %r8
callq 0x8091
movl (%r15), %ecx
leaq 0x4e38(%r12), %rbx
leaq 0x4e18(%r12), %rax
movq %rax, 0x18(%rsp)
leaq 0x100(%r12), %rbp
movq %r12, %r13
leaq 0x4220(%r12), %rax
movq %rax, 0x20(%rsp)
leaq 0x30(%rsp), %rax
movq (%rax), %r15
xorl %r12d, %r12d
testl %ecx, %ecx
movl $0x0, %eax
movl %ecx, 0x10(%rsp)
cmovgl %ecx, %eax
movl %eax, 0x14(%rsp)
movq %rax, 0x28(%rsp)
cmpq %r12, 0x28(%rsp)
je 0x87af
movzbl 0x40(%rsp,%r12), %eax
movl %eax, (%rsp)
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movq %rbp, %rdx
movq 0x20(%rsp), %rcx
movq %r14, %r8
movq %r15, %r9
callq 0x10a24
movq %rax, 0x140(%rsp,%r12,8)
movq %r13, %rdi
movq %rax, %rsi
callq 0x124c6
incq %r12
addq $0x100, %r14            # imm = 0x100
jmp 0x8765
cmpl $0x31, 0x4bd0(%r13)
jne 0x88a0
movq 0x140(%rsp), %rax
movq 0x108(%rax), %r14
movl (%r14), %eax
cmpl $0x18, %eax
ja 0x88b2
movl $0x1ec0000, %ecx        # imm = 0x1EC0000
btl %eax, %ecx
jae 0x88b2
movl 0x14(%rsp), %ebx
movl 0x10(%rsp), %eax
cmpl $0x1, %eax
je 0x8828
pushq $0x16
popq %rdx
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x14da9
movq %rax, %r15
movb $0x1, 0x14(%rax)
subl $0x1, %ebx
jb 0x8825
movq 0x18(%rsp), %rdi
movq %r15, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x159f0
jmp 0x880c
movq %r15, %r14
leaq 0x4ba8(%r13), %r12
leaq 0x940(%rsp), %r15
xorl %ebx, %ebx
movl $0x800, %edx            # imm = 0x800
movq %r15, %rdi
xorl %esi, %esi
callq 0x3190
cmpq %rbx, 0x28(%rsp)
je 0x887f
cmpl $0x0, 0x4b84(%r13)
movq 0x140(%rsp,%rbx,8), %rsi
je 0x886b
movq %r13, %rdi
callq 0x8c92
jmp 0x887a
movq 0x120(%rsi), %rax
movq %rax, 0x940(%rsp,%rbx,8)
incq %rbx
jmp 0x8848
movq %r12, %rdi
callq 0x10f6e
xorl %edx, %edx
cmpl $0x0, 0x4b84(%r13)
cmoveq %r15, %rdx
movq %r13, %rdi
movq %r14, %rsi
callq 0x127a5
addq $0x11148, %rsp          # imm = 0x11148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq %r14, %rdx
callq 0x15100
movq %rax, %r14
jmp 0x87e6