// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x28, %rsp
movq %rdi, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
movq 0x10(%rsp), %rax
cmpl $0x2, 0x10(%rax)
je 0x11531
movq 0x10(%rsp), %rax
movl 0x10(%rax), %eax
movq %rax, (%rsp)
subq $0x3, %rax
ja 0x114fc
movq (%rsp), %rax
leaq 0x19311(%rip), %rcx     # 0x2a604
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x112fe
movq 0x18(%rsp), %rax
cmpq $0x0, 0x5f0(%rax)
je 0x1138b
jmp 0x1130f
jmp 0x11311
movq 0x18(%rsp), %rax
movq 0x5f0(%rax), %rax
cmpq $0x0, 0x58(%rax)
je 0x1135e
movq 0x21ccd(%rip), %rax     # 0x32ff8
movq (%rax), %rdi
leaq 0x18e1b(%rip), %rsi     # 0x2a150
leaq 0x18f28(%rip), %rdx     # 0x2a264
leaq 0x19521(%rip), %rcx     # 0x2a864
leaq 0x192f2(%rip), %r8      # 0x2a63c
movl $0x17c, %r9d            # imm = 0x17C
movb $0x0, %al
callq 0x2240
ud2
callq 0x2040
jmp 0x11360
movq 0x18(%rsp), %rdi
leaq 0x19506(%rip), %rsi     # 0x2a872
movl $0x34, %edx
callq 0x2760
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq 0x5f0(%rax), %rax
movq %rcx, 0x58(%rax)
jmp 0x1138b
movb $0x0, 0x27(%rsp)
jmp 0x11646
jmp 0x11397
movq 0x18(%rsp), %rax
cmpq $0x0, 0x5f0(%rax)
je 0x11424
jmp 0x113a8
jmp 0x113aa
movq 0x18(%rsp), %rax
movq 0x5f0(%rax), %rax
cmpq $0x0, 0x58(%rax)
je 0x113f7
movq 0x21c34(%rip), %rax     # 0x32ff8
movq (%rax), %rdi
leaq 0x18d82(%rip), %rsi     # 0x2a150
leaq 0x18e8f(%rip), %rdx     # 0x2a264
leaq 0x19488(%rip), %rcx     # 0x2a864
leaq 0x19259(%rip), %r8      # 0x2a63c
movl $0x17e, %r9d            # imm = 0x17E
movb $0x0, %al
callq 0x2240
ud2
callq 0x2040
jmp 0x113f9
movq 0x18(%rsp), %rdi
leaq 0x193de(%rip), %rsi     # 0x2a7e3
movl $0x23, %edx
callq 0x2760
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq 0x5f0(%rax), %rax
movq %rcx, 0x58(%rax)
jmp 0x11424
movb $0x0, 0x27(%rsp)
jmp 0x11646
jmp 0x11430
movq 0x21bc1(%rip), %rax     # 0x32ff8
movq (%rax), %rdi
leaq 0x18d99(%rip), %rsi     # 0x2a1da
leaq 0x1941c(%rip), %rdx     # 0x2a864
leaq 0x191ed(%rip), %rcx     # 0x2a63c
movl $0x17f, %r8d            # imm = 0x17F
movb $0x0, %al
callq 0x2240
ud2
callq 0x2040
jmp 0x11465
movq 0x18(%rsp), %rax
cmpq $0x0, 0x5f0(%rax)
je 0x114f2
jmp 0x11476
jmp 0x11478
movq 0x18(%rsp), %rax
movq 0x5f0(%rax), %rax
cmpq $0x0, 0x58(%rax)
je 0x114c5
movq 0x21b66(%rip), %rax     # 0x32ff8
movq (%rax), %rdi
leaq 0x18cb4(%rip), %rsi     # 0x2a150
leaq 0x18dc1(%rip), %rdx     # 0x2a264
leaq 0x193ba(%rip), %rcx     # 0x2a864
leaq 0x1918b(%rip), %r8      # 0x2a63c
movl $0x181, %r9d            # imm = 0x181
movb $0x0, %al
callq 0x2240
ud2
callq 0x2040
jmp 0x114c7
movq 0x18(%rsp), %rdi
leaq 0x19375(%rip), %rsi     # 0x2a848
movl $0x1b, %edx
callq 0x2760
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq 0x5f0(%rax), %rax
movq %rcx, 0x58(%rax)
jmp 0x114f2
movb $0x0, 0x27(%rsp)
jmp 0x11646
jmp 0x114fe
movq 0x21af3(%rip), %rax     # 0x32ff8
movq (%rax), %rdi
leaq 0x18ccb(%rip), %rsi     # 0x2a1da
leaq 0x1934e(%rip), %rdx     # 0x2a864
leaq 0x1911f(%rip), %rcx     # 0x2a63c
movl $0x183, %r8d            # imm = 0x183
movb $0x0, %al
callq 0x2240
ud2
callq 0x2040
jmp 0x11533
movq 0x10(%rsp), %rax
cmpl $0x0, 0x4c(%rax)
jne 0x11578
movq 0x21ab3(%rip), %rax     # 0x32ff8
movq (%rax), %rdi
leaq 0x18c01(%rip), %rsi     # 0x2a150
leaq 0x18d0e(%rip), %rdx     # 0x2a264
leaq 0x19307(%rip), %rcx     # 0x2a864
leaq 0x190d8(%rip), %r8      # 0x2a63c
movl $0x18a, %r9d            # imm = 0x18A
movb $0x0, %al
callq 0x2240
ud2
callq 0x2040
jmp 0x1157a
jmp 0x1157c
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movq 0x10(%rsp), %rcx
movslq 0x28(%rcx), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq 0x10(%rsp), %rcx
movq 0x30(%rcx), %rcx
subq %rcx, %rax
sarq $0x3, %rax
cmpq $0x2, %rax
jge 0x115e5
movq 0x21a46(%rip), %rax     # 0x32ff8
movq (%rax), %rdi
leaq 0x18b94(%rip), %rsi     # 0x2a150
leaq 0x18ca1(%rip), %rdx     # 0x2a264
leaq 0x1929a(%rip), %rcx     # 0x2a864
leaq 0x1906b(%rip), %r8      # 0x2a63c
movl $0x18b, %r9d            # imm = 0x18B
movb $0x0, %al
callq 0x2240
ud2
callq 0x2040
jmp 0x115e7
cmpq $0x0, 0x8(%rsp)
jne 0x11607
movq 0x10(%rsp), %rax
movq 0x38(%rax), %rax
movabsq $0x7ffc000000000000, %rcx # imm = 0x7FFC000000000000
movq %rcx, (%rax)
jmp 0x1161b
movq 0x8(%rsp), %rax
movq (%rax), %rcx
movq 0x10(%rsp), %rax
movq 0x38(%rax), %rax
movq %rcx, (%rax)
movq 0x18(%rsp), %rax
movq 0x5f0(%rax), %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x50(%rax)
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x5f0(%rax)
movb $0x1, 0x27(%rsp)
movb 0x27(%rsp), %al
andb $0x1, %al
addq $0x28, %rsp
retq
nopw %cs:(%rax,%rax)