// File: /workspace/github_c_makefile_star2_O0/vtereshkov[P]umka-lang/src/umka_expr.c
// Function: parseDynArrayLiteral
static void parseDynArrayLiteral(Compiler *comp, const Type **type, Const *constant)
{
    if (!(*type)->isVariadicParamList)
        lexEat(&comp->lex, TOK_LBRACE);

    ConstArray constItems;
    if (constant)
        constArrayAlloc(&constItems, &comp->storage, (*type)->base);

    // Dynamic array is first parsed as a static array of unknown length, then converted to a dynamic array
    Type *staticArrayType = typeAdd(&comp->types, &comp->blocks, TYPE_ARRAY);
    staticArrayType->base = (*type)->base;
    const int itemSize = typeSize(&comp->types, staticArrayType->base);

    // Parse array
    const TokenKind rightEndTok = (*type)->isVariadicParamList ? TOK_RPAR : TOK_RBRACE;
    if (comp->lex.tok.kind != rightEndTok)
    {
        while ((*type)->isVariadicParamList || comp->lex.tok.kind != TOK_RBRACE)
        {
            const Type *itemType = staticArrayType->base;

            Const *constItem = NULL;
            if (constant)
            {
                constArrayAppend(&constItems, (Const){0});
                constItem = &constItems.data[staticArrayType->numItems];
            }

            parseExpr(comp, &itemType, constItem);

            // Special case: variadic parameter list's first item is already a dynamic array compatible with the variadic parameter list
            if ((*type)->isVariadicParamList && typeCompatible(*type, itemType) && staticArrayType->numItems == 0)
                return;

            doAssertImplicitTypeConv(comp, staticArrayType->base, &itemType, constItem);

            typeResizeArray(staticArrayType, staticArrayType->numItems + 1);

            if (comp->lex.tok.kind != TOK_COMMA)
                break;
            lexNext(&comp->lex);
        }
    }

    if (!(*type)->isVariadicParamList)
    {
        // Allow closing brace on a new line
        if (comp->lex.tok.kind == TOK_IMPLICIT_SEMICOLON)
            lexNext(&comp->lex);

        lexEat(&comp->lex, TOK_RBRACE);
    }

    if (constant)
    {
        // Allocate array
        Const constStaticArray = {.ptrVal = storageAdd(&comp->storage, staticArrayType->numItems * itemSize)};

        // Assign items
        for (int i = staticArrayType->numItems - 1; i >= 0; i--)
            constAssign(&comp->consts, (char *)constStaticArray.ptrVal + i * itemSize, &constItems.data[i], staticArrayType->base->kind, itemSize);

        constArrayFree(&constItems);

        *constant = constStaticArray;
    }
    else
    {
        // Allocate array
        const int staticArrayOffset = identAllocStack(&comp->idents, &comp->types, &comp->blocks, staticArrayType);

        // Assign items
        for (int i = staticArrayType->numItems - 1; i >= 0; i--)
        {
            genPushLocalPtr(&comp->gen, staticArrayOffset + i * itemSize);
            genSwapAssign(&comp->gen, staticArrayType->base->kind, staticArrayType->base->size);
        }

        genPushLocalPtr(&comp->gen, staticArrayOffset);
    }

    // Convert to dynamic array
    doAssertImplicitTypeConv(comp, *type, (const Type **)&staticArrayType, constant);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
testb $0x1, 0x15(%rax)
jne 0x13d79
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
movl $0x3c, %esi
callq 0x1b150
cmpq $0x0, -0x18(%rbp)
je 0x13d9f
movq -0x8(%rbp), %rsi
addq $0xf0, %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rdx
leaq -0x38(%rbp), %rdi
callq 0x96b0
movq -0x8(%rbp), %rdi
addq $0x4e18, %rdi           # imm = 0x4E18
movq -0x8(%rbp), %rsi
addq $0x4220, %rsi           # imm = 0x4220
movl $0x12, %edx
callq 0x21950
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
addq $0x4e18, %rdi           # imm = 0x4E18
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x21fe0
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movb 0x15(%rax), %dl
movl $0x3d, %eax
movl $0x39, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movl 0x4bd0(%rax), %eax
cmpl -0x48(%rbp), %eax
je 0x13f2e
jmp 0x13e23
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movb $0x1, %al
testb $0x1, 0x15(%rcx)
movb %al, -0x75(%rbp)
jne 0x13e46
movq -0x8(%rbp), %rax
cmpl $0x3d, 0x4bd0(%rax)
setne %al
movb %al, -0x75(%rbp)
movb -0x75(%rbp), %al
testb $0x1, %al
jne 0x13e52
jmp 0x13f2c
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x13e99
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x9720
movq -0x30(%rbp), %rax
movq -0x40(%rbp), %rcx
movslq 0x10(%rcx), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rdx
leaq -0x50(%rbp), %rsi
callq 0xe8c0
movq -0x10(%rbp), %rax
movq (%rax), %rax
testb $0x1, 0x15(%rax)
je 0x13edc
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x50(%rbp), %rsi
callq 0x22790
testb $0x1, %al
jne 0x13ecd
jmp 0x13edc
movq -0x40(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jne 0x13edc
jmp 0x140c8
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x58(%rbp), %rcx
leaq -0x50(%rbp), %rdx
callq 0xd6e0
movq -0x40(%rbp), %rdi
movq -0x40(%rbp), %rax
movl 0x10(%rax), %esi
addl $0x1, %esi
callq 0x14a00
movq -0x8(%rbp), %rax
cmpl $0x3f, 0x4bd0(%rax)
je 0x13f17
jmp 0x13f2c
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
callq 0x1ad90
jmp 0x13e23
jmp 0x13f2e
movq -0x10(%rbp), %rax
movq (%rax), %rax
testb $0x1, 0x15(%rax)
jne 0x13f6d
movq -0x8(%rbp), %rax
cmpl $0x4a, 0x4bd0(%rax)
jne 0x13f58
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
callq 0x1ad90
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
movl $0x3d, %esi
callq 0x1b150
cmpq $0x0, -0x18(%rbp)
je 0x1400e
movq -0x8(%rbp), %rdi
addq $0xf0, %rdi
movq -0x40(%rbp), %rax
movl 0x10(%rax), %eax
imull -0x44(%rbp), %eax
movslq %eax, %rsi
callq 0x4b20
movq %rax, -0x68(%rbp)
movq -0x40(%rbp), %rax
movl 0x10(%rax), %eax
subl $0x1, %eax
movl %eax, -0x6c(%rbp)
cmpl $0x0, -0x6c(%rbp)
jl 0x13ff5
movq -0x8(%rbp), %rdi
addq $0x4e68, %rdi           # imm = 0x4E68
movq -0x68(%rbp), %rsi
movl -0x6c(%rbp), %eax
imull -0x44(%rbp), %eax
cltq
addq %rax, %rsi
movq -0x30(%rbp), %rdx
movslq -0x6c(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdx
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movl (%rax), %ecx
movl -0x44(%rbp), %r8d
callq 0x88c0
movl -0x6c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x13fa7
leaq -0x38(%rbp), %rdi
callq 0x98a0
movq -0x18(%rbp), %rax
movq -0x68(%rbp), %rcx
movq %rcx, (%rax)
jmp 0x140b0
movq -0x8(%rbp), %rdi
addq $0x4e38, %rdi           # imm = 0x4E38
movq -0x8(%rbp), %rsi
addq $0x4e18, %rsi           # imm = 0x4E18
movq -0x8(%rbp), %rdx
addq $0x4220, %rdx           # imm = 0x4220
movq -0x40(%rbp), %rcx
callq 0x1a320
movl %eax, -0x70(%rbp)
movq -0x40(%rbp), %rax
movl 0x10(%rax), %eax
subl $0x1, %eax
movl %eax, -0x74(%rbp)
cmpl $0x0, -0x74(%rbp)
jl 0x1409d
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movl -0x70(%rbp), %esi
movl -0x74(%rbp), %eax
imull -0x44(%rbp), %eax
addl %eax, %esi
callq 0x169a0
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movl (%rax), %esi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movl 0xc0(%rax), %edx
callq 0x17120
movl -0x74(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x14048
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
movl -0x70(%rbp), %esi
callq 0x169a0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x18(%rbp), %rcx
leaq -0x40(%rbp), %rdx
callq 0xd6e0
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)