// File: /workspace/github_c_makefile_star2_O0/vtereshkov[P]umka-lang/src/umka_stmt.c
// Function: parseForHeader
static void parseForHeader(Compiler *comp, ForPostStmt *postStmt)
{
    // [shortVarDecl ";"]
    if (doShortVarDeclLookahead(comp))
    {
        parseShortVarDecl(comp);
        lexEat(&comp->lex, TOK_SEMICOLON);
    }

    genForCondProlog(&comp->gen);

    // Additional scope embracing expr (needed for timely garbage collection in expr, since it is computed at each iteration)
    blocksEnter(&comp->blocks);

    // expr
    const Type *type = comp->boolType;
    parseExpr(comp, &type, NULL);
    typeAssertCompatible(&comp->types, comp->boolType, type);

    // Additional scope embracing expr
    doGarbageCollection(comp);
    identWarnIfUnusedAll(&comp->idents, blocksCurrent(&comp->blocks));
    blocksLeave(&comp->blocks);

    // [";" simpleStmt]
    if (comp->lex.tok.kind == TOK_SEMICOLON || comp->lex.tok.kind == TOK_IMPLICIT_SEMICOLON)
    {
        lexNext(&comp->lex);

        if (doForPostIncDecStmtLookahead(comp))
        {
            // Special case: simpleStmt = ident ("++" | "--").
            genWhileCondEpilog(&comp->gen);

            postStmt->indexIdent = identAssertFind(&comp->idents, &comp->modules, &comp->blocks, comp->blocks.module, comp->lex.tok.name, NULL);

            if (postStmt->indexIdent->kind != IDENT_VAR)
                comp->error.handler(comp->error.context, "%s is not a variable", postStmt->indexIdent->name);           
            
            if (identIsOuterLocalVar(&comp->blocks, postStmt->indexIdent))
                comp->error.handler(comp->error.context, "%s is not specified as a captured variable", postStmt->indexIdent->name);

            typeAssertCompatible(&comp->types, comp->intType, postStmt->indexIdent->type);

            lexNext(&comp->lex);
            postStmt->op = comp->lex.tok.kind;

            lexNext(&comp->lex);
            postStmt->isDeferred = true;
        }
        else
        {
            // General case
            genForCondEpilog(&comp->gen);
            
            // Additional scope embracing simpleStmt (needed for timely garbage collection in simpleStmt, since it is executed at each iteration)
            blocksEnter(&comp->blocks);

            parseSimpleStmt(comp);

            // Additional scope embracing simpleStmt
            doGarbageCollection(comp);
            identWarnIfUnusedAll(&comp->idents, blocksCurrent(&comp->blocks));
            blocksLeave(&comp->blocks);

            genForPostStmtEpilog(&comp->gen);

            postStmt->indexIdent = NULL;
            postStmt->op = TOK_NONE;
            postStmt->isDeferred = false;            
        }
    }
    else
    {
        // Special case: simpleStmt omitted - treat it as deferred
        genWhileCondEpilog(&comp->gen);

        postStmt->indexIdent = NULL;
        postStmt->op = TOK_NONE;
        postStmt->isDeferred = true;        
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1f910
testb $0x1, %al
jne 0x2148f
jmp 0x214ad
movq -0x8(%rbp), %rdi
callq 0xa8f0
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
movl $0x40, %esi
callq 0x1b150
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
callq 0x18940
movq -0x8(%rbp), %rdi
addq $0x4220, %rdi           # imm = 0x4220
callq 0x5e60
movq -0x8(%rbp), %rax
movq 0x5268(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x18(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xe8c0
movq -0x8(%rbp), %rdi
addq $0x4e18, %rdi           # imm = 0x4E18
movq -0x8(%rbp), %rax
movq 0x5268(%rax), %rsi
movq -0x18(%rbp), %rdx
callq 0x22870
movq -0x8(%rbp), %rdi
callq 0x1d3a0
movq -0x8(%rbp), %rax
addq $0x4e38, %rax           # imm = 0x4E38
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
addq $0x4220, %rdi           # imm = 0x4220
callq 0x6020
movq -0x20(%rbp), %rdi
movl %eax, %esi
callq 0x1a7e0
movq -0x8(%rbp), %rdi
addq $0x4220, %rdi           # imm = 0x4220
callq 0x5fa0
movq -0x8(%rbp), %rax
cmpl $0x40, 0x4bd0(%rax)
je 0x2156c
movq -0x8(%rbp), %rax
cmpl $0x4a, 0x4bd0(%rax)
jne 0x21773
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
callq 0x1ad90
movq -0x8(%rbp), %rdi
callq 0x21810
testb $0x1, %al
jne 0x2158e
jmp 0x216d8
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
callq 0x188c0
movq -0x8(%rbp), %rdi
addq $0x4e38, %rdi           # imm = 0x4E38
movq -0x8(%rbp), %rsi
addq $0x100, %rsi            # imm = 0x100
movq -0x8(%rbp), %rdx
addq $0x4220, %rdx           # imm = 0x4220
movq -0x8(%rbp), %rax
movl 0x4b88(%rax), %ecx
movq -0x8(%rbp), %r8
addq $0x4ba8, %r8            # imm = 0x4BA8
addq $0x28, %r8
addq $0x8, %r8
xorl %eax, %eax
movl %eax, %r9d
callq 0x19880
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpl $0x1, (%rax)
je 0x21628
movq -0x8(%rbp), %rax
movq 0x50f8(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x5118(%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
addq $0x4, %rdx
leaq 0x1b7842(%rip), %rsi    # 0x1d8e66
movb $0x0, %al
callq *%rcx
movq -0x8(%rbp), %rdi
addq $0x4220, %rdi           # imm = 0x4220
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x199e0
testb $0x1, %al
jne 0x21645
jmp 0x21671
movq -0x8(%rbp), %rax
movq 0x50f8(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x5118(%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
addq $0x4, %rdx
leaq 0x1b71ff(%rip), %rsi    # 0x1d886c
movb $0x0, %al
callq *%rcx
movq -0x8(%rbp), %rdi
addq $0x4e18, %rdi           # imm = 0x4E18
movq -0x8(%rbp), %rax
movq 0x5240(%rax), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x108(%rax), %rdx
callq 0x22870
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
callq 0x1ad90
movq -0x8(%rbp), %rax
movl 0x4bd0(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
callq 0x1ad90
movq -0x10(%rbp), %rax
movb $0x1, 0xc(%rax)
jmp 0x21771
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
callq 0x18960
movq -0x8(%rbp), %rdi
addq $0x4220, %rdi           # imm = 0x4220
callq 0x5e60
movq -0x8(%rbp), %rdi
callq 0x1eef0
movq -0x8(%rbp), %rdi
callq 0x1d3a0
movq -0x8(%rbp), %rax
addq $0x4e38, %rax           # imm = 0x4E38
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
addq $0x4220, %rdi           # imm = 0x4220
callq 0x6020
movq -0x28(%rbp), %rdi
movl %eax, %esi
callq 0x1a7e0
movq -0x8(%rbp), %rdi
addq $0x4220, %rdi           # imm = 0x4220
callq 0x5fa0
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
callq 0x18990
movq -0x10(%rbp), %rax
movq $0x0, (%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0xc(%rax)
jmp 0x217a1
movq -0x8(%rbp), %rdi
addq $0x4e70, %rdi           # imm = 0x4E70
callq 0x188c0
movq -0x10(%rbp), %rax
movq $0x0, (%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x10(%rbp), %rax
movb $0x1, 0xc(%rax)
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)