// File: /workspace/github_c_makefile_star2_O2/atomlang[P]atomlang/src/pk_vm.c
// Function: vmSwitchFiber
bool vmSwitchFiber(PKVM* vm, Fiber* fiber, Var* value) {
  if (fiber->state != FIBER_YIELDED) {
    switch (fiber->state) {
      case FIBER_NEW:
        _ERR_FAIL(newString(vm, "The fiber hasn't started. call fiber_run() "
          "to start."));
      case FIBER_RUNNING:
        _ERR_FAIL(newString(vm, "The fiber has already been running."));
      case FIBER_YIELDED: UNREACHABLE();
      case FIBER_DONE:
        _ERR_FAIL(newString(vm, "The fiber has done running."));
    }
    UNREACHABLE();
  }

  // Pass the resume argument if it has any.

  // Assert if we have a call frame and the stack size enough for the return
  // value and the resumed value.
  ASSERT(fiber->frame_count != 0, OOPS);
  ASSERT((fiber->stack + fiber->stack_size) - fiber->sp >= 2, OOPS);

  // fb->ret will points to the return value of the 'yield()' call.
  if (value == NULL) *fiber->ret = VAR_NULL;
  else *fiber->ret = *value;

  // Switch fiber.
  fiber->caller = vm->fiber;
  vm->fiber = fiber;

  // On success return true.
  return true;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0x10(%rsi), %ebp
cmpl $0x2, %ebp
jne 0x9822
cmpl $0x0, 0x4c(%rsi)
je 0x98e2
movslq 0x28(%rsi), %rax
shlq $0x3, %rax
addq 0x20(%rsi), %rax
subq 0x30(%rsi), %rax
cmpq $0x8, %rax
jle 0x9910
testq %rdx, %rdx
je 0x985a
movq (%rdx), %rax
jmp 0x9864
cmpl $0x3, %ebp
je 0x98a1
cmpl $0x1, %ebp
je 0x987f
testl %ebp, %ebp
jne 0x9945
movq 0x5f0(%rbx), %rax
testq %rax, %rax
je 0x98d5
cmpq $0x0, 0x58(%rax)
jne 0x9973
leaq 0xefc0(%rip), %rsi      # 0x18816
pushq $0x34
jmp 0x98c1
movabsq $0x7ffc000000000000, %rax # imm = 0x7FFC000000000000
movq 0x38(%rsi), %rcx
movq %rax, (%rcx)
movq 0x5f0(%rbx), %rax
movq %rax, 0x50(%rsi)
movq %rsi, 0x5f0(%rbx)
jmp 0x98d5
movq 0x5f0(%rbx), %rax
testq %rax, %rax
je 0x98d5
cmpq $0x0, 0x58(%rax)
jne 0x99a1
leaq 0xeeea(%rip), %rsi      # 0x18787
pushq $0x23
jmp 0x98c1
movq 0x5f0(%rbx), %rax
testq %rax, %rax
je 0x98d5
cmpq $0x0, 0x58(%rax)
jne 0x99d2
leaq 0xef2d(%rip), %rsi      # 0x187ec
pushq $0x1b
popq %rdx
movq %rbx, %rdi
callq 0x261f
movq 0x5f0(%rbx), %rcx
movq %rax, 0x58(%rcx)
cmpl $0x2, %ebp
sete %al
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
movq 0x1970f(%rip), %rax     # 0x22ff8
movq (%rax), %rdi
leaq 0xe7fd(%rip), %rsi      # 0x180f0
leaq 0xe90a(%rip), %rdx      # 0x18204
leaq 0xef07(%rip), %rcx      # 0x18808
leaq 0xecd8(%rip), %r8       # 0x185e0
movl $0x18a, %r9d            # imm = 0x18A
jmp 0x993c
movq 0x196e1(%rip), %rax     # 0x22ff8
movq (%rax), %rdi
leaq 0xe7cf(%rip), %rsi      # 0x180f0
leaq 0xe8dc(%rip), %rdx      # 0x18204
leaq 0xeed9(%rip), %rcx      # 0x18808
leaq 0xecaa(%rip), %r8       # 0x185e0
movl $0x18b, %r9d            # imm = 0x18B
xorl %eax, %eax
callq 0x2250
ud2
movq 0x196ac(%rip), %rax     # 0x22ff8
movq (%rax), %rdi
leaq 0xe824(%rip), %rsi      # 0x1817a
leaq 0xeeab(%rip), %rdx      # 0x18808
leaq 0xec7c(%rip), %rcx      # 0x185e0
movl $0x183, %r8d            # imm = 0x183
xorl %eax, %eax
callq 0x2250
ud2
movq 0x1967e(%rip), %rax     # 0x22ff8
movq (%rax), %rdi
leaq 0xe76c(%rip), %rsi      # 0x180f0
leaq 0xe879(%rip), %rdx      # 0x18204
leaq 0xee76(%rip), %rcx      # 0x18808
leaq 0xec47(%rip), %r8       # 0x185e0
movl $0x17c, %r9d            # imm = 0x17C
jmp 0x993c
movq 0x19650(%rip), %rax     # 0x22ff8
movq (%rax), %rdi
leaq 0xe73e(%rip), %rsi      # 0x180f0
leaq 0xe84b(%rip), %rdx      # 0x18204
leaq 0xee48(%rip), %rcx      # 0x18808
leaq 0xec19(%rip), %r8       # 0x185e0
movl $0x17e, %r9d            # imm = 0x17E
jmp 0x993c
movq 0x1961f(%rip), %rax     # 0x22ff8
movq (%rax), %rdi
leaq 0xe70d(%rip), %rsi      # 0x180f0
leaq 0xe81a(%rip), %rdx      # 0x18204
leaq 0xee17(%rip), %rcx      # 0x18808
leaq 0xebe8(%rip), %r8       # 0x185e0
movl $0x181, %r9d            # imm = 0x181
jmp 0x993c