{-# LANGUAGE BangPatterns #-}

import qualified Data.ByteString.Lazy  as L
import qualified Data.IntMap as Map

data State = State Int (Map.IntMap ())

main :: IO ()
main = do
    _ <- srloop (initialState 2 17) L.empty
    return ()

initialState :: Int -> Int -> State
initialState _ _ = State 0 Map.empty

srloop :: State -> L.ByteString -> IO [()]
srloop = loop
    where
        loop s str = do
            (s1, rm, outs) <- g s [] str
            if null outs
                then loop s rm
                else return outs

{-# NOINLINE g #-}
g :: State -> [()] -> L.ByteString -> IO (State, L.ByteString, [()])
g !s@(State _ !_) list str = return (s, str, reverse list)
