library test;
import self as self;
import "dart:async" as asy;
import "dart:core" as core;

static method test() → dynamic {
  function f0() → dynamic
    return 42;
  function f1() → dynamic /* originally async */ {
    final asy::_AsyncAwaitCompleter<dynamic>* :async_completer = new asy::_AsyncAwaitCompleter::•<dynamic>();
    asy::FutureOr<dynamic>* :return_value;
    dynamic :async_stack_trace;
    dynamic :async_op_then;
    dynamic :async_op_error;
    dynamic :await_jump_var = 0;
    dynamic :await_ctx_var;
    function :async_op([dynamic :result, dynamic :exception, dynamic :stack_trace]) → dynamic yielding 
      try {
        #L1:
        {
          :return_value = 42;
          break #L1;
        }
        asy::_completeOnAsyncReturn(:async_completer, :return_value);
        return;
      }
      on dynamic catch(dynamic :exception, dynamic :stack_trace) {
        :async_completer.{asy::Completer::completeError}(:exception, :stack_trace);
      }
    :async_stack_trace = asy::_asyncStackTraceHelper(:async_op);
    :async_op_then = asy::_asyncThenWrapperHelper(:async_op);
    :async_op_error = asy::_asyncErrorWrapperHelper(:async_op);
    :async_completer.start(:async_op);
    return :async_completer.{asy::Completer::future};
  }
  function f2() → dynamic {
    return 42;
  }
  function f3() → dynamic /* originally async */ {
    final asy::_AsyncAwaitCompleter<dynamic>* :async_completer = new asy::_AsyncAwaitCompleter::•<dynamic>();
    asy::FutureOr<dynamic>* :return_value;
    dynamic :async_stack_trace;
    dynamic :async_op_then;
    dynamic :async_op_error;
    dynamic :await_jump_var = 0;
    dynamic :await_ctx_var;
    function :async_op([dynamic :result, dynamic :exception, dynamic :stack_trace]) → dynamic yielding 
      try {
        #L2:
        {
          :return_value = 42;
          break #L2;
        }
        asy::_completeOnAsyncReturn(:async_completer, :return_value);
        return;
      }
      on dynamic catch(dynamic :exception, dynamic :stack_trace) {
        :async_completer.{asy::Completer::completeError}(:exception, :stack_trace);
      }
    :async_stack_trace = asy::_asyncStackTraceHelper(:async_op);
    :async_op_then = asy::_asyncThenWrapperHelper(:async_op);
    :async_op_error = asy::_asyncErrorWrapperHelper(:async_op);
    :async_completer.start(:async_op);
    return :async_completer.{asy::Completer::future};
  }
  function f4() → dynamic /* originally sync* */ {
    dynamic :await_jump_var = 0;
    dynamic :await_ctx_var;
    function :sync_op(core::_SyncIterator<dynamic>* :iterator) → core::bool* yielding {
      {
        {
          :iterator.{core::_SyncIterator::_current} = 42;
          [yield] true;
        }
      }
      return false;
    }
    return new core::_SyncIterable::•<dynamic>(:sync_op);
  }
  function f5() → dynamic /* originally async* */ {
    asy::_AsyncStarStreamController<dynamic>* :controller;
    dynamic :controller_stream;
    dynamic :async_stack_trace;
    dynamic :async_op_then;
    dynamic :async_op_error;
    dynamic :await_jump_var = 0;
    dynamic :await_ctx_var;
    dynamic :saved_try_context_var0;
    dynamic :saved_try_context_var1;
    function :async_op([dynamic :result, dynamic :exception, dynamic :stack_trace]) → dynamic yielding 
      try
        try {
          #L3:
          {
            if(:controller.{asy::_AsyncStarStreamController::add}(42))
              return null;
            else
              [yield] null;
          }
          return;
        }
        on dynamic catch(dynamic :exception, dynamic :stack_trace) {
          :controller.{asy::_AsyncStarStreamController::addError}(:exception, :stack_trace);
        }
      finally {
        :controller.{asy::_AsyncStarStreamController::close}();
      }
    :async_stack_trace = asy::_asyncStackTraceHelper(:async_op);
    :async_op_then = asy::_asyncThenWrapperHelper(:async_op);
    :async_op_error = asy::_asyncErrorWrapperHelper(:async_op);
    :controller = new asy::_AsyncStarStreamController::•<dynamic>(:async_op);
    :controller_stream = :controller.{asy::_AsyncStarStreamController::stream};
    return :controller_stream;
  }
  function f6() → core::num*
    return 42;
  function f7() → dynamic
    return f7.call();
  function f8() → dynamic
    return f5.call();
  dynamic v0 = f0;
  dynamic v1 = f1;
  dynamic v2 = f2;
  dynamic v3 = f3;
  dynamic v4 = f4;
  dynamic v5 = f5;
  dynamic v6 = f6;
  dynamic v7 = f7;
  dynamic v8 = f8;
}
static method main() → dynamic {}
