// File: /workspace/github_c_makefile_star2_O3/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 0x7a70
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)
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)
movslq %ebx, %rax
leaq (,%rax,8), %rcx
leaq 0x6f(,%rax,8), %rdx
leaq 0xae(,%rax,8), %r15
testq %rdx, %rdx
cmovnsq %rdx, %r15
andq $-0x40, %r15
testl %eax, %eax
movl %ebx, 0x4(%rsp)
movq %rcx, 0x10(%rsp)
js 0x1b640
cmpq $0x7fffffff, %r15       # imm = 0x7FFFFFFF
jg 0x1b640
xorl %r13d, %r13d
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
testq %rax, %rax
je 0x1b6a7
movl 0x28(%r14), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x28(%r14)
movl %eax, (%r12)
movl $0x0, 0x4(%r12)
movl %ebp, 0x8(%r12)
xorl %eax, %eax
movq %rax, 0xc(%r12)
movl %r15d, 0x14(%r12)
movq %rax, 0x18(%r12)
movq %r13, 0x20(%r12)
leaq (%r12,%rbx), %rax
addq $0x30, %rax
movq %rax, 0x28(%r12)
addq %rbx, 0x30(%r14)
testq %r13, %r13
je 0x1b556
movq %r12, 0x18(%r13)
movq %r12, %rax
addq $0x30, %rax
movq %r12, 0x10(%r14)
movq 0x18(%r14), %rcx
testq %rcx, %rcx
movq 0x8(%rsp), %rbp
je 0x1b574
cmpq %rax, %rcx
jbe 0x1b578
movq %rax, 0x18(%r14)
movq 0x20(%r14), %rdx
xorl %eax, %eax
movq 0x28(%r12), %rcx
testq %rdx, %rdx
je 0x1b58d
cmpq %rcx, %rdx
jae 0x1b591
movq %rcx, 0x20(%r14)
imull %r15d, %eax
movslq %eax, %rbx
leaq (%r12,%rbx), %r13
addq $0x30, %r13
movslq %r15d, %rdx
movq %r13, %rdi
xorl %esi, %esi
callq 0x3190
movl $0x1, (%r13)
movq 0x10(%rsp), %rax
movl %eax, 0x4(%r13)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r13)
movq 0x38(%r14), %rax
movslq 0x8(%rax), %rax
movq %rax, 0x18(%r13)
movb $0x1, 0x20(%r13)
incl 0xc(%r12)
incl 0x4(%r12)
leaq (%r12,%rbx), %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 0x7a70
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
leaq 0x10(%r14), %rbx
movq 0x20(%rbp), %rdi
leaq 0x5faf3(%rip), %rdx     # 0x7b142
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
callq *0x8(%rbp)
movq (%rbx), %r13
testq %r13, %r13
je 0x1b4ce
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %r12d, %r12d
movq %r13, %rcx
movl 0xc(%rcx), %edx
cmpl 0x8(%rcx), %edx
jge 0x1b694
movl 0x14(%rcx), %edx
cmpl %r15d, %edx
je 0x1b6c9
setg %sil
cmpl %eax, %edx
setl %dil
testb %dil, %sil
cmovneq %rcx, %r12
cmovnel %edx, %eax
movq 0x20(%rcx), %rcx
testq %rcx, %rcx
jne 0x1b670
testq %r12, %r12
jne 0x1b6cc
jmp 0x1b4d1
movq 0x40(%r14), %rcx
movq 0x20(%rcx), %rdi
leaq 0x56bf9(%rip), %rdx     # 0x722af
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
callq *0x8(%rcx)
movq 0x10(%r14), %r13
jmp 0x1b509
movq %rcx, %r12
movl 0xc(%r12), %eax
movl 0x14(%r12), %r15d
jmp 0x1b591