(function (_, kotlin_kotlin) {
  'use strict';
  //region block: imports
  var imul = Math.imul;
  var VOID = kotlin_kotlin.$_$.c;
  var copyOfRange = kotlin_kotlin.$_$.w6;
  var protoOf = kotlin_kotlin.$_$.od;
  var objectCreate = kotlin_kotlin.$_$.nd;
  var toCharArray = kotlin_kotlin.$_$.dh;
  var initMetadataForCompanion = kotlin_kotlin.$_$.qc;
  var getKClassFromExpression = kotlin_kotlin.$_$.he;
  var THROW_CCE = kotlin_kotlin.$_$.vi;
  var Unit_instance = kotlin_kotlin.$_$.b1;
  var contentEquals = kotlin_kotlin.$_$.s6;
  var contentHashCode = kotlin_kotlin.$_$.t6;
  var IndexOutOfBoundsException_init_$Create$ = kotlin_kotlin.$_$.b3;
  var _UByte___init__impl__g9hnc4 = kotlin_kotlin.$_$.d4;
  var _UByte___get_data__impl__jof9qr = kotlin_kotlin.$_$.e4;
  var compareTo = kotlin_kotlin.$_$.gc;
  var StringBuilder_init_$Create$ = kotlin_kotlin.$_$.f2;
  var _Char___init__impl__6a9atx = kotlin_kotlin.$_$.q3;
  var Comparable = kotlin_kotlin.$_$.ii;
  var initMetadataForClass = kotlin_kotlin.$_$.pc;
  var decodeToString = kotlin_kotlin.$_$.df;
  var initMetadataForObject = kotlin_kotlin.$_$.vc;
  //endregion
  //region block: pre-declaration
  initMetadataForCompanion(Companion);
  initMetadataForClass(ByteString, 'ByteString', VOID, VOID, [Comparable]);
  initMetadataForObject(UnsafeByteStringOperations, 'UnsafeByteStringOperations');
  //endregion
  function ByteString_init_$Init$(data, startIndex, endIndex, $this) {
    startIndex = startIndex === VOID ? 0 : startIndex;
    endIndex = endIndex === VOID ? data.length : endIndex;
    ByteString.call($this, copyOfRange(data, startIndex, endIndex), null);
    return $this;
  }
  function ByteString_init_$Create$(data, startIndex, endIndex) {
    return ByteString_init_$Init$(data, startIndex, endIndex, objectCreate(protoOf(ByteString)));
  }
  function Companion() {
    Companion_instance = this;
    this.e2o_1 = new ByteString(new Int8Array(0), null);
    this.f2o_1 = toCharArray('0123456789abcdef');
  }
  protoOf(Companion).g2o = function (byteArray) {
    return new ByteString(byteArray, null);
  };
  var Companion_instance;
  function Companion_getInstance() {
    if (Companion_instance == null)
      new Companion();
    return Companion_instance;
  }
  function ByteString(data, dummy) {
    Companion_getInstance();
    this.h2o_1 = data;
    this.i2o_1 = 0;
  }
  protoOf(ByteString).i1 = function () {
    return this.h2o_1.length;
  };
  protoOf(ByteString).equals = function (other) {
    if (this === other)
      return true;
    if (other == null || !getKClassFromExpression(this).equals(getKClassFromExpression(other)))
      return false;
    if (!(other instanceof ByteString))
      THROW_CCE();
    if (!(other.h2o_1.length === this.h2o_1.length))
      return false;
    if (!(other.i2o_1 === 0) && !(this.i2o_1 === 0) && !(other.i2o_1 === this.i2o_1))
      return false;
    return contentEquals(this.h2o_1, other.h2o_1);
  };
  protoOf(ByteString).hashCode = function () {
    var hc = this.i2o_1;
    if (hc === 0) {
      hc = contentHashCode(this.h2o_1);
      this.i2o_1 = hc;
    }
    return hc;
  };
  protoOf(ByteString).k1 = function (index) {
    if (index < 0 || index >= this.i1())
      throw IndexOutOfBoundsException_init_$Create$('index (' + index + ') is out of byte string bounds: [0..' + this.i1() + ')');
    return this.h2o_1[index];
  };
  protoOf(ByteString).b1u = function (startIndex, endIndex) {
    var tmp;
    if (startIndex === endIndex) {
      tmp = Companion_getInstance().e2o_1;
    } else {
      tmp = ByteString_init_$Create$(this.h2o_1, startIndex, endIndex);
    }
    return tmp;
  };
  protoOf(ByteString).j2o = function (startIndex, endIndex, $super) {
    endIndex = endIndex === VOID ? this.i1() : endIndex;
    return $super === VOID ? this.b1u(startIndex, endIndex) : $super.b1u.call(this, startIndex, endIndex);
  };
  protoOf(ByteString).k2o = function (other) {
    if (other === this)
      return 0;
    var localData = this.h2o_1;
    var otherData = other.h2o_1;
    var inductionVariable = 0;
    var tmp0 = this.i1();
    // Inline function 'kotlin.math.min' call
    var b = other.i1();
    var last = Math.min(tmp0, b);
    if (inductionVariable < last)
      do {
        var i = inductionVariable;
        inductionVariable = inductionVariable + 1 | 0;
        // Inline function 'kotlin.toUByte' call
        var this_0 = localData[i];
        var tmp0_0 = _UByte___init__impl__g9hnc4(this_0);
        // Inline function 'kotlin.toUByte' call
        var this_1 = otherData[i];
        // Inline function 'kotlin.UByte.compareTo' call
        var other_0 = _UByte___init__impl__g9hnc4(this_1);
        // Inline function 'kotlin.UByte.toInt' call
        var tmp = _UByte___get_data__impl__jof9qr(tmp0_0) & 255;
        // Inline function 'kotlin.UByte.toInt' call
        var tmp$ret$5 = _UByte___get_data__impl__jof9qr(other_0) & 255;
        var cmp = compareTo(tmp, tmp$ret$5);
        if (!(cmp === 0))
          return cmp;
      }
       while (inductionVariable < last);
    return compareTo(this.i1(), other.i1());
  };
  protoOf(ByteString).d = function (other) {
    return this.k2o(other instanceof ByteString ? other : THROW_CCE());
  };
  protoOf(ByteString).toString = function () {
    if (isEmpty(this)) {
      return 'ByteString(size=0)';
    }
    var sizeStr = this.i1().toString();
    var len = (22 + sizeStr.length | 0) + imul(this.i1(), 2) | 0;
    // Inline function 'kotlin.with' call
    var $this$with = StringBuilder_init_$Create$(len);
    $this$with.q('ByteString(size=');
    $this$with.q(sizeStr);
    $this$with.q(' hex=');
    var localData = this.h2o_1;
    var inductionVariable = 0;
    var last = this.i1();
    if (inductionVariable < last)
      do {
        var i = inductionVariable;
        inductionVariable = inductionVariable + 1 | 0;
        var b = localData[i];
        $this$with.s(Companion_getInstance().f2o_1[(b >>> 4 | 0) & 15]);
        $this$with.s(Companion_getInstance().f2o_1[b & 15]);
      }
       while (inductionVariable < last);
    return $this$with.s(_Char___init__impl__6a9atx(41)).toString();
  };
  protoOf(ByteString).l2o = function () {
    return this.h2o_1;
  };
  function ByteString_0(bytes) {
    var tmp;
    // Inline function 'kotlin.collections.isEmpty' call
    if (bytes.length === 0) {
      tmp = Companion_getInstance().e2o_1;
    } else {
      tmp = Companion_getInstance().g2o(bytes);
    }
    return tmp;
  }
  function decodeToString_0(_this__u8e3s4) {
    return decodeToString(_this__u8e3s4.l2o());
  }
  function isEmpty(_this__u8e3s4) {
    return _this__u8e3s4.i1() === 0;
  }
  function UnsafeByteStringOperations() {
  }
  protoOf(UnsafeByteStringOperations).m2o = function (array) {
    return Companion_getInstance().g2o(array);
  };
  var UnsafeByteStringOperations_instance;
  function UnsafeByteStringOperations_getInstance() {
    return UnsafeByteStringOperations_instance;
  }
  //region block: init
  UnsafeByteStringOperations_instance = new UnsafeByteStringOperations();
  //endregion
  //region block: exports
  _.$_$ = _.$_$ || {};
  _.$_$.a = UnsafeByteStringOperations_instance;
  _.$_$.b = ByteString_init_$Create$;
  _.$_$.c = ByteString_0;
  _.$_$.d = decodeToString_0;
  //endregion
  return _;
}(module.exports, require('./kotlin-kotlin-stdlib.js')));

//# sourceMappingURL=kotlinx-io-kotlinx-io-bytestring.js.map
