// File: /workspace/github_c_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rsi, %rax
movq %rdi, %rbx
leaq 0x32ed0(%rip), %r15     # 0x1089f4
movzbl (%rax), %ecx
leal -0x13(%rcx), %edx
cmpl $0xa, %edx
ja 0xd5b4b
movslq (%r15,%rdx,4), %rdx
addq %r15, %rdx
jmpq *%rdx
movq 0x8(%r14), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq *0x18(%rax)
movq 0x20(%rax), %rax
jmp 0xd5b70
cmpl $0x1, %ecx
jne 0xd5b7f
movq 0x8(%r14), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0xd64d1
jmp 0xd5b70
movq 0x8(%r14), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0xb54b
movq 0x10(%r14), %r14
cmpb $0x1, (%r14)
je 0xd5b24
jmp 0xd5d05
leaq 0x7f82a(%rip), %rdx     # 0x1553b0
cmpb $0x1, (%rcx,%rdx)
jne 0xd5c01
cmpb $0x30, %cl
jb 0xd5d82
testb $0x20, 0x2(%rax)
je 0xd5d82
cmpb $0x1, (%r14)
jne 0xd5d70
xorl %ecx, %ecx
movq %r14, %rdx
incq %rcx
movq 0x10(%rdx), %rdx
cmpb $0x1, (%rdx)
je 0xd5bae
jmp 0xd5d72
movq 0x560(%rbx), %rcx
movq %rax, 0x8(%rcx)
movq 0x560(%rbx), %rax
movq %r14, 0x10(%rax)
movq 0x560(%rbx), %rsi
movq 0xc30(%rbx), %rdx
movq %rbx, %rdi
movl $0x18, %ecx
jmp 0xd5cee
movq 0x10(%r14), %rcx
cmpq 0x110(%rbx), %rcx
je 0xd5d14
movq 0x1900(%rbx), %r15
movq 0x7d489(%rip), %rcx     # 0x153098
movq 0x6e8(%rbx), %rdx
movq %rcx, 0x8(%rdx)
movq 0x10(%rdx), %rcx
movq %rax, 0x8(%rcx)
movq 0x10(%rcx), %rax
movq %r14, 0x8(%rax)
movq 0x6e8(%rbx), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x38dfa
movq %r15, %rax
jmp 0xd5d05
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd5793
movq 0x560(%rbx), %rcx
movq %rax, 0x8(%rcx)
movq 0x560(%rbx), %rcx
movq %r14, 0x10(%rcx)
movq 0x8d8(%rbx), %rcx
movq 0x8(%rax), %rax
movq (%rcx,%rax,8), %rax
movq 0x560(%rbx), %rsi
movq %rbx, %rdi
callq *0x48(%rax)
jmp 0xd5cf3
movq 0x560(%rbx), %rcx
movq %rax, 0x8(%rcx)
movq 0x560(%rbx), %rax
movq %r14, 0x10(%rax)
movq 0x560(%rbx), %rsi
movq 0xfa8(%rbx), %rdx
movq %rbx, %rdi
movl $0x16, %ecx
jmp 0xd5cee
movq 0x560(%rbx), %rcx
movq %rax, 0x8(%rcx)
movq 0x560(%rbx), %rax
movq %r14, 0x10(%rax)
movq 0x560(%rbx), %rsi
movq 0xef0(%rbx), %rdx
movq %rbx, %rdi
movl $0x17, %ecx
callq 0xd6155
movq 0x120(%rbx), %rcx
movq 0x560(%rbx), %rdx
movq %rcx, 0x8(%rdx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%r14), %rcx
cmpb $0xb, (%rcx)
jne 0xd5d3a
movq 0x8(%rcx), %rdx
movq %rbx, %rdi
movq %rax, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x82ada
movq 0x1548(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0x70c14(%rip), %rdx     # 0x146960
movq 0x140(%rbx), %r8
movq 0x74d5e(%rip), %r9      # 0x14aab8
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa4e4
xorl %ecx, %ecx
cmpq %rcx, 0x18(%rax)
jg 0xd5d82
cmpq %rcx, 0x28(%rax)
jge 0xd5ec5
movq (%rbx), %rcx
movq 0x50(%rbx), %rdx
movq %rcx, (%rdx)
movq 0x8(%rbx), %rcx
movq 0x50(%rbx), %rdx
movq %rcx, 0x8(%rdx)
movq 0x10(%rbx), %rcx
movq 0x50(%rbx), %rdx
movq %rcx, 0x10(%rdx)
movq 0x50(%rbx), %rcx
movq $0x1df, 0x18(%rcx)      # imm = 0x1DF
addq $0x20, 0x50(%rbx)
movq %rax, (%rbx)
testb $0x10, 0x3(%rax)
jne 0xd5dc6
movq %r14, %r15
jmp 0xd5eab
cmpb $0x1, (%r14)
jne 0xd5ea4
movq %r14, 0x4c8(%rbx)
movq 0x8(%r14), %r12
movq 0x90(%rbx), %rax
movq 0x110(%rbx), %r13
cmpq 0x98(%rbx), %rax
ja 0xd5e01
movq %rbx, %rdi
callq 0xa550
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r15
movq $0x200001, (%r15)       # imm = 0x200001
movq %r12, 0x8(%r15)
movq %r13, 0x10(%r15)
movq %r15, 0x4e8(%rbx)
movq 0x10(%r14), %r14
cmpb $0x1, (%r14)
jne 0xd5e8d
movq %r15, %r12
movq 0x8(%r14), %r13
movq 0x90(%rbx), %rax
movq 0x110(%rbx), %rbp
cmpq 0x98(%rbx), %rax
ja 0xd5e5d
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 %rax, 0x10(%r12)
movq 0x10(%r14), %r14
cmpb $0x1, (%r14)
movq %rax, %r12
je 0xd5e33
movq 0x110(%rbx), %rax
movq %rax, 0x4e8(%rbx)
movq %rax, 0x4c8(%rbx)
jmp 0xd5eab
movq 0x110(%rbx), %r15
movq %r15, 0x10(%rbx)
movl $0x198, %esi            # imm = 0x198
movq %rbx, %rdi
callq 0xfd85
movq 0x20(%rbx), %rax
jmp 0xd5d05
movq 0x10(%rax), %rax
movq %rbx, %rdi
movq %r14, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *%rax