// File: /workspace/github_c_makefile_star2_O0/BernardTatin[P]s7sh/s7.c
// Function: implicit_index
static s7_pointer implicit_index(s7_scheme *sc, s7_pointer obj, s7_pointer indices)
                {
                    s7_pointer res;
                    /* (let ((lst '("12" "34"))) (lst 0 1)) -> #\2
                     * (let ((lst (list #(1 2) #(3 4)))) (lst 0 1)) -> 2
                     *
                     * this can get tricky:
                     *   ((list (lambda (a) (+ a 1)) (lambda (b) (* b 2))) 1 2) -> 4
                     * but what if func takes rest/optional args, etc?
                     *   ((list (lambda args (car args))) 0 "hi" 0)
                     *   should this return #\h or "hi"?? currently it is "hi" which is consistent with ((lambda args (car args)) "hi" 0)
                     * but ((lambda (arg) arg) "hi" 0) is currently an error (too many arguments)
                     * maybe it should be (((lambda (arg) arg) "hi") 0) -> #\h
                     */

                    switch (type(obj))
                    {
                        case T_VECTOR:                       /* (#(#(1 2) #(3 4)) 1 1) -> 4 */
                            return(vector_ref_1(sc, obj, indices));

                        case T_FLOAT_VECTOR:
                            set_car(sc->u1_1, obj);
                            set_cdr(sc->u1_1, indices);
                            res = univect_ref(sc, sc->u1_1, sc->float_vector_ref_symbol, T_FLOAT_VECTOR);
                            set_car(sc->u1_1, sc->F);
                            return(res);

                        case T_INT_VECTOR:
                            set_car(sc->u1_1, obj);
                            set_cdr(sc->u1_1, indices);
                            res = univect_ref(sc, sc->u1_1, sc->int_vector_ref_symbol, T_INT_VECTOR);
                            set_car(sc->u1_1, sc->F);
                            return(res);

                        case T_BYTE_VECTOR:
                            set_car(sc->u1_1, obj);
                            set_cdr(sc->u1_1, indices);
                            res = univect_ref(sc, sc->u1_1, sc->byte_vector_ref_symbol, T_BYTE_VECTOR);
                            set_car(sc->u1_1, sc->F);
                            return(res);

                        case T_STRING:                       /* (#("12" "34") 0 1) -> #\2 */
                            if (is_null(cdr(indices)))
                            {
                                if (!is_t_integer(car(indices)))
                                    return(wrong_type_argument(sc, sc->string_ref_symbol, 2, car(indices), T_INTEGER));
                                return(string_ref_p_pi_direct(sc, obj, integer(car(indices))));
                            }
                            return(s7_error(sc, sc->wrong_number_of_args_symbol, set_elist_3(sc, too_many_arguments_string, obj, indices)));

                        case T_PAIR:                         /* (#((1 2) (3 4)) 1 0) -> 3, (#((1 (2 3))) 0 1 0) -> 2 */
                            obj = list_ref_1(sc, obj, car(indices));
                            if (is_pair(cdr(indices)))
                                return(implicit_index(sc, obj, cdr(indices)));
                            return(obj);

                        case T_HASH_TABLE:                   /* ((vector (hash-table '(a . 1) '(b . 2))) 0 'a) -> 1 */
                            obj = s7_hash_table_ref(sc, obj, car(indices));
                            if (is_pair(cdr(indices)))
                                return(implicit_index(sc, obj, cdr(indices)));
                            return(obj);

                        case T_C_OBJECT:
                            /* return((*(c_object_ref(sc, obj)))(sc, cons(sc, obj, indices))); */
                            set_car(sc->u1_1, obj);
                            set_cdr(sc->u1_1, indices);
                            res = (*(c_object_ref(sc, obj)))(sc, sc->u1_1);
                            set_car(sc->u1_1, sc->F);
                            return(res);

                        case T_LET:
                            obj = s7_let_ref(sc, obj, car(indices));
                            if (is_pair(cdr(indices)))
                                return(implicit_index(sc, obj, cdr(indices)));
                            return(obj);

                        case T_ITERATOR: /* indices is not nil, so this is an error */
                            return(s7_error(sc, sc->wrong_number_of_args_symbol, set_elist_3(sc, too_many_arguments_string, obj, indices)));

                        default:                             /* (#(a b c) 0 1) -> error, but ((list (lambda (x) x)) 0 "hi") -> "hi" */
                            if (is_applicable(obj))            /* (apply (list cons cons) (list 1 2)) needs the argnum check mentioned below */
                            {
                                if ((is_c_function(obj)) &&
                                        (is_safe_procedure(obj)))
                                {
                                    s7_int len;
                                    len = safe_list_length(indices);
                                    if ((c_function_required_args(obj) <= len) &&
                                            (c_function_all_args(obj) >= len))
                                        return(c_function_call(obj)(sc, indices));
                                }
                                push_stack(sc, OP_EVAL_DONE, sc->args, sc->code);
                                sc->code = obj;
                                sc->args = (needs_copied_args(obj)) ? copy_list(sc, indices) : indices;
                                eval(sc, OP_APPLY);
                                return(sc->value);
                                /* return(s7_apply_function(sc, obj, indices)); -- needs argnum check */ /* was g_apply 23-Jan-19 which assumes we're not in map */
                            }
                            return(s7_error(sc, sc->wrong_number_of_args_symbol, set_elist_3(sc, too_many_arguments_string, obj, indices)));
                    }
                }

