// Licensing scope: see ../../LICENSE and this directory's LICENSE and NOTICE.
// Potentially incorporated Binaryen expression retains Apache-2.0 terms.
// Original Starshine contributions use the scoped MIT grant in ../../LICENSE.
// Modified for Starshine through 2026: implementation and validation use
// Starshine's representations and APIs; this is not an unchanged upstream file.
// Conservative notice retention does not establish copying or independence.

///|
// Qualified blocks have no inputs and no branches/early returns. Their ordered
// children have exactly the same scalar dependency and rewrite meaning when
// replayed in the parent. Indexed, tuple and other control stays on HOT.
fn dae2_raw_branchless_instructions(
  instructions : Array[@lib.Instruction],
  first_block~ : Int32 = -1,
) -> Array[@lib.Instruction]? {
  let mut first = first_block
  if first < 0 {
    for index in 0.. {
        match block_type {
          @lib.VoidBlockType | @lib.ValTypeBlockType(_) => ()
          _ => return None
        }
        sequences.push(children)
        positions.push(0)
      }
      @lib.Return if sequences.length() > 1 => return None
      // No label can remain or be rebased when an enclosing block is removed.
      @lib.Loop(_, _)
      | @lib.If(_, _, _)
      | @lib.Try(_, _, _, _)
      | @lib.TryTable(_, _, _)
      | @lib.Br(_)
      | @lib.BrIf(_)
      | @lib.BrTable(_, _)
      | @lib.Unreachable => return None
      _ => output.push(instr)
    }
  }
  Some(output)
}