





'''simple docstring'''


from collections.abc import Generator
from math import sin


def 	__a(SCREAMING_SNAKE_CASE_  :					bytes    ):



    '''simple docstring'''





    if len(SCREAMING_SNAKE_CASE_    ) != 32:
        raise ValueError("Input must be of length 32"    )

    _lowerCAmelCase				=      B""
    for i in [3, 2, 1, 0]:
        little_endian += string_aa[8 * i : 8 * i + 8]
    return little_endian


def 	__a(SCREAMING_SNAKE_CASE_  :					int    ):



    '''simple docstring'''





    if i < 0:
        raise ValueError("Input must be non-negative"    )

    _lowerCAmelCase				=      format(SCREAMING_SNAKE_CASE_		,       "08x"    )[-8:]
    _lowerCAmelCase				=      B""
    for i in [3, 2, 1, 0]:
        little_endian_hex += hex_rep[2 * i : 2 * i + 2].encode("utf-8"    )
    return little_endian_hex


def 	__a(SCREAMING_SNAKE_CASE_  :					bytes    ):



    '''simple docstring'''





    _lowerCAmelCase				=      B""
    for char in message:
        bit_string += format(SCREAMING_SNAKE_CASE_		,       "08b"    ).encode("utf-8"    )
    _lowerCAmelCase				=      format(len(SCREAMING_SNAKE_CASE_    )		,       "064b"    ).encode("utf-8"    )

    # Pad bit_string to a multiple of 512 chars
    bit_string += b"1"
    while len(SCREAMING_SNAKE_CASE_    ) % 512 != 448:
        bit_string += b"0"
    bit_string += to_little_endian(start_len[32:]    ) + to_little_endian(start_len[:32]    )

    return bit_string


def 	__a(SCREAMING_SNAKE_CASE_  :					bytes    ):



    '''simple docstring'''





    if len(SCREAMING_SNAKE_CASE_    ) % 512 != 0:
        raise ValueError("Input must have length that's a multiple of 512"    )

    for pos in range(0		,       len(SCREAMING_SNAKE_CASE_    )		,       512    ):
        _lowerCAmelCase				=      bit_string[pos : pos + 512]
        _lowerCAmelCase				=      []
        for i in range(0		,       512		,       32    ):
            block_words.append(int(to_little_endian(block[i : i + 32]    )		,       2    )    )
        yield block_words


def 	__a(SCREAMING_SNAKE_CASE_  :					int    ):



    '''simple docstring'''





    if i < 0:
        raise ValueError("Input must be non-negative"    )

    _lowerCAmelCase				=      format(SCREAMING_SNAKE_CASE_		,       "032b"    )
    _lowerCAmelCase				=      ""
    for c in i_str:
        new_str += "1" if c == "0" else "0"
    return int(SCREAMING_SNAKE_CASE_		,       2    )


def 	__a(SCREAMING_SNAKE_CASE_  :					int		,       SCREAMING_SNAKE_CASE_  :					int    ):



    '''simple docstring'''





    return (a + b) % 2**32


def 	__a(SCREAMING_SNAKE_CASE_  :					int		,       SCREAMING_SNAKE_CASE_  :					int    ):



    '''simple docstring'''





    if i < 0:
        raise ValueError("Input must be non-negative"    )
    if shift < 0:
        raise ValueError("Shift must be non-negative"    )
    return ((i << shift) ^ (i >> (32 - shift))) % 2**32


