// File: /workspace/github_c_makefile_star2_O3/BernardTatin[P]s7sh/s7.c
// Function: g_call_with_exit
static s7_pointer g_call_with_exit(s7_scheme *sc, s7_pointer args)
    {
#define H_call_with_exit "(call-with-exit (lambda (exiter) ...)) is call/cc without the ability to jump back into a previous computation."
#define Q_call_with_exit s7_make_signature(sc, 2, sc->values_symbol, sc->is_procedure_symbol)

        s7_pointer p, x;
        /* (call-with-exit (lambda (return) ...)) */

        p = car(args);
        if (!is_t_procedure(p))                  /* this includes continuations */
            return(method_or_bust_with_type_one_arg(sc, p, sc->call_with_exit_symbol, args, a_procedure_string));

        x = make_goto(sc);
        push_stack(sc, OP_DEACTIVATE_GOTO, x, p); /* this means call-with-exit is not tail-recursive */
        push_stack(sc, OP_APPLY, cons_unchecked(sc, x, sc->nil), p);

        /* if the lambda body calls the argument as a function,
         *   it is applied to its arguments, apply notices that it is a goto, and...
         *
         *      (conceptually...) sc->stack_top = call_exit_goto_loc(sc->code);
         *      s_pop(sc, (is_not_null(sc->args)) ? car(sc->args) : sc->nil);
         *
         *   which jumps to the point of the goto returning car(args).
         *
         * There is one gotcha: we can't jump back in from outside, so if the caller saves the goto
         *   and tries to invoke it outside the call-with-exit block, we have to
         *   make sure it triggers an error.  So, if the escape is called, it then
         *   deactivates itself.  Otherwise the block returns, we pop to OP_DEACTIVATE_GOTO,
         *   and it finds the goto in sc->args.
         * Even worse:
         (let ((cc #f))
         (call-with-exit
         (lambda (c3)
         (call/cc (lambda (ret) (set! cc ret)))
         (c3)))
         (cc))
         * where we jump back into a call-with-exit body via call/cc, the goto has to be re-established.
         *
         * I think call-with-exit could be based on catch, but it's a simpler notion,
         *   and certainly at the source level it is easier to read.
         */
        return(sc->nil);
    }

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x8(%rsi), %r14
movzbl (%r14), %eax
leaq 0xcfd74(%rip), %rdx     # 0x14c330
cmpb $0x0, (%rax,%rdx)
je 0x7c6b9
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x7c5e5
movq %rbx, %rdi
callq 0xa550
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movq $0x26, (%rax)
movq 0x50(%rbx), %rcx
subq 0x48(%rbx), %rcx
sarq $0x3, %rcx
movq %rcx, 0x8(%rax)
movq 0x68(%rbx), %rcx
subq 0x60(%rbx), %rcx
shrq $0x3, %rcx
movslq %ecx, %rcx
movq %rcx, 0x10(%rax)
movb $0x1, 0x18(%rax)
movq 0x50(%rbx), %rcx
movq %r14, (%rcx)
movq 0x8(%rbx), %rcx
movq 0x50(%rbx), %rdx
movq %rcx, 0x8(%rdx)
movq 0x50(%rbx), %rcx
movq %rax, 0x10(%rcx)
movq 0x50(%rbx), %rcx
movq $0x204, 0x18(%rcx)      # imm = 0x204
movq 0x50(%rbx), %rcx
leaq 0x20(%rcx), %rdx
movq %rdx, 0x50(%rbx)
movq %r14, 0x20(%rcx)
movq 0x8(%rbx), %rcx
movq 0x50(%rbx), %rdx
movq %rcx, 0x8(%rdx)
movq 0x90(%rbx), %rcx
movq 0x110(%rbx), %rdx
leaq -0x8(%rcx), %rsi
movq %rsi, 0x90(%rbx)
movq -0x8(%rcx), %rcx
movq $0x200001, (%rcx)       # imm = 0x200001
movq %rax, 0x8(%rcx)
movq %rdx, 0x10(%rcx)
movq 0x50(%rbx), %rax
movq %rcx, 0x10(%rax)
movq 0x50(%rbx), %rax
movq $0x198, 0x18(%rax)      # imm = 0x198
addq $0x20, 0x50(%rbx)
movq 0x110(%rbx), %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movq %rsi, %rcx
movq 0xcf8(%rbx), %rdx
movq 0xd8f36(%rip), %r8      # 0x155600
movq %rbx, %rdi
movq %r14, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0xfa261