import {
  collectionSizeOrDefault36dulx8yinfqm as collectionSizeOrDefault,
  mapCapacity1h45rc3eh9p2l as mapCapacity,
  coerceAtLeast2bkz8m9ik7hep as coerceAtLeast,
  LinkedHashMap_init_$Create$1gzy1x4a46gd4 as LinkedHashMap_init_$Create$,
  Unit_instancev9v8hjid95df as Unit_instance,
  protoOf180f3jzyo7rfj as protoOf,
  initMetadataForCompanion1wyw17z38v6ac as initMetadataForCompanion,
  enumEntries20mr21zbe3az4 as enumEntries,
  objectCreate1ve4bgxiu4x98 as objectCreate,
  Enum3alwj03lh1n41 as Enum,
  initMetadataForClassbxx6q50dy2s7 as initMetadataForClass,
  VOID3gxj6tk5isa35 as VOID,
  toString1pkumu07cwy4m as toString,
  getStringHashCode26igk1bx568vk as getStringHashCode,
  initMetadataForInterface1egvbzx539z91 as initMetadataForInterface,
  isInterface3d6p8outrmvmk as isInterface,
  IllegalArgumentException_init_$Create$i4126l9nkbuo as IllegalArgumentException_init_$Create$,
  CoroutineImpl2sn3kjnwmfr10 as CoroutineImpl,
  THROW_CCE2g6jy02ryeudk as THROW_CCE,
  get_COROUTINE_SUSPENDED3ujt3p13qm4iy as get_COROUTINE_SUSPENDED,
  initMetadataForLambda3af3he42mmnh as initMetadataForLambda,
  ensureNotNull1e947j3ixpazm as ensureNotNull,
  CancellationException_init_$Create$3ch6sfo7bilrl as CancellationException_init_$Create$,
  CancellationException3b36o9qz53rgr as CancellationException,
  initMetadataForCoroutine1i7lbatuf5bnt as initMetadataForCoroutine,
  toString30pk9tzaqopn as toString_0,
  fromInt2ii0rejb1w62w as fromInt,
  ArrayList_init_$Create$37gc04va6yfo2 as ArrayList_init_$Create$,
  IllegalStateException_init_$Create$1h4bcfod21ri0 as IllegalStateException_init_$Create$,
  joinToString1cxrrlmo0chqs as joinToString,
  initMetadataForObject1cxne3s9w65el as initMetadataForObject,
  Exceptiondt2hlxn7j7vw as Exception,
  Exception_init_$Init$1giio8zw2zqqc as Exception_init_$Init$,
  captureStack1fzi4aczwc4hg as captureStack,
  defineProp3ur6h3slcvq4x as defineProp,
  compareTo3ankvs086tmwq as compareTo,
  decodeToString1dbzcjd620q25 as decodeToString,
  Randomei1bbeye8rr8 as Random,
  throwUninitializedPropertyAccessException14fok093f3k3t as throwUninitializedPropertyAccessException,
  RuntimeException1r3t0zl97011n as RuntimeException,
  RuntimeException_init_$Init$2o5rfs7mzby0b as RuntimeException_init_$Init$,
  ArrayList_init_$Create$2byt5m5yn22yy as ArrayList_init_$Create$_0,
  split2bvyvnrlcifjv as split,
  first58ocm7j58k3q as first,
  isCharSequence1ju9jr1w86plq as isCharSequence,
  trim11nh7r46at6sx as trim,
  drop3na99dw9feawf as drop,
  noWhenBranchMatchedException2a6r7ubxgky5j as noWhenBranchMatchedException,
} from './kotlin-kotlin-stdlib.mjs';
import {
  Dispatchers_getInstance2p2r3ndn98nn as Dispatchers_getInstance,
  launch1c91vkjzdi9sd as launch,
  CoroutineStart_UNDISPATCHED_getInstance3vhik5zct4e74 as CoroutineStart_UNDISPATCHED_getInstance,
  ChannelResult2y4k69ac6y3du as ChannelResult,
  _ChannelResult___get_isSuccess__impl__odq1z912b5ogo8613be as _ChannelResult___get_isSuccess__impl__odq1z9,
  CoroutineScopefcb5f5dwqcas as CoroutineScope,
  cancelConsumed2i0oizqhmljf6 as cancelConsumed,
  ClosedSendChannelException29m33prpq9jaw as ClosedSendChannelException,
  ClosedReceiveChannelException3ofg6gf5f5b38 as ClosedReceiveChannelException,
  CompletableDeferred2lnqvsbvx74d3 as CompletableDeferred,
  Job13y4jkazwjho0 as Job,
  Key_instance2rlngjw9v1qsd as Key_instance,
  CoroutineName2g5zosw74tf0f as CoroutineName,
  Factory_getInstance3boxsed5qz5iy as Factory_getInstance,
  DisposableHandle1uzxt8frdchxn as DisposableHandle,
  CopyableThrowable1mvc99jcyvivf as CopyableThrowable,
  Channel3r72atmcithql as Channel,
  withTimeoutOrNull3fn9ef0keo2ht as withTimeoutOrNull,
  BufferOverflow_SUSPEND_getInstance3j24qbb4wnzlq as BufferOverflow_SUSPEND_getInstance,
  BufferOverflow_DROP_OLDEST_getInstance3u1027cpcc1wz as BufferOverflow_DROP_OLDEST_getInstance,
  _ChannelResult___get_isClosed__impl__mg7kuu1g5u2zmbzbfb4 as _ChannelResult___get_isClosed__impl__mg7kuu,
  close$default1evna6yun3t5h as close$default,
  cancel$default1fq6eekptkf7a as cancel$default,
  SendChannel38sllbxw662ws as SendChannel,
  ReceiveChannel24wu5e2tj9lbp as ReceiveChannel,
} from './kotlinx-coroutines-core.mjs';
import {
  get_isTraceEnabled82xibuu04nxp as get_isTraceEnabled,
  ChannelIOException2i3t76lsrbgox as ChannelIOException,
  KtorSimpleLogger1xdphsp5l4e48 as KtorSimpleLogger,
  initCauseBridge1upxfqhavblt6 as initCauseBridge,
  getTimeMillis12o7k17x9fmwi as getTimeMillis,
  hex2ofqpe9ngcu1i as hex,
} from './ktor-ktor-utils.mjs';
import {
  BytePacketBuilder2biodf4wxvlba as BytePacketBuilder,
  writeFully359t6q8kam2g5 as writeFully,
  buildjygoh729rhy8 as build,
  get_size2imoy2jq11jxl as get_size,
  readText27783kyxjxi1g as readText,
  Charsets_getInstanceqkyjyusuh1b0 as Charsets_getInstance,
  toByteArray1i3ns5jnoqlv6 as toByteArray,
  ClosedByteChannelException3il8gfpye60w as ClosedByteChannelException,
  writeText19qfzm98fbm4l as writeText,
} from './ktor-ktor-io.mjs';
import {
  readByteArray1ri21h2rciakw as readByteArray,
  IOException_init_$Create$1sfdrtkx2q59o as IOException_init_$Create$,
  Buffergs925ekssbch as Buffer,
} from './kotlinx-io-kotlinx-io-core.mjs';
import {
  atomic$ref$130aurmcwdfdf1 as atomic$ref$1,
  atomic$boolean$1iggki4z65a2h as atomic$boolean$1,
} from './kotlinx-atomicfu.mjs';
//region block: imports
var imul = Math.imul;
//endregion
//region block: pre-declaration
initMetadataForCompanion(Companion);
initMetadataForClass(Codes, 'Codes', VOID, Enum);
initMetadataForClass(CloseReason, 'CloseReason');
function send(frame, $completion) {
  return this.s32().s18(frame, $completion);
}
initMetadataForInterface(WebSocketSession, 'WebSocketSession', VOID, VOID, [CoroutineScope], [1, 0]);
initMetadataForInterface(DefaultWebSocketSession, 'DefaultWebSocketSession', VOID, VOID, [WebSocketSession], [1, 0]);
initMetadataForCompanion(Companion_0);
initMetadataForLambda(DefaultWebSocketSessionImpl$start$slambda, CoroutineImpl, VOID, [1]);
initMetadataForLambda(DefaultWebSocketSessionImpl$runIncomingProcessor$slambda, CoroutineImpl, VOID, [1]);
initMetadataForLambda(DefaultWebSocketSessionImpl$runOutgoingProcessor$slambda, CoroutineImpl, VOID, [1]);
initMetadataForLambda(DefaultWebSocketSessionImpl$runOrCancelPinger$slambda, CoroutineImpl, VOID, [1]);
initMetadataForCoroutine($outgoingProcessorLoopCOROUTINE$, CoroutineImpl);
initMetadataForCoroutine($sendCloseSequenceCOROUTINE$, CoroutineImpl);
initMetadataForCoroutine($checkMaxFrameSizeCOROUTINE$, CoroutineImpl);
initMetadataForClass(DefaultWebSocketSessionImpl, 'DefaultWebSocketSessionImpl', VOID, VOID, [DefaultWebSocketSession, WebSocketSession], [1, 0, 2]);
initMetadataForObject(NonDisposableHandle, 'NonDisposableHandle', VOID, VOID, [DisposableHandle]);
initMetadataForClass(FrameTooBigException, 'FrameTooBigException', VOID, Exception, [CopyableThrowable]);
initMetadataForCompanion(Companion_1);
initMetadataForClass(FrameType, 'FrameType', VOID, Enum);
initMetadataForLambda(ponger$slambda, CoroutineImpl, VOID, [1]);
initMetadataForLambda(pinger$slambda$slambda, CoroutineImpl, VOID, [1]);
initMetadataForLambda(pinger$slambda$slambda_1, CoroutineImpl, VOID, [1]);
initMetadataForLambda(pinger$slambda, CoroutineImpl, VOID, [1]);
initMetadataForCompanion(Companion_2);
initMetadataForClass(WebSocketChannelsConfig, 'WebSocketChannelsConfig', WebSocketChannelsConfig);
initMetadataForCompanion(Companion_3);
initMetadataForClass(ChannelConfig, 'ChannelConfig');
initMetadataForClass(ChannelOverflow, 'ChannelOverflow', VOID, Enum);
initMetadataForCompanion(Companion_4);
initMetadataForClass(BoundedChannel, 'BoundedChannel', VOID, VOID, [SendChannel, ReceiveChannel], [1, 0]);
initMetadataForClass(ChannelOverflowException, 'ChannelOverflowException', VOID, RuntimeException);
initMetadataForInterface(WebSocketExtension, 'WebSocketExtension');
initMetadataForClass(WebSocketExtensionsConfig, 'WebSocketExtensionsConfig', WebSocketExtensionsConfig);
initMetadataForClass(WebSocketExtensionHeader, 'WebSocketExtensionHeader');
initMetadataForCoroutine($closeCOROUTINE$, CoroutineImpl);
initMetadataForClass(Frame, 'Frame');
initMetadataForClass(Binary, 'Binary', VOID, Frame);
initMetadataForClass(Text, 'Text', VOID, Frame);
initMetadataForClass(Close, 'Close', Close_init_$Create$_0, Frame);
initMetadataForClass(Ping, 'Ping', VOID, Frame);
initMetadataForClass(Pong, 'Pong', VOID, Frame);
initMetadataForCompanion(Companion_5);
//endregion
var Codes_NORMAL_instance;
var Codes_GOING_AWAY_instance;
var Codes_PROTOCOL_ERROR_instance;
var Codes_CANNOT_ACCEPT_instance;
var Codes_CLOSED_ABNORMALLY_instance;
var Codes_NOT_CONSISTENT_instance;
var Codes_VIOLATED_POLICY_instance;
var Codes_TOO_BIG_instance;
var Codes_NO_EXTENSION_instance;
var Codes_INTERNAL_ERROR_instance;
var Codes_SERVICE_RESTART_instance;
var Codes_TRY_AGAIN_LATER_instance;
function Companion() {
  Companion_instance = this;
  var tmp = this;
  // Inline function 'kotlin.collections.associateBy' call
  var this_0 = get_entries();
  var capacity = coerceAtLeast(mapCapacity(collectionSizeOrDefault(this_0, 10)), 16);
  // Inline function 'kotlin.collections.associateByTo' call
  var destination = LinkedHashMap_init_$Create$(capacity);
  var _iterator__ex2g4s = this_0.t();
  while (_iterator__ex2g4s.u()) {
    var element = _iterator__ex2g4s.v();
    var tmp$ret$2 = element.h32_1;
    destination.s2(tmp$ret$2, element);
  }
  tmp.i32_1 = destination;
  this.j32_1 = Codes_INTERNAL_ERROR_getInstance();
}
protoOf(Companion).k32 = function (code) {
  return this.i32_1.z2(code);
};
var Companion_instance;
function Companion_getInstance() {
  Codes_initEntries();
  if (Companion_instance == null)
    new Companion();
  return Companion_instance;
}
function values() {
  return [Codes_NORMAL_getInstance(), Codes_GOING_AWAY_getInstance(), Codes_PROTOCOL_ERROR_getInstance(), Codes_CANNOT_ACCEPT_getInstance(), Codes_CLOSED_ABNORMALLY_getInstance(), Codes_NOT_CONSISTENT_getInstance(), Codes_VIOLATED_POLICY_getInstance(), Codes_TOO_BIG_getInstance(), Codes_NO_EXTENSION_getInstance(), Codes_INTERNAL_ERROR_getInstance(), Codes_SERVICE_RESTART_getInstance(), Codes_TRY_AGAIN_LATER_getInstance()];
}
function get_entries() {
  if ($ENTRIES == null)
    $ENTRIES = enumEntries(values());
  return $ENTRIES;
}
var Codes_entriesInitialized;
function Codes_initEntries() {
  if (Codes_entriesInitialized)
    return Unit_instance;
  Codes_entriesInitialized = true;
  Codes_NORMAL_instance = new Codes('NORMAL', 0, 1000);
  Codes_GOING_AWAY_instance = new Codes('GOING_AWAY', 1, 1001);
  Codes_PROTOCOL_ERROR_instance = new Codes('PROTOCOL_ERROR', 2, 1002);
  Codes_CANNOT_ACCEPT_instance = new Codes('CANNOT_ACCEPT', 3, 1003);
  Codes_CLOSED_ABNORMALLY_instance = new Codes('CLOSED_ABNORMALLY', 4, 1006);
  Codes_NOT_CONSISTENT_instance = new Codes('NOT_CONSISTENT', 5, 1007);
  Codes_VIOLATED_POLICY_instance = new Codes('VIOLATED_POLICY', 6, 1008);
  Codes_TOO_BIG_instance = new Codes('TOO_BIG', 7, 1009);
  Codes_NO_EXTENSION_instance = new Codes('NO_EXTENSION', 8, 1010);
  Codes_INTERNAL_ERROR_instance = new Codes('INTERNAL_ERROR', 9, 1011);
  Codes_SERVICE_RESTART_instance = new Codes('SERVICE_RESTART', 10, 1012);
  Codes_TRY_AGAIN_LATER_instance = new Codes('TRY_AGAIN_LATER', 11, 1013);
  Companion_getInstance();
}
var $ENTRIES;
function CloseReason_init_$Init$(code, message, $this) {
  CloseReason.call($this, code.h32_1, message);
  return $this;
}
function CloseReason_init_$Create$(code, message) {
  return CloseReason_init_$Init$(code, message, objectCreate(protoOf(CloseReason)));
}
function Codes(name, ordinal, code) {
  Enum.call(this, name, ordinal);
  this.h32_1 = code;
}
function Codes_NORMAL_getInstance() {
  Codes_initEntries();
  return Codes_NORMAL_instance;
}
function Codes_GOING_AWAY_getInstance() {
  Codes_initEntries();
  return Codes_GOING_AWAY_instance;
}
function Codes_PROTOCOL_ERROR_getInstance() {
  Codes_initEntries();
  return Codes_PROTOCOL_ERROR_instance;
}
function Codes_CANNOT_ACCEPT_getInstance() {
  Codes_initEntries();
  return Codes_CANNOT_ACCEPT_instance;
}
function Codes_CLOSED_ABNORMALLY_getInstance() {
  Codes_initEntries();
  return Codes_CLOSED_ABNORMALLY_instance;
}
function Codes_NOT_CONSISTENT_getInstance() {
  Codes_initEntries();
  return Codes_NOT_CONSISTENT_instance;
}
function Codes_VIOLATED_POLICY_getInstance() {
  Codes_initEntries();
  return Codes_VIOLATED_POLICY_instance;
}
function Codes_TOO_BIG_getInstance() {
  Codes_initEntries();
  return Codes_TOO_BIG_instance;
}
function Codes_NO_EXTENSION_getInstance() {
  Codes_initEntries();
  return Codes_NO_EXTENSION_instance;
}
function Codes_INTERNAL_ERROR_getInstance() {
  Codes_initEntries();
  return Codes_INTERNAL_ERROR_instance;
}
function Codes_SERVICE_RESTART_getInstance() {
  Codes_initEntries();
  return Codes_SERVICE_RESTART_instance;
}
function Codes_TRY_AGAIN_LATER_getInstance() {
  Codes_initEntries();
  return Codes_TRY_AGAIN_LATER_instance;
}
function CloseReason(code, message) {
  this.l32_1 = code;
  this.m32_1 = message;
}
protoOf(CloseReason).n32 = function () {
  return Companion_getInstance().k32(this.l32_1);
};
protoOf(CloseReason).toString = function () {
  var tmp0_elvis_lhs = this.n32();
  return 'CloseReason(reason=' + toString(tmp0_elvis_lhs == null ? this.l32_1 : tmp0_elvis_lhs) + ', message=' + this.m32_1 + ')';
};
protoOf(CloseReason).hashCode = function () {
  var result = this.l32_1;
  result = imul(result, 31) + getStringHashCode(this.m32_1) | 0;
  return result;
};
protoOf(CloseReason).equals = function (other) {
  if (this === other)
    return true;
  if (!(other instanceof CloseReason))
    return false;
  if (!(this.l32_1 === other.l32_1))
    return false;
  if (!(this.m32_1 === other.m32_1))
    return false;
  return true;
};
function get_LOGGER() {
  _init_properties_DefaultWebSocketSession_kt__469s0y();
  return LOGGER;
}
var LOGGER;
function get_IncomingProcessorCoroutineName() {
  _init_properties_DefaultWebSocketSession_kt__469s0y();
  return IncomingProcessorCoroutineName;
}
var IncomingProcessorCoroutineName;
function get_OutgoingProcessorCoroutineName() {
  _init_properties_DefaultWebSocketSession_kt__469s0y();
  return OutgoingProcessorCoroutineName;
}
var OutgoingProcessorCoroutineName;
function get_NORMAL_CLOSE() {
  _init_properties_DefaultWebSocketSession_kt__469s0y();
  return NORMAL_CLOSE;
}
var NORMAL_CLOSE;
var OUTGOING_CHANNEL_CONFIG;
function DefaultWebSocketSession() {
}
function DefaultWebSocketSession_0(session, pingIntervalMillis, timeoutMillis, channelsConfig) {
  pingIntervalMillis = pingIntervalMillis === VOID ? 0n : pingIntervalMillis;
  timeoutMillis = timeoutMillis === VOID ? 15000n : timeoutMillis;
  channelsConfig = channelsConfig === VOID ? Companion_getInstance_2().u32_1 : channelsConfig;
  _init_properties_DefaultWebSocketSession_kt__469s0y();
  // Inline function 'kotlin.require' call
  if (!!isInterface(session, DefaultWebSocketSession)) {
    var message = 'Cannot wrap other DefaultWebSocketSession';
    throw IllegalArgumentException_init_$Create$(toString(message));
  }
  return new DefaultWebSocketSessionImpl(session, pingIntervalMillis, timeoutMillis, channelsConfig.v32_1, channelsConfig.w32_1);
}
function runIncomingProcessor($this, ponger) {
  var tmp = get_IncomingProcessorCoroutineName().hf(Dispatchers_getInstance().k12_1);
  return launch($this, tmp, VOID, DefaultWebSocketSessionImpl$runIncomingProcessor$slambda_0($this, ponger, null));
}
function runOutgoingProcessor($this) {
  var tmp = get_OutgoingProcessorCoroutineName().hf(Dispatchers_getInstance().k12_1);
  var tmp_0 = CoroutineStart_UNDISPATCHED_getInstance();
  return launch($this, tmp, tmp_0, DefaultWebSocketSessionImpl$runOutgoingProcessor$slambda_0($this, null));
}
function outgoingProcessorLoop($this, $completion) {
  var tmp = new $outgoingProcessorLoopCOROUTINE$($this, $completion);
  tmp.l8_1 = Unit_instance;
  tmp.m8_1 = null;
  return tmp.r8();
}
function sendCloseSequence($this, reason, exception, $completion) {
  exception = exception === VOID ? null : exception;
  var tmp = new $sendCloseSequenceCOROUTINE$($this, reason, exception, $completion);
  tmp.l8_1 = Unit_instance;
  tmp.m8_1 = null;
  return tmp.r8();
}
function tryClose($this) {
  return $this.b34_1.atomicfu$compareAndSet(false, true);
}
function runOrCancelPinger($this) {
  var interval = $this.e34_1;
  var tmp;
  if ($this.b34_1.kotlinx$atomicfu$value) {
    tmp = null;
  } else if (interval > 0n) {
    var tmp_0 = $this.u33_1.s32();
    var tmp_1 = $this.f34_1;
    tmp = pinger($this, tmp_0, interval, tmp_1, DefaultWebSocketSessionImpl$runOrCancelPinger$slambda_0($this, null));
  } else {
    tmp = null;
  }
  var newPinger = tmp;
  var tmp0_safe_receiver = $this.v33_1.atomicfu$getAndSet(newPinger);
  if (tmp0_safe_receiver == null)
    null;
  else
    tmp0_safe_receiver.a19();
  var tmp2_safe_receiver = newPinger == null ? null : new ChannelResult(newPinger.t18(Companion_getInstance_0().h34_1));
  if (tmp2_safe_receiver == null)
    null;
  else
    _ChannelResult___get_isSuccess__impl__odq1z9(tmp2_safe_receiver.d17_1);
  if ($this.b34_1.kotlinx$atomicfu$value && !(newPinger == null)) {
    runOrCancelPinger($this);
  }
}
function checkMaxFrameSize($this, packet, frame, $completion) {
  var tmp = new $checkMaxFrameSizeCOROUTINE$($this, packet, frame, $completion);
  tmp.l8_1 = Unit_instance;
  tmp.m8_1 = null;
  return tmp.r8();
}
function processIncomingExtensions($this, frame) {
  // Inline function 'kotlin.collections.fold' call
  var accumulator = frame;
  var _iterator__ex2g4s = $this.u34().t();
  while (_iterator__ex2g4s.u()) {
    var element = _iterator__ex2g4s.v();
    var current = accumulator;
    accumulator = element.v34(current);
  }
  return accumulator;
}
function processOutgoingExtensions($this, frame) {
  // Inline function 'kotlin.collections.fold' call
  var accumulator = frame;
  var _iterator__ex2g4s = $this.u34().t();
  while (_iterator__ex2g4s.u()) {
    var element = _iterator__ex2g4s.v();
    var current = accumulator;
    accumulator = element.w34(current);
  }
  return accumulator;
}
function Companion_0() {
  Companion_instance_0 = this;
  this.h34_1 = new Pong(new Int8Array(0), NonDisposableHandle_instance);
}
var Companion_instance_0;
function Companion_getInstance_0() {
  if (Companion_instance_0 == null)
    new Companion_0();
  return Companion_instance_0;
}
function DefaultWebSocketSessionImpl$start$slambda($incomingJob, $outgoingJob, this$0, resultContinuation) {
  this.f35_1 = $incomingJob;
  this.g35_1 = $outgoingJob;
  this.h35_1 = this$0;
  CoroutineImpl.call(this, resultContinuation);
}
protoOf(DefaultWebSocketSessionImpl$start$slambda).o1p = function ($this$launch, $completion) {
  var tmp = this.p1p($this$launch, $completion);
  tmp.l8_1 = Unit_instance;
  tmp.m8_1 = null;
  return tmp.r8();
};
protoOf(DefaultWebSocketSessionImpl$start$slambda).d9 = function (p1, $completion) {
  return this.o1p((!(p1 == null) ? isInterface(p1, CoroutineScope) : false) ? p1 : THROW_CCE(), $completion);
};
protoOf(DefaultWebSocketSessionImpl$start$slambda).r8 = function () {
  var suspendResult = this.l8_1;
  $sm: do
    try {
      var tmp = this.j8_1;
      switch (tmp) {
        case 0:
          this.k8_1 = 3;
          this.j8_1 = 1;
          suspendResult = this.f35_1.at(this);
          if (suspendResult === get_COROUTINE_SUSPENDED()) {
            return suspendResult;
          }

          continue $sm;
        case 1:
          this.j8_1 = 2;
          suspendResult = this.g35_1.at(this);
          if (suspendResult === get_COROUTINE_SUSPENDED()) {
            return suspendResult;
          }

          continue $sm;
        case 2:
          this.h35_1.x33_1.et();
          return Unit_instance;
        case 3:
          throw this.m8_1;
      }
    } catch ($p) {
      var e = $p;
      if (this.k8_1 === 3) {
        throw e;
      } else {
        this.j8_1 = this.k8_1;
        this.m8_1 = e;
      }
    }
   while (true);
};
protoOf(DefaultWebSocketSessionImpl$start$slambda).p1p = function ($this$launch, completion) {
  var i = new DefaultWebSocketSessionImpl$start$slambda(this.f35_1, this.g35_1, this.h35_1, completion);
  i.i35_1 = $this$launch;
  return i;
};
function DefaultWebSocketSessionImpl$start$slambda_0($incomingJob, $outgoingJob, this$0, resultContinuation) {
  var i = new DefaultWebSocketSessionImpl$start$slambda($incomingJob, $outgoingJob, this$0, resultContinuation);
  var l = function ($this$launch, $completion) {
    return i.o1p($this$launch, $completion);
  };
  l.$arity = 1;
  return l;
}
function DefaultWebSocketSessionImpl$runIncomingProcessor$slambda(this$0, $ponger, resultContinuation) {
  this.r35_1 = this$0;
  this.s35_1 = $ponger;
  CoroutineImpl.call(this, resultContinuation);
}
protoOf(DefaultWebSocketSessionImpl$runIncomingProcessor$slambda).o1p = function ($this$launch, $completion) {
  var tmp = this.p1p($this$launch, $completion);
  tmp.l8_1 = Unit_instance;
  tmp.m8_1 = null;
  return tmp.r8();
};
protoOf(DefaultWebSocketSessionImpl$runIncomingProcessor$slambda).d9 = function (p1, $completion) {
  return this.o1p((!(p1 == null) ? isInterface(p1, CoroutineScope) : false) ? p1 : THROW_CCE(), $completion);
};
protoOf(DefaultWebSocketSessionImpl$runIncomingProcessor$slambda).r8 = function () {
  var suspendResult = this.l8_1;
  $sm: do
    try {
      var tmp = this.j8_1;
      switch (tmp) {
        case 0:
          this.k8_1 = 39;
          this.d36_1 = null;
          this.w35_1 = null;
          this.v35_1 = false;
          this.x35_1 = Unit_instance;
          this.j8_1 = 1;
          continue $sm;
        case 1:
          this.j8_1 = 2;
          continue $sm;
        case 2:
          this.k8_1 = 33;
          this.k8_1 = 32;
          this.h36_1 = this.r35_1.u33_1.r32();
          this.j8_1 = 3;
          continue $sm;
        case 3:
          this.a36_1 = this.h36_1;
          this.z35_1 = null;
          this.j8_1 = 4;
          continue $sm;
        case 4:
          this.j8_1 = 5;
          continue $sm;
        case 5:
          this.j8_1 = 6;
          continue $sm;
        case 6:
          this.k8_1 = 29;
          this.k8_1 = 28;
          this.g36_1 = this.a36_1.t();
          this.j8_1 = 7;
          continue $sm;
        case 7:
          this.j8_1 = 8;
          suspendResult = this.g36_1.v16(this);
          if (suspendResult === get_COROUTINE_SUSPENDED()) {
            return suspendResult;
          }

          continue $sm;
        case 8:
          if (!suspendResult) {
            this.j8_1 = 26;
            continue $sm;
          }

          var e = this.g36_1.v();
          this.f36_1 = e;
          this.j8_1 = 9;
          continue $sm;
        case 9:
          this.e36_1 = this.f36_1;
          var this_0 = get_LOGGER();
          if (get_isTraceEnabled(this_0)) {
            this_0.h2j('WebSocketSession(' + toString(this.t35_1) + ') receiving frame ' + this.e36_1.toString());
          }

          var tmp0_subject = this.e36_1;
          if (tmp0_subject instanceof Close) {
            if (!this.r35_1.s32().x16()) {
              this.j8_1 = 18;
              var tmp_0 = this.r35_1.s32();
              var tmp1_elvis_lhs = readReason(this.e36_1);
              suspendResult = tmp_0.s18(Close_init_$Create$(tmp1_elvis_lhs == null ? get_NORMAL_CLOSE() : tmp1_elvis_lhs), this);
              if (suspendResult === get_COROUTINE_SUSPENDED()) {
                return suspendResult;
              }
              continue $sm;
            } else {
              this.j8_1 = 19;
              continue $sm;
            }
          } else {
            if (tmp0_subject instanceof Pong) {
              var tmp2_safe_receiver = this.r35_1.v33_1.kotlinx$atomicfu$value;
              if (tmp2_safe_receiver == null) {
                this.c36_1 = null;
                this.j8_1 = 17;
                continue $sm;
              } else {
                this.j8_1 = 16;
                suspendResult = tmp2_safe_receiver.s18(this.e36_1, this);
                if (suspendResult === get_COROUTINE_SUSPENDED()) {
                  return suspendResult;
                }
                continue $sm;
              }
            } else {
              if (tmp0_subject instanceof Ping) {
                this.j8_1 = 15;
                suspendResult = this.s35_1.s18(this.e36_1, this);
                if (suspendResult === get_COROUTINE_SUSPENDED()) {
                  return suspendResult;
                }
                continue $sm;
              } else {
                this.j8_1 = 10;
                suspendResult = checkMaxFrameSize(this.r35_1, this.w35_1, this.e36_1, this);
                if (suspendResult === get_COROUTINE_SUSPENDED()) {
                  return suspendResult;
                }
                continue $sm;
              }
            }
          }

        case 10:
          if (!this.e36_1.i36_1) {
            if (this.d36_1 == null) {
              this.d36_1 = this.e36_1;
            }
            if (this.w35_1 == null) {
              this.w35_1 = BytePacketBuilder();
            }
            writeFully(this.w35_1, this.e36_1.k36_1);
            this.j8_1 = 21;
            continue $sm;
          } else {
            this.j8_1 = 11;
            continue $sm;
          }

        case 11:
          if (this.d36_1 == null) {
            this.j8_1 = 14;
            suspendResult = this.r35_1.z33_1.s18(processIncomingExtensions(this.r35_1, this.e36_1), this);
            if (suspendResult === get_COROUTINE_SUSPENDED()) {
              return suspendResult;
            }
            continue $sm;
          } else {
            this.j8_1 = 12;
            continue $sm;
          }

        case 12:
          writeFully(ensureNotNull(this.w35_1), this.e36_1.k36_1);
          var defragmented = Companion_getInstance_5().q36(true, this.d36_1.j36_1, readByteArray(build(this.w35_1)), this.d36_1.m36_1, this.d36_1.n36_1, this.d36_1.o36_1);
          this.d36_1 = null;
          this.j8_1 = 13;
          suspendResult = this.r35_1.z33_1.s18(processIncomingExtensions(this.r35_1, defragmented), this);
          if (suspendResult === get_COROUTINE_SUSPENDED()) {
            return suspendResult;
          }

          continue $sm;
        case 13:
          var tmp_1 = this;
          tmp_1.b36_1 = Unit_instance;
          this.j8_1 = 20;
          continue $sm;
        case 14:
          this.j8_1 = 21;
          continue $sm;
        case 15:
          var tmp_2 = this;
          tmp_2.b36_1 = Unit_instance;
          this.j8_1 = 20;
          continue $sm;
        case 16:
          var tmp_3 = this;
          tmp_3.c36_1 = Unit_instance;
          this.j8_1 = 17;
          continue $sm;
        case 17:
          this.b36_1 = this.c36_1;
          this.j8_1 = 20;
          continue $sm;
        case 18:
          this.j8_1 = 19;
          continue $sm;
        case 19:
          this.v35_1 = true;
          this.j8_1 = 22;
          var tmp_4 = this;
          continue $sm;
        case 20:
          if (false) {
            this.j8_1 = 9;
            continue $sm;
          }

          this.j8_1 = 21;
          continue $sm;
        case 21:
          this.j8_1 = 7;
          continue $sm;
        case 22:
          this.k8_1 = 32;
          cancelConsumed(this.a36_1, this.z35_1);
          this.k8_1 = 39;
          this.j8_1 = 23;
          continue $sm;
        case 23:
          this.k8_1 = 39;
          this.s35_1.a19();
          var tmp0_safe_receiver = this.w35_1;
          if (tmp0_safe_receiver == null)
            null;
          else {
            tmp0_safe_receiver.j4();
          }

          this.r35_1.z33_1.a19();
          if (!this.v35_1) {
            this.j8_1 = 24;
            suspendResult = close(this.r35_1, CloseReason_init_$Create$(Codes_CLOSED_ABNORMALLY_getInstance(), 'Connection was closed without close frame'), this);
            if (suspendResult === get_COROUTINE_SUSPENDED()) {
              return suspendResult;
            }
            continue $sm;
          } else {
            this.j8_1 = 25;
            continue $sm;
          }

        case 24:
          this.j8_1 = 25;
          continue $sm;
        case 25:
          var tmp_5 = this;
          return Unit_instance;
        case 26:
          this.j8_1 = 27;
          var tmp_6 = this;
          continue $sm;
        case 27:
          this.k8_1 = 32;
          cancelConsumed(this.a36_1, this.z35_1);
          this.j8_1 = 31;
          continue $sm;
        case 28:
          this.k8_1 = 29;
          var tmp_7 = this.m8_1;
          if (tmp_7 instanceof Error) {
            var e_0 = this.m8_1;
            var tmp_8 = this;
            this.z35_1 = e_0;
            throw e_0;
          } else {
            throw this.m8_1;
          }

        case 29:
          this.k8_1 = 32;
          var t = this.m8_1;
          cancelConsumed(this.a36_1, this.z35_1);
          throw t;
        case 30:
          this.k8_1 = 32;
          cancelConsumed(this.a36_1, this.z35_1);
          if (false) {
            this.j8_1 = 3;
            continue $sm;
          }

          this.j8_1 = 31;
          continue $sm;
        case 31:
          this.x35_1 = Unit_instance;
          this.k8_1 = 39;
          this.j8_1 = 36;
          continue $sm;
        case 32:
          this.k8_1 = 33;
          var tmp_9 = this.m8_1;
          if (tmp_9 instanceof ClosedSendChannelException) {
            var _unused_var__etf5q3 = this.m8_1;
            var tmp_10 = this;
            tmp_10.x35_1 = Unit_instance;
            this.k8_1 = 39;
            this.j8_1 = 36;
            continue $sm;
          } else {
            var tmp_11 = this.m8_1;
            if (tmp_11 instanceof Error) {
              var cause = this.m8_1;
              var tmp_12 = this;
              this.s35_1.a19();
              tmp_12.x35_1 = this.r35_1.z33_1.y18(cause);
              this.k8_1 = 39;
              this.j8_1 = 36;
              continue $sm;
            } else {
              throw this.m8_1;
            }
          }

        case 33:
          this.k8_1 = 39;
          this.y35_1 = this.m8_1;
          this.s35_1.a19();
          var tmp0_safe_receiver_0 = this.w35_1;
          if (tmp0_safe_receiver_0 == null)
            null;
          else {
            tmp0_safe_receiver_0.j4();
          }

          this.r35_1.z33_1.a19();
          if (!this.v35_1) {
            this.j8_1 = 34;
            suspendResult = close(this.r35_1, CloseReason_init_$Create$(Codes_CLOSED_ABNORMALLY_getInstance(), 'Connection was closed without close frame'), this);
            if (suspendResult === get_COROUTINE_SUSPENDED()) {
              return suspendResult;
            }
            continue $sm;
          } else {
            this.j8_1 = 35;
            continue $sm;
          }

        case 34:
          this.j8_1 = 35;
          continue $sm;
        case 35:
          throw this.y35_1;
        case 36:
          this.u35_1 = this.x35_1;
          this.k8_1 = 39;
          this.s35_1.a19();
          var tmp0_safe_receiver_1 = this.w35_1;
          if (tmp0_safe_receiver_1 == null)
            null;
          else {
            tmp0_safe_receiver_1.j4();
          }

          this.r35_1.z33_1.a19();
          if (!this.v35_1) {
            this.j8_1 = 37;
            suspendResult = close(this.r35_1, CloseReason_init_$Create$(Codes_CLOSED_ABNORMALLY_getInstance(), 'Connection was closed without close frame'), this);
            if (suspendResult === get_COROUTINE_SUSPENDED()) {
              return suspendResult;
            }
            continue $sm;
          } else {
            this.j8_1 = 38;
            continue $sm;
          }

        case 37:
          this.j8_1 = 38;
          continue $sm;
        case 38:
          return Unit_instance;
        case 39:
          throw this.m8_1;
      }
    } catch ($p) {
      var e_1 = $p;
      if (this.k8_1 === 39) {
        throw e_1;
      } else {
        this.j8_1 = this.k8_1;
        this.m8_1 = e_1;
      }
    }
   while (true);
};
protoOf(DefaultWebSocketSessionImpl$runIncomingProcessor$slambda).p1p = function ($this$launch, completion) {
  var i = new DefaultWebSocketSessionImpl$runIncomingProcessor$slambda(this.r35_1, this.s35_1, completion);
  i.t35_1 = $this$launch;
  return i;
};
function DefaultWebSocketSessionImpl$runIncomingProcessor$slambda_0(this$0, $ponger, resultContinuation) {
  var i = new DefaultWebSocketSessionImpl$runIncomingProcessor$slambda(this$0, $ponger, resultContinuation);
  var l = function ($this$launch, $completion) {
    return i.o1p($this$launch, $completion);
  };
  l.$arity = 1;
  return l;
}
function DefaultWebSocketSessionImpl$runOutgoingProcessor$slambda(this$0, resultContinuation) {
  this.z36_1 = this$0;
  CoroutineImpl.call(this, resultContinuation);
}
protoOf(DefaultWebSocketSessionImpl$runOutgoingProcessor$slambda).o1p = function ($this$launch, $completion) {
  var tmp = this.p1p($this$launch, $completion);
  tmp.l8_1 = Unit_instance;
  tmp.m8_1 = null;
  return tmp.r8();
};
protoOf(DefaultWebSocketSessionImpl$runOutgoingProcessor$slambda).d9 = function (p1, $completion) {
  return this.o1p((!(p1 == null) ? isInterface(p1, CoroutineScope) : false) ? p1 : THROW_CCE(), $completion);
};
protoOf(DefaultWebSocketSessionImpl$runOutgoingProcessor$slambda).r8 = function () {
  var suspendResult = this.l8_1;
  $sm: do
    try {
      var tmp = this.j8_1;
      switch (tmp) {
        case 0:
          this.k8_1 = 13;
          this.j8_1 = 1;
          continue $sm;
        case 1:
          this.j8_1 = 2;
          continue $sm;
        case 2:
          this.k8_1 = 9;
          this.k8_1 = 4;
          this.j8_1 = 3;
          suspendResult = outgoingProcessorLoop(this.z36_1, this);
          if (suspendResult === get_COROUTINE_SUSPENDED()) {
            return suspendResult;
          }

          continue $sm;
        case 3:
          this.k8_1 = 13;
          this.j8_1 = 11;
          continue $sm;
        case 4:
          this.k8_1 = 9;
          var tmp_0 = this.m8_1;
          if (tmp_0 instanceof ClosedSendChannelException) {
            var _unused_var__etf5q3 = this.m8_1;
            this.k8_1 = 13;
            this.j8_1 = 11;
            continue $sm;
          } else {
            var tmp_1 = this.m8_1;
            if (tmp_1 instanceof ClosedReceiveChannelException) {
              var _unused_var__etf5q3_0 = this.m8_1;
              this.k8_1 = 13;
              this.j8_1 = 11;
              continue $sm;
            } else {
              var tmp_2 = this.m8_1;
              if (tmp_2 instanceof CancellationException) {
                var _unused_var__etf5q3_1 = this.m8_1;
                this.j8_1 = 5;
                suspendResult = sendCloseSequence(this.z36_1, CloseReason_init_$Create$(Codes_NORMAL_getInstance(), ''), VOID, this);
                if (suspendResult === get_COROUTINE_SUSPENDED()) {
                  return suspendResult;
                }
                continue $sm;
              } else {
                var tmp_3 = this.m8_1;
                if (tmp_3 instanceof ChannelIOException) {
                  var _unused_var__etf5q3_2 = this.m8_1;
                  this.k8_1 = 13;
                  this.j8_1 = 11;
                  continue $sm;
                } else {
                  var tmp_4 = this.m8_1;
                  if (tmp_4 instanceof Error) {
                    var cause = this.m8_1;
                    this.z36_1.a34_1.dt(CancellationException_init_$Create$('Failed to send frame', cause));
                    this.j8_1 = 6;
                    suspendResult = closeExceptionally(this.z36_1.u33_1, cause, this);
                    if (suspendResult === get_COROUTINE_SUSPENDED()) {
                      return suspendResult;
                    }
                    continue $sm;
                  } else {
                    throw this.m8_1;
                  }
                }
              }
            }
          }

        case 5:
          this.k8_1 = 13;
          this.j8_1 = 11;
          continue $sm;
        case 6:
          this.k8_1 = 13;
          this.j8_1 = 7;
          continue $sm;
        case 7:
          this.k8_1 = 13;
          this.z36_1.a34_1.c19();
          this.j8_1 = 8;
          suspendResult = close(this.z36_1.u33_1, VOID, this);
          if (suspendResult === get_COROUTINE_SUSPENDED()) {
            return suspendResult;
          }

          continue $sm;
        case 8:
          return Unit_instance;
        case 9:
          this.k8_1 = 13;
          this.b37_1 = this.m8_1;
          this.z36_1.a34_1.c19();
          this.j8_1 = 10;
          suspendResult = close(this.z36_1.u33_1, VOID, this);
          if (suspendResult === get_COROUTINE_SUSPENDED()) {
            return suspendResult;
          }

          continue $sm;
        case 10:
          throw this.b37_1;
        case 11:
          this.k8_1 = 13;
          this.z36_1.a34_1.c19();
          this.j8_1 = 12;
          suspendResult = close(this.z36_1.u33_1, VOID, this);
          if (suspendResult === get_COROUTINE_SUSPENDED()) {
            return suspendResult;
          }

          continue $sm;
        case 12:
          return Unit_instance;
        case 13:
          throw this.m8_1;
      }
    } catch ($p) {
      var e = $p;
      if (this.k8_1 === 13) {
        throw e;
      } else {
        this.j8_1 = this.k8_1;
        this.m8_1 = e;
      }
    }
   while (true);
};
protoOf(DefaultWebSocketSessionImpl$runOutgoingProcessor$slambda).p1p = function ($this$launch, completion) {
  var i = new DefaultWebSocketSessionImpl$runOutgoingProcessor$slambda(this.z36_1, completion);
  i.a37_1 = $this$launch;
  return i;
};
function DefaultWebSocketSessionImpl$runOutgoingProcessor$slambda_0(this$0, resultContinuation) {
  var i = new DefaultWebSocketSessionImpl$runOutgoingProcessor$slambda(this$0, resultContinuation);
  var l = function ($this$launch, $completion) {
    return i.o1p($this$launch, $completion);
  };
  l.$arity = 1;
  return l;
}
function DefaultWebSocketSessionImpl$runOrCancelPinger$slambda(this$0, resultContinuation) {
  this.k37_1 = this$0;
  CoroutineImpl.call(this, resultContinuation);
}
protoOf(DefaultWebSocketSessionImpl$runOrCancelPinger$slambda).m37 = function (it, $completion) {
  var tmp = this.n37(it, $completion);
  tmp.l8_1 = Unit_instance;
  tmp.m8_1 = null;
  return tmp.r8();
};
protoOf(DefaultWebSocketSessionImpl$runOrCancelPinger$slambda).d9 = function (p1, $completion) {
  return this.m37(p1 instanceof CloseReason ? p1 : THROW_CCE(), $completion);
};
protoOf(DefaultWebSocketSessionImpl$runOrCancelPinger$slambda).r8 = function () {
  var suspendResult = this.l8_1;
  $sm: do
    try {
      var tmp = this.j8_1;
      switch (tmp) {
        case 0:
          this.k8_1 = 2;
          this.j8_1 = 1;
          suspendResult = sendCloseSequence(this.k37_1, this.l37_1, IOException_init_$Create$('Ping timeout'), this);
          if (suspendResult === get_COROUTINE_SUSPENDED()) {
            return suspendResult;
          }

          continue $sm;
        case 1:
          return Unit_instance;
        case 2:
          throw this.m8_1;
      }
    } catch ($p) {
      var e = $p;
      if (this.k8_1 === 2) {
        throw e;
      } else {
        this.j8_1 = this.k8_1;
        this.m8_1 = e;
      }
    }
   while (true);
};
protoOf(DefaultWebSocketSessionImpl$runOrCancelPinger$slambda).n37 = function (it, completion) {
  var i = new DefaultWebSocketSessionImpl$runOrCancelPinger$slambda(this.k37_1, completion);
  i.l37_1 = it;
  return i;
};
function DefaultWebSocketSessionImpl$runOrCancelPinger$slambda_0(this$0, resultContinuation) {
  var i = new DefaultWebSocketSessionImpl$runOrCancelPinger$slambda(this$0, resultContinuation);
  var l = function (it, $completion) {
    return i.m37(it, $completion);
  };
  l.$arity = 1;
  return l;
}
function $outgoingProcessorLoopCOROUTINE$(_this__u8e3s4, resultContinuation) {
  CoroutineImpl.call(this, resultContinuation);
  this.f33_1 = _this__u8e3s4;
}
protoOf($outgoingProcessorLoopCOROUTINE$).r8 = function () {
  var suspendResult = this.l8_1;
  $sm: do
    try {
      var tmp = this.j8_1;
      switch (tmp) {
        case 0:
          this.k8_1 = 7;
          this.h33_1 = this.f33_1.a34_1.t();
          this.j8_1 = 1;
          continue $sm;
        case 1:
          this.j8_1 = 2;
          suspendResult = this.h33_1.v16(this);
          if (suspendResult === get_COROUTINE_SUSPENDED()) {
            return suspendResult;
          }

          continue $sm;
        case 2:
          if (!suspendResult) {
            this.j8_1 = 6;
            continue $sm;
          }

          var frame = this.h33_1.v();
          var this_0 = get_LOGGER();
          if (get_isTraceEnabled(this_0)) {
            this_0.h2j('Sending ' + frame.toString() + ' from session ' + toString(this.f33_1));
          }

          if (frame instanceof Close) {
            this.j8_1 = 3;
            suspendResult = sendCloseSequence(this.f33_1, readReason(frame), VOID, this);
            if (suspendResult === get_COROUTINE_SUSPENDED()) {
              return suspendResult;
            }
            continue $sm;
          } else {
            var tmp_0;
            if (frame instanceof Text) {
              tmp_0 = true;
            } else {
              tmp_0 = frame instanceof Binary;
            }
            if (tmp_0) {
              this.g33_1 = processOutgoingExtensions(this.f33_1, frame);
              this.j8_1 = 4;
              continue $sm;
            } else {
              this.g33_1 = frame;
              this.j8_1 = 4;
              continue $sm;
            }
          }

        case 3:
          this.j8_1 = 6;
          var tmp_1 = this;
          continue $sm;
        case 4:
          var processedFrame = this.g33_1;
          this.j8_1 = 5;
          suspendResult = this.f33_1.u33_1.s32().s18(processedFrame, this);
          if (suspendResult === get_COROUTINE_SUSPENDED()) {
            return suspendResult;
          }

          continue $sm;
        case 5:
          this.j8_1 = 1;
          continue $sm;
        case 6:
          return Unit_instance;
        case 7:
          throw this.m8_1;
      }
    } catch ($p) {
      var e = $p;
      if (this.k8_1 === 7) {
        throw e;
      } else {
        this.j8_1 = this.k8_1;
        this.m8_1 = e;
      }
    }
   while (true);
};
function $sendCloseSequenceCOROUTINE$(_this__u8e3s4, reason, exception, resultContinuation) {
  CoroutineImpl.call(this, resultContinuation);
  this.q33_1 = _this__u8e3s4;
  this.r33_1 = reason;
  this.s33_1 = exception;
}
protoOf($sendCloseSequenceCOROUTINE$).r8 = function () {
  var suspendResult = this.l8_1;
  $sm: do
    try {
      var tmp = this.j8_1;
      switch (tmp) {
        case 0:
          this.k8_1 = 6;
          if (!tryClose(this.q33_1))
            return Unit_instance;
          var this_0 = get_LOGGER();
          if (get_isTraceEnabled(this_0)) {
            this_0.h2j('Sending Close Sequence for session ' + toString(this.q33_1) + ' with reason ' + toString_0(this.r33_1) + ' and exception ' + toString_0(this.s33_1));
          }

          this.q33_1.x33_1.my();
          var tmp_0 = this;
          var tmp0_elvis_lhs = this.r33_1;
          tmp_0.t33_1 = tmp0_elvis_lhs == null ? CloseReason_init_$Create$(Codes_NORMAL_getInstance(), '') : tmp0_elvis_lhs;
          this.j8_1 = 1;
          continue $sm;
        case 1:
          this.k8_1 = 5;
          runOrCancelPinger(this.q33_1);
          if (!(this.t33_1.l32_1 === Codes_CLOSED_ABNORMALLY_getInstance().h32_1)) {
            this.j8_1 = 2;
            suspendResult = this.q33_1.u33_1.s32().s18(Close_init_$Create$(this.t33_1), this);
            if (suspendResult === get_COROUTINE_SUSPENDED()) {
              return suspendResult;
            }
            continue $sm;
          } else {
            this.j8_1 = 3;
            continue $sm;
          }

        case 2:
          this.j8_1 = 3;
          continue $sm;
        case 3:
          this.k8_1 = 6;
          this.j8_1 = 4;
          continue $sm;
        case 4:
          this.k8_1 = 6;
          this.q33_1.w33_1.ky(this.t33_1);
          if (!(this.s33_1 == null)) {
            this.q33_1.a34_1.y18(this.s33_1);
            this.q33_1.z33_1.y18(this.s33_1);
          }

          return Unit_instance;
        case 5:
          this.k8_1 = 6;
          var t = this.m8_1;
          this.q33_1.w33_1.ky(this.t33_1);
          if (!(this.s33_1 == null)) {
            this.q33_1.a34_1.y18(this.s33_1);
            this.q33_1.z33_1.y18(this.s33_1);
          }

          throw t;
        case 6:
          throw this.m8_1;
      }
    } catch ($p) {
      var e = $p;
      if (this.k8_1 === 6) {
        throw e;
      } else {
        this.j8_1 = this.k8_1;
        this.m8_1 = e;
      }
    }
   while (true);
};
function $checkMaxFrameSizeCOROUTINE$(_this__u8e3s4, packet, frame, resultContinuation) {
  CoroutineImpl.call(this, resultContinuation);
  this.q34_1 = _this__u8e3s4;
  this.r34_1 = packet;
  this.s34_1 = frame;
}
protoOf($checkMaxFrameSizeCOROUTINE$).r8 = function () {
  var suspendResult = this.l8_1;
  $sm: do
    try {
      var tmp = this.j8_1;
      switch (tmp) {
        case 0:
          this.k8_1 = 3;
          var tmp_0 = this;
          var tmp_1 = this.s34_1.k36_1.length;
          var tmp0_safe_receiver = this.r34_1;
          var tmp1_elvis_lhs = tmp0_safe_receiver == null ? null : get_size(tmp0_safe_receiver);
          tmp_0.t34_1 = tmp_1 + (tmp1_elvis_lhs == null ? 0 : tmp1_elvis_lhs) | 0;
          if (fromInt(this.t34_1) > this.q34_1.q32()) {
            var tmp2_safe_receiver = this.r34_1;
            if (tmp2_safe_receiver == null)
              null;
            else {
              tmp2_safe_receiver.j4();
            }
            this.j8_1 = 2;
            suspendResult = close(this.q34_1, CloseReason_init_$Create$(Codes_TOO_BIG_getInstance(), 'Frame is too big: ' + this.t34_1 + '. Max size is ' + this.q34_1.q32().toString()), this);
            if (suspendResult === get_COROUTINE_SUSPENDED()) {
              return suspendResult;
            }
            continue $sm;
          } else {
            this.j8_1 = 1;
            continue $sm;
          }

        case 1:
          return Unit_instance;
        case 2:
          throw new FrameTooBigException(fromInt(this.t34_1));
        case 3:
          throw this.m8_1;
      }
    } catch ($p) {
      var e = $p;
      if (this.k8_1 === 3) {
        throw e;
      } else {
        this.j8_1 = this.k8_1;
        this.m8_1 = e;
      }
    }
   while (true);
};
function DefaultWebSocketSessionImpl(raw, pingIntervalMillis, timeoutMillis, incomingFramesConfig, outgoingFramesConfig) {
  Companion_getInstance_0();
  this.u33_1 = raw;
  this.v33_1 = atomic$ref$1(null);
  this.w33_1 = CompletableDeferred();
  this.x33_1 = Job();
  this.y33_1 = this.u33_1.ur().ff(Key_instance).hf(this.x33_1).hf(new CoroutineName('ws-default'));
  this.z33_1 = from(Factory_getInstance(), incomingFramesConfig);
  this.a34_1 = from(Factory_getInstance(), outgoingFramesConfig);
  this.b34_1 = atomic$boolean$1(false);
  var tmp = this;
  // Inline function 'kotlin.collections.mutableListOf' call
  tmp.c34_1 = ArrayList_init_$Create$();
  this.d34_1 = atomic$boolean$1(false);
  this.e34_1 = pingIntervalMillis;
  this.f34_1 = timeoutMillis;
  this.g34_1 = this.w33_1;
}
protoOf(DefaultWebSocketSessionImpl).ur = function () {
  return this.y33_1;
};
protoOf(DefaultWebSocketSessionImpl).r32 = function () {
  return this.z33_1;
};
protoOf(DefaultWebSocketSessionImpl).s32 = function () {
  return this.a34_1;
};
protoOf(DefaultWebSocketSessionImpl).u34 = function () {
  return this.c34_1;
};
protoOf(DefaultWebSocketSessionImpl).p32 = function (value) {
  this.u33_1.p32(value);
};
protoOf(DefaultWebSocketSessionImpl).q32 = function () {
  return this.u33_1.q32();
};
protoOf(DefaultWebSocketSessionImpl).o32 = function (negotiatedExtensions) {
  if (!this.d34_1.atomicfu$compareAndSet(false, true)) {
    // Inline function 'kotlin.error' call
    var message = 'WebSocket session ' + toString(this) + ' is already started.';
    throw IllegalStateException_init_$Create$(toString(message));
  }
  // Inline function 'io.ktor.util.logging.trace' call
  var this_0 = get_LOGGER();
  if (get_isTraceEnabled(this_0)) {
    var tmp$ret$2 = 'Starting default WebSocketSession(' + toString(this) + ') ' + ('with negotiated extensions: ' + joinToString(negotiatedExtensions));
    this_0.h2j(tmp$ret$2);
  }
  this.c34_1.j1(negotiatedExtensions);
  runOrCancelPinger(this);
  var incomingJob = runIncomingProcessor(this, ponger(this, this.s32()));
  var outgoingJob = runOutgoingProcessor(this);
  launch(this, VOID, VOID, DefaultWebSocketSessionImpl$start$slambda_0(incomingJob, outgoingJob, this, null));
};
protoOf(DefaultWebSocketSessionImpl).i1g = function ($completion) {
  return this.u33_1.i1g($completion);
};
var properties_initialized_DefaultWebSocketSession_kt_6cjlhc;
function _init_properties_DefaultWebSocketSession_kt__469s0y() {
  if (!properties_initialized_DefaultWebSocketSession_kt_6cjlhc) {
    properties_initialized_DefaultWebSocketSession_kt_6cjlhc = true;
    LOGGER = KtorSimpleLogger('io.ktor.websocket.WebSocket');
    IncomingProcessorCoroutineName = new CoroutineName('ws-incoming-processor');
    OutgoingProcessorCoroutineName = new CoroutineName('ws-outgoing-processor');
    NORMAL_CLOSE = CloseReason_init_$Create$(Codes_NORMAL_getInstance(), 'OK');
    var tmp0_safe_receiver = get_OUTGOING_CHANNEL_CAPACITY();
    var tmp;
    if (tmp0_safe_receiver == null) {
      tmp = null;
    } else {
      // Inline function 'kotlin.let' call
      tmp = new ChannelConfig(tmp0_safe_receiver, ChannelOverflow_SUSPEND_getInstance());
    }
    OUTGOING_CHANNEL_CONFIG = tmp;
  }
}
function readReason(_this__u8e3s4) {
  if (_this__u8e3s4.k36_1.length < 2) {
    return null;
  }
  // Inline function 'io.ktor.utils.io.core.buildPacket' call
  var builder = new Buffer();
  writeFully(builder, _this__u8e3s4.k36_1);
  var packet = builder;
  var code = packet.wo();
  var message = readText(packet);
  return new CloseReason(code, message);
}
function NonDisposableHandle() {
}
protoOf(NonDisposableHandle).fv = function () {
  return Unit_instance;
};
protoOf(NonDisposableHandle).toString = function () {
  return 'NonDisposableHandle';
};
protoOf(NonDisposableHandle).hashCode = function () {
  return 207988788;
};
protoOf(NonDisposableHandle).equals = function (other) {
  if (this === other)
    return true;
  if (!(other instanceof NonDisposableHandle))
    return false;
  return true;
};
var NonDisposableHandle_instance;
function NonDisposableHandle_getInstance() {
  return NonDisposableHandle_instance;
}
function FrameTooBigException(frameSize) {
  Exception_init_$Init$(this);
  captureStack(this, FrameTooBigException);
  this.o37_1 = frameSize;
  delete this.message;
}
protoOf(FrameTooBigException).e = function () {
  return 'Frame is too big: ' + this.o37_1.toString();
};
protoOf(FrameTooBigException).vy = function () {
  // Inline function 'kotlin.also' call
  var this_0 = new FrameTooBigException(this.o37_1);
  initCauseBridge(this_0, this);
  return this_0;
};
var FrameType_TEXT_instance;
var FrameType_BINARY_instance;
var FrameType_CLOSE_instance;
var FrameType_PING_instance;
var FrameType_PONG_instance;
function Companion_1() {
  Companion_instance_1 = this;
  var tmp = this;
  var tmp0 = get_entries_0();
  var tmp$ret$0;
  $l$block_0: {
    // Inline function 'kotlin.collections.maxByOrNull' call
    var iterator = tmp0.t();
    if (!iterator.u()) {
      tmp$ret$0 = null;
      break $l$block_0;
    }
    var maxElem = iterator.v();
    if (!iterator.u()) {
      tmp$ret$0 = maxElem;
      break $l$block_0;
    }
    var maxValue = maxElem.s37_1;
    do {
      var e = iterator.v();
      var v = e.s37_1;
      if (compareTo(maxValue, v) < 0) {
        maxElem = e;
        maxValue = v;
      }
    }
     while (iterator.u());
    tmp$ret$0 = maxElem;
  }
  tmp.t37_1 = ensureNotNull(tmp$ret$0).s37_1;
  var tmp_0 = this;
  var tmp_1 = 0;
  var tmp_2 = this.t37_1 + 1 | 0;
  // Inline function 'kotlin.arrayOfNulls' call
  var tmp_3 = Array(tmp_2);
  while (tmp_1 < tmp_2) {
    var tmp_4 = tmp_1;
    var tmp0_0 = get_entries_0();
    var tmp$ret$5;
    $l$block_2: {
      // Inline function 'kotlin.collections.singleOrNull' call
      var single = null;
      var found = false;
      var _iterator__ex2g4s = tmp0_0.t();
      while (_iterator__ex2g4s.u()) {
        var element = _iterator__ex2g4s.v();
        if (element.s37_1 === tmp_4) {
          if (found) {
            tmp$ret$5 = null;
            break $l$block_2;
          }
          single = element;
          found = true;
        }
      }
      if (!found) {
        tmp$ret$5 = null;
        break $l$block_2;
      }
      tmp$ret$5 = single;
    }
    tmp_3[tmp_4] = tmp$ret$5;
    tmp_1 = tmp_1 + 1 | 0;
  }
  tmp_0.u37_1 = tmp_3;
}
var Companion_instance_1;
function Companion_getInstance_1() {
  FrameType_initEntries();
  if (Companion_instance_1 == null)
    new Companion_1();
  return Companion_instance_1;
}
function values_0() {
  return [FrameType_TEXT_getInstance(), FrameType_BINARY_getInstance(), FrameType_CLOSE_getInstance(), FrameType_PING_getInstance(), FrameType_PONG_getInstance()];
}
function get_entries_0() {
  if ($ENTRIES_0 == null)
    $ENTRIES_0 = enumEntries(values_0());
  return $ENTRIES_0;
}
var FrameType_entriesInitialized;
function FrameType_initEntries() {
  if (FrameType_entriesInitialized)
    return Unit_instance;
  FrameType_entriesInitialized = true;
  FrameType_TEXT_instance = new FrameType('TEXT', 0, false, 1);
  FrameType_BINARY_instance = new FrameType('BINARY', 1, false, 2);
  FrameType_CLOSE_instance = new FrameType('CLOSE', 2, true, 8);
  FrameType_PING_instance = new FrameType('PING', 3, true, 9);
  FrameType_PONG_instance = new FrameType('PONG', 4, true, 10);
  Companion_getInstance_1();
}
var $ENTRIES_0;
function FrameType(name, ordinal, controlFrame, opcode) {
  Enum.call(this, name, ordinal);
  this.r37_1 = controlFrame;
  this.s37_1 = opcode;
}
function FrameType_TEXT_getInstance() {
  FrameType_initEntries();
  return FrameType_TEXT_instance;
}
function FrameType_BINARY_getInstance() {
  FrameType_initEntries();
  return FrameType_BINARY_instance;
}
function FrameType_CLOSE_getInstance() {
  FrameType_initEntries();
  return FrameType_CLOSE_instance;
}
function FrameType_PING_getInstance() {
  FrameType_initEntries();
  return FrameType_PING_instance;
}
function FrameType_PONG_getInstance() {
  FrameType_initEntries();
  return FrameType_PONG_instance;
}
function get_PongerCoroutineName() {
  _init_properties_PingPong_kt__9aqxey();
  return PongerCoroutineName;
}
var PongerCoroutineName;
function get_PingerCoroutineName() {
  _init_properties_PingPong_kt__9aqxey();
  return PingerCoroutineName;
}
var PingerCoroutineName;
function ponger(_this__u8e3s4, outgoing) {
  _init_properties_PingPong_kt__9aqxey();
  var channel = Channel(5);
  var tmp = get_PongerCoroutineName();
  launch(_this__u8e3s4, tmp, VOID, ponger$slambda_0(channel, outgoing, null));
  return channel;
}
function pinger(_this__u8e3s4, outgoing, periodMillis, timeoutMillis, onTimeout) {
  _init_properties_PingPong_kt__9aqxey();
  var actorJob = Job();
  var channel = Channel(2147483647);
  var tmp = actorJob.hf(get_PingerCoroutineName());
  launch(_this__u8e3s4, tmp, VOID, pinger$slambda_0(periodMillis, timeoutMillis, onTimeout, channel, outgoing, null));
  var tmp_0 = ensureNotNull(_this__u8e3s4.ur().w8(Key_instance));
  tmp_0.ws(pinger$lambda(actorJob));
  return channel;
}
function ponger$slambda($channel, $outgoing, resultContinuation) {
  this.d38_1 = $channel;
  this.e38_1 = $outgoing;
  CoroutineImpl.call(this, resultContinuation);
}
protoOf(ponger$slambda).o1p = function ($this$launch, $completion) {
  var tmp = this.p1p($this$launch, $completion);
  tmp.l8_1 = Unit_instance;
  tmp.m8_1 = null;
  return tmp.r8();
};
protoOf(ponger$slambda).d9 = function (p1, $completion) {
  return this.o1p((!(p1 == null) ? isInterface(p1, CoroutineScope) : false) ? p1 : THROW_CCE(), $completion);
};
protoOf(ponger$slambda).r8 = function () {
  var suspendResult = this.l8_1;
  $sm: do
    try {
      var tmp = this.j8_1;
      switch (tmp) {
        case 0:
          this.k8_1 = 14;
          this.k8_1 = 13;
          this.j38_1 = this.d38_1;
          this.j8_1 = 1;
          continue $sm;
        case 1:
          this.h38_1 = this.j38_1;
          this.g38_1 = null;
          this.j8_1 = 2;
          continue $sm;
        case 2:
          this.j8_1 = 3;
          continue $sm;
        case 3:
          this.k8_1 = 10;
          this.k8_1 = 9;
          this.i38_1 = this.h38_1.t();
          this.j8_1 = 4;
          continue $sm;
        case 4:
          this.j8_1 = 5;
          suspendResult = this.i38_1.v16(this);
          if (suspendResult === get_COROUTINE_SUSPENDED()) {
            return suspendResult;
          }

          continue $sm;
        case 5:
          if (!suspendResult) {
            this.j8_1 = 7;
            continue $sm;
          }

          var e = this.i38_1.v();
          get_LOGGER().h2j('Received ping message, sending pong message');
          this.j8_1 = 6;
          suspendResult = this.e38_1.s18(new Pong(e.k36_1), this);
          if (suspendResult === get_COROUTINE_SUSPENDED()) {
            return suspendResult;
          }

          continue $sm;
        case 6:
          this.j8_1 = 4;
          continue $sm;
        case 7:
          this.j8_1 = 8;
          var tmp_0 = this;
          continue $sm;
        case 8:
          this.k8_1 = 13;
          cancelConsumed(this.h38_1, this.g38_1);
          this.j8_1 = 12;
          continue $sm;
        case 9:
          this.k8_1 = 10;
          var tmp_1 = this.m8_1;
          if (tmp_1 instanceof Error) {
            var e_0 = this.m8_1;
            var tmp_2 = this;
            this.g38_1 = e_0;
            throw e_0;
          } else {
            throw this.m8_1;
          }

        case 10:
          this.k8_1 = 13;
          var t = this.m8_1;
          cancelConsumed(this.h38_1, this.g38_1);
          throw t;
        case 11:
          this.k8_1 = 13;
          cancelConsumed(this.h38_1, this.g38_1);
          if (false) {
            this.j8_1 = 1;
            continue $sm;
          }

          this.j8_1 = 12;
          continue $sm;
        case 12:
          this.k8_1 = 14;
          this.j8_1 = 15;
          continue $sm;
        case 13:
          this.k8_1 = 14;
          var tmp_3 = this.m8_1;
          if (tmp_3 instanceof ClosedSendChannelException) {
            var _unused_var__etf5q3 = this.m8_1;
            this.j8_1 = 15;
            continue $sm;
          } else {
            throw this.m8_1;
          }

        case 14:
          throw this.m8_1;
        case 15:
          this.k8_1 = 14;
          return Unit_instance;
      }
    } catch ($p) {
      var e_1 = $p;
      if (this.k8_1 === 14) {
        throw e_1;
      } else {
        this.j8_1 = this.k8_1;
        this.m8_1 = e_1;
      }
    }
   while (true);
};
protoOf(ponger$slambda).p1p = function ($this$launch, completion) {
  var i = new ponger$slambda(this.d38_1, this.e38_1, completion);
  i.f38_1 = $this$launch;
  return i;
};
function ponger$slambda_0($channel, $outgoing, resultContinuation) {
  var i = new ponger$slambda($channel, $outgoing, resultContinuation);
  var l = function ($this$launch, $completion) {
    return i.o1p($this$launch, $completion);
  };
  l.$arity = 1;
  return l;
}
function pinger$slambda$slambda($channel, resultContinuation) {
  this.s38_1 = $channel;
  CoroutineImpl.call(this, resultContinuation);
}
protoOf(pinger$slambda$slambda).o1p = function ($this$withTimeoutOrNull, $completion) {
  var tmp = this.p1p($this$withTimeoutOrNull, $completion);
  tmp.l8_1 = Unit_instance;
  tmp.m8_1 = null;
  return tmp.r8();
};
protoOf(pinger$slambda$slambda).d9 = function (p1, $completion) {
  return this.o1p((!(p1 == null) ? isInterface(p1, CoroutineScope) : false) ? p1 : THROW_CCE(), $completion);
};
protoOf(pinger$slambda$slambda).r8 = function () {
  var suspendResult = this.l8_1;
  $sm: do
    try {
      var tmp = this.j8_1;
      switch (tmp) {
        case 0:
          this.k8_1 = 3;
          this.j8_1 = 1;
          continue $sm;
        case 1:
          if (!true) {
            this.j8_1 = 4;
            continue $sm;
          }

          this.j8_1 = 2;
          suspendResult = this.s38_1.w18(this);
          if (suspendResult === get_COROUTINE_SUSPENDED()) {
            return suspendResult;
          }

          continue $sm;
        case 2:
          this.j8_1 = 1;
          continue $sm;
        case 3:
          throw this.m8_1;
        case 4:
          return Unit_instance;
      }
    } catch ($p) {
      var e = $p;
      if (this.k8_1 === 3) {
        throw e;
      } else {
        this.j8_1 = this.k8_1;
        this.m8_1 = e;
      }
    }
   while (true);
};
protoOf(pinger$slambda$slambda).p1p = function ($this$withTimeoutOrNull, completion) {
  var i = new pinger$slambda$slambda(this.s38_1, completion);
  i.t38_1 = $this$withTimeoutOrNull;
  return i;
};
function pinger$slambda$slambda_0($channel, resultContinuation) {
  var i = new pinger$slambda$slambda($channel, resultContinuation);
  var l = function ($this$withTimeoutOrNull, $completion) {
    return i.o1p($this$withTimeoutOrNull, $completion);
  };
  l.$arity = 1;
  return l;
}
function pinger$slambda$slambda_1($outgoing, $pingMessage, $channel, resultContinuation) {
  this.c39_1 = $outgoing;
  this.d39_1 = $pingMessage;
  this.e39_1 = $channel;
  CoroutineImpl.call(this, resultContinuation);
}
protoOf(pinger$slambda$slambda_1).o1p = function ($this$withTimeoutOrNull, $completion) {
  var tmp = this.p1p($this$withTimeoutOrNull, $completion);
  tmp.l8_1 = Unit_instance;
  tmp.m8_1 = null;
  return tmp.r8();
};
protoOf(pinger$slambda$slambda_1).d9 = function (p1, $completion) {
  return this.o1p((!(p1 == null) ? isInterface(p1, CoroutineScope) : false) ? p1 : THROW_CCE(), $completion);
};
protoOf(pinger$slambda$slambda_1).r8 = function () {
  var suspendResult = this.l8_1;
  $sm: do
    try {
      var tmp = this.j8_1;
      switch (tmp) {
        case 0:
          this.k8_1 = 6;
          get_LOGGER().h2j('WebSocket Pinger: sending ping frame');
          this.j8_1 = 1;
          suspendResult = this.c39_1.s18(new Ping(toByteArray(this.d39_1, Charsets_getInstance().p1q_1)), this);
          if (suspendResult === get_COROUTINE_SUSPENDED()) {
            return suspendResult;
          }

          continue $sm;
        case 1:
          this.j8_1 = 2;
          continue $sm;
        case 2:
          if (!true) {
            this.j8_1 = 5;
            continue $sm;
          }

          this.j8_1 = 3;
          suspendResult = this.e39_1.w18(this);
          if (suspendResult === get_COROUTINE_SUSPENDED()) {
            return suspendResult;
          }

          continue $sm;
        case 3:
          this.g39_1 = suspendResult;
          if (decodeToString(this.g39_1.k36_1, 0, 0 + this.g39_1.k36_1.length | 0) === this.d39_1) {
            get_LOGGER().h2j('WebSocket Pinger: received valid pong frame ' + this.g39_1.toString());
            this.j8_1 = 5;
            continue $sm;
          } else {
            this.j8_1 = 4;
            continue $sm;
          }

        case 4:
          get_LOGGER().h2j('WebSocket Pinger: received invalid pong frame ' + this.g39_1.toString() + ', continue waiting');
          this.j8_1 = 2;
          continue $sm;
        case 5:
          return Unit_instance;
        case 6:
          throw this.m8_1;
      }
    } catch ($p) {
      var e = $p;
      if (this.k8_1 === 6) {
        throw e;
      } else {
        this.j8_1 = this.k8_1;
        this.m8_1 = e;
      }
    }
   while (true);
};
protoOf(pinger$slambda$slambda_1).p1p = function ($this$withTimeoutOrNull, completion) {
  var i = new pinger$slambda$slambda_1(this.c39_1, this.d39_1, this.e39_1, completion);
  i.f39_1 = $this$withTimeoutOrNull;
  return i;
};
function pinger$slambda$slambda_2($outgoing, $pingMessage, $channel, resultContinuation) {
  var i = new pinger$slambda$slambda_1($outgoing, $pingMessage, $channel, resultContinuation);
  var l = function ($this$withTimeoutOrNull, $completion) {
    return i.o1p($this$withTimeoutOrNull, $completion);
  };
  l.$arity = 1;
  return l;
}
function pinger$slambda($periodMillis, $timeoutMillis, $onTimeout, $channel, $outgoing, resultContinuation) {
  this.p39_1 = $periodMillis;
  this.q39_1 = $timeoutMillis;
  this.r39_1 = $onTimeout;
  this.s39_1 = $channel;
  this.t39_1 = $outgoing;
  CoroutineImpl.call(this, resultContinuation);
}
protoOf(pinger$slambda).o1p = function ($this$launch, $completion) {
  var tmp = this.p1p($this$launch, $completion);
  tmp.l8_1 = Unit_instance;
  tmp.m8_1 = null;
  return tmp.r8();
};
protoOf(pinger$slambda).d9 = function (p1, $completion) {
  return this.o1p((!(p1 == null) ? isInterface(p1, CoroutineScope) : false) ? p1 : THROW_CCE(), $completion);
};
protoOf(pinger$slambda).r8 = function () {
  var suspendResult = this.l8_1;
  $sm: do
    try {
      var tmp = this.j8_1;
      switch (tmp) {
        case 0:
          this.k8_1 = 9;
          get_LOGGER().h2j('Starting WebSocket pinger coroutine with period ' + this.p39_1.toString() + ' ms and timeout ' + this.q39_1.toString() + ' ms');
          this.w39_1 = Random(getTimeMillis());
          this.v39_1 = new Int8Array(32);
          this.k8_1 = 7;
          this.j8_1 = 1;
          continue $sm;
        case 1:
          if (!true) {
            this.j8_1 = 6;
            continue $sm;
          }

          this.j8_1 = 2;
          suspendResult = withTimeoutOrNull(this.p39_1, pinger$slambda$slambda_0(this.s39_1, null), this);
          if (suspendResult === get_COROUTINE_SUSPENDED()) {
            return suspendResult;
          }

          continue $sm;
        case 2:
          this.w39_1.dh(this.v39_1);
          var pingMessage = '[ping ' + hex(this.v39_1) + ' ping]';
          this.j8_1 = 3;
          suspendResult = withTimeoutOrNull(this.q39_1, pinger$slambda$slambda_2(this.t39_1, pingMessage, this.s39_1, null), this);
          if (suspendResult === get_COROUTINE_SUSPENDED()) {
            return suspendResult;
          }

          continue $sm;
        case 3:
          var rc = suspendResult;
          if (rc == null) {
            get_LOGGER().h2j('WebSocket pinger has timed out');
            this.j8_1 = 5;
            suspendResult = this.r39_1(CloseReason_init_$Create$(Codes_INTERNAL_ERROR_getInstance(), 'Ping timeout'), this);
            if (suspendResult === get_COROUTINE_SUSPENDED()) {
              return suspendResult;
            }
            continue $sm;
          } else {
            this.j8_1 = 4;
            continue $sm;
          }

        case 4:
          this.j8_1 = 1;
          continue $sm;
        case 5:
          this.j8_1 = 6;
          continue $sm;
        case 6:
          this.k8_1 = 9;
          this.j8_1 = 8;
          continue $sm;
        case 7:
          this.k8_1 = 9;
          var tmp_0 = this.m8_1;
          if (tmp_0 instanceof CancellationException) {
            var ignore = this.m8_1;
            this.j8_1 = 8;
            continue $sm;
          } else {
            var tmp_1 = this.m8_1;
            if (tmp_1 instanceof ClosedReceiveChannelException) {
              var ignore_0 = this.m8_1;
              this.j8_1 = 8;
              continue $sm;
            } else {
              var tmp_2 = this.m8_1;
              if (tmp_2 instanceof ClosedSendChannelException) {
                var ignore_1 = this.m8_1;
                this.j8_1 = 8;
                continue $sm;
              } else {
                var tmp_3 = this.m8_1;
                if (tmp_3 instanceof ClosedByteChannelException) {
                  var ignore_2 = this.m8_1;
                  this.j8_1 = 8;
                  continue $sm;
                } else {
                  throw this.m8_1;
                }
              }
            }
          }

        case 8:
          this.k8_1 = 9;
          return Unit_instance;
        case 9:
          throw this.m8_1;
      }
    } catch ($p) {
      var e = $p;
      if (this.k8_1 === 9) {
        throw e;
      } else {
        this.j8_1 = this.k8_1;
        this.m8_1 = e;
      }
    }
   while (true);
};
protoOf(pinger$slambda).p1p = function ($this$launch, completion) {
  var i = new pinger$slambda(this.p39_1, this.q39_1, this.r39_1, this.s39_1, this.t39_1, completion);
  i.u39_1 = $this$launch;
  return i;
};
function pinger$slambda_0($periodMillis, $timeoutMillis, $onTimeout, $channel, $outgoing, resultContinuation) {
  var i = new pinger$slambda($periodMillis, $timeoutMillis, $onTimeout, $channel, $outgoing, resultContinuation);
  var l = function ($this$launch, $completion) {
    return i.o1p($this$launch, $completion);
  };
  l.$arity = 1;
  return l;
}
function pinger$lambda($actorJob) {
  return function (it) {
    $actorJob.et();
    return Unit_instance;
  };
}
var properties_initialized_PingPong_kt_fbfhmc;
function _init_properties_PingPong_kt__9aqxey() {
  if (!properties_initialized_PingPong_kt_fbfhmc) {
    properties_initialized_PingPong_kt_fbfhmc = true;
    PongerCoroutineName = new CoroutineName('ws-ponger');
    PingerCoroutineName = new CoroutineName('ws-pinger');
  }
}
function Companion_2() {
  Companion_instance_2 = this;
  var tmp = this;
  // Inline function 'kotlin.apply' call
  var this_0 = new WebSocketChannelsConfig();
  this_0.v32_1 = this_0.x39();
  this_0.w32_1 = this_0.x39();
  tmp.u32_1 = this_0;
}
var Companion_instance_2;
function Companion_getInstance_2() {
  if (Companion_instance_2 == null)
    new Companion_2();
  return Companion_instance_2;
}
function WebSocketChannelsConfig() {
  Companion_getInstance_2();
  this.v32_1 = Companion_getInstance_3().y39_1;
  this.w32_1 = Companion_getInstance_3().y39_1;
}
protoOf(WebSocketChannelsConfig).x39 = function () {
  return Companion_getInstance_3().y39_1;
};
function from(_this__u8e3s4, config) {
  // Inline function 'kotlin.with' call
  var tmp;
  if (config.z39_1 === 2147483647) {
    tmp = Channel(2147483647);
  } else if (config.a3a_1.equals(ChannelOverflow_SUSPEND_getInstance())) {
    tmp = Channel(config.z39_1, BufferOverflow_SUSPEND_getInstance());
  } else if (config.a3a_1.equals(ChannelOverflow_CLOSE_getInstance())) {
    tmp = new BoundedChannel(config.z39_1);
  } else {
    // Inline function 'kotlin.error' call
    var message = 'Unsupported channel config.';
    throw IllegalStateException_init_$Create$(toString(message));
  }
  return tmp;
}
function Companion_3() {
  Companion_instance_3 = this;
  this.y39_1 = new ChannelConfig(2147483647, ChannelOverflow_SUSPEND_getInstance());
}
var Companion_instance_3;
function Companion_getInstance_3() {
  if (Companion_instance_3 == null)
    new Companion_3();
  return Companion_instance_3;
}
function ChannelConfig(capacity, onOverflow) {
  Companion_getInstance_3();
  this.z39_1 = capacity;
  this.a3a_1 = onOverflow;
}
protoOf(ChannelConfig).b3a = function () {
  return this.a3a_1.equals(ChannelOverflow_SUSPEND_getInstance()) && !(this.z39_1 === 2147483647);
};
var ChannelOverflow_SUSPEND_instance;
var ChannelOverflow_CLOSE_instance;
var ChannelOverflow_entriesInitialized;
function ChannelOverflow_initEntries() {
  if (ChannelOverflow_entriesInitialized)
    return Unit_instance;
  ChannelOverflow_entriesInitialized = true;
  ChannelOverflow_SUSPEND_instance = new ChannelOverflow('SUSPEND', 0);
  ChannelOverflow_CLOSE_instance = new ChannelOverflow('CLOSE', 1);
}
function ChannelOverflow(name, ordinal) {
  Enum.call(this, name, ordinal);
}
function BoundedChannel$Companion$createDelegate$lambda($channel) {
  return function (it) {
    var tmp;
    var tmp_0;
    if ($channel._v == null) {
      throwUninitializedPropertyAccessException('channel');
    } else {
      tmp_0 = $channel._v;
    }
    if (!tmp_0.x16()) {
      var tmp_1;
      if ($channel._v == null) {
        throwUninitializedPropertyAccessException('channel');
      } else {
        tmp_1 = $channel._v;
      }
      tmp_1.y18(new ChannelOverflowException('Channel overflowed'));
      tmp = Unit_instance;
    }
    return Unit_instance;
  };
}
function Companion_4() {
}
protoOf(Companion_4).c3a = function (capacity) {
  var channel = {_v: null};
  var tmp = BufferOverflow_DROP_OLDEST_getInstance();
  // Inline function 'kotlin.also' call
  var this_0 = Channel(capacity, tmp, BoundedChannel$Companion$createDelegate$lambda(channel));
  channel._v = this_0;
  return this_0;
};
var Companion_instance_4;
function Companion_getInstance_4() {
  return Companion_instance_4;
}
function BoundedChannel(capacity, delegate) {
  delegate = delegate === VOID ? Companion_instance_4.c3a(capacity) : delegate;
  this.d3a_1 = delegate;
}
protoOf(BoundedChannel).e3a = function (element) {
  var result = this.d3a_1.t18(element);
  if (!_ChannelResult___get_isSuccess__impl__odq1z9(result) && !_ChannelResult___get_isClosed__impl__mg7kuu(result)) {
    this.y18(new ChannelOverflowException('Channel overflowed'));
  }
  return result;
};
protoOf(BoundedChannel).t18 = function (element) {
  return this.e3a(element);
};
protoOf(BoundedChannel).f3a = function (element, $completion) {
  return this.d3a_1.s18(element, $completion);
};
protoOf(BoundedChannel).s18 = function (element, $completion) {
  return this.f3a(element, $completion);
};
protoOf(BoundedChannel).y18 = function (cause) {
  return this.d3a_1.y18(cause);
};
protoOf(BoundedChannel).x16 = function () {
  return this.d3a_1.x16();
};
protoOf(BoundedChannel).g3a = function ($completion) {
  return this.d3a_1.w18($completion);
};
protoOf(BoundedChannel).w18 = function ($completion) {
  return this.g3a($completion);
};
protoOf(BoundedChannel).t = function () {
  return this.d3a_1.t();
};
protoOf(BoundedChannel).dt = function (cause) {
  this.d3a_1.dt(cause);
};
function ChannelOverflowException(message) {
  RuntimeException_init_$Init$(message, this);
  captureStack(this, ChannelOverflowException);
}
function ChannelOverflow_SUSPEND_getInstance() {
  ChannelOverflow_initEntries();
  return ChannelOverflow_SUSPEND_instance;
}
function ChannelOverflow_CLOSE_getInstance() {
  ChannelOverflow_initEntries();
  return ChannelOverflow_CLOSE_instance;
}
function WebSocketExtension() {
}
function WebSocketExtensionsConfig() {
  var tmp = this;
  // Inline function 'kotlin.collections.mutableListOf' call
  tmp.j3a_1 = ArrayList_init_$Create$();
  var tmp_0 = this;
  // Inline function 'kotlin.arrayOf' call
  // Inline function 'kotlin.js.unsafeCast' call
  // Inline function 'kotlin.js.asDynamic' call
  tmp_0.k3a_1 = [false, false, false];
}
protoOf(WebSocketExtensionsConfig).y2l = function () {
  // Inline function 'kotlin.collections.map' call
  var this_0 = this.j3a_1;
  // Inline function 'kotlin.collections.mapTo' call
  var destination = ArrayList_init_$Create$_0(collectionSizeOrDefault(this_0, 10));
  var _iterator__ex2g4s = this_0.t();
  while (_iterator__ex2g4s.u()) {
    var item = _iterator__ex2g4s.v();
    var tmp$ret$2 = item();
    destination.e1(tmp$ret$2);
  }
  return destination;
};
function parametersToString($this) {
  return $this.m3a_1.r() ? '' : '; ' + joinToString($this.m3a_1, ';');
}
function WebSocketExtensionHeader(name, parameters) {
  this.l3a_1 = name;
  this.m3a_1 = parameters;
}
protoOf(WebSocketExtensionHeader).toString = function () {
  return this.l3a_1 + ' ' + parametersToString(this);
};
function parseWebSocketExtensions(value) {
  // Inline function 'kotlin.collections.map' call
  var this_0 = split(value, [',']);
  // Inline function 'kotlin.collections.mapTo' call
  var destination = ArrayList_init_$Create$_0(collectionSizeOrDefault(this_0, 10));
  var _iterator__ex2g4s = this_0.t();
  while (_iterator__ex2g4s.u()) {
    var item = _iterator__ex2g4s.v();
    var extension = split(item, [';']);
    // Inline function 'kotlin.text.trim' call
    var this_1 = first(extension);
    var name = toString(trim(isCharSequence(this_1) ? this_1 : THROW_CCE()));
    // Inline function 'kotlin.collections.map' call
    var this_2 = drop(extension, 1);
    // Inline function 'kotlin.collections.mapTo' call
    var destination_0 = ArrayList_init_$Create$_0(collectionSizeOrDefault(this_2, 10));
    var _iterator__ex2g4s_0 = this_2.t();
    while (_iterator__ex2g4s_0.u()) {
      var item_0 = _iterator__ex2g4s_0.v();
      // Inline function 'kotlin.text.trim' call
      var tmp$ret$6 = toString(trim(isCharSequence(item_0) ? item_0 : THROW_CCE()));
      destination_0.e1(tmp$ret$6);
    }
    var parameters = destination_0;
    var tmp$ret$2 = new WebSocketExtensionHeader(name, parameters);
    destination.e1(tmp$ret$2);
  }
  return destination;
}
function WebSocketSession() {
}
function close(_this__u8e3s4, reason, $completion) {
  reason = reason === VOID ? CloseReason_init_$Create$(Codes_NORMAL_getInstance(), '') : reason;
  var tmp = new $closeCOROUTINE$(_this__u8e3s4, reason, $completion);
  tmp.l8_1 = Unit_instance;
  tmp.m8_1 = null;
  return tmp.r8();
}
function closeExceptionally(_this__u8e3s4, cause, $completion) {
  var tmp;
  if (cause instanceof CancellationException) {
    tmp = CloseReason_init_$Create$(Codes_NORMAL_getInstance(), '');
  } else {
    tmp = CloseReason_init_$Create$(Codes_INTERNAL_ERROR_getInstance(), cause.toString());
  }
  var reason = tmp;
  return close(_this__u8e3s4, reason, $completion);
}
function $closeCOROUTINE$(_this__u8e3s4, reason, resultContinuation) {
  CoroutineImpl.call(this, resultContinuation);
  this.v3a_1 = _this__u8e3s4;
  this.w3a_1 = reason;
}
protoOf($closeCOROUTINE$).r8 = function () {
  var suspendResult = this.l8_1;
  $sm: do
    try {
      var tmp = this.j8_1;
      switch (tmp) {
        case 0:
          this.k8_1 = 4;
          this.k8_1 = 3;
          this.j8_1 = 1;
          suspendResult = this.v3a_1.t32(Close_init_$Create$(this.w3a_1), this);
          if (suspendResult === get_COROUTINE_SUSPENDED()) {
            return suspendResult;
          }

          continue $sm;
        case 1:
          this.j8_1 = 2;
          suspendResult = this.v3a_1.i1g(this);
          if (suspendResult === get_COROUTINE_SUSPENDED()) {
            return suspendResult;
          }

          continue $sm;
        case 2:
          this.k8_1 = 4;
          this.j8_1 = 5;
          continue $sm;
        case 3:
          this.k8_1 = 4;
          var tmp_0 = this.m8_1;
          if (tmp_0 instanceof Error) {
            var _unused_var__etf5q3 = this.m8_1;
            this.j8_1 = 5;
            continue $sm;
          } else {
            throw this.m8_1;
          }

        case 4:
          throw this.m8_1;
        case 5:
          this.k8_1 = 4;
          return Unit_instance;
      }
    } catch ($p) {
      var e = $p;
      if (this.k8_1 === 4) {
        throw e;
      } else {
        this.j8_1 = this.k8_1;
        this.m8_1 = e;
      }
    }
   while (true);
};
function Binary_init_$Init$(fin, data, $this) {
  Binary.call($this, fin, data, false, false, false);
  return $this;
}
function Binary_init_$Create$(fin, data) {
  return Binary_init_$Init$(fin, data, objectCreate(protoOf(Binary)));
}
function Text_init_$Init$(fin, data, $this) {
  Text.call($this, fin, data, false, false, false);
  return $this;
}
function Text_init_$Init$_0(text, $this) {
  Text_init_$Init$(true, toByteArray(text), $this);
  return $this;
}
function Text_init_$Create$(text) {
  return Text_init_$Init$_0(text, objectCreate(protoOf(Text)));
}
function Close_init_$Init$(reason, $this) {
  // Inline function 'io.ktor.utils.io.core.buildPacket' call
  var builder = new Buffer();
  builder.eq(reason.l32_1);
  writeText(builder, reason.m32_1);
  Close_init_$Init$_0(builder, $this);
  return $this;
}
function Close_init_$Create$(reason) {
  return Close_init_$Init$(reason, objectCreate(protoOf(Close)));
}
function Close_init_$Init$_0(packet, $this) {
  Close.call($this, readByteArray(packet));
  return $this;
}
function Close_init_$Init$_1($this) {
  Close.call($this, Companion_getInstance_5().p36_1);
  return $this;
}
function Close_init_$Create$_0() {
  return Close_init_$Init$_1(objectCreate(protoOf(Close)));
}
function Binary(fin, data, rsv1, rsv2, rsv3) {
  rsv1 = rsv1 === VOID ? false : rsv1;
  rsv2 = rsv2 === VOID ? false : rsv2;
  rsv3 = rsv3 === VOID ? false : rsv3;
  Frame.call(this, fin, FrameType_BINARY_getInstance(), data, NonDisposableHandle_instance, rsv1, rsv2, rsv3);
}
function Text(fin, data, rsv1, rsv2, rsv3) {
  rsv1 = rsv1 === VOID ? false : rsv1;
  rsv2 = rsv2 === VOID ? false : rsv2;
  rsv3 = rsv3 === VOID ? false : rsv3;
  Frame.call(this, fin, FrameType_TEXT_getInstance(), data, NonDisposableHandle_instance, rsv1, rsv2, rsv3);
}
function Close(data) {
  Frame.call(this, true, FrameType_CLOSE_getInstance(), data, NonDisposableHandle_instance, false, false, false);
}
function Ping(data) {
  Frame.call(this, true, FrameType_PING_getInstance(), data, NonDisposableHandle_instance, false, false, false);
}
function Pong(data, disposableHandle) {
  disposableHandle = disposableHandle === VOID ? NonDisposableHandle_instance : disposableHandle;
  Frame.call(this, true, FrameType_PONG_getInstance(), data, disposableHandle, false, false, false);
}
function Companion_5() {
  Companion_instance_5 = this;
  this.p36_1 = new Int8Array(0);
}
protoOf(Companion_5).q36 = function (fin, frameType, data, rsv1, rsv2, rsv3) {
  var tmp;
  switch (frameType.a1_1) {
    case 1:
      tmp = new Binary(fin, data, rsv1, rsv2, rsv3);
      break;
    case 0:
      tmp = new Text(fin, data, rsv1, rsv2, rsv3);
      break;
    case 2:
      tmp = new Close(data);
      break;
    case 3:
      tmp = new Ping(data);
      break;
    case 4:
      tmp = new Pong(data, NonDisposableHandle_instance);
      break;
    default:
      noWhenBranchMatchedException();
      break;
  }
  return tmp;
};
var Companion_instance_5;
function Companion_getInstance_5() {
  if (Companion_instance_5 == null)
    new Companion_5();
  return Companion_instance_5;
}
function Frame(fin, frameType, data, disposableHandle, rsv1, rsv2, rsv3) {
  Companion_getInstance_5();
  disposableHandle = disposableHandle === VOID ? NonDisposableHandle_instance : disposableHandle;
  rsv1 = rsv1 === VOID ? false : rsv1;
  rsv2 = rsv2 === VOID ? false : rsv2;
  rsv3 = rsv3 === VOID ? false : rsv3;
  this.i36_1 = fin;
  this.j36_1 = frameType;
  this.k36_1 = data;
  this.l36_1 = disposableHandle;
  this.m36_1 = rsv1;
  this.n36_1 = rsv2;
  this.o36_1 = rsv3;
}
protoOf(Frame).toString = function () {
  return 'Frame ' + this.j36_1.toString() + ' (fin=' + this.i36_1 + ', buffer len = ' + this.k36_1.length + ')';
};
function get_OUTGOING_CHANNEL_CAPACITY() {
  return OUTGOING_CHANNEL_CAPACITY;
}
var OUTGOING_CHANNEL_CAPACITY;
//region block: post-declaration
protoOf(DefaultWebSocketSessionImpl).t32 = send;
defineProp(protoOf(FrameTooBigException), 'message', function () {
  return this.e();
});
protoOf(BoundedChannel).a19 = close$default;
protoOf(BoundedChannel).c19 = cancel$default;
//endregion
//region block: init
NonDisposableHandle_instance = new NonDisposableHandle();
Companion_instance_4 = new Companion_4();
OUTGOING_CHANNEL_CAPACITY = null;
//endregion
//region block: exports
export {
  Companion_getInstance as Companion_getInstance2xymkrjuj4ub8,
  Companion_getInstance_2 as Companion_getInstance1u99479g32m9i,
  Codes_CLOSED_ABNORMALLY_getInstance as Codes_CLOSED_ABNORMALLY_getInstance2rjj5xk3ewrku,
  Codes_NORMAL_getInstance as Codes_NORMAL_getInstance1akc4vzdzyb59,
  send as send3kjrrxgwu0vpw,
  Binary_init_$Create$ as Binary_init_$Create$3ji9zus3m6s2e,
  Close_init_$Create$ as Close_init_$Create$lgyf6kdpsq84,
  Text_init_$Create$ as Text_init_$Create$33xdsiuzmxup1,
  CloseReason as CloseReason10cphaqpp3ct7,
  DefaultWebSocketSession_0 as DefaultWebSocketSessionmehckluw85jl,
  DefaultWebSocketSession as DefaultWebSocketSession3h8506yqzs5fx,
  WebSocketChannelsConfig as WebSocketChannelsConfig1qogztyrywmj9,
  WebSocketExtensionsConfig as WebSocketExtensionsConfig3sf1f7u7xi63m,
  WebSocketExtension as WebSocketExtensionixqq2y77p4e0,
  WebSocketSession as WebSocketSessionzi1ianvyj32u,
  from as from3gpkuvfyl3bft,
  parseWebSocketExtensions as parseWebSocketExtensionszyo25w86ylog,
};
//endregion


