// File: /workspace/github_c_makefile_star2_O3/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 0xb491
leaq 0x4ba8(%r14), %rdi
movq %rdi, 0x8(%rsp)
movl $0x41, %esi
callq 0x1637d
movq %r14, 0x10(%rsp)
movq %r14, %rdi
xorl %esi, %esi
callq 0xa954
movl (%rbx), %ebp
testl %ebp, %ebp
jle 0xc4a9
movq 0x10(%rsp), %rcx
leaq 0x4e38(%rcx), %rdx
movq %rdx, 0x20(%rsp)
leaq 0x4e18(%rcx), %rdx
movq %rdx, 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 %rax, %r13
movq %rax, %r9
callq 0x152ff
movq %rax, 0x930(%rsp,%r12,8)
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x17011
movq %r13, %rax
incq %r12
addq $0x100, %r15            # imm = 0x100
cmpq %r12, %rbp
jne 0xc45b
movq 0x10(%rsp), %r14
cmpl $0x31, 0x4bd0(%r14)
jne 0xc5e2
movq 0x930(%rsp), %rax
movq 0x108(%rax), %r12
movl (%r12), %eax
cmpl $0x18, %eax
ja 0xc5f4
movl $0x1ec0000, %ecx        # imm = 0x1EC0000
btl %eax, %ecx
jae 0xc5f4
movq %rbp, %r13
cmpl $0x1, %r13d
jne 0xc50d
leaq 0x130(%rsp), %rdi
movl $0x800, %edx            # imm = 0x800
xorl %esi, %esi
callq 0x3190
movq %r12, %r15
movq 0x8(%rsp), %r12
jmp 0xc569
leaq 0x4e18(%r14), %rbx
leaq 0x4220(%r14), %rsi
movq %rbx, %rdi
movl $0x16, %edx
callq 0x19a70
movq %rax, %r15
movb $0x1, 0x14(%rax)
testl %r13d, %r13d
jle 0xc5a0
movl %r13d, %ebp
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x1a697
decl %ebp
jne 0xc537
leaq 0x130(%rsp), %rdi
movl $0x800, %edx            # imm = 0x800
xorl %esi, %esi
callq 0x3190
testl %r13d, %r13d
movq 0x8(%rsp), %r12
jle 0xc5b9
xorl %ebx, %ebx
cmpl $0x0, 0x4b84(%r14)
movq 0x930(%rsp,%rbx,8), %rsi
je 0xc587
movq %r14, %rdi
callq 0xc9da
jmp 0xc596
movq 0x120(%rsi), %rax
movq %rax, 0x130(%rsp,%rbx,8)
incq %rbx
cmpq %rbx, %r13
jne 0xc56b
jmp 0xc5b9
leaq 0x130(%rsp), %rdi
movl $0x800, %edx            # imm = 0x800
xorl %esi, %esi
callq 0x3190
movq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x15914
xorl %eax, %eax
cmpl $0x0, 0x4b84(%r14)
leaq 0x130(%rsp), %rdx
cmovneq %rax, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x17310
addq $0x11138, %rsp          # imm = 0x11138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4e18(%r14), %rdi
leaq 0x4220(%r14), %rsi
movq %r12, %rdx
callq 0x19e01
movq %rax, %r12
jmp 0xc4e6