// File: /workspace/github_c_makefile_star2_O1/vtereshkov[P]umka-lang/src/umka_vm.c
// Function: vmInit
void vmInit(VM *vm, Storage *storage, int stackSize, bool fileSystemEnabled, Error *error)
{
    vm->storage = storage;
    vm->fiber = vm->mainFiber = storageAdd(vm->storage, sizeof(Fiber));
    vm->fiber->parent = NULL;
    vm->fiber->refCntChangeCandidates = &vm->refCntChangeCandidates;
    vm->fiber->vm = vm;
    vm->fiber->alive = true;
    vm->fiber->fileSystemEnabled = fileSystemEnabled;

    pageInit(&vm->pages, vm->fiber, error);

    vm->fiber->stack = chunkAlloc(&vm->pages, stackSize * sizeof(Slot), NULL, NULL, true, error);
    vm->fiber->stackSize = stackSize;

    candidateInit(&vm->refCntChangeCandidates, vm->storage);

    memset(&vm->hooks, 0, sizeof(vm->hooks));
    vm->terminatedNormally = false;
    vm->error = error;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %rbp
movl %ecx, %r15d
movl %edx, %ebx
movq %rsi, %rax
movq %rdi, %r14
movq %rsi, 0x78(%rdi)
movl $0x80, %esi
movq %rax, %rdi
callq 0xcca8
movq %rax, 0x8(%r14)
movq %rax, (%r14)
xorl %ecx, %ecx
movq %rcx, 0x58(%rax)
leaq 0x48(%r14), %rdx
movq %rdx, 0x68(%rax)
movq %r14, 0x70(%rax)
movb $0x1, 0x78(%rax)
movb %r15b, 0x79(%rax)
leaq 0x10(%r14), %r12
movq %rcx, 0x20(%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r14)
movl $0x1, 0x28(%r14)
movq %rcx, 0x30(%r14)
movq %rax, 0x38(%r14)
movq %rbp, 0x40(%r14)
movl %ebx, 0x4(%rsp)
movslq %ebx, %rax
leaq (,%rax,8), %rbx
leaq 0x6f(,%rax,8), %rcx
leaq 0xae(,%rax,8), %r15
testq %rcx, %rcx
cmovnsq %rcx, %r15
andq $-0x40, %r15
testl %eax, %eax
js 0x20751
movl $0x80000000, %eax       # imm = 0x80000000
cmpq %rax, %r15
jge 0x20751
movq (%r12), %rax
testq %rax, %rax
je 0x205cd
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %r13d, %r13d
movl 0xc(%rax), %edx
cmpl 0x8(%rax), %edx
jge 0x205c2
movl 0x14(%rax), %edx
cmpl %r15d, %edx
je 0x205d2
setg %sil
cmpl %ecx, %edx
setl %dil
testb %dil, %sil
cmovneq %rax, %r13
cmovnel %edx, %ecx
movq 0x20(%rax), %rax
testq %rax, %rax
jne 0x2059e
jmp 0x205d5
xorl %r13d, %r13d
jmp 0x205d5
movq %rax, %r13
movq %rbx, 0x10(%rsp)
testq %r13, %r13
jne 0x2069e
movq %rbp, 0x8(%rsp)
movl $0x100000, %eax         # imm = 0x100000
xorl %edx, %edx
idivq %r15
testq %rax, %rax
movl $0x1, %ebp
cmovnel %eax, %ebp
movl %ebp, %eax
imull %r15d, %eax
movslq %eax, %rbx
leaq 0x30(%rbx), %rdi
callq 0x3290
movq %rax, %r12
movq %rax, %r13
testq %rax, %rax
je 0x20761
movl 0x28(%r14), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x28(%r14)
movl %eax, (%r13)
movl $0x0, 0x4(%r13)
movl %ebp, 0x8(%r13)
xorl %eax, %eax
movq %rax, 0xc(%r13)
movl %r15d, 0x14(%r13)
movq %rax, 0x18(%r13)
movq 0x10(%r14), %rax
movq %rax, 0x20(%r13)
leaq (%r12,%rbx), %rcx
addq $0x30, %rcx
movq %rcx, 0x28(%r13)
addq %rbx, 0x30(%r14)
testq %rax, %rax
je 0x20668
movq %r13, 0x18(%rax)
addq $0x30, %r12
movq %r13, 0x10(%r14)
movq 0x18(%r14), %rax
testq %rax, %rax
movq 0x8(%rsp), %rbp
je 0x20683
cmpq %r12, %rax
jbe 0x20687
movq %r12, 0x18(%r14)
movq 0x20(%r14), %rax
testq %rax, %rax
je 0x20696
cmpq 0x28(%r13), %rax
jae 0x2069e
movq 0x28(%r13), %rax
movq %rax, 0x20(%r14)
movslq 0xc(%r13), %rbx
movslq 0x14(%r13), %rdx
imulq %rdx, %rbx
leaq (%rbx,%r13), %r12
addq $0x30, %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0x3190
movl $0x1, (%r12)
movq 0x10(%rsp), %rax
movl %eax, 0x4(%r12)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r12)
movq 0x38(%r14), %rax
movslq 0x8(%rax), %rax
movq %rax, 0x18(%r12)
movb $0x1, 0x20(%r12)
incl 0xc(%r13)
incl 0x4(%r13)
leaq (%rbx,%r13), %rax
addq $0x58, %rax
movq (%r14), %rcx
movq %rax, 0x10(%rcx)
movl 0x4(%rsp), %eax
movl %eax, 0x28(%rcx)
movq 0x78(%r14), %rdi
movq %rdi, 0x58(%r14)
movl $0x64, 0x54(%r14)
movl $0x960, %esi            # imm = 0x960
callq 0xcca8
movq %rax, 0x48(%r14)
movl $0xffffffff, 0x50(%r14) # imm = 0xFFFFFFFF
xorps %xmm0, %xmm0
movups %xmm0, 0x60(%r14)
movb $0x0, 0x70(%r14)
movq %rbp, 0x80(%r14)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x34b7
jmp 0x2058d
leaq 0x40(%r14), %rdi
callq 0x34d1
jmp 0x2061e