replaceLoadsAndStores :: [Instruction] -> B.ByteString -> B.ByteString -> [Instruction]
replaceLoadsAndStores program oldValue newValue =
  map (update oldValue newValue) program
  where
    update old new instruction =
      case (instruction !! 0) of
        "LoadG" ->
          if (instruction !! 1) == oldValue then
            ["LoadG", newValue]
          else instruction
        "StoG" ->
          if (instruction !! 1) == oldValue then
            ["StoG", newValue]
          else instruction
        _ -> instruction


{-
  Uniqify: increment the address of every global load and store
-}
replaceLoadsAndStores :: [Instruction] -> B.ByteString -> B.ByteString -> [Instruction]
replaceLoadsAndStores program oldValue newValue =
  map (update oldValue newValue) program
  where
    update old new instruction =
      case (instruction !! 0) of
        "LoadG" ->
          if (instruction !! 1) == oldValue then
            ["LoadG", newValue]
          else instruction
        "StoG" ->
          if (instruction !! 1) == oldValue then
            ["StoG", newValue]
          else instruction
        _ -> instruction


{-
  Uniqify: increment the address of every global load and store
-}
replaceLoadsAndStores program oldValue newValue =
  map (update oldValue newValue) program
  where
    update old new instruction =
      case (instruction !! 0) of
        "LoadG" ->
          if (instruction !! 1) == oldValue then
            ["LoadG", newValue]
          else instruction
        "StoG" ->
          if (instruction !! 1) == oldValue then
            ["StoG", newValue]
          else instruction
        _ -> instruction


{-
  Uniqify: increment the address of every global load and store
-}