import hashlib
import ctypes


def GetSwitchId(label):
  """Generate a hash consistent with flags_ui::GetSwitchUMAId()."""
  digest = hashlib.md5(label.encode('utf-8')).hexdigest()
  first_eight_bytes = digest[:16]
  long_value = int(first_eight_bytes, 16)
  signed_32bit = ctypes.c_int(long_value).value
  return signed_32bit