;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
;; RUN: wasm-split %s --export-prefix='%' -g -o1 %t.1.wasm -o2 %t.2.wasm --keep-funcs=foo --jspi
;; RUN: wasm-dis %t.1.wasm | filecheck %s --check-prefix PRIMARY
;; RUN: wasm-dis %t.2.wasm | filecheck %s --check-prefix SECONDARY

;; Check that the call to bar first checks if the secondary module is loaded and
;; that bar is moved to the secondary module.

(module
 ;; PRIMARY:      (type $0 (func (param i32) (result i32)))

 ;; PRIMARY:      (type $1 (func))

 ;; PRIMARY:      (import "env" "__load_secondary_module" (func $fimport$0))

 ;; PRIMARY:      (import "placeholder" "0" (func $placeholder_0 (param i32) (result i32)))

 ;; PRIMARY:      (global $global$0 (mut i32) (i32.const 0))

 ;; PRIMARY:      (table $0 1 funcref)

 ;; PRIMARY:      (elem $0 (i32.const 0) $placeholder_0)

 ;; PRIMARY:      (export "foo" (func $foo))
 (export "foo" (func $foo))
 ;; PRIMARY:      (export "load_secondary_module_status" (global $global$0))

 ;; PRIMARY:      (export "%table" (table $0))

 ;; PRIMARY:      (func $foo (param $0 i32) (result i32)
 ;; PRIMARY-NEXT:  (if
 ;; PRIMARY-NEXT:   (i32.eqz
 ;; PRIMARY-NEXT:    (global.get $global$0)
 ;; PRIMARY-NEXT:   )
 ;; PRIMARY-NEXT:   (then
 ;; PRIMARY-NEXT:    (call $fimport$0)
 ;; PRIMARY-NEXT:   )
 ;; PRIMARY-NEXT:  )
 ;; PRIMARY-NEXT:  (call_indirect (type $0)
 ;; PRIMARY-NEXT:   (i32.const 0)
 ;; PRIMARY-NEXT:   (i32.const 0)
 ;; PRIMARY-NEXT:  )
 ;; PRIMARY-NEXT: )
 (func $foo (param i32) (result i32)
  (call $bar (i32.const 0))
 )
 ;; SECONDARY:      (type $0 (func (param i32) (result i32)))

 ;; SECONDARY:      (import "primary" "%table" (table $timport$0 1 funcref))

 ;; SECONDARY:      (import "primary" "foo" (func $foo (param i32) (result i32)))

 ;; SECONDARY:      (elem $0 (i32.const 0) $bar)

 ;; SECONDARY:      (func $bar (param $0 i32) (result i32)
 ;; SECONDARY-NEXT:  (call $foo
 ;; SECONDARY-NEXT:   (i32.const 1)
 ;; SECONDARY-NEXT:  )
 ;; SECONDARY-NEXT: )
 (func $bar (param i32) (result i32)
  (call $foo (i32.const 1))
 )
)