// File: /workspace/github_c_makefile_star2_O1/BernardTatin[P]s7sh/s7.c
// Function: g_catch
static s7_pointer g_catch(s7_scheme *sc, s7_pointer args)
                {
#define H_catch "(catch tag thunk handler) evaluates thunk; if an error occurs that matches the tag (#t matches all), the handler is called"
#define Q_catch s7_make_signature(sc, 4, sc->values_symbol, s7_make_signature(sc, 2, sc->is_symbol_symbol, sc->is_boolean_symbol), sc->is_procedure_symbol, sc->is_procedure_symbol)

                    s7_pointer p, proc, err;

                    /* Guile sets up the catch before looking for arg errors:
                     *   (catch #t log (lambda args "hiho")) -> "hiho"
                     * which is consistent in that (catch #t (lambda () (log))...) should probably be the same as (catch #t log ...)
                     * but what if the error handler arg is messed up?  Seems weird to handle args in reverse order with an intervening frame etc.
                     */

                    proc = cadr(args);
                    err = caddr(args);
                    /* if (is_let(err)) check_method(sc, err, sc->catch_symbol, args); */ /* causes exit from s7! */

                    new_cell(sc, p, T_CATCH);
                    catch_tag(p) = car(args);
                    catch_goto_loc(p) = s7_stack_top(sc);
                    catch_op_loc(p) = (int32_t)(sc->op_stack_now - sc->op_stack);
                    catch_set_handler(p, err);

                    if (is_any_macro(err))
                        push_stack(sc, OP_CATCH_2, args, p);
                    else push_stack(sc, OP_CATCH, args, p);      /* args ignored but maybe safer for GC? */

                    /* not sure about these error checks -- they can be omitted */
                    if (!is_thunk(sc, proc))
                        return(wrong_type_argument_with_type(sc, sc->catch_symbol, 2, proc, a_thunk_string));

                    if (!is_applicable(err))
                        return(wrong_type_argument_with_type(sc, sc->catch_symbol, 3, err, something_applicable_string));

                    /* should we check here for (aritable? err 2)?
                     *  (catch #t (lambda () 1) "hiho") -> 1
                     * currently this is checked only if the error handler is called
                     */

                    if (is_closure(proc))                        /* not also lambda* here because we need to handle the arg defaults */
                    {
                        /* is_thunk above checks is_aritable(proc, 0), but if it's (lambda args ...) we have to set up the frame with args=()
                         *    the case that caught this: (catch #t make-hook ...)
                         */
                        sc->code = closure_body(proc);
                        if (is_symbol(closure_args(proc)))
                            new_frame_with_slot(sc, closure_let(proc), sc->envir, closure_args(proc), sc->nil);
                        else new_frame(sc, closure_let(proc), sc->envir);
                        push_stack_no_args(sc, sc->begin_op, T_Pair(sc->code));
                    }
                    else push_stack(sc, OP_APPLY, sc->nil, proc);

                    return(sc->F);
                }

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r12
movq %rdi, %rbx
movq 0x10(%rsi), %rax
movq 0x8(%rax), %r14
movq 0x10(%rax), %rax
movq 0x8(%rax), %r15
movq 0x90(%rdi), %rax
cmpq 0x98(%rdi), %rax
ja 0x846b4
movq %rbx, %rdi
callq 0xb389
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movq $0x19, (%rax)
movq 0x8(%r12), %rcx
movq %rcx, 0x18(%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)
movq %r15, 0x20(%rax)
movzbl (%r15), %ecx
leaq 0xcfc64(%rip), %rdx     # 0x154370
cmpb $0x0, (%rcx,%rdx)
movq 0x50(%rbx), %rcx
movq %rax, (%rcx)
movq 0x8(%rbx), %rax
movq 0x50(%rbx), %rcx
movq %rax, 0x8(%rcx)
movq 0x50(%rbx), %rax
movq %r12, 0x10(%rax)
movq 0x50(%rbx), %rax
movl $0x217, %ecx            # imm = 0x217
movl $0x1e0, %edx            # imm = 0x1E0
cmovneq %rcx, %rdx
movq %rdx, 0x18(%rax)
addq $0x20, 0x50(%rbx)
cmpb $0x26, (%r14)
jb 0x8483f
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x41fac
testb %al, %al
je 0x8483f
movzbl (%r15), %eax
leaq 0xd8c40(%rip), %rcx     # 0x15d3b0
cmpb $0x0, (%rax,%rcx)
je 0x84875
cmpb $0x28, (%r14)
jne 0x8489d
movq 0x10(%r14), %rax
movq %rax, (%rbx)
movq 0x8(%r14), %r15
cmpb $0xa, (%r15)
jne 0x848c6
movq 0x90(%rbx), %rax
movq 0x110(%rbx), %r12
cmpq 0x98(%rbx), %rax
ja 0x847b8
movq %rbx, %rdi
callq 0xb389
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movq $0x20001c, (%rax)       # imm = 0x20001C
movq 0x250(%rbx), %rcx
incq %rcx
movq %rcx, 0x250(%rbx)
movq %rcx, 0x18(%rax)
movq 0x18(%r14), %rcx
movq %rcx, 0x10(%rax)
movq %rax, 0x8(%rbx)
movq 0x90(%rbx), %rcx
leaq -0x8(%rcx), %rdx
movq %rdx, 0x90(%rbx)
movq -0x8(%rcx), %rcx
movq $0x20, (%rcx)
movq %r15, 0x8(%rcx)
movq %r12, 0x10(%rcx)
movq %rcx, 0x18(%r15)
movq 0x250(%rbx), %rdx
movq %rdx, 0x20(%r15)
incl 0x28(%r15)
movq $0x0, 0x18(%rcx)
movq %rcx, 0x8(%rax)
jmp 0x84924
movq 0xd28(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xca10f(%rip), %rdx     # 0x14e960
movq 0x140(%rbx), %r8
movq 0xd5ad1(%rip), %r9      # 0x15a330
movq %rbx, %rdi
movq %r14, %rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xb31d
movq 0xd28(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xca0e1(%rip), %rdx     # 0x14e968
movq 0x140(%rbx), %r8
movq 0xd8d8b(%rip), %r9      # 0x15d620
movq %rbx, %rdi
movq %r15, %rcx
jmp 0x84865
movq 0x50(%rbx), %rax
movq %r14, (%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)
movl $0x198, %eax            # imm = 0x198
jmp 0x84941
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x848de
movq %rbx, %rdi
callq 0xb389
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movq $0x20001c, (%rax)       # imm = 0x20001C
movq 0x250(%rbx), %rcx
incq %rcx
movq %rcx, 0x250(%rbx)
movq %rcx, 0x18(%rax)
movq $0x0, 0x8(%rax)
movq 0x18(%r14), %rcx
movq %rcx, 0x10(%rax)
movq %rax, 0x8(%rbx)
movq (%rbx), %rax
movq 0x50(%rbx), %rcx
movq %rax, (%rcx)
movq 0x8(%rbx), %rax
movq 0x50(%rbx), %rcx
movq %rax, 0x8(%rcx)
movq 0x688(%rbx), %rax
movq 0x50(%rbx), %rcx
movq %rax, 0x18(%rcx)
addq $0x20, 0x50(%rbx)
movq 0x120(%rbx), %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq