// File: /workspace/github_c_makefile_star2_O2/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 0x4144
movq %rax, 0x8(%r14)
movq %rax, (%r14)
andq $0x0, 0x58(%rax)
leaq 0x48(%r14), %rcx
movq %rcx, 0x68(%rax)
movq %r14, 0x70(%rax)
movb $0x1, 0x78(%rax)
movb %r15b, 0x79(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r14)
andq $0x0, 0x20(%r14)
movl $0x1, 0x28(%r14)
andq $0x0, 0x30(%r14)
movq %rax, 0x38(%r14)
movq %rbp, 0x40(%r14)
movl %ebx, 0x4(%rsp)
movslq %ebx, %rcx
leaq (,%rcx,8), %rbx
leaq 0x6f(,%rcx,8), %r12
pushq $0x40
popq %rsi
movq %r12, %rax
cqto
idivq %rsi
subq %rdx, %r12
testl %ecx, %ecx
js 0x1686f
movl $0x80000000, %eax       # imm = 0x80000000
cmpq %rax, %r12
jge 0x1686f
leaq 0x10(%r14), %rax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %r15d, %r15d
movq %rbx, 0x10(%rsp)
movq (%rax), %rax
testq %rax, %rax
je 0x166f9
movl 0xc(%rax), %edx
cmpl 0x8(%rax), %edx
jge 0x166f3
movl 0x14(%rax), %edx
cmpl %r12d, %edx
je 0x167ba
setg %sil
cmpl %ecx, %edx
setl %dil
testb %dil, %sil
cmovneq %rax, %r15
cmovnel %edx, %ecx
addq $0x20, %rax
jmp 0x166c3
testq %r15, %r15
jne 0x167bd
movq %rbp, 0x8(%rsp)
movl $0x100000, %eax         # imm = 0x100000
xorl %edx, %edx
idivq %r12
testq %rax, %rax
pushq $0x1
popq %rbp
cmovnel %eax, %ebp
movl %ebp, %eax
imull %r12d, %eax
movslq %eax, %rbx
leaq 0x30(%rbx), %rdi
callq 0x3290
movq %rax, %r13
movq %rax, %r15
testq %rax, %rax
je 0x1688a
movl 0x28(%r14), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x28(%r14)
movl %eax, (%r15)
andl $0x0, 0x4(%r15)
movl %ebp, 0x8(%r15)
andq $0x0, 0xc(%r15)
movl %r12d, 0x14(%r15)
andq $0x0, 0x18(%r15)
movq 0x10(%r14), %rax
movq %rax, 0x20(%r15)
leaq (%rbx,%r13), %rcx
addq $0x30, %rcx
movq %rcx, 0x28(%r15)
addq %rbx, 0x30(%r14)
testq %rax, %rax
je 0x16781
movq %r15, 0x18(%rax)
addq $0x30, %r13
movq %r15, 0x10(%r14)
movq 0x18(%r14), %rax
testq %rax, %rax
movq 0x8(%rsp), %rbp
je 0x1679c
cmpq %r13, %rax
jbe 0x167a0
movq %r13, 0x18(%r14)
movq 0x20(%r14), %rdx
xorl %eax, %eax
movq 0x28(%r15), %rcx
testq %rdx, %rdx
je 0x167b4
cmpq %rcx, %rdx
jae 0x167c5
movq %rcx, 0x20(%r14)
jmp 0x167c5
movq %rax, %r15
movl 0xc(%r15), %eax
movl 0x14(%r15), %r12d
imull %r12d, %eax
movslq %eax, %rbx
leaq (%r15,%rbx), %r13
addq $0x30, %r13
movslq %r12d, %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(%r15)
incl 0x4(%r15)
leaq (%r15,%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 0x4144
movq %rax, 0x48(%r14)
orl $-0x1, 0x50(%r14)
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 0x20(%rbp), %rdi
leaq 0x581c0(%rip), %rdx     # 0x6ea3a
pushq $-0x1
popq %rsi
movq %rbx, %rcx
xorl %eax, %eax
callq *0x8(%rbp)
jmp 0x166b2
movq 0x40(%r14), %rcx
movq 0x20(%rcx), %rdi
leaq 0x4fa16(%rip), %rdx     # 0x662af
pushq $-0x1
popq %rsi
xorl %eax, %eax
callq *0x8(%rcx)
jmp 0x1673b