// File: /workspace/github_c_makefile_star2_O2/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 0x5ec3c
cmpb $0x1, (%r14)
jne 0x5ec7e
movq 0x8(%r14), %rdx
cmpb $0x1, (%rdx)
jne 0x5ed78
movq 0x10(%rax), %rax
cmpq %rcx, %rax
jne 0x5ec49
movq 0x8(%r15), %r15
movzbl (%r15), %eax
leaq 0xc348a(%rip), %rcx     # 0x1220a0
cmpb $0x1, (%rax,%rcx)
jne 0x5edd9
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 0x2db7b
movq 0x10(%rax), %rax
cmpq %rcx, %rax
je 0x5f1d3
movq 0x8(%rax), %r12
cmpb $0x24, (%r12)
ja 0x5ecac
movq 0xbf0(%rbx), %rdx
movq 0xc599e(%rip), %r8      # 0x124600
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 0xc736d
movq 0xbf0(%rbx), %rdx
movq 0xc5964(%rip), %r8      # 0x1245f0
pushq $0x2
popq %r9
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rcx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xcf9a
pushq $0x2
popq %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x32378
testb %al, %al
je 0x5eda0
movq 0x110(%rbx), %rbp
cmpq %rbp, %r14
je 0x5f1d3
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2dada
testq %rax, %rax
je 0x5efb4
movq (%r12), %rax
btl $0x15, %eax
setae %cl
cmpb $0x30, %al
setb %dl
orb %cl, %dl
jne 0x5ee6c
movq 0x10(%r12), %r12
leaq 0x7ad5(%rip), %rax      # 0x667df
cmpq %rax, %r12
je 0x5f1e9
leaq 0x7aef(%rip), %rax      # 0x66809
cmpq %rax, %r12
je 0x5f1ff
movq 0x8(%r15), %rax
movq 0x570(%rbx), %rcx
movq %rax, 0x8(%rcx)
cmpb $0x1, (%r14)
jne 0x5f1d3
movq 0x8(%r14), %rax
cmpb $0x1, (%rax)
jne 0x5f21e
movq 0x8(%rax), %rax
movq 0x578(%rbx), %rcx
movq %rax, 0x8(%rcx)
movq 0x570(%rbx), %rsi
movq %rbx, %rdi
callq *%r12
cmpq 0x120(%rbx), %rax
jne 0x5f24e
movq 0x10(%r14), %r14
jmp 0x5ed32
movq 0xbf0(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xb6bd6(%rip), %rdx     # 0x115960
movq 0x140(%rbx), %r8
movq 0xc5858(%rip), %r9      # 0x1245f0
movq %rbx, %rdi
movq %r14, %rcx
jmp 0x5edc6
movq 0xbf0(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xb6bb6(%rip), %rdx     # 0x115968
movq 0x140(%rbx), %r8
movq 0xc5828(%rip), %r9      # 0x1245e8
movq %rbx, %rdi
movq %r12, %rcx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9bbb
cmpb $0x13, %al
jne 0x5f164
movq %r14, %r12
movq 0x8(%r12), %rax
cmpb $0x1, (%rax)
jne 0x5ee10
movq 0x8(%rax), %rsi
cmpq %r15, %rsi
je 0x5f1f5
cmpb $0x13, (%rsi)
jne 0x5ee10
movq %r15, %rdi
callq 0xc57a7
testb %al, %al
jne 0x5f1f5
movq 0x10(%r12), %r12
cmpb $0x1, (%r12)
jne 0x5ee5d
movq 0x8(%r12), %rax
cmpb $0x1, (%rax)
jne 0x5ee48
movq 0x8(%rax), %rsi
cmpq %r15, %rsi
je 0x5f1f5
cmpb $0x13, (%rsi)
jne 0x5ee48
movq %r15, %rdi
callq 0xc57a7
testb %al, %al
jne 0x5f1f5
movq 0x10(%r12), %r12
cmpb $0x1, (%r12)
jne 0x5ee5d
movq 0x10(%r14), %r14
cmpq %r14, %r12
jne 0x5ede4
addq $0x120, %rbx            # imm = 0x120
movq %rbx, %r12
jmp 0x5f1f9
cmpb $0x28, %al
jne 0x5efb4
movq 0x8(%r12), %rax
cmpb $0x1, (%rax)
jne 0x5efb4
movq 0x10(%rax), %rcx
cmpb $0x1, (%rcx)
jne 0x5efb4
movq 0x10(%r12), %r13
cmpq %rbp, 0x10(%r13)
jne 0x5efb4
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 0x5eeec
movq %rdi, 0x10(%rsp)
movq %rbx, %rdi
movq %r8, 0x8(%rsp)
movq %rsi, (%rsp)
callq 0x9c27
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
pushq $0x20
popq %rdx
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)
andq $0x0, 0x18(%rax)
movq %rax, 0x18(%rcx)
movq %rbx, %rdi
movq %r13, %rsi
callq 0xcac0c
leaq 0x6bca5(%rip), %rcx     # 0xcac50
cmpq %rcx, %rax
je 0x5f254
movq 0x90(%rbx), %rax
movq 0x110(%rbx), %rbp
cmpq 0x98(%rbx), %rax
ja 0x5efda
movq %rbx, %rdi
callq 0x9c27
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 0x5f03a
movq %rbx, %rdi
callq 0x9c27
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 0x5f0c1
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 0x5f142
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 0x5f102
movq %rbx, %rdi
callq 0x9c27
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 0x5f1da
leaq 0xc2bb5(%rip), %r12     # 0x121d20
movq %r14, %r13
movq 0x8(%r13), %rax
cmpb $0x1, (%rax)
jne 0x5f193
movq 0x8(%rax), %rdx
movzbl (%r15), %eax
movq %rbx, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq *(%r12,%rax,8)
testb %al, %al
jne 0x5f218
movq 0x10(%r13), %r13
cmpb $0x1, (%r13)
jne 0x5f1d3
movq 0x8(%r13), %rax
cmpb $0x1, (%rax)
jne 0x5f1bf
movq 0x8(%rax), %rdx
movzbl (%r15), %eax
movq %rbx, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq *(%r12,%rax,8)
testb %al, %al
jne 0x5f218
movq 0x10(%r13), %r13
cmpb $0x1, (%r13)
jne 0x5f1d3
movq 0x10(%r14), %r14
cmpq %r14, %r13
jne 0x5f16e
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 0x5ec26
addq $0x8, %r12
movq (%r12), %rax
jmp 0x5f1da
movq %rbx, %rdi
movq %r15, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5ea6f
movq 0x8(%r13), %rax
jmp 0x5f1da
movq 0xbf0(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xb6730(%rip), %rdx     # 0x115960
movq 0x10(%r15), %rax
movq 0x8(%rax), %rcx
movq 0x140(%rbx), %r8
movq 0xc53aa(%rip), %r9      # 0x1245f0
movq %rbx, %rdi
jmp 0x5edc6
movq 0x8(%r14), %rax
jmp 0x5f1da
leaq 0x120(%rbx), %r12
movq 0x8(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %r13
movq 0x2260(%rbx), %r15
cmpb $0x1, (%r14)
jne 0x5f1f9
movq 0x8(%r14), %rax
movq 0x8(%rax), %rax
movq %rax, 0x10(%r13)
andl $0x0, 0x2258(%rbx)
movq %r15, %rdi
callq *(%r15)
testb %al, %al
jne 0x5f297
movq 0x10(%r14), %r14
jmp 0x5f26e
addq $0x8, %r14
movq %r14, %r12
jmp 0x5f1f9