{-# LINE 1 "src/GHC/Internal/InfoProv/Types/Compat.hsc" #-}
{-# LANGUAGE CApiFFI #-}
{-# LANGUAGE CPP     #-}


module GHC.Internal.InfoProv.Types.Compat (
    lookupIpeId
) where

import Data.Word
import Foreign.Ptr

{-# LINE 12 "src/GHC/Internal/InfoProv/Types/Compat.hsc" #-}
import Foreign.C.Types
import Foreign.Marshal.Alloc
import GHC.Stack.Profiler.Internal.Util (castPtrToWord64)

{-# LINE 16 "src/GHC/Internal/InfoProv/Types/Compat.hsc" #-}

import qualified GHC.Internal.InfoProv.Types as InfoProv


{-# LINE 24 "src/GHC/Internal/InfoProv/Types/Compat.hsc" #-}
foreign import ccall "lookupIPE" c_lookupIPE ::
  Ptr InfoProv.StgInfoTable ->
  Ptr InfoProv.InfoProvEnt ->
  IO CBool

{-# LINE 29 "src/GHC/Internal/InfoProv/Types/Compat.hsc" #-}

lookupIpeId :: Ptr InfoProv.StgInfoTable -> IO (Maybe Word64)
lookupIpeId :: Ptr StgInfoTable -> IO (Maybe Word64)
lookupIpeId Ptr StgInfoTable
itbl = do

{-# LINE 37 "src/GHC/Internal/InfoProv/Types/Compat.hsc" #-}
  Int -> (Ptr InfoProvEnt -> IO (Maybe Word64)) -> IO (Maybe Word64)
forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes ((Int
72)) ((Ptr InfoProvEnt -> IO (Maybe Word64)) -> IO (Maybe Word64))
-> (Ptr InfoProvEnt -> IO (Maybe Word64)) -> IO (Maybe Word64)
forall a b. (a -> b) -> a -> b
$ \Ptr InfoProvEnt
p -> do
{-# LINE 38 "src/GHC/Internal/InfoProv/Types/Compat.hsc" #-}
    res <- c_lookupIPE itbl p
    case res of
      1 -> pure $ Just $ castPtrToWord64 itbl
      _ -> return Nothing

{-# LINE 43 "src/GHC/Internal/InfoProv/Types/Compat.hsc" #-}