def 	__a(SCREAMING_SNAKE_CASE_  :					bytes    ):



    '''simple docstring'''





    _lowerCAmelCase				=      preprocess(SCREAMING_SNAKE_CASE_    )

    _lowerCAmelCase				=      [int(2**32 * abs(sin(i + 1    )    )    ) for i in range(64    )]

    # Starting states
    _lowerCAmelCase				=      0X67452301
    _lowerCAmelCase				=      0XEFCDAB89
    _lowerCAmelCase				=      0X98BADCFE
    _lowerCAmelCase				=      0X10325476

    _lowerCAmelCase				=      [
        7,
        12,
        17,
        22,
        7,
        12,
        17,
        22,
        7,
        12,
        17,
        22,
        7,
        12,
        17,
        22,
        5,
        9,
        14,
        20,
        5,
        9,
        14,
        20,
        5,
        9,
        14,
        20,
        5,
        9,
        14,
        20,
        4,
        11,
        16,
        23,
        4,
        11,
        16,
        23,
        4,
        11,
        16,
        23,
        4,
        11,
        16,
        23,
        6,
        10,
        15,
        21,
        6,
        10,
        15,
        21,
        6,
        10,
        15,
        21,
        6,
        10,
        15,
        21,
    ]

    # Process bit string in chunks, each with 16 32-char words
    for block_words in get_block_words(SCREAMING_SNAKE_CASE_    ):
        _lowerCAmelCase				=      aa
        _lowerCAmelCase				=      ba
        _lowerCAmelCase				=      ca
        _lowerCAmelCase				=      da

        # Hash current chunk
        for i in range(64    ):
            if i <= 15:
                # f = (b & c) | (not_32(b) & d)     # Alternate definition for f
                _lowerCAmelCase				=      d ^ (b & (c ^ d))
                _lowerCAmelCase				=      i
            elif i <= 31:
                # f = (d & b) | (not_32(d) & c)     # Alternate definition for f
                _lowerCAmelCase				=      c ^ (d & (b ^ c))
                _lowerCAmelCase				=      (5 * i + 1) % 16
            elif i <= 47:
                _lowerCAmelCase				=      b ^ c ^ d
                _lowerCAmelCase				=      (3 * i + 5) % 16
            else:
                _lowerCAmelCase				=      c ^ (b | not_aa(SCREAMING_SNAKE_CASE_    ))
                _lowerCAmelCase				=      (7 * i) % 16
            _lowerCAmelCase				=      (f + a + added_consts[i] + block_words[g]) % 2**32
            _lowerCAmelCase				=      d
            _lowerCAmelCase				=      c
            _lowerCAmelCase				=      b
            _lowerCAmelCase				=      sum_aa(SCREAMING_SNAKE_CASE_		,       left_rotate_aa(SCREAMING_SNAKE_CASE_		,       shift_amounts[i]    )    )

        # Add hashed chunk to running total
        _lowerCAmelCase				=      sum_aa(SCREAMING_SNAKE_CASE_		,       SCREAMING_SNAKE_CASE_    )
        _lowerCAmelCase				=      sum_aa(SCREAMING_SNAKE_CASE_		,       SCREAMING_SNAKE_CASE_    )
        _lowerCAmelCase				=      sum_aa(SCREAMING_SNAKE_CASE_		,       SCREAMING_SNAKE_CASE_    )
        _lowerCAmelCase				=      sum_aa(SCREAMING_SNAKE_CASE_		,       SCREAMING_SNAKE_CASE_    )

    _lowerCAmelCase				=      reformat_hex(SCREAMING_SNAKE_CASE_    ) + reformat_hex(SCREAMING_SNAKE_CASE_    ) + reformat_hex(SCREAMING_SNAKE_CASE_    ) + reformat_hex(SCREAMING_SNAKE_CASE_    )
    return digest


if __name__ == "__main__":
       import doctest

       doctest.testmod()









'''simple docstring'''


from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


_SCREAMING_SNAKE_CASE	 =							{"configuration_xglm": ["XGLM_PRETRAINED_CONFIG_ARCHIVE_MAP", "XGLMConfig"]}

try:
       if not is_sentencepiece_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       _SCREAMING_SNAKE_CASE	 =							["XGLMTokenizer"]

try:
       if not is_tokenizers_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       _SCREAMING_SNAKE_CASE	 =							["XGLMTokenizerFast"]

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       _SCREAMING_SNAKE_CASE	 =							[
           "XGLM_PRETRAINED_MODEL_ARCHIVE_LIST",
           "XGLMForCausalLM",
           "XGLMModel",
           "XGLMPreTrainedModel",
       ]


try:
       if not is_flax_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       _SCREAMING_SNAKE_CASE	 =							[
           "FlaxXGLMForCausalLM",
           "FlaxXGLMModel",
           "FlaxXGLMPreTrainedModel",
       ]


try:
       if not is_tf_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       _SCREAMING_SNAKE_CASE	 =							[
           "TF_XGLM_PRETRAINED_MODEL_ARCHIVE_LIST",
           "TFXGLMForCausalLM",
           "TFXGLMModel",
           "TFXGLMPreTrainedModel",
       ]


if TYPE_CHECKING:
       from .configuration_xglm import XGLM_PRETRAINED_CONFIG_ARCHIVE_MAP, XGLMConfig

       try:
              if not is_sentencepiece_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .tokenization_xglm import XGLMTokenizer

       try:
              if not is_tokenizers_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .tokenization_xglm_fast import XGLMTokenizerFast

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_xglm import XGLM_PRETRAINED_MODEL_ARCHIVE_LIST, XGLMForCausalLM, XGLMModel, XGLMPreTrainedModel

       try:
              if not is_flax_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_flax_xglm import FlaxXGLMForCausalLM, FlaxXGLMModel, FlaxXGLMPreTrainedModel

       try:
              if not is_tf_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_tf_xglm import (
                  TF_XGLM_PRETRAINED_MODEL_ARCHIVE_LIST,
                  TFXGLMForCausalLM,
                  TFXGLMModel,
                  TFXGLMPreTrainedModel,
              )


else:
       import sys

       _SCREAMING_SNAKE_CASE	 =							_LazyModule(__name__, globals()["__file__"], _import_structure)


