(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 _$args719_
      (apply make-struct-instance std/coroutine#cort::t _$args719_)))
  (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 _$args716_
      (apply make-struct-instance std/coroutine#cothr::t _$args716_)))
  (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 (_proc710_ . _args711_)
      (call-with-current-continuation
       (lambda (_k713_)
         (std/coroutine#coroutine-start!
          _k713_
          (if (null? _args711_)
              _proc710_
              (lambda () (apply _proc710_ _args711_))))))))
  (define std/coroutine#cothread
    (lambda (_proc701_ . _args702_)
      (let* ((_cothr704_
              (let ((__tmp4321 (make-mutex 'coroutine))
                    (__tmp4320 (make-condition-variable 'coroutine)))
                (declare (not safe))
                (##structure
                 std/coroutine#cothr::t
                 __tmp4321
                 __tmp4320
                 'run
                 '#f)))
             (_thread707_
              (make-thread
               (lambda ()
                 (std/coroutine#cothread-start!
                  _cothr704_
                  _proc701_
                  _args702_))
               'cothread)))
        (thread-specific-set! _thread707_ _cothr704_)
        (thread-start! _thread707_))))
  (define std/coroutine#cothread?
    (lambda (_thread699_)
      (if (thread? _thread699_)
          (let ((__tmp4322 (thread-specific _thread699_)))
            (declare (not safe))
            (##structure-direct-instance-of?
             __tmp4322
             'std/coroutine#cothr::t))
          '#f)))
  (define std/coroutine#continue
    (lambda (_c696_ . _args697_)
      (if (let ()
            (declare (not safe))
            (##structure-direct-instance-of? _c696_ 'std/coroutine#cort::t))
          (std/coroutine#coroutine-continue! _c696_ _args697_)
          (if (std/coroutine#cothread? _c696_)
              (std/coroutine#cothread-continue!
               (thread-specific _c696_)
               _args697_)
              (error '"Illegal argument; not continuable" _c696_)))))
  (define std/coroutine#yield
    (lambda _args687_
      (let ((_$e689_ (std/coroutine#current-coroutine)))
        (if _$e689_
            ((lambda (_g691693_)
               (std/coroutine#coroutine-yield! _g691693_ _args687_))
             _$e689_)
            (if (let ((__tmp4323 (thread-specific (current-thread))))
                  (declare (not safe))
                  (##structure-direct-instance-of?
                   __tmp4323
                   'std/coroutine#cothr::t))
                (std/coroutine#cothread-yield!
                 (thread-specific (current-thread))
                 _args687_)
                (error '"Not in a coroutine continuation"))))))
  (define std/coroutine#coroutine-start!
    (lambda (_k675_ _thunk676_)
      (let ((_c678_ (let ()
                      (declare (not safe))
                      (##structure std/coroutine#cort::t '#f '#f '#f))))
        (call-with-parameters
         (lambda ()
           (call-with-current-continuation
            (lambda (_kk681_)
              (##direct-structure-set!
               _c678_
               _kk681_
               '1
               std/coroutine#cort::t
               '#f)
              (_k675_ _c678_)))
           (call-with-values
            _thunk676_
            (lambda _res683_
              (let ((_k685_ (##direct-structure-ref
                             _c678_
                             '1
                             std/coroutine#cort::t
                             '#f)))
                (##direct-structure-set!
                 _c678_
                 '#t
                 '2
                 std/coroutine#cort::t
                 '#f)
                (##direct-structure-set!
                 _c678_
                 _res683_
                 '3
                 std/coroutine#cort::t
                 '#f)
                (##direct-structure-set!
                 _c678_
                 '#f
                 '1
                 std/coroutine#cort::t
                 '#f)
                (apply _k685_ _res683_)))))
         std/coroutine#current-coroutine
         _c678_))))
  (define std/coroutine#coroutine-continue!
    (lambda (_c634_ _args635_)
      (let* ((_c636644_ _c634_)
             (_E638648_ (lambda () (error '"No clause matching" _c636644_)))
             (_K639657_
              (lambda (_res651_ _end?652_ _k653_)
                (if _end?652_
                    (apply values _res651_)
                    (call-with-current-continuation
                     (lambda (_kk655_)
                       (##direct-structure-set!
                        _c634_
                        _kk655_
                        '1
                        std/coroutine#cort::t
                        '#f)
                       (apply _k653_ _args635_)))))))
        (if (let ()
              (declare (not safe))
              (##structure-direct-instance-of?
               _c636644_
               'std/coroutine#cort::t))
            (let* ((_e640660_
                    (let () (declare (not safe)) (##vector-ref _c636644_ '1)))
                   (_k663_ _e640660_)
                   (_e641665_
                    (let () (declare (not safe)) (##vector-ref _c636644_ '2)))
                   (_end?668_ _e641665_)
                   (_e642670_
                    (let () (declare (not safe)) (##vector-ref _c636644_ '3)))
                   (_res673_ _e642670_))
              (_K639657_ _res673_ _end?668_ _k663_))
            (_E638648_)))))
  (define std/coroutine#coroutine-yield!
    (lambda (_c607_ _args608_)
      (let* ((_c609615_ _c607_)
             (_E611619_ (lambda () (error '"No clause matching" _c609615_)))
             (_K612626_
              (lambda (_k622_)
                (call-with-current-continuation
                 (lambda (_kk624_)
                   (##direct-structure-set!
                    _c607_
                    _kk624_
                    '1
                    std/coroutine#cort::t
                    '#f)
                   (apply _k622_ _args608_))))))
        (if (let ()
              (declare (not safe))
              (##structure-direct-instance-of?
               _c609615_
               'std/coroutine#cort::t))
            (let* ((_e613629_
                    (let () (declare (not safe)) (##vector-ref _c609615_ '1)))
                   (_k632_ _e613629_))
              (_K612626_ _k632_))
            (_E611619_)))))
  (define std/coroutine#cothread-start!
    (lambda (_c593_ _proc594_ _args595_)
      (call-with-parameters
       (lambda ()
         (with-exception-catcher
          (lambda (_g597599_)
            (if '#t
                (let ((_e602_ _g597599_))
                  (std/coroutine#cothread-signal! _c593_ 'error _e602_))
                (raise _g597599_)))
          (lambda ()
            (std/coroutine#cothread-wait! _c593_)
            (let ((_val605_ (apply _proc594_ _args595_)))
              (std/coroutine#cothread-signal! _c593_ 'end _val605_)))))
       std/coroutine#current-coroutine
       '#f)))
  (define std/coroutine#cothread-stop!__%
    (lambda (_thread578_ _val579_)
      (if (thread? _thread578_)
          (let ((_spec581_ (thread-specific _thread578_)))
            (if (let ()
                  (declare (not safe))
                  (##structure-direct-instance-of?
                   _spec581_
                   'std/coroutine#cothr::t))
                (std/coroutine#cothread-signal! _spec581_ 'end _val579_)
                (error '"Not a coroutine thread" _thread578_ _spec581_)))
          (error '"Expected coroutine thread" _thread578_))))
  (define std/coroutine#cothread-stop!__0
    (lambda (_thread586_)
      (let ((_val588_ '#!void))
        (std/coroutine#cothread-stop!__% _thread586_ _val588_))))
  (define std/coroutine#cothread-stop!
    (lambda _g4325_
      (let ((_g4324_ (let () (declare (not safe)) (##length _g4325_))))
        (cond ((let () (declare (not safe)) (##fx= _g4324_ 1))
               (apply std/coroutine#cothread-stop!__0 _g4325_))
              ((let () (declare (not safe)) (##fx= _g4324_ 2))
               (apply std/coroutine#cothread-stop!__% _g4325_))
              (else
               (##raise-wrong-number-of-arguments-exception
                std/coroutine#cothread-stop!
                _g4325_))))))
  (define std/coroutine#cothread-continue!
    (lambda (_c519_ _val520_)
      (let* ((_c521530_ _c519_)
             (_E523534_ (lambda () (error '"No clause matching" _c521530_)))
             (_K524554_
              (lambda (_kont537_ _state538_ _cv539_ _mx540_)
                (mutex-lock! _mx540_)
                (let ((_$e542_ _state538_))
                  (if (eq? 'run _$e542_)
                      (begin
                        (##direct-structure-set!
                         _c519_
                         _val520_
                         '4
                         std/coroutine#cothr::t
                         '#f)
                        (##direct-structure-set!
                         _c519_
                         'continue
                         '3
                         std/coroutine#cothr::t
                         '#f)
                        (condition-variable-signal! _cv539_)
                        (mutex-unlock! _mx540_ _cv539_)
                        (let _lp545_ ()
                          (mutex-lock! _mx540_)
                          (let ((_state548_
                                 (##direct-structure-ref
                                  _c519_
                                  '3
                                  std/coroutine#cothr::t
                                  '#f))
                                (_kont549_
                                 (##direct-structure-ref
                                  _c519_
                                  '4
                                  std/coroutine#cothr::t
                                  '#f)))
                            (let ((_$e551_ _state548_))
                              (if (eq? 'continue _$e551_)
                                  (begin
                                    (mutex-unlock! _mx540_ _cv539_)
                                    (_lp545_))
                                  (if (eq? 'yield _$e551_)
                                      (begin
                                        (##direct-structure-set!
                                         _c519_
                                         'run
                                         '3
                                         std/coroutine#cothr::t
                                         '#f)
                                        (mutex-unlock! _mx540_)
                                        _kont549_)
                                      (if (eq? 'end _$e551_)
                                          (begin
                                            (mutex-unlock! _mx540_)
                                            _kont549_)
                                          (if (eq? 'error _$e551_)
                                              (begin
                                                (mutex-unlock! _mx540_)
                                                (raise _kont549_))
                                              (begin
                                                (mutex-unlock! _mx540_)
                                                (error '"Illegal cothread state"
                                                       _state548_))))))))))
                      (if (eq? 'end _$e542_)
                          (begin (mutex-unlock! _mx540_) _kont537_)
                          (if (eq? 'error _$e542_)
                              (begin (mutex-unlock! _mx540_) (raise _kont537_))
                              (error '"Illegal cothread state"
                                     _state538_))))))))
        (if (let ()
              (declare (not safe))
              (##structure-direct-instance-of?
               _c521530_
               'std/coroutine#cothr::t))
            (let* ((_e525557_
                    (let () (declare (not safe)) (##vector-ref _c521530_ '1)))
                   (_mx560_ _e525557_)
                   (_e526562_
                    (let () (declare (not safe)) (##vector-ref _c521530_ '2)))
                   (_cv565_ _e526562_)
                   (_e527567_
                    (let () (declare (not safe)) (##vector-ref _c521530_ '3)))
                   (_state570_ _e527567_)
                   (_e528572_
                    (let () (declare (not safe)) (##vector-ref _c521530_ '4)))
                   (_kont575_ _e528572_))
              (_K524554_ _kont575_ _state570_ _cv565_ _mx560_))
            (_E523534_)))))
  (define std/coroutine#cothread-yield!
    (lambda (_c514_ _args515_)
      (let ((_kont517_
             (std/coroutine#cothread-yield-values!
              _c514_
              (apply values _args515_))))
        (std/coroutine#cothread-wait! _c514_)
        _kont517_)))
  (define std/coroutine#cothread-yield-values!
    (lambda (_c465_ _val466_)
      (let* ((_c467476_ _c465_)
             (_E469480_ (lambda () (error '"No clause matching" _c467476_)))
             (_K470491_
              (lambda (_kont483_ _state484_ _cv485_ _mx486_)
                (mutex-lock! _mx486_)
                (let ((_$e488_ _state484_))
                  (if (eq? 'continue _$e488_)
                      (begin
                        (##direct-structure-set!
                         _c465_
                         _val466_
                         '4
                         std/coroutine#cothr::t
                         '#f)
                        (##direct-structure-set!
                         _c465_
                         'yield
                         '3
                         std/coroutine#cothr::t
                         '#f)
                        (condition-variable-signal! _cv485_)
                        (mutex-unlock! _mx486_)
                        _kont483_)
                      (begin
                        (mutex-unlock! _mx486_)
                        (error '"Illegal cothread state" _state484_)))))))
        (if (let ()
              (declare (not safe))
              (##structure-direct-instance-of?
               _c467476_
               'std/coroutine#cothr::t))
            (let* ((_e471494_
                    (let () (declare (not safe)) (##vector-ref _c467476_ '1)))
                   (_mx497_ _e471494_)
                   (_e472499_
                    (let () (declare (not safe)) (##vector-ref _c467476_ '2)))
                   (_cv502_ _e472499_)
                   (_e473504_
                    (let () (declare (not safe)) (##vector-ref _c467476_ '3)))
                   (_state507_ _e473504_)
                   (_e474509_
                    (let () (declare (not safe)) (##vector-ref _c467476_ '4)))
                   (_kont512_ _e474509_))
              (_K470491_ _kont512_ _state507_ _cv502_ _mx497_))
            (_E469480_)))))
  (define std/coroutine#cothread-signal!
    (lambda (_c432_ _state433_ _val434_)
      (let* ((_c435442_ _c432_)
             (_E437446_ (lambda () (error '"No clause matching" _c435442_)))
             (_K438452_
              (lambda (_cv449_ _mx450_)
                (mutex-lock! _mx450_)
                (if (memq (##direct-structure-ref
                           _c432_
                           '3
                           std/coroutine#cothr::t
                           '#f)
                          '(end error))
                    '#!void
                    (begin
                      (##direct-structure-set!
                       _c432_
                       _val434_
                       '4
                       std/coroutine#cothr::t
                       '#f)
                      (##direct-structure-set!
                       _c432_
                       _state433_
                       '3
                       std/coroutine#cothr::t
                       '#f)
                      (condition-variable-signal! _cv449_)))
                (mutex-unlock! _mx450_))))
        (if (let ()
              (declare (not safe))
              (##structure-direct-instance-of?
               _c435442_
               'std/coroutine#cothr::t))
            (let* ((_e439455_
                    (let () (declare (not safe)) (##vector-ref _c435442_ '1)))
                   (_mx458_ _e439455_)
                   (_e440460_
                    (let () (declare (not safe)) (##vector-ref _c435442_ '2)))
                   (_cv463_ _e440460_))
              (_K438452_ _cv463_ _mx458_))
            (_E437446_)))))
  (define std/coroutine#cothread-wait!
    (lambda (_c390_)
      (let* ((_c391398_ _c390_)
             (_E393402_ (lambda () (error '"No clause matching" _c391398_)))
             (_K394419_
              (lambda (_cv405_ _mx406_)
                (let _lp408_ ()
                  (mutex-lock! _mx406_)
                  (let* ((_state411_
                          (##direct-structure-ref
                           _c390_
                           '3
                           std/coroutine#cothr::t
                           '#f))
                         (_$e413_ _state411_))
                    (if (or (eq? 'run _$e413_) (eq? 'yield _$e413_))
                        (begin (mutex-unlock! _mx406_ _cv405_) (_lp408_))
                        (if (eq? 'continue _$e413_)
                            (mutex-unlock! _mx406_)
                            (begin
                              (mutex-unlock! _mx406_)
                              (error '"Illegal cothread state"
                                     _state411_)))))))))
        (if (let ()
              (declare (not safe))
              (##structure-direct-instance-of?
               _c391398_
               'std/coroutine#cothr::t))
            (let* ((_e395422_
                    (let () (declare (not safe)) (##vector-ref _c391398_ '1)))
                   (_mx425_ _e395422_)
                   (_e396427_
                    (let () (declare (not safe)) (##vector-ref _c391398_ '2)))
                   (_cv430_ _e396427_))
              (_K394419_ _cv430_ _mx425_))
            (_E393402_))))))
