(declare (block) (standard-bindings) (extended-bindings))
(begin
  (define std/coroutine#current-coroutine (make-parameter '#f))
  (define std/coroutine#cort::t
    (make-struct-type
     'std/coroutine#cort::t
     '#f
     '3
     'cort
     '((final: . #t))
     '#f
     '(k end? res)))
  (define std/coroutine#cort? (make-struct-predicate std/coroutine#cort::t))
  (define std/coroutine#make-cort
    (lambda _$args30317_
      (apply make-struct-instance std/coroutine#cort::t _$args30317_)))
  (define std/coroutine#cort-k
    (make-struct-field-accessor std/coroutine#cort::t '0))
  (define std/coroutine#cort-end?
    (make-struct-field-accessor std/coroutine#cort::t '1))
  (define std/coroutine#cort-res
    (make-struct-field-accessor std/coroutine#cort::t '2))
  (define std/coroutine#cort-k-set!
    (make-struct-field-mutator std/coroutine#cort::t '0))
  (define std/coroutine#cort-end?-set!
    (make-struct-field-mutator std/coroutine#cort::t '1))
  (define std/coroutine#cort-res-set!
    (make-struct-field-mutator std/coroutine#cort::t '2))
  (define std/coroutine#cothr::t
    (make-struct-type
     'std/coroutine#cothr::t
     '#f
     '4
     'cothr
     '((final: . #t))
     '#f
     '(mx cv state val)))
  (define std/coroutine#cothr? (make-struct-predicate std/coroutine#cothr::t))
  (define std/coroutine#make-cothr
    (lambda _$args30314_
      (apply make-struct-instance std/coroutine#cothr::t _$args30314_)))
  (define std/coroutine#cothr-mx
    (make-struct-field-accessor std/coroutine#cothr::t '0))
  (define std/coroutine#cothr-cv
    (make-struct-field-accessor std/coroutine#cothr::t '1))
  (define std/coroutine#cothr-state
    (make-struct-field-accessor std/coroutine#cothr::t '2))
  (define std/coroutine#cothr-val
    (make-struct-field-accessor std/coroutine#cothr::t '3))
  (define std/coroutine#cothr-mx-set!
    (make-struct-field-mutator std/coroutine#cothr::t '0))
  (define std/coroutine#cothr-cv-set!
    (make-struct-field-mutator std/coroutine#cothr::t '1))
  (define std/coroutine#cothr-state-set!
    (make-struct-field-mutator std/coroutine#cothr::t '2))
  (define std/coroutine#cothr-val-set!
    (make-struct-field-mutator std/coroutine#cothr::t '3))
  (define std/coroutine#coroutine
    (lambda (_proc30308_ . _args30309_)
      (call-with-current-continuation
       (lambda (_k30311_)
         (std/coroutine#coroutine-start!
          _k30311_
          (if (null? _args30309_)
              _proc30308_
              (lambda () (apply _proc30308_ _args30309_))))))))
  (define std/coroutine#cothread
    (lambda (_proc30299_ . _args30300_)
      (let* ((_cothr30302_
              (##structure
               std/coroutine#cothr::t
               (make-mutex 'coroutine)
               (make-condition-variable 'coroutine)
               'run
               '#f))
             (_thread30305_
              (make-thread
               (lambda ()
                 (std/coroutine#cothread-start!
                  _cothr30302_
                  _proc30299_
                  _args30300_))
               'cothread)))
        (thread-specific-set! _thread30305_ _cothr30302_)
        (thread-start! _thread30305_))))
  (define std/coroutine#cothread?
    (lambda (_thread30297_)
      (if (thread? _thread30297_)
          (##structure-direct-instance-of?
           (thread-specific _thread30297_)
           'std/coroutine#cothr::t)
          '#f)))
  (define std/coroutine#continue
    (lambda (_c30294_ . _args30295_)
      (if (##structure-direct-instance-of? _c30294_ 'std/coroutine#cort::t)
          (std/coroutine#coroutine-continue! _c30294_ _args30295_)
          (if (std/coroutine#cothread? _c30294_)
              (std/coroutine#cothread-continue!
               (thread-specific _c30294_)
               _args30295_)
              (error '"Illegal argument; not continuable" _c30294_)))))
  (define std/coroutine#yield
    (lambda _args30285_
      (let ((_$e30287_ (std/coroutine#current-coroutine)))
        (if _$e30287_
            ((lambda (_g3028930291_)
               (std/coroutine#coroutine-yield! _g3028930291_ _args30285_))
             _$e30287_)
            (if (##structure-direct-instance-of?
                 (thread-specific (current-thread))
                 'std/coroutine#cothr::t)
                (std/coroutine#cothread-yield!
                 (thread-specific (current-thread))
                 _args30285_)
                (error '"Not in a coroutine continuation"))))))
  (define std/coroutine#coroutine-start!
    (lambda (_k30273_ _thunk30274_)
      (let ((_c30276_ (##structure std/coroutine#cort::t '#f '#f '#f)))
        (call-with-parameters
         (lambda ()
           (call-with-current-continuation
            (lambda (_kk30279_)
              (##direct-structure-set!
               _c30276_
               _kk30279_
               '1
               std/coroutine#cort::t
               '#f)
              (_k30273_ _c30276_)))
           (call-with-values
            _thunk30274_
            (lambda _res30281_
              (let ((_k30283_
                     (##direct-structure-ref
                      _c30276_
                      '1
                      std/coroutine#cort::t
                      '#f)))
                (##direct-structure-set!
                 _c30276_
                 '#t
                 '2
                 std/coroutine#cort::t
                 '#f)
                (##direct-structure-set!
                 _c30276_
                 _res30281_
                 '3
                 std/coroutine#cort::t
                 '#f)
                (##direct-structure-set!
                 _c30276_
                 '#f
                 '1
                 std/coroutine#cort::t
                 '#f)
                (apply _k30283_ _res30281_)))))
         std/coroutine#current-coroutine
         _c30276_))))
  (define std/coroutine#coroutine-continue!
    (lambda (_c30232_ _args30233_)
      (let* ((_c3023430242_ _c30232_)
             (_E3023630246_
              (lambda () (error '"No clause matching" _c3023430242_)))
             (_K3023730255_
              (lambda (_res30249_ _end?30250_ _k30251_)
                (if _end?30250_
                    (apply values _res30249_)
                    (call-with-current-continuation
                     (lambda (_kk30253_)
                       (##direct-structure-set!
                        _c30232_
                        _kk30253_
                        '1
                        std/coroutine#cort::t
                        '#f)
                       (apply _k30251_ _args30233_)))))))
        (if (##structure-direct-instance-of?
             _c3023430242_
             'std/coroutine#cort::t)
            (let* ((_e3023830258_ (##vector-ref _c3023430242_ '1))
                   (_k30261_ _e3023830258_)
                   (_e3023930263_ (##vector-ref _c3023430242_ '2))
                   (_end?30266_ _e3023930263_)
                   (_e3024030268_ (##vector-ref _c3023430242_ '3))
                   (_res30271_ _e3024030268_))
              (_K3023730255_ _res30271_ _end?30266_ _k30261_))
            (_E3023630246_)))))
  (define std/coroutine#coroutine-yield!
    (lambda (_c30205_ _args30206_)
      (let* ((_c3020730213_ _c30205_)
             (_E3020930217_
              (lambda () (error '"No clause matching" _c3020730213_)))
             (_K3021030224_
              (lambda (_k30220_)
                (call-with-current-continuation
                 (lambda (_kk30222_)
                   (##direct-structure-set!
                    _c30205_
                    _kk30222_
                    '1
                    std/coroutine#cort::t
                    '#f)
                   (apply _k30220_ _args30206_))))))
        (if (##structure-direct-instance-of?
             _c3020730213_
             'std/coroutine#cort::t)
            (let* ((_e3021130227_ (##vector-ref _c3020730213_ '1))
                   (_k30230_ _e3021130227_))
              (_K3021030224_ _k30230_))
            (_E3020930217_)))))
  (define std/coroutine#cothread-start!
    (lambda (_c30191_ _proc30192_ _args30193_)
      (call-with-parameters
       (lambda ()
         (with-exception-catcher
          (lambda (_g3019530197_)
            (if '#t
                (let ((_e30200_ _g3019530197_))
                  (std/coroutine#cothread-signal! _c30191_ 'error _e30200_))
                (raise _g3019530197_)))
          (lambda ()
            (std/coroutine#cothread-wait! _c30191_)
            (let ((_val30203_ (apply _proc30192_ _args30193_)))
              (std/coroutine#cothread-signal! _c30191_ 'end _val30203_)))))
       std/coroutine#current-coroutine
       '#f)))
  (define std/coroutine#cothread-stop!__%
    (lambda (_thread30176_ _val30177_)
      (if (thread? _thread30176_)
          (let ((_spec30179_ (thread-specific _thread30176_)))
            (if (##structure-direct-instance-of?
                 _spec30179_
                 'std/coroutine#cothr::t)
                (std/coroutine#cothread-signal! _spec30179_ 'end _val30177_)
                (error '"Not a coroutine thread" _thread30176_ _spec30179_)))
          (error '"Expected coroutine thread" _thread30176_))))
  (define std/coroutine#cothread-stop!__0
    (lambda (_thread30184_)
      (let ((_val30186_ '#!void))
        (std/coroutine#cothread-stop!__% _thread30184_ _val30186_))))
  (define std/coroutine#cothread-stop!
    (lambda _g30320_
      (let ((_g30319_ (length _g30320_)))
        (cond ((##fx= _g30319_ 1)
               (apply std/coroutine#cothread-stop!__0 _g30320_))
              ((##fx= _g30319_ 2)
               (apply std/coroutine#cothread-stop!__% _g30320_))
              (else
               (##raise-wrong-number-of-arguments-exception
                std/coroutine#cothread-stop!
                _g30320_))))))
  (define std/coroutine#cothread-continue!
    (lambda (_c30117_ _val30118_)
      (let* ((_c3011930128_ _c30117_)
             (_E3012130132_
              (lambda () (error '"No clause matching" _c3011930128_)))
             (_K3012230152_
              (lambda (_kont30135_ _state30136_ _cv30137_ _mx30138_)
                (mutex-lock! _mx30138_)
                (let ((_$e30140_ _state30136_))
                  (if (eq? 'run _$e30140_)
                      (begin
                        (##direct-structure-set!
                         _c30117_
                         _val30118_
                         '4
                         std/coroutine#cothr::t
                         '#f)
                        (##direct-structure-set!
                         _c30117_
                         'continue
                         '3
                         std/coroutine#cothr::t
                         '#f)
                        (condition-variable-signal! _cv30137_)
                        (mutex-unlock! _mx30138_ _cv30137_)
                        (let _lp30143_ ()
                          (mutex-lock! _mx30138_)
                          (let ((_state30146_
                                 (##direct-structure-ref
                                  _c30117_
                                  '3
                                  std/coroutine#cothr::t
                                  '#f))
                                (_kont30147_
                                 (##direct-structure-ref
                                  _c30117_
                                  '4
                                  std/coroutine#cothr::t
                                  '#f)))
                            (let ((_$e30149_ _state30146_))
                              (if (eq? 'continue _$e30149_)
                                  (begin
                                    (mutex-unlock! _mx30138_ _cv30137_)
                                    (_lp30143_))
                                  (if (eq? 'yield _$e30149_)
                                      (begin
                                        (##direct-structure-set!
                                         _c30117_
                                         'run
                                         '3
                                         std/coroutine#cothr::t
                                         '#f)
                                        (mutex-unlock! _mx30138_)
                                        _kont30147_)
                                      (if (eq? 'end _$e30149_)
                                          (begin
                                            (mutex-unlock! _mx30138_)
                                            _kont30147_)
                                          (if (eq? 'error _$e30149_)
                                              (begin
                                                (mutex-unlock! _mx30138_)
                                                (raise _kont30147_))
                                              (begin
                                                (mutex-unlock! _mx30138_)
                                                (error '"Illegal cothread state"
                                                       _state30146_))))))))))
                      (if (eq? 'end _$e30140_)
                          (begin (mutex-unlock! _mx30138_) _kont30135_)
                          (if (eq? 'error _$e30140_)
                              (begin
                                (mutex-unlock! _mx30138_)
                                (raise _kont30135_))
                              (error '"Illegal cothread state"
                                     _state30136_))))))))
        (if (##structure-direct-instance-of?
             _c3011930128_
             'std/coroutine#cothr::t)
            (let* ((_e3012330155_ (##vector-ref _c3011930128_ '1))
                   (_mx30158_ _e3012330155_)
                   (_e3012430160_ (##vector-ref _c3011930128_ '2))
                   (_cv30163_ _e3012430160_)
                   (_e3012530165_ (##vector-ref _c3011930128_ '3))
                   (_state30168_ _e3012530165_)
                   (_e3012630170_ (##vector-ref _c3011930128_ '4))
                   (_kont30173_ _e3012630170_))
              (_K3012230152_ _kont30173_ _state30168_ _cv30163_ _mx30158_))
            (_E3012130132_)))))
  (define std/coroutine#cothread-yield!
    (lambda (_c30112_ _args30113_)
      (let ((_kont30115_
             (std/coroutine#cothread-yield-values!
              _c30112_
              (apply values _args30113_))))
        (std/coroutine#cothread-wait! _c30112_)
        _kont30115_)))
  (define std/coroutine#cothread-yield-values!
    (lambda (_c30063_ _val30064_)
      (let* ((_c3006530074_ _c30063_)
             (_E3006730078_
              (lambda () (error '"No clause matching" _c3006530074_)))
             (_K3006830089_
              (lambda (_kont30081_ _state30082_ _cv30083_ _mx30084_)
                (mutex-lock! _mx30084_)
                (let ((_$e30086_ _state30082_))
                  (if (eq? 'continue _$e30086_)
                      (begin
                        (##direct-structure-set!
                         _c30063_
                         _val30064_
                         '4
                         std/coroutine#cothr::t
                         '#f)
                        (##direct-structure-set!
                         _c30063_
                         'yield
                         '3
                         std/coroutine#cothr::t
                         '#f)
                        (condition-variable-signal! _cv30083_)
                        (mutex-unlock! _mx30084_)
                        _kont30081_)
                      (begin
                        (mutex-unlock! _mx30084_)
                        (error '"Illegal cothread state" _state30082_)))))))
        (if (##structure-direct-instance-of?
             _c3006530074_
             'std/coroutine#cothr::t)
            (let* ((_e3006930092_ (##vector-ref _c3006530074_ '1))
                   (_mx30095_ _e3006930092_)
                   (_e3007030097_ (##vector-ref _c3006530074_ '2))
                   (_cv30100_ _e3007030097_)
                   (_e3007130102_ (##vector-ref _c3006530074_ '3))
                   (_state30105_ _e3007130102_)
                   (_e3007230107_ (##vector-ref _c3006530074_ '4))
                   (_kont30110_ _e3007230107_))
              (_K3006830089_ _kont30110_ _state30105_ _cv30100_ _mx30095_))
            (_E3006730078_)))))
  (define std/coroutine#cothread-signal!
    (lambda (_c30030_ _state30031_ _val30032_)
      (let* ((_c3003330040_ _c30030_)
             (_E3003530044_
              (lambda () (error '"No clause matching" _c3003330040_)))
             (_K3003630050_
              (lambda (_cv30047_ _mx30048_)
                (mutex-lock! _mx30048_)
                (if (memq (##direct-structure-ref
                           _c30030_
                           '3
                           std/coroutine#cothr::t
                           '#f)
                          '(end error))
                    '#!void
                    (begin
                      (##direct-structure-set!
                       _c30030_
                       _val30032_
                       '4
                       std/coroutine#cothr::t
                       '#f)
                      (##direct-structure-set!
                       _c30030_
                       _state30031_
                       '3
                       std/coroutine#cothr::t
                       '#f)
                      (condition-variable-signal! _cv30047_)))
                (mutex-unlock! _mx30048_))))
        (if (##structure-direct-instance-of?
             _c3003330040_
             'std/coroutine#cothr::t)
            (let* ((_e3003730053_ (##vector-ref _c3003330040_ '1))
                   (_mx30056_ _e3003730053_)
                   (_e3003830058_ (##vector-ref _c3003330040_ '2))
                   (_cv30061_ _e3003830058_))
              (_K3003630050_ _cv30061_ _mx30056_))
            (_E3003530044_)))))
  (define std/coroutine#cothread-wait!
    (lambda (_c29988_)
      (let* ((_c2998929996_ _c29988_)
             (_E2999130000_
              (lambda () (error '"No clause matching" _c2998929996_)))
             (_K2999230017_
              (lambda (_cv30003_ _mx30004_)
                (let _lp30006_ ()
                  (mutex-lock! _mx30004_)
                  (let* ((_state30009_
                          (##direct-structure-ref
                           _c29988_
                           '3
                           std/coroutine#cothr::t
                           '#f))
                         (_$e30011_ _state30009_))
                    (if (or (eq? 'run _$e30011_) (eq? 'yield _$e30011_))
                        (begin (mutex-unlock! _mx30004_ _cv30003_) (_lp30006_))
                        (if (eq? 'continue _$e30011_)
                            (mutex-unlock! _mx30004_)
                            (begin
                              (mutex-unlock! _mx30004_)
                              (error '"Illegal cothread state"
                                     _state30009_)))))))))
        (if (##structure-direct-instance-of?
             _c2998929996_
             'std/coroutine#cothr::t)
            (let* ((_e2999330020_ (##vector-ref _c2998929996_ '1))
                   (_mx30023_ _e2999330020_)
                   (_e2999430025_ (##vector-ref _c2998929996_ '2))
                   (_cv30028_ _e2999430025_))
              (_K2999230017_ _cv30028_ _mx30023_))
            (_E2999130000_))))))
