(declare (block) (standard-bindings) (extended-bindings))
(begin
  (define std/debug/memleak#heap-summary
    (lambda ()
      (let () (declare (not safe)) (##gc))
      (let* ((_mem709_ (std/debug/heap#memory-usage))
             (_g4325_ (std/debug/heap#count-still1)))
        (begin
          (let ((_g4326_ (let ()
                           (declare (not safe))
                           (if (##values? _g4325_)
                               (##vector-length _g4325_)
                               1))))
            (if (not (let () (declare (not safe)) (##fx= _g4326_ 2)))
                (error "Context expects 2 values" _g4326_)))
          (let ((_still711_
                 (let () (declare (not safe)) (##vector-ref _g4325_ 0)))
                (_refcounted712_
                 (let () (declare (not safe)) (##vector-ref _g4325_ 1))))
            (let* ((_live714_
                    (std/debug/heap#walk-heap!__%
                     '#f
                     absent-value
                     absent-value))
                   (_heap-stats716_ (make-table 'test: eq?))
                   (_frame-stats718_ (make-table 'test: eq?)))
              (table-for-each
               (lambda (_obj721_ _g4327_)
                 (let ((_t723_ (std/generic/dispatch#type-of _obj721_)))
                   (hash-update! _heap-stats716_ _t723_ 1+ '0)
                   (if (eq? _t723_ 'frame)
                       (let ((_c725_ (std/debug/memleak#frame-creator-name
                                      _obj721_)))
                         (hash-update! _frame-stats718_ _c725_ 1+ '0))
                       '#!void)))
               _live714_)
              (vector _mem709_
                      (cons (table-length _live714_)
                            (cons _still711_ (cons _refcounted712_ '())))
                      _heap-stats716_
                      _frame-stats718_)))))))
  (define std/debug/memleak#heap-summary-delta
    (lambda (_old623_ _new624_)
      (let ((_old625639_ _old623_) (_new626641_ _new624_))
        (let* ((_E628645_
                (lambda ()
                  (error '"No clause matching" _old625639_ _new626641_)))
               (_K629665_
                (lambda (_frame-old648_
                         _heap-old649_
                         _counts-old650_
                         _mem-old651_
                         _frame-new652_
                         _heap-new653_
                         _counts-new654_
                         _mem-new655_)
                  (let ((_mem-delta660_
                         (map (lambda (_a657_ _b658_)
                                (cons (car _a657_)
                                      (- (cdr _a657_) (cdr _b658_))))
                              _mem-new655_
                              _mem-old651_))
                        (_counts-delta661_
                         (map - _counts-new654_ _counts-old650_))
                        (_heap-delta662_
                         (std/debug/memleak#hash-delta
                          _heap-new653_
                          _heap-old649_))
                        (_frame-delta663_
                         (std/debug/memleak#hash-delta
                          _frame-new652_
                          _frame-old648_)))
                    (vector _mem-delta660_
                            _counts-delta661_
                            _heap-delta662_
                            _frame-delta663_)))))
          (if (let () (declare (not safe)) (##vector? _old625639_))
              (if (let ((__tmp4328
                         (let ()
                           (declare (not safe))
                           (##vector-length _old625639_))))
                    (declare (not safe))
                    (##fx= __tmp4328 '4))
                  (let* ((_e634668_
                          (let ()
                            (declare (not safe))
                            (##vector-ref _old625639_ '0)))
                         (_mem-old671_ _e634668_)
                         (_e635673_
                          (let ()
                            (declare (not safe))
                            (##vector-ref _old625639_ '1)))
                         (_counts-old676_ _e635673_)
                         (_e636678_
                          (let ()
                            (declare (not safe))
                            (##vector-ref _old625639_ '2)))
                         (_heap-old681_ _e636678_)
                         (_e637683_
                          (let ()
                            (declare (not safe))
                            (##vector-ref _old625639_ '3)))
                         (_frame-old686_ _e637683_))
                    (if (let () (declare (not safe)) (##vector? _new626641_))
                        (if (let ((__tmp4329
                                   (let ()
                                     (declare (not safe))
                                     (##vector-length _new626641_))))
                              (declare (not safe))
                              (##fx= __tmp4329 '4))
                            (let* ((_e630688_
                                    (let ()
                                      (declare (not safe))
                                      (##vector-ref _new626641_ '0)))
                                   (_mem-new691_ _e630688_)
                                   (_e631693_
                                    (let ()
                                      (declare (not safe))
                                      (##vector-ref _new626641_ '1)))
                                   (_counts-new696_ _e631693_)
                                   (_e632698_
                                    (let ()
                                      (declare (not safe))
                                      (##vector-ref _new626641_ '2)))
                                   (_heap-new701_ _e632698_)
                                   (_e633703_
                                    (let ()
                                      (declare (not safe))
                                      (##vector-ref _new626641_ '3)))
                                   (_frame-new706_ _e633703_))
                              (_K629665_
                               _frame-old686_
                               _heap-old681_
                               _counts-old676_
                               _mem-old671_
                               _frame-new706_
                               _heap-new701_
                               _counts-new696_
                               _mem-new691_))
                            (_E628645_))
                        (_E628645_)))
                  (_E628645_))
              (_E628645_))))))
  (define std/debug/memleak#hash-delta
    (lambda (_new607_ _old608_)
      (letrec* ((_delta610_ (make-table 'test: eq?)))
        (table-for-each
         (lambda (_key612_ _count613_)
           (let ((_$e615_ (table-ref _old608_ _key612_ '#f)))
             (if _$e615_
                 ((lambda (_old-count618_)
                    (table-set!
                     _delta610_
                     _key612_
                     (- _count613_ _old-count618_)))
                  _$e615_)
                 (table-set! _delta610_ _key612_ _count613_))))
         _new607_)
        (table-for-each
         (lambda (_key620_ _count621_)
           (if (table-ref _delta610_ _key620_ '#f)
               '#!void
               (table-set! _delta610_ _key620_ (- _count621_))))
         _old608_)
        _delta610_)))
  (define std/debug/memleak#dump-heap-summary!__%
    (lambda (_summary472_ _port473_)
      (letrec ((_display-pair475_
                (lambda (_el567_)
                  (let* ((_el568575_ _el567_)
                         (_E570579_
                          (lambda () (error '"No clause matching" _el568575_)))
                         (_K571585_
                          (lambda (_val582_ _key583_)
                            (if (zero? _val582_)
                                '#!void
                                (displayln _key583_ '": " _val582_)))))
                    (if (let () (declare (not safe)) (##pair? _el568575_))
                        (let ((_hd572588_
                               (let ()
                                 (declare (not safe))
                                 (##car _el568575_)))
                              (_tl573590_
                               (let ()
                                 (declare (not safe))
                                 (##cdr _el568575_))))
                          (let* ((_key593_ _hd572588_) (_val595_ _tl573590_))
                            (_K571585_ _val595_ _key593_)))
                        (_E570579_)))))
               (_cmp-count476_
                (lambda (_a564_ _b565_) (> (cdr _a564_) (cdr _b565_))))
               (_display-list?477_
                (lambda (_lst560_)
                  (find (lambda (_el562_) (not (zero? (cdr _el562_))))
                        _lst560_))))
        (call-with-parameters
         (lambda ()
           (let* ((_summary479494_ _summary472_)
                  (_E481498_
                   (lambda () (error '"No clause matching" _summary479494_)))
                  (_K482518_
                   (lambda (_frame501_
                            _heap502_
                            _refcounted503_
                            _still504_
                            _live505_
                            _mem506_)
                     (displayln '"==================================")
                     (displayln
                      '"timestamp: "
                      (let () (declare (not safe)) (##current-time-point)))
                     (let ((_lst510_
                            (filter (lambda (_el508_)
                                      (not (eq? (car _el508_) 'gc-alloc)))
                                    _mem506_)))
                       (if (_display-list?477_ _lst510_)
                           (begin
                             (displayln '"=== memory usage ===")
                             (for-each _display-pair475_ _lst510_))
                           '#!void))
                     (let ((_lst512_
                            (cons (cons 'objects _live505_)
                                  (cons (cons 'still _still504_)
                                        (cons (cons 'refcounted
                                                    _refcounted503_)
                                              '())))))
                       (if (_display-list?477_ _lst512_)
                           (begin
                             (displayln '"=== heap summary ===")
                             (for-each _display-pair475_ _lst512_))
                           '#!void))
                     (let ((_lst514_
                            (std/sort#sort
                             (table->list _heap502_)
                             _cmp-count476_)))
                       (if (_display-list?477_ _lst514_)
                           (begin
                             (displayln '"=== heap type counts ===")
                             (for-each _display-pair475_ _lst514_))
                           '#!void))
                     (let ((_lst516_
                            (std/sort#sort
                             (table->list _frame501_)
                             _cmp-count476_)))
                       (if (_display-list?477_ _lst516_)
                           (begin
                             (displayln '"=== frame counts ===")
                             (for-each _display-pair475_ _lst516_))
                           '#!void))
                     (displayln '"=================================="))))
             (if (let () (declare (not safe)) (##vector? _summary479494_))
                 (if (let ((__tmp4330
                            (let ()
                              (declare (not safe))
                              (##vector-length _summary479494_))))
                       (declare (not safe))
                       (##fx= __tmp4330 '4))
                     (let* ((_e483521_
                             (let ()
                               (declare (not safe))
                               (##vector-ref _summary479494_ '0)))
                            (_mem524_ _e483521_)
                            (_e484526_
                             (let ()
                               (declare (not safe))
                               (##vector-ref _summary479494_ '1))))
                       (if (let () (declare (not safe)) (##pair? _e484526_))
                           (let ((_hd487529_
                                  (let ()
                                    (declare (not safe))
                                    (##car _e484526_)))
                                 (_tl488531_
                                  (let ()
                                    (declare (not safe))
                                    (##cdr _e484526_))))
                             (let ((_live534_ _hd487529_))
                               (if (let ()
                                     (declare (not safe))
                                     (##pair? _tl488531_))
                                   (let ((_hd489536_
                                          (let ()
                                            (declare (not safe))
                                            (##car _tl488531_)))
                                         (_tl490538_
                                          (let ()
                                            (declare (not safe))
                                            (##cdr _tl488531_))))
                                     (let ((_still541_ _hd489536_))
                                       (if (let ()
                                             (declare (not safe))
                                             (##pair? _tl490538_))
                                           (let ((_hd491543_
                                                  (let ()
                                                    (declare (not safe))
                                                    (##car _tl490538_)))
                                                 (_tl492545_
                                                  (let ()
                                                    (declare (not safe))
                                                    (##cdr _tl490538_))))
                                             (let ((_refcounted548_
                                                    _hd491543_))
                                               (if (let ()
                                                     (declare (not safe))
                                                     (##null? _tl492545_))
                                                   (let* ((_e485550_
                                                           (let ()
                                                             (declare
                                                               (not safe))
                                                             (##vector-ref
                                                              _summary479494_
                                                              '2)))
                                                          (_heap553_ _e485550_)
                                                          (_e486555_
                                                           (let ()
                                                             (declare
                                                               (not safe))
                                                             (##vector-ref
                                                              _summary479494_
                                                              '3)))
                                                          (_frame558_
                                                           _e486555_))
                                                     (_K482518_
                                                      _frame558_
                                                      _heap553_
                                                      _refcounted548_
                                                      _still541_
                                                      _live534_
                                                      _mem524_))
                                                   (_E481498_))))
                                           (_E481498_))))
                                   (_E481498_))))
                           (_E481498_)))
                     (_E481498_))
                 (_E481498_))))
         current-output-port
         _port473_))))
  (define std/debug/memleak#dump-heap-summary!__0
    (lambda (_summary600_)
      (let ((_port602_ (current-error-port)))
        (std/debug/memleak#dump-heap-summary!__% _summary600_ _port602_))))
  (define std/debug/memleak#dump-heap-summary!
    (lambda _g4332_
      (let ((_g4331_ (let () (declare (not safe)) (##length _g4332_))))
        (cond ((let () (declare (not safe)) (##fx= _g4331_ 1))
               (apply std/debug/memleak#dump-heap-summary!__0 _g4332_))
              ((let () (declare (not safe)) (##fx= _g4331_ 2))
               (apply std/debug/memleak#dump-heap-summary!__% _g4332_))
              (else
               (##raise-wrong-number-of-arguments-exception
                std/debug/memleak#dump-heap-summary!
                _g4332_))))))
  (define std/debug/memleak#watch-heap!__%__%
    (lambda (__414417_
             _initial-delay410419_
             _period411421_
             _dump!412423_
             _port425_)
      (let* ((_initial-delay427_
              (if (eq? _initial-delay410419_ absent-value)
                  '60
                  _initial-delay410419_))
             (_period429_
              (if (eq? _period411421_ absent-value)
                  (* '60 '15)
                  _period411421_))
             (_dump!431_
              (if (eq? _dump!412423_ absent-value)
                  std/debug/memleak#dump-heap-summary!
                  _dump!412423_)))
        (thread-sleep! _initial-delay427_)
        (let ((_summary433_ (std/debug/memleak#heap-summary)))
          (_dump!431_ _summary433_ _port425_)
          (force-output _port425_)
          (let _lp435_ ((_prev-summary437_ _summary433_))
            (thread-sleep! _period429_)
            (let ((_summary439_ (std/debug/memleak#heap-summary)))
              (_dump!431_
               (std/debug/memleak#heap-summary-delta
                _prev-summary437_
                _summary439_)
               _port425_)
              (force-output _port425_)
              (_lp435_ _summary439_)))))))
  (define std/debug/memleak#watch-heap!__%__0
    (lambda (__414444_ _initial-delay410445_ _period411446_ _dump!412447_)
      (let ((_port449_ (current-error-port)))
        (std/debug/memleak#watch-heap!__%__%
         __414444_
         _initial-delay410445_
         _period411446_
         _dump!412447_
         _port449_))))
  (define std/debug/memleak#watch-heap!__%
    (lambda _g4334_
      (let ((_g4333_ (let () (declare (not safe)) (##length _g4334_))))
        (cond ((let () (declare (not safe)) (##fx= _g4333_ 4))
               (apply std/debug/memleak#watch-heap!__%__0 _g4334_))
              ((let () (declare (not safe)) (##fx= _g4333_ 5))
               (apply std/debug/memleak#watch-heap!__%__% _g4334_))
              (else
               (##raise-wrong-number-of-arguments-exception
                std/debug/memleak#watch-heap!__%
                _g4334_))))))
  (define std/debug/memleak#watch-heap!__@
    (lambda (_keys409460_ . _args462_)
      (apply std/debug/memleak#watch-heap!__%
             _keys409460_
             (table-ref _keys409460_ 'delay: absent-value)
             (table-ref _keys409460_ 'period: absent-value)
             (table-ref _keys409460_ 'dump: absent-value)
             _args462_)))
  (define std/debug/memleak#watch-heap!
    (lambda _args413468_
      (apply keyword-dispatch
             '#(#f #f delay: #f period: dump:)
             std/debug/memleak#watch-heap!__@
             _args413468_)))
  (define std/debug/memleak#frame-creator
    (lambda (_frame406_)
      (let ((__tmp4335
             (let ()
               (declare (not safe))
               (##make-continuation _frame406_ '#f))))
        (declare (not safe))
        (##continuation-creator __tmp4335))))
  (define std/debug/memleak#frame-creator-name
    (lambda (_frame402_)
      (let ((_creator404_ (std/debug/memleak#frame-creator _frame402_)))
        (if (procedure? _creator404_)
            (let () (declare (not safe)) (##procedure-name _creator404_))
            '#f)))))
