// File: /workspace/github_c_makefile_star2_O2/BernardTatin[P]s7sh/s7.c
// Function: g_dynamic_wind
static s7_pointer g_dynamic_wind(s7_scheme *sc, s7_pointer args)
                {
#define H_dynamic_wind "(dynamic-wind init body finish) calls init, then body, then finish, \
                    each a function of no arguments, guaranteeing that finish is called even if body is exited"
#define Q_dynamic_wind s7_make_circular_signature(sc, 1, 2, sc->values_symbol, sc->is_procedure_symbol)

                    s7_pointer p, inp, outp;

                    if (!is_dwind_thunk(sc, car(args)))
                        return(method_or_bust_with_type(sc, car(args), sc->dynamic_wind_symbol, args, a_thunk_string, 1));
                    if (!is_thunk(sc, cadr(args)))
                        return(method_or_bust_with_type(sc, cadr(args), sc->dynamic_wind_symbol, args, a_thunk_string, 2));
                    if (!is_dwind_thunk(sc, caddr(args)))
                        return(method_or_bust_with_type(sc, caddr(args), sc->dynamic_wind_symbol, args, a_thunk_string, 3));

                    /* this won't work:
                       (let ((final (lambda (a b c) (list a b c))))
                       (dynamic-wind
                       (lambda () #f)
                       (lambda () (set! final (lambda () (display "in final"))))
                       final))
                     * but why not?  'final' is a thunk by the time it is evaluated. catch (the error handler) is similar.
                     * It can't work here because we set up the dynamic_wind_out slot below and
                     *   even if the thunk check was removed, we'd still be trying to apply the original function.
                     */
                    new_cell(sc, p, T_DYNAMIC_WIND);                          /* don't mark car/cdr, don't copy */
                    dynamic_wind_in(p) = closure_or_f(sc, car(args));
                    dynamic_wind_body(p) = cadr(args);
                    dynamic_wind_out(p) = closure_or_f(sc, caddr(args));

                    inp = dynamic_wind_in(p);
                    if ((is_any_closure(inp)) && (!is_safe_closure(inp)))    /* wrap this use of inp in a with-baffle */
                        dynamic_wind_in(p) = make_baffled_closure(sc, inp);

                    outp = dynamic_wind_out(p);
                    if ((is_any_closure(outp)) && (!is_safe_closure(outp)))
                        dynamic_wind_out(p) = make_baffled_closure(sc, outp);

                    /* since we don't care about the in and out results, and they are thunks, if the body is not a pair,
                     *   or is a quoted thing, we just ignore that function.
                     */
                    push_stack(sc, OP_DYNAMIC_WIND, sc->nil, p);          /* args will be the saved result, code = s7_dynwind_t obj */
                    if (inp != sc->F)
                    {
                        dynamic_wind_state(p) = DWIND_INIT;
                        push_stack(sc, OP_APPLY, sc->nil, dynamic_wind_in(p));
                    }
                    else
                    {
                        dynamic_wind_state(p) = DWIND_BODY;
                        push_stack(sc, OP_APPLY, sc->nil, dynamic_wind_body(p));
                    }
                    return(sc->F);
                }

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movq 0x8(%rsi), %r15
movq %r15, %rsi
callq 0xcc820
testb %al, %al
je 0x65821
movq 0x10(%r14), %rax
movq 0x8(%rax), %rsi
cmpb $0x26, (%rsi)
jb 0x6583f
movq %rbx, %rdi
xorl %edx, %edx
callq 0x32378
movq 0x10(%r14), %rcx
testb %al, %al
je 0x6583b
movq 0x10(%rcx), %rax
movq 0x8(%rax), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0xcc820
testb %al, %al
je 0x65867
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x656f0
movq %rbx, %rdi
callq 0x9c27
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r12
movq $0x1a, (%r12)
movq 0x8(%r14), %rsi
movq %rbx, %rdi
callq 0xcc860
movq %rax, %r15
movq %rax, 0x8(%r12)
movq 0x10(%r14), %rax
movq 0x8(%rax), %rax
movq %rax, 0x18(%r12)
movq 0x10(%r14), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0xcc860
movq %rax, 0x10(%r12)
movzbl (%r15), %ecx
leaq 0xbc494(%rip), %r14     # 0x121be0
cmpb $0x1, (%rcx,%r14)
jne 0x6576f
testb $0x10, 0x1(%r15)
jne 0x6576f
movq %rbx, %rdi
movq %r15, %rsi
callq 0xcc894
movq %rax, 0x8(%r12)
movq 0x10(%r12), %rax
movzbl (%rax), %ecx
cmpb $0x1, (%rcx,%r14)
jne 0x6578f
testb $0x10, 0x1(%rax)
jne 0x6578f
movq %rbx, %rdi
movq %rax, %rsi
callq 0xcc894
movq %rax, 0x10(%r12)
movq 0x50(%rbx), %rax
movq %r12, (%rax)
movq 0x8(%rbx), %rax
movq 0x50(%rbx), %rcx
movq %rax, 0x8(%rcx)
movq 0x50(%rbx), %rax
movq 0x110(%rbx), %rcx
movq %rcx, 0x10(%rax)
movq 0x50(%rbx), %rax
movq $0x1e1, 0x18(%rax)      # imm = 0x1E1
addq $0x20, 0x50(%rbx)
xorl %eax, %eax
cmpq 0x120(%rbx), %r15
sete %al
movl %eax, 0x20(%r12)
shll $0x4, %eax
movq 0x8(%r12,%rax), %rax
movq 0x50(%rbx), %rcx
movq %rax, (%rcx)
movq 0x8(%rbx), %rax
movq 0x50(%rbx), %rcx
movq %rax, 0x8(%rcx)
movq 0x50(%rbx), %rax
movq 0x110(%rbx), %rcx
movq %rcx, 0x10(%rax)
movq 0x50(%rbx), %rax
movq $0x198, 0x18(%rax)      # imm = 0x198
addq $0x20, 0x50(%rbx)
movq 0x120(%rbx), %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0xe98(%rbx), %rdx
movq 0xbbb01(%rip), %r8      # 0x121330
pushq $0x1
popq %r9
movq %rbx, %rdi
movq %r15, %rsi
jmp 0x65854
movq 0x8(%rcx), %rsi
movq 0xe98(%rbx), %rdx
movq 0xbbae3(%rip), %r8      # 0x121330
pushq $0x2
popq %r9
movq %rbx, %rdi
movq %r14, %rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xcf9a
movq 0xe98(%rbx), %rdx
movq 0xbbabb(%rip), %r8      # 0x121330
pushq $0x3
jmp 0x65831