// File: /workspace/github_c_makefile_star2_O3/BernardTatin[P]s7sh/s7.c
// Function: g_assoc
static s7_pointer g_assoc(s7_scheme *sc, s7_pointer args)
                {
#define H_assoc "(assoc obj alist (func #f)) returns the key-value pair associated (via equal?) with the key obj in the association list alist.\
                    If 'func' is a function of 2 arguments, it is used for the comparison instead of 'equal?"
#define Q_assoc s7_make_signature(sc, 4, s7_make_signature(sc, 2, sc->is_pair_symbol, sc->is_boolean_symbol), sc->T, sc->is_list_symbol, sc->is_procedure_symbol)

                    s7_pointer x, y, obj, eq_func = NULL;

                    x = cadr(args);
                    if (!is_null(x))
                    {
                        if (!is_pair(x))
                            return(method_or_bust_with_type(sc, x, sc->assoc_symbol, args, an_association_list_string, 2));

                        if ((is_pair(x)) && (!is_pair(car(x))))
                            return(wrong_type_argument_with_type(sc, sc->assoc_symbol, 2, x, an_association_list_string)); /* we're assuming caar below so it better exist */
                    }

                    if (is_not_null(cddr(args)))
                    {
                        /* check third arg before second (trailing arg error check) */
                        eq_func = caddr(args);

                        if (type(eq_func) < T_CONTINUATION)
                            return(method_or_bust_with_type_one_arg(sc, eq_func, sc->assoc_symbol, args, a_procedure_string));

                        if (!s7_is_aritable(sc, eq_func, 2))
                            return(wrong_type_argument_with_type(sc, sc->assoc_symbol, 3, eq_func, an_eq_func_string));
                    }
                    if (is_null(x)) return(sc->F);

                    if (eq_func)
                    {
                        /* here we know x is a pair, but need to protect against circular lists */
                        if (s7_list_length(sc, x) != 0)
                        {
                            /* now maybe there's a simple case */
                            if ((is_safe_procedure(eq_func)) &&
                                    (is_c_function(eq_func)))
                            {
                                s7_function func;

                                func = c_function_call(eq_func);
                                if (func == g_is_eq) return(s7_assq(sc, car(args), x));
                                if (func == g_is_eqv) return(g_assv(sc, args));
                                set_car(sc->t2_1, car(args));

                                for (; is_pair(x); x = cdr(x))
                                {
                                    if (!is_pair(car(x)))
                                        return(wrong_type_argument_with_type(sc, sc->assoc_symbol, 2, cadr(args), an_association_list_string));
                                    set_car(sc->t2_2, caar(x));
                                    if (is_true(sc, func(sc, sc->t2_1)))
                                        return(car(x));
                                    /* I wonder if the assoc equality function should get the cons, not just caar? */
                                }
                                return(sc->F);
                            }

                            if ((is_closure(eq_func)) &&
                                    (is_pair(closure_args(eq_func))) &&
                                    (is_pair(cdr(closure_args(eq_func))))) /* not dotted arg list */
                            {
                                s7_pointer body;
                                body = closure_body(eq_func);
                                if (is_null(cdr(body)))
                                {
                                    s7_function func;

                                    new_frame_with_two_slots(sc, sc->envir, sc->envir, car(closure_args(eq_func)), car(args), cadr(closure_args(eq_func)), sc->F);
                                    func = s7_bool_optimize(sc, body);
                                    if (func)
                                    {
                                        s7_pointer b;
                                        b = next_slot(let_slots(sc->envir));

                                        if (func == opt_bool_any)
                                        {
                                            opt_info *o;
                                            o = sc->opts[0];
                                            for (; is_pair(x); x = cdr(x))
                                            {
                                                slot_set_value(b, caar(x));
                                                sc->pc = 0;
                                                if (o->v[0].fb(o))
                                                    return(car(x));
                                            }
                                            return(sc->F);
                                        }
                                    }
                                }
                            }
                        }

                        /* member_if is similar.  Do not call eval here with op_eval_done to return!  An error will longjmp past the
                         *   assoc point, leaving the op_eval_done on the stack, causing s7 to quit.
                         */
                        y = cons(sc, args, sc->nil);
                        set_opt1_fast(y, x);
                        set_opt2_slow(y, x);
                        push_stack(sc, OP_ASSOC_IF, cons(sc, y, sc->nil), eq_func);
                        if (needs_copied_args(eq_func))
                            push_stack(sc, OP_APPLY, list_2(sc, car(args), caar(x)), eq_func);
                        else
                        {
                            set_car(sc->t2_1, car(args));
                            set_car(sc->t2_2, caar(x));
                            push_stack(sc, OP_APPLY, sc->t2_1, eq_func);
                        }
                        return(sc->unspecified);
                    }

                    x = cadr(args);
                    obj = car(args);
                    if (is_simple(obj))
                        return(s7_assq(sc, obj, x));

                    y = x;
                    if (is_string(obj))
                    {
                        s7_pointer val;
                        while (true)
                        {
                            if (is_pair(car(x)))
                            {
                                val = caar(x);
                                if ((val == obj) ||
                                        ((is_string(val)) &&
                                         (scheme_strings_are_equal(obj, val))))
                                    return(car(x));
                            }
                            x = cdr(x);
                            if (!is_pair(x)) return(sc->F);

                            if (is_pair(car(x)))
                            {
                                val = caar(x);
                                if ((val == obj) ||
                                        ((is_string(val)) &&
                                         (scheme_strings_are_equal(obj, val))))
                                    return(car(x));
                            }
                            x = cdr(x);
                            if (!is_pair(x)) return(sc->F);

                            y = cdr(y);
                            if (x == y) return(sc->F);
                        }
                        return(sc->F);
                    }

                    while (true)
                    {
                        if ((is_pair(car(x))) && (s7_is_equal(sc, obj, caar(x)))) return(car(x));
                        x = cdr(x);
                        if (!is_pair(x)) return(sc->F);

                        if ((is_pair(car(x))) && (s7_is_equal(sc, obj, caar(x)))) return(car(x));
                        x = cdr(x);
                        if (!is_pair(x)) return(sc->F);

                        y = cdr(y);
                        if (x == y) return(sc->F);
                    }
                    return(sc->F); /* not reached */
                }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r15
