;;; TOOL: run-interp-wasi
;;; ARGS: --trace
;;
;; For details of fs_write API see:
;;   https://github.com/WebAssembly/WASI/blob/master/phases/snapshot/docs.md#fd_write
;;
;; It takes 4 args: fd, iovec, iovec_len, out_len
;;
;; Data Layout:
;;
;; 0-8  : "hello\n\0\0"
;; 8-12 : iovs ptr : 8
;; 12-20: iovs[0]  : 0, 4
;; 20-24: bytes written out param
;;

(import "wasi_snapshot_preview1" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32)))
(memory (export "memory") 1)
(data (i32.const  0) "hello\n\00\00")
(data (i32.const  8) "\08\00\00\00")
(data (i32.const 12) "\00\00\00\00\06\00\00\00")
(data (i32.const 20) "\00\00\00\00")

(func (export "_start")
  (call $fd_write (i32.const 1) (i32.const 12) (i32.const 1) (i32.const 20))
  drop
)
(;; STDOUT ;;;
hello
#0.    0: V:0  | i32.const 1
#0.    8: V:1  | i32.const 12
#0.   16: V:2  | i32.const 1
#0.   24: V:3  | i32.const 20
#0.   32: V:4  | call_import $0
>>> running wasi function "fd_write":
#0.   40: V:1  | drop
#0.   44: V:0  | return
;;; STDOUT ;;)
