// File: /workspace/github_c_makefile_star2_O0/vtereshkov[P]umka-lang/src/umka_vm.c
// Function: pageFree
static void pageFree(HeapPages *pages, bool warnLeak)
{
    HeapPage *page = pages->first;
    while (page)
    {
        HeapPage *next = page->next;

        // Report memory leaks
        if (warnLeak)
        {
            fprintf(stderr, "Warning: Memory leak at %p (%d refs)\n", page->data, page->refCnt);

#ifdef UMKA_DETAILED_LEAK_INFO
            for (int i = 0; i < page->numOccupiedChunks; i++)
            {
                const HeapChunk *chunk = (const HeapChunk *)(page->data + i * page->chunkSize);
                if (chunk->refCnt == 0)
                    continue;

                const DebugInfo *debug = &pages->fiber->debugPerInstr[chunk->ip];
                fprintf(stderr, "    Chunk allocated in %s: %s (%d)\n", debug->fnName, debug->fileName, debug->line);
            }
#endif
        }

        // Call custom deallocators, if any
        for (int i = 0; i < page->numOccupiedChunks && page->numChunksWithOnFree > 0; i++)
        {
            HeapChunk *chunk = (HeapChunk *)(page->data + i * page->chunkSize);
            if (chunk->refCnt == 0 || !chunk->onFree)
                continue;

            chunk->onFree(doGetOnFreeParams(chunk->data), doGetOnFreeResult(pages));
            page->numChunksWithOnFree--;
        }

        free(page);
        page = next;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movb %sil, %al
movq %rdi, -0x30(%rbp)
andb $0x1, %al
movb %al, -0x31(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x2577c
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x48(%rbp)
testb $0x1, -0x31(%rbp)
je 0x25633
movq 0x1c09e5(%rip), %rax    # 0x1e5ff8
movq (%rax), %rdi
movq -0x40(%rbp), %rdx
addq $0x30, %rdx
movq -0x40(%rbp), %rax
movl 0x4(%rax), %ecx
leaq 0x1b87b1(%rip), %rsi    # 0x1ddddd
movb $0x0, %al
callq 0x3230
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %ecx
movq -0x40(%rbp), %rdx
xorl %eax, %eax
cmpl 0xc(%rdx), %ecx
movb %al, -0x59(%rbp)
jge 0x25659
movq -0x40(%rbp), %rax
cmpl $0x0, 0x10(%rax)
setg %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
testb $0x1, %al
jne 0x25665
jmp 0x25766
movq -0x40(%rbp), %rax
addq $0x30, %rax
movl -0x4c(%rbp), %ecx
movq -0x40(%rbp), %rdx
imull 0x14(%rdx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpl $0x0, (%rax)
je 0x25696
movq -0x58(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x2569b
jmp 0x25758
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x58(%rbp), %rcx
addq $0x28, %rcx
movq %rcx, -0x18(%rbp)
leaq 0x1c124a(%rip), %rcx    # 0x1e6900
movq %rcx, -0x20(%rbp)
movq -0x20(%rbp), %rcx
movq $0x2, (%rcx)
movq -0x20(%rbp), %rcx
movq $0x1, 0x10(%rcx)
movq -0x20(%rbp), %rcx
movq $0x0, 0x8(%rcx)
movq -0x20(%rbp), %rcx
movq $0x0, 0x18(%rcx)
movq -0x20(%rbp), %rcx
movq $0x0, 0x20(%rcx)
leaq 0x1c1234(%rip), %rcx    # 0x1e6930
addq $0x20, %rcx
movq %rcx, -0x28(%rbp)
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq %rdx, -0x20(%rcx)
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq %rdx, (%rcx)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rcx
movq %rcx, -0x8(%rbp)
leaq 0x1c122a(%rip), %rcx    # 0x1e6958
movq %rcx, -0x10(%rbp)
movq -0x8(%rbp), %rcx
movq 0x30(%rcx), %rcx
movq 0x20(%rcx), %rdx
movq -0x10(%rbp), %rcx
movq %rdx, (%rcx)
movq -0x10(%rbp), %rsi
callq *%rax
movq -0x40(%rbp), %rax
movl 0x10(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x10(%rax)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x2563a
movq -0x40(%rbp), %rdi
callq 0x3040
movq -0x48(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x255ef
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)