// File: /workspace/github_c_makefile_star2_O0/vtereshkov[P]umka-lang/src/umka_decl.c
// Function: parseArrayType
static const Type *parseArrayType(Compiler *comp)
{
    lexEat(&comp->lex, TOK_LBRACKET);

    TypeKind typeKind;
    Const len;

    if (comp->lex.tok.kind == TOK_RBRACKET)
    {
        // Dynamic array
        typeKind = TYPE_DYNARRAY;
        len.intVal = 0;
    }
    else
    {
        // Conventional array
        typeKind = TYPE_ARRAY;
        const Type *indexType = NULL;
        parseExpr(comp, &indexType, &len);
        typeAssertCompatible(&comp->types, comp->intType, indexType);
        if (len.intVal < 0 || len.intVal > INT_MAX)
            comp->error.handler(comp->error.context, "Illegal array length");
    }

    lexEat(&comp->lex, TOK_RBRACKET);

    const Type *baseType = (typeKind == TYPE_DYNARRAY) ? parseTypeOrForwardType(comp) : parseType(comp, NULL);
    if (baseType->kind == TYPE_VOID)
        comp->error.handler(comp->error.context, "Array items cannot be void");

    if (len.intVal > 0 && typeSize(&comp->types, baseType) > INT_MAX / len.intVal)
        comp->error.handler(comp->error.context, "Array is too large");

    Type *type = typeAdd(&comp->types, &comp->blocks, typeKind);
    type->base = baseType;
    typeResizeArray(type, len.intVal);
    return type;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
movl $0x3a, %esi
callq 0x1b150
movq -0x8(%rbp), %rax
cmpl $0x3b, 0x4bd0(%rax)
jne 0x9dbf
movl $0x13, -0xc(%rbp)
movq $0x0, -0x18(%rbp)
jmp 0x9e32
movl $0x12, -0xc(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x20(%rbp), %rsi
leaq -0x18(%rbp), %rdx
callq 0xe8c0
movq -0x8(%rbp), %rdi
addq $0x4e18, %rdi           # imm = 0x4E18
movq -0x8(%rbp), %rax
movq 0x5240(%rax), %rsi
movq -0x20(%rbp), %rdx
callq 0x22870
cmpq $0x0, -0x18(%rbp)
jl 0x9e0f
cmpq $0x7fffffff, -0x18(%rbp) # imm = 0x7FFFFFFF
jle 0x9e30
movq -0x8(%rbp), %rax
movq 0x50f8(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x5118(%rax), %rdi
leaq 0x1ce411(%rip), %rsi    # 0x1d823d
movb $0x0, %al
callq *%rcx
jmp 0x9e32
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
movl $0x3b, %esi
callq 0x1b150
cmpl $0x13, -0xc(%rbp)
jne 0x9e5c
movq -0x8(%rbp), %rdi
callq 0xb140
movq %rax, -0x38(%rbp)
jmp 0x9e6d
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x9b80
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x9e9f
movq -0x8(%rbp), %rax
movq 0x50f8(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x5118(%rax), %rdi
leaq 0x1ce3b7(%rip), %rsi    # 0x1d8252
movb $0x0, %al
callq *%rcx
cmpq $0x0, -0x18(%rbp)
jle 0x9ef8
movq -0x8(%rbp), %rdi
addq $0x4e18, %rdi           # imm = 0x4E18
movq -0x28(%rbp), %rsi
callq 0x21fe0
cltq
movq %rax, -0x40(%rbp)
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cqto
idivq -0x18(%rbp)
movq %rax, %rcx
movq -0x40(%rbp), %rax
cmpq %rcx, %rax
jle 0x9ef8
movq -0x8(%rbp), %rax
movq 0x50f8(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x5118(%rax), %rdi
leaq 0x1ce379(%rip), %rsi    # 0x1d826d
movb $0x0, %al
callq *%rcx
movq -0x8(%rbp), %rdi
addq $0x4e18, %rdi           # imm = 0x4E18
movq -0x8(%rbp), %rsi
addq $0x4220, %rsi           # imm = 0x4220
movl -0xc(%rbp), %edx
callq 0x21950
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %esi
callq 0xb350
movq -0x30(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nop