// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rsi
callq 0x1cffa0
testb $0x1, %al
jne 0xa0290
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rsi
movq 0x28(%rsp), %rax
movq 0xe98(%rax), %rdx
movq 0x20(%rsp), %rcx
movq 0x181c0d(%rip), %r8     # 0x221e88
movl $0x1, %r9d
callq 0x14130
movq %rax, 0x30(%rsp)
jmp 0xa062d
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movzbl (%rax), %eax
cmpl $0x26, %eax
jl 0xa02c4
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x3cbf0
testb $0x1, %al
jne 0xa0303
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rsi
movq 0x28(%rsp), %rax
movq 0xe98(%rax), %rdx
movq 0x20(%rsp), %rcx
movq 0x181b9a(%rip), %r8     # 0x221e88
movl $0x2, %r9d
callq 0x14130
movq %rax, 0x30(%rsp)
jmp 0xa062d
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x1cffa0
testb $0x1, %al
jne 0xa0365
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rsi
movq 0x28(%rsp), %rax
movq 0xe98(%rax), %rdx
movq 0x20(%rsp), %rcx
movq 0x181b38(%rip), %r8     # 0x221e88
movl $0x3, %r9d
callq 0x14130
movq %rax, 0x30(%rsp)
jmp 0xa062d
jmp 0xa0367
movq 0x28(%rsp), %rax
movq 0x90(%rax), %rax
movq 0x28(%rsp), %rcx
cmpq 0x98(%rcx), %rax
ja 0xa038b
movq 0x28(%rsp), %rdi
callq 0xc670
movq 0x28(%rsp), %rcx
movq 0x90(%rcx), %rax
movq %rax, %rdx
addq $-0x8, %rdx
movq %rdx, 0x90(%rcx)
movq -0x8(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq $0x1a, (%rax)
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rsi
callq 0x1d0080
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x1d0080
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movzbl (%rax), %eax
movl %eax, %ecx
leaq 0x1822fb(%rip), %rax    # 0x222730
testb $0x1, (%rax,%rcx)
je 0xa0468
movq 0x10(%rsp), %rax
movzwl (%rax), %eax
andl $0x1000, %eax           # imm = 0x1000
cmpl $0x0, %eax
jne 0xa0468
movq 0x28(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x1d0140
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movzbl (%rax), %eax
movl %eax, %ecx
leaq 0x1822a9(%rip), %rax    # 0x222730
testb $0x1, (%rax,%rcx)
je 0xa04ba
movq 0x8(%rsp), %rax
movzwl (%rax), %eax
andl $0x1000, %eax           # imm = 0x1000
cmpl $0x0, %eax
jne 0xa04ba
movq 0x28(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x1d0140
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x10(%rax)
jmp 0xa04bc
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rax
movq 0x50(%rax), %rax
movq %rcx, (%rax)
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rcx
movq 0x28(%rsp), %rax
movq 0x50(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x28(%rsp), %rax
movq 0x110(%rax), %rcx
movq 0x28(%rsp), %rax
movq 0x50(%rax), %rax
movq %rcx, 0x10(%rax)
movq 0x28(%rsp), %rax
movq 0x50(%rax), %rax
movl $0x1e1, %ecx            # imm = 0x1E1
movq %rcx, 0x18(%rax)
movq 0x28(%rsp), %rax
movq 0x50(%rax), %rcx
addq $0x20, %rcx
movq %rcx, 0x50(%rax)
movq 0x10(%rsp), %rax
movq 0x28(%rsp), %rcx
cmpq 0x120(%rcx), %rax
je 0xa05a7
movq 0x18(%rsp), %rax
movl $0x0, 0x20(%rax)
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rcx
movq 0x28(%rsp), %rax
movq 0x50(%rax), %rax
movq %rcx, (%rax)
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rcx
movq 0x28(%rsp), %rax
movq 0x50(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x28(%rsp), %rax
movq 0x110(%rax), %rcx
movq 0x28(%rsp), %rax
movq 0x50(%rax), %rax
movq %rcx, 0x10(%rax)
movq 0x28(%rsp), %rax
movq 0x50(%rax), %rax
movl $0x198, %ecx            # imm = 0x198
movq %rcx, 0x18(%rax)
movq 0x28(%rsp), %rax
movq 0x50(%rax), %rcx
addq $0x20, %rcx
movq %rcx, 0x50(%rax)
jmp 0xa061c
movq 0x18(%rsp), %rax
movl $0x1, 0x20(%rax)
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x28(%rsp), %rax
movq 0x50(%rax), %rax
movq %rcx, (%rax)
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rcx
movq 0x28(%rsp), %rax
movq 0x50(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x28(%rsp), %rax
movq 0x110(%rax), %rcx
movq 0x28(%rsp), %rax
movq 0x50(%rax), %rax
movq %rcx, 0x10(%rax)
movq 0x28(%rsp), %rax
movq 0x50(%rax), %rax
movl $0x198, %ecx            # imm = 0x198
movq %rcx, 0x18(%rax)
movq 0x28(%rsp), %rax
movq 0x50(%rax), %rcx
addq $0x20, %rcx
movq %rcx, 0x50(%rax)
jmp 0xa061c
movq 0x28(%rsp), %rax
movq 0x120(%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
addq $0x38, %rsp
retq
nopw (%rax,%rax)