    {-# LANGUAGE CPP, BangPatterns, MagicHash, UnboxedTuples #-}
    --
    -- (c) The University of Glasgow 2002
    --
    -- Unboxed mutable Ints

    module FastMutInt(
            FastMutInt, newFastMutInt,
            readFastMutInt, writeFastMutInt
      ) where

    #define SIZEOF_HSINT  4

    import GHC.Exts
    # if __GLASGOW_HASKELL__>=612
    import GHC.IO     (IO(IO))
    #else
    import GHC.IOBase (IO(IO))
    #endif

    data FastMutInt = FastMutInt (MutableByteArray# RealWorld)

    newFastMutInt :: IO FastMutInt
    newFastMutInt :: IO FastMutInt
    newFastMutInt = (State# RealWorld -> (# State# RealWorld, FastMutInt #))
    -> IO FastMutInt
    forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
    IO ((State# RealWorld -> (# State# RealWorld, FastMutInt #))
     -> IO FastMutInt)
    -> (State# RealWorld -> (# State# RealWorld, FastMutInt #))
    -> IO FastMutInt
    forall a b. (a -> b) -> a -> b
    $ \State# RealWorld
    s ->
      case Int#
    -> State# RealWorld
    -> (# State# RealWorld, MutableByteArray# RealWorld #)
    forall d. Int# -> State# d -> (# State# d, MutableByteArray# d #)
    newByteArray# Int#
    size State# RealWorld
    s of { (# State# RealWorld
    s, MutableByteArray# RealWorld
    arr #) ->
      (# State# RealWorld
    s, MutableByteArray# RealWorld -> FastMutInt
    FastMutInt MutableByteArray# RealWorld
    arr #) }
      where !(I# Int#
    size) = SIZEOF_HSINT

    readFastMutInt :: FastMutInt -> IO Int
    readFastMutInt :: FastMutInt -> IO Int
    readFastMutInt (FastMutInt MutableByteArray# RealWorld
    arr) = (State# RealWorld -> (# State# RealWorld, Int #)) -> IO Int
    forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
    IO ((State# RealWorld -> (# State# RealWorld, Int #)) -> IO Int)
    -> (State# RealWorld -> (# State# RealWorld, Int #)) -> IO Int
    forall a b. (a -> b) -> a -> b
    $ \State# RealWorld
    s ->
      case MutableByteArray# RealWorld
    -> Int# -> State# RealWorld -> (# State# RealWorld, Int# #)
    forall d.
    MutableByteArray# d -> Int# -> State# d -> (# State# d, Int# #)
    readIntArray# MutableByteArray# RealWorld
    arr Int#
    0# State# RealWorld
    s of { (# State# RealWorld
    s, Int#
    i #) ->
      (# State# RealWorld
    s, Int# -> Int
    I# Int#
    i #) }

    writeFastMutInt :: FastMutInt -> Int -> IO ()
    writeFastMutInt :: FastMutInt -> Int -> IO ()
    writeFastMutInt (FastMutInt MutableByteArray# RealWorld
    arr) (I# Int#
    i) = (State# RealWorld -> (# State# RealWorld, () #)) -> IO ()
    forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
    IO ((State# RealWorld -> (# State# RealWorld, () #)) -> IO ())
    -> (State# RealWorld -> (# State# RealWorld, () #)) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \State# RealWorld
    s ->
      case MutableByteArray# RealWorld
    -> Int# -> Int# -> State# RealWorld -> State# RealWorld
    forall d.
    MutableByteArray# d -> Int# -> Int# -> State# d -> State# d
    writeIntArray# MutableByteArray# RealWorld
    arr Int#
    0# Int#
    i State# RealWorld
    s of { State# RealWorld
    s ->
      (# State# RealWorld
    s, () #) }