Why does this code fails on release mode?

I'm trying to implement a simple stackful coroutine running on RISC-V to learn Rust and here is my code and cargo config:
Rust Playground

# .cargo/config.toml
[build]
target = "riscv64gc-unknown-linux-musl"

[target.riscv64gc-unknown-linux-musl]
linker = "rust-lld"
rustflags = ["-C", "target-feature=+crt-static"]

When I use debug mode or uncomment the println! statements in the code, the program runs correctly. But when I compile in release mode and run it on QEMU, the test fails and produces the following output:

TASK 1 STARTING
task: 1 counter: 0
TASK 2 STARTING
task: 2 counter: 0
TASK 3 STARTING
task: 3 counter: 0
task: 2 counter: 1
task: 3 counter: 1
task: 3 counter: 2
All tasks finished!

thread 'main' panicked at src\main.rs:28:5:
assertion `left == right` failed
  left: 0
 right: 3
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Why does this happen?Thank you all in advance.

Compare to original. (x86 version, from memory and I'm not trying it out.)
task_schedule was probably inline(never)
call to switch was asm! and had clobber.
Not sure what is happening in your spawn (without looking more closely,) it does not set stack up like x86.

Even though x86 code did this; after taking pointer (in init) you should not use original reference again.