// File: /workspace/github_c_makefile_star2_O1/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 $0x11138, %rsp          # imm = 0x11138
movq %rdi, %r14
leaq 0x2c(%rsp), %rbx
movl $0x0, (%rbx)
leaq 0x1130(%rsp), %r15
leaq 0x30(%rsp), %rdx
movq %r15, %rsi
movl $0x100, %ecx            # imm = 0x100
movq %rbx, %r8
callq 0x10647
leaq 0x4ba8(%r14), %rdi
movq %rdi, 0x8(%rsp)
movl $0x41, %esi
callq 0x1b41f
movq %r14, 0x10(%rsp)
movq %r14, %rdi
xorl %esi, %esi
callq 0xfb34
movslq (%rbx), %rbp
testq %rbp, %rbp
jle 0x1163f
movq %rax, %r13
movq 0x10(%rsp), %rcx
leaq 0x4e38(%rcx), %rsi
movq %rsi, 0x20(%rsp)
leaq 0x4e18(%rcx), %rsi
movq %rsi, 0x18(%rsp)
leaq 0x100(%rcx), %r14
leaq 0x4220(%rcx), %rbx
xorl %r12d, %r12d
movzbl 0x30(%rsp,%r12), %ecx
movl %ecx, (%rsp)
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %r14, %rdx
movq %rbx, %rcx
movq %r15, %r8
movq %r13, %r9
callq 0x1a36e
movq %rax, 0x130(%rsp,%r12,8)
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x1c086
incq %r12
addq $0x100, %r15            # imm = 0x100
cmpq %r12, %rbp
jne 0x115f7
movq 0x10(%rsp), %r13
cmpl $0x31, 0x4bd0(%r13)
jne 0x11746
movq %rbp, %r12
movq 0x130(%rsp), %rax
movq 0x108(%rax), %r15
movl (%r15), %eax
cmpl $0x18, %eax
ja 0x11758
movl $0x1ec0000, %ecx        # imm = 0x1EC0000
btl %eax, %ecx
jae 0x11758
movq %r12, %rbp
cmpl $0x1, %ebp
je 0x116d0
leaq 0x4e18(%r13), %rbx
leaq 0x4220(%r13), %rsi
movq %rbx, %rdi
movl $0x16, %edx
callq 0x1ea48
movq %rax, %r14
movb $0x1, 0x14(%rax)
testl %ebp, %ebp
jle 0x116cd
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x1f6e2
decl %ebp
jne 0x116ac
movq %r14, %r15
movq 0x8(%rsp), %r14
movq %r12, %rbp
jmp 0x116d5
movq %r14, %r15
movq 0x8(%rsp), %r14
leaq 0x930(%rsp), %r12
movl $0x800, %edx            # imm = 0x800
movq %r12, %rdi
xorl %esi, %esi
callq 0x3190
testl %ebp, %ebp
jle 0x11725
xorl %ebx, %ebx
cmpl $0x0, 0x4b84(%r13)
movq 0x130(%rsp,%rbx,8), %rsi
je 0x1170e
movq %r13, %rdi
callq 0x11b32
jmp 0x1171d
movq 0x120(%rsi), %rax
movq %rax, 0x930(%rsp,%rbx,8)
incq %rbx
cmpq %rbx, %rbp
jne 0x116f2
movq %r14, %rdi
callq 0x1a984
xorl %edx, %edx
cmpl $0x0, 0x4b84(%r13)
cmoveq %r12, %rdx
movq %r13, %rdi
movq %r15, %rsi
callq 0x1c385
addq $0x11138, %rsp          # imm = 0x11138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4e18(%r13), %rdi
leaq 0x4220(%r13), %rsi
movq %r15, %rdx
callq 0x1edd3
movq %rax, %r15
jmp 0x1167e