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

import "dart:async";

static method main() → 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;
  dynamic :saved_try_context_var0;
  function :async_op([dynamic :result, dynamic :exception, dynamic :stack_trace]) → dynamic yielding 
    try {
      #L1:
      {
        dynamic f = () → asy::Stream<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 {
                #L2:
                {
                  if(:controller.{asy::_AsyncStarStreamController::add}(null))
                    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;
        };
        asy::Stream<dynamic> y = f.call();
        asy::Stream<core::String> z = f.call();
        [yield] let dynamic #t1 = asy::_awaitHelper(f.call().first, :async_op_then, :async_op_error, :async_op) in null;
        core::String s = :result;
      }
      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};
}