movq %rdi, %rbx
movq 0x10(%rsi), %rax
movq 0x8(%rax), %r14
movq 0x110(%rdi), %rcx
cmpq %rcx, %r14
je 0x7546e
cmpb $0x1, (%r14)
jne 0x754b0
movq 0x8(%r14), %rdx
cmpb $0x1, (%rdx)
jne 0x755bd
movq 0x10(%rax), %rax
cmpq %rcx, %rax
jne 0x7547b
movq 0x8(%r15), %r15
movzbl (%r15), %eax
leaq 0xddc58(%rip), %rcx     # 0x1530a0
cmpb $0x1, (%rax,%rcx)
jne 0x7561e
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x39db6
movq 0x10(%rax), %rax
cmpq %rcx, %rax
je 0x75918
movq 0x8(%rax), %r12
cmpb $0x24, (%r12)
ja 0x754e0
movq 0xbf0(%rbx), %rdx
movq 0xe016c(%rip), %r8      # 0x155600
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rcx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xfa261
movq 0xbf0(%rbx), %rdx
movq 0xe0132(%rip), %r8      # 0x1555f0
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rcx
movl $0x2, %r9d
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe659
movl $0x2, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3f86f
testb %al, %al
je 0x755e5
movq 0x110(%rbx), %rbp
cmpq %rbp, %r14
je 0x75918
movq %rbx, %rdi
movq %r14, %rsi
callq 0x39d0d
testq %rax, %rax
je 0x756f9
movq (%r12), %rax
btl $0x15, %eax
setae %cl
cmpb $0x30, %al
setb %dl
orb %cl, %dl
jne 0x756d3
movq 0x10(%r12), %r12
leaq 0xa393(%rip), %rax      # 0x7f8d3
cmpq %rax, %r12
je 0x7592e
leaq 0xa3ad(%rip), %rax      # 0x7f8fd
cmpq %rax, %r12
je 0x75944
movq 0x8(%r15), %rax
movq 0x570(%rbx), %rcx
movq %rax, 0x8(%rcx)
cmpb $0x1, (%r14)
jne 0x75918
movq 0x8(%r14), %rax
cmpb $0x1, (%rax)
jne 0x75963
movq 0x8(%rax), %rax
movq 0x578(%rbx), %rcx
movq %rax, 0x8(%rcx)
movq 0x570(%rbx), %rsi
movq %rbx, %rdi
callq *%r12
movq %rax, %rcx
movq 0x120(%rbx), %rax
cmpq %rax, %rcx
jne 0x75993
movq 0x10(%r14), %r14
cmpb $0x1, (%r14)
je 0x75572
jmp 0x7591f
movq 0xbf0(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xd1391(%rip), %rdx     # 0x146960
movq 0x140(%rbx), %r8
movq 0xe0013(%rip), %r9      # 0x1555f0
movq %rbx, %rdi
movq %r14, %rcx
jmp 0x7560b
movq 0xbf0(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xd1371(%rip), %rdx     # 0x146968
movq 0x140(%rbx), %r8
movq 0xdffe3(%rip), %r9      # 0x1555e8
movq %rbx, %rdi
movq %r12, %rcx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa4e4
cmpb $0x13, %al
jne 0x758a9
movq %r14, %r12
movq 0x8(%r12), %rax
cmpb $0x1, (%rax)
jne 0x75664
movq 0x8(%rax), %rax
cmpq %r15, %rax
je 0x7593a
cmpb $0x13, (%rax)
jne 0x75664
movq 0x8(%r15), %rdx
cmpq 0x8(%rax), %rdx
jne 0x75664
movq 0x10(%r15), %rdi
movq 0x10(%rax), %rsi
callq 0x8c146
testb %al, %al
jne 0x7593a
movq 0x10(%r12), %r12
cmpb $0x1, (%r12)
jne 0x756c4
movq 0x8(%r12), %rax
cmpb $0x1, (%rax)
jne 0x756ab
movq 0x8(%rax), %rax
cmpq %r15, %rax
je 0x7593a
cmpb $0x13, (%rax)
jne 0x756ab
movq 0x8(%r15), %rdx
cmpq 0x8(%rax), %rdx
jne 0x756ab
movq 0x10(%r15), %rdi
movq 0x10(%rax), %rsi
callq 0x8c146
testb %al, %al
jne 0x7593a
movq 0x10(%r12), %r12
cmpb $0x1, (%r12)
jne 0x756c4
movq 0x10(%r14), %r14
cmpq %r14, %r12
jne 0x75629
addq $0x120, %rbx            # imm = 0x120
movq %rbx, %r12
jmp 0x7593e
cmpb $0x28, %al
jne 0x756f9
movq 0x8(%r12), %rax
cmpb $0x1, (%rax)
jne 0x756f9
movq 0x10(%rax), %rcx
cmpb $0x1, (%rcx)
jne 0x756f9
movq 0x10(%r12), %r13
cmpq %rbp, 0x10(%r13)
je 0x75999
movq 0x90(%rbx), %rax
movq 0x110(%rbx), %rbp
cmpq 0x98(%rbx), %rax
ja 0x7571f
movq %rbx, %rdi
callq 0xa550
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r13
movq $0x200001, (%r13)       # imm = 0x200001
movq %r15, 0x8(%r13)
movq %rbp, 0x10(%r13)
movq %r14, 0x18(%r13)
movq %r14, 0x20(%r13)
movq 0x50(%rbx), %rax
movq %r12, (%rax)
movq 0x8(%rbx), %rax
movq 0x50(%rbx), %rcx
movq %rax, 0x8(%rcx)
movq 0x90(%rbx), %rax
movq 0x110(%rbx), %rbp
cmpq 0x98(%rbx), %rax
ja 0x7577f
movq %rbx, %rdi
callq 0xa550
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movq $0x200001, (%rax)       # imm = 0x200001
movq %r13, 0x8(%rax)
movq %rbp, 0x10(%rax)
movq 0x50(%rbx), %rcx
movq %rax, 0x10(%rcx)
movq 0x50(%rbx), %rax
movq $0x211, 0x18(%rax)      # imm = 0x211
movq 0x50(%rbx), %rax
addq $0x20, %rax
movq %rax, 0x50(%rbx)
testb $0x10, 0x3(%r12)
jne 0x75806
movq 0x8(%r15), %rax
movq 0x570(%rbx), %rcx
movq %rax, 0x8(%rcx)
movq 0x8(%r14), %rax
movq 0x8(%rax), %rax
movq 0x578(%rbx), %rcx
movq %rax, 0x8(%rcx)
movq 0x50(%rbx), %rax
movq %r12, (%rax)
movq 0x8(%rbx), %rax
movq 0x50(%rbx), %rcx
movq %rax, 0x8(%rcx)
movq 0x570(%rbx), %rax
jmp 0x75887
movq %r12, (%rax)
movq 0x8(%rbx), %rax
movq 0x50(%rbx), %rcx
movq %rax, 0x8(%rcx)
movq 0x8(%r15), %r15
movq 0x8(%r14), %rax
movq 0x8(%rax), %r14
movq 0x90(%rbx), %rax
movq 0x110(%rbx), %r12
cmpq 0x98(%rbx), %rax
ja 0x75847
movq %rbx, %rdi
callq 0xa550
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rcx
movl $0x200001, %edx         # imm = 0x200001
movq %rdx, (%rcx)
movq %r14, 0x8(%rcx)
movq %r12, 0x10(%rcx)
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rsi
movq %rsi, 0x90(%rbx)
movq -0x8(%rax), %rax
movq %rdx, (%rax)
movq %r15, 0x8(%rax)
movq %rcx, 0x10(%rax)
movq 0x50(%rbx), %rcx
movq %rax, 0x10(%rcx)
movq 0x50(%rbx), %rax
movq $0x198, 0x18(%rax)      # imm = 0x198
addq $0x20, 0x50(%rbx)
movq 0x130(%rbx), %rax
jmp 0x7591f
leaq 0xdd470(%rip), %r12     # 0x152d20
movq %r14, %r13
movq 0x8(%r13), %rax
cmpb $0x1, (%rax)
jne 0x758d8
movq 0x8(%rax), %rdx
movzbl (%r15), %eax
movq %rbx, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq *(%r12,%rax,8)
testb %al, %al
jne 0x7595d
movq 0x10(%r13), %r13
cmpb $0x1, (%r13)
jne 0x75918
movq 0x8(%r13), %rax
cmpb $0x1, (%rax)
jne 0x75904
movq 0x8(%rax), %rdx
movzbl (%r15), %eax
movq %rbx, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq *(%r12,%rax,8)
testb %al, %al
jne 0x7595d
movq 0x10(%r13), %r13
cmpb $0x1, (%r13)
jne 0x75918
movq 0x10(%r14), %r14
cmpq %r14, %r13
jne 0x758b3
movq 0x120(%rbx), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%r15), %rsi
movq %rbx, %rdi
jmp 0x75458
addq $0x8, %r12
movq (%r12), %rax
jmp 0x7591f
movq %rbx, %rdi
movq %r15, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7529f
movq 0x8(%r13), %rax
jmp 0x7591f
movq 0xbf0(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xd0feb(%rip), %rdx     # 0x146960
movq 0x10(%r15), %rax
movq 0x8(%rax), %rcx
movq 0x140(%rbx), %r8
movq 0xdfc65(%rip), %r9      # 0x1555f0
movq %rbx, %rdi
jmp 0x7560b
movq 0x8(%r14), %rax
jmp 0x7591f
movq 0x8(%rax), %rbp
movq 0x8(%r15), %rsi
movq 0x8(%rcx), %rdi
movq 0x90(%rbx), %rax
movq 0x120(%rbx), %r8
cmpq 0x98(%rbx), %rax
ja 0x759e7
movq %rdi, 0x10(%rsp)
movq %rbx, %rdi
movq %r8, 0x8(%rsp)
movq %rsi, (%rsp)
callq 0xa550
movq (%rsp), %rsi
movq 0x8(%rsp), %r8
movq 0x10(%rsp), %rdi
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 0x8(%rbx), %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
movl $0x20, %edx
movq %rdx, (%rcx)
movq %rbp, 0x8(%rcx)
movq %rsi, 0x10(%rcx)
movq %rcx, 0x18(%rbp)
movq 0x250(%rbx), %rsi
movq %rsi, 0x20(%rbp)
incl 0x28(%rbp)
movq %rcx, 0x8(%rax)
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rsi
movq %rsi, 0x90(%rbx)
movq -0x8(%rax), %rax
movq %rdx, (%rax)
movq %rdi, 0x8(%rax)
movq %r8, 0x10(%rax)
movq %rax, 0x18(%rdi)
movq 0x250(%rbx), %rdx
movq %rdx, 0x20(%rdi)
incl 0x28(%rdi)
movq $0x0, 0x18(%rax)
movq %rax, 0x18(%rcx)
movq %rbx, %rdi
movq %r13, %rsi
callq 0xfdea3
testq %rax, %rax
je 0x756f9
leaq 0x88436(%rip), %rcx     # 0xfdeea
cmpq %rcx, %rax
jne 0x756f9
leaq 0x120(%rbx), %r12
cmpb $0x1, (%r14)
jne 0x7593e
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %r13
movq 0x2260(%rbx), %r15
movq 0x8(%r14), %rax
movq 0x8(%rax), %rax
movq %rax, 0x10(%r13)
movl $0x0, 0x2258(%rbx)
movq %r15, %rdi
callq *(%r15)
testb %al, %al
jne 0x75b10
movq 0x10(%r14), %r14
cmpb $0x1, (%r14)
je 0x75ae1
jmp 0x7593e
addq $0x8, %r14
movq %r14, %r12
jmp 0x7593e