// Assembly:
subq $0xa8, %rsp
movq %rdi, 0x98(%rsp)
movq %rsi, 0x90(%rsp)
movq %rdx, 0x88(%rsp)
movq 0x90(%rsp), %rax
movzbl (%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, 0x50(%rsp)
subl $0x1c, %eax
ja 0x16c317
movq 0x50(%rsp), %rax
leaq 0x74b30(%rip), %rcx     # 0x1e0798
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x98(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq 0x88(%rsp), %rdx
callq 0x16b410
movq %rax, 0xa0(%rsp)
jmp 0x16c527
movq 0x90(%rsp), %rcx
movq 0x98(%rsp), %rax
movq 0x560(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x88(%rsp), %rcx
movq 0x98(%rsp), %rax
movq 0x560(%rax), %rax
movq %rcx, 0x10(%rax)
movq 0x98(%rsp), %rdi
movq 0x98(%rsp), %rax
movq 0x560(%rax), %rsi
movq 0x98(%rsp), %rax
movq 0xef0(%rax), %rdx
movl $0x17, %ecx
callq 0x16c830
movq %rax, 0x80(%rsp)
movq 0x98(%rsp), %rax
movq 0x120(%rax), %rcx
movq 0x98(%rsp), %rax
movq 0x560(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x80(%rsp), %rax
movq %rax, 0xa0(%rsp)
jmp 0x16c527
movq 0x90(%rsp), %rcx
movq 0x98(%rsp), %rax
movq 0x560(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x88(%rsp), %rcx
movq 0x98(%rsp), %rax
movq 0x560(%rax), %rax
movq %rcx, 0x10(%rax)
movq 0x98(%rsp), %rdi
movq 0x98(%rsp), %rax
movq 0x560(%rax), %rsi
movq 0x98(%rsp), %rax
movq 0xfa8(%rax), %rdx
movl $0x16, %ecx
callq 0x16c830
movq %rax, 0x80(%rsp)
movq 0x98(%rsp), %rax
movq 0x120(%rax), %rcx
movq 0x98(%rsp), %rax
movq 0x560(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x80(%rsp), %rax
movq %rax, 0xa0(%rsp)
jmp 0x16c527
movq 0x90(%rsp), %rcx
movq 0x98(%rsp), %rax
movq 0x560(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x88(%rsp), %rcx
movq 0x98(%rsp), %rax
movq 0x560(%rax), %rax
movq %rcx, 0x10(%rax)
movq 0x98(%rsp), %rdi
movq 0x98(%rsp), %rax
movq 0x560(%rax), %rsi
movq 0x98(%rsp), %rax
movq 0xc30(%rax), %rdx
movl $0x18, %ecx
callq 0x16c830
movq %rax, 0x80(%rsp)
movq 0x98(%rsp), %rax
movq 0x120(%rax), %rcx
movq 0x98(%rsp), %rax
movq 0x560(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x80(%rsp), %rax
movq %rax, 0xa0(%rsp)
jmp 0x16c527
movq 0x88(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x98(%rsp), %rcx
cmpq 0x110(%rcx), %rax
jne 0x16c01e
movq 0x88(%rsp), %rax
movq 0x8(%rax), %rax
movzbl (%rax), %eax
cmpl $0xb, %eax
je 0x16bfec
movq 0x98(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x98(%rsp), %rax
movq 0x1548(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x48(%rsp)
movq $0x2, 0x78(%rsp)
movq 0x78(%rsp), %rax
andq $-0x800, %rax           # imm = 0xF800
cmpq $0x0, %rax
jne 0x16bf1c
movq 0x78(%rsp), %rcx
leaq 0xaa572(%rip), %rax     # 0x216480
movq (%rax,%rcx,8), %rax
movq %rax, 0x38(%rsp)
jmp 0x16bf9f
jmp 0x16bf1e
movq 0x98(%rsp), %rax
movq 0x90(%rax), %rax
movq 0x98(%rsp), %rcx
cmpq 0x98(%rcx), %rax
ja 0x16bf4b
movq 0x98(%rsp), %rdi
callq 0xc670
movq 0x98(%rsp), %rcx
movq 0x90(%rcx), %rax
movq %rax, %rdx
addq $-0x8, %rdx
movq %rdx, 0x90(%rcx)
movq -0x8(%rax), %rax
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rax
movq $0xb, (%rax)
movq 0x78(%rsp), %rcx
movq 0x68(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x68(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x48(%rsp), %rsi
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rdx
movq 0x88(%rsp), %rax
movq 0x8(%rax), %rcx
movq 0x98(%rsp), %rax
movq 0x140(%rax), %r8
movq 0xae60e(%rip), %r9      # 0x21a5e8
callq 0xc560
movq %rax, 0xa0(%rsp)
jmp 0x16c527
movq 0x98(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq 0x88(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdx
callq 0xaa470
movq %rax, 0xa0(%rsp)
jmp 0x16c527
movq 0x98(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x98(%rsp), %rax
movq 0x1900(%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x98(%rsp), %rdi
movq 0xb6b9a(%rip), %rsi     # 0x222be8
movq 0x90(%rsp), %rdx
movq 0x88(%rsp), %rcx
callq 0xf240
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq %rax, %rdx
callq 0x2f940
movq %rax, 0xa0(%rsp)
jmp 0x16c527
movq 0x98(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq 0x88(%rsp), %rax
movq 0x8(%rax), %rdx
callq 0x16cf70
movq %rax, 0x90(%rsp)
movq 0x88(%rsp), %rax
movq 0x10(%rax), %rax
movzbl (%rax), %eax
cmpl $0x1, %eax
jne 0x16c0ed
movq 0x98(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq 0x88(%rsp), %rax
movq 0x10(%rax), %rdx
callq 0x16bc20
movq %rax, 0xa0(%rsp)
jmp 0x16c527
movq 0x90(%rsp), %rax
movq %rax, 0xa0(%rsp)
jmp 0x16c527
movq 0x98(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq 0x88(%rsp), %rax
movq 0x8(%rax), %rdx
callq 0x2a770
movq %rax, 0x90(%rsp)
movq 0x88(%rsp), %rax
movq 0x10(%rax), %rax
movzbl (%rax), %eax
cmpl $0x1, %eax
jne 0x16c16d
movq 0x98(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq 0x88(%rsp), %rax
movq 0x10(%rax), %rdx
callq 0x16bc20
movq %rax, 0xa0(%rsp)
jmp 0x16c527
movq 0x90(%rsp), %rax
movq %rax, 0xa0(%rsp)
jmp 0x16c527
movq 0x90(%rsp), %rcx
movq 0x98(%rsp), %rax
movq 0x560(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x88(%rsp), %rcx
movq 0x98(%rsp), %rax
movq 0x560(%rax), %rax
movq %rcx, 0x10(%rax)
movq 0x98(%rsp), %rax
movq 0x8d8(%rax), %rax
movq 0x90(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq 0x48(%rax), %rax
movq 0x98(%rsp), %rdi
movq 0x98(%rsp), %rcx
movq 0x560(%rcx), %rsi
callq *%rax
movq %rax, 0x80(%rsp)
movq 0x98(%rsp), %rax
movq 0x120(%rax), %rcx
movq 0x98(%rsp), %rax
movq 0x560(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x80(%rsp), %rax
movq %rax, 0xa0(%rsp)
jmp 0x16c527
movq 0x98(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq 0x88(%rsp), %rax
movq 0x8(%rax), %rdx
callq 0xe490
movq %rax, 0x90(%rsp)
movq 0x88(%rsp), %rax
movq 0x10(%rax), %rax
movzbl (%rax), %eax
cmpl $0x1, %eax
jne 0x16c29e
movq 0x98(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq 0x88(%rsp), %rax
movq 0x10(%rax), %rdx
callq 0x16bc20
movq %rax, 0xa0(%rsp)
jmp 0x16c527
movq 0x90(%rsp), %rax
movq %rax, 0xa0(%rsp)
jmp 0x16c527
movq 0x98(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x98(%rsp), %rax
movq 0x1900(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x98(%rsp), %rdi
movq 0xb6905(%rip), %rsi     # 0x222be8
movq 0x90(%rsp), %rdx
movq 0x88(%rsp), %rcx
callq 0xf240
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq %rax, %rdx
callq 0x2f940
movq %rax, 0xa0(%rsp)
jmp 0x16c527
movq 0x90(%rsp), %rax
movzbl (%rax), %eax
movl %eax, %ecx
leaq 0xb8bd5(%rip), %rax     # 0x224f00
testb $0x1, (%rax,%rcx)
je 0x16c4ca
movq 0x90(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x30, %eax
jl 0x16c3c1
movq 0x90(%rsp), %rax
movq (%rax), %rax
andq $0x200000, %rax         # imm = 0x200000
cmpq $0x0, %rax
je 0x16c3c1
movq 0x88(%rsp), %rdi
callq 0x3a070
movq %rax, 0x58(%rsp)
movq 0x90(%rsp), %rax
movq 0x18(%rax), %rax
cmpq 0x58(%rsp), %rax
jg 0x16c3bf
movq 0x90(%rsp), %rax
movq 0x28(%rax), %rax
cmpq 0x58(%rsp), %rax
jl 0x16c3bf
movq 0x90(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x98(%rsp), %rdi
movq 0x88(%rsp), %rsi
callq *%rax
movq %rax, 0xa0(%rsp)
jmp 0x16c527
jmp 0x16c3c1
jmp 0x16c3c3
movq 0x98(%rsp), %rax
movq (%rax), %rcx
movq 0x98(%rsp), %rax
movq 0x50(%rax), %rax
movq %rcx, (%rax)
movq 0x98(%rsp), %rax
movq 0x8(%rax), %rcx
movq 0x98(%rsp), %rax
movq 0x50(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x98(%rsp), %rax
movq 0x10(%rax), %rcx
movq 0x98(%rsp), %rax
movq 0x50(%rax), %rax
movq %rcx, 0x10(%rax)
movq 0x98(%rsp), %rax
movq 0x50(%rax), %rax
movl $0x1df, %ecx            # imm = 0x1DF
movq %rcx, 0x18(%rax)
movq 0x98(%rsp), %rax
movq 0x50(%rax), %rcx
addq $0x20, %rcx
movq %rcx, 0x50(%rax)
movq 0x90(%rsp), %rcx
movq 0x98(%rsp), %rax
movq %rcx, (%rax)
movq 0x90(%rsp), %rax
movq (%rax), %rax
andq $0x10000000, %rax       # imm = 0x10000000
cmpq $0x0, %rax
je 0x16c484
movq 0x98(%rsp), %rdi
movq 0x88(%rsp), %rsi
callq 0x44270
movq %rax, 0x10(%rsp)
jmp 0x16c491
movq 0x88(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rcx
movq 0x98(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x98(%rsp), %rdi
movl $0x198, %esi            # imm = 0x198
callq 0x163d0
movq 0x98(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0xa0(%rsp)
jmp 0x16c527
movq 0x98(%rsp), %rax
movq %rax, (%rsp)
movq 0x98(%rsp), %rax
movq 0x1900(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x98(%rsp), %rdi
movq 0xb66ef(%rip), %rsi     # 0x222be8
movq 0x90(%rsp), %rdx
movq 0x88(%rsp), %rcx
callq 0xf240
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rax, %rdx
callq 0x2f940
movq %rax, 0xa0(%rsp)
movq 0xa0(%rsp), %rax
addq $0xa8, %rsp
retq
nopw (%rax,%rax)