// File: /workspace/github_c_makefile_star2_O2/BernardTatin[P]s7sh/s7.c
// Function: g_subvector
static s7_pointer g_subvector(s7_scheme *sc, s7_pointer args)
                {
#define H_subvector "(subvector original-vector new-dimensions (offset 0)) returns \
                    a vector that points to the same elements as the original-vector but with different dimensional info."
#define Q_subvector s7_make_signature(sc, 4, sc->is_subvector_symbol, sc->is_vector_symbol, s7_make_signature(sc, 2, sc->is_pair_symbol, sc->is_integer_symbol), sc->is_integer_symbol)

                    /* (let ((v1 #2d((1 2 3) (4 5 6)))) (let ((v2 (subvector v1 '(6)))) v2)) -> #(1 2 3 4 5 6)
                     * (let ((v1 #(1 2 3 4 5 6))) (let ((v2 (subvector v1 '(3 2)))) v2)) -> #2D((1 2) (3 4) (5 6))
                     */
                    s7_pointer orig, dims, x;
                    vdims_t *v;
                    s7_int new_len, orig_len, offset = 0;

                    orig = car(args);
                    if (!is_any_vector(orig))
                        return(method_or_bust(sc, orig, sc->subvector_symbol, args, T_VECTOR, 1));

                    orig_len = vector_length(orig);

                    if (!is_null(cddr(args)))
                    {
                        s7_pointer off;
                        off = caddr(args);
                        if (!s7_is_integer(off))
                            return(method_or_bust(sc, off, sc->subvector_symbol, args, T_INTEGER, 3));
                        offset = s7_integer(off);
                        if ((offset < 0) ||
                                (offset >= orig_len))  /* we need this if, for example, offset == 9223372036854775807 */
                            return(out_of_range(sc, sc->subvector_symbol, small_int(3), off, (offset < 0) ? its_negative_string : its_too_large_string));
                    }

                    dims = cadr(args);
                    if (is_t_integer(dims))
                    {
                        new_len = s7_integer(dims);
                        if ((new_len > orig_len) || (new_len > sc->max_vector_length)) /* (subvector (make-vector 3) most-positive-fixnum 1) ! */
                            return(out_of_range(sc, sc->subvector_symbol, small_int(2), dims, its_too_large_string));
                        if ((new_len < 0) ||
                                ((new_len + offset) > orig_len))
                            return(out_of_range(sc, sc->subvector_symbol, small_int(2), dims, (new_len < 0) ? its_negative_string : its_too_large_string));
                        v = NULL;
                    }
                    else
                    {
                        s7_pointer y;
                        s7_int i;
                        if ((is_null(dims)) ||
                                (!s7_is_proper_list(sc, dims)))
                            return(method_or_bust(sc, dims, sc->subvector_symbol, args, T_PAIR, 2));

                        for (y = dims; is_pair(y); y = cdr(y))
                            if ((!s7_is_integer(car(y)))        ||       /* (subvector v '((1 2) (3 4))) */
                                    (s7_integer(car(y)) > orig_len) ||
                                    (s7_integer(car(y)) < 0))
                                return(s7_error(sc, sc->wrong_type_arg_symbol,
                                            set_elist_1(sc, wrap_string(sc, "subvector: new dimensions should be a list of integers that fits the original vector", 84))));

                        v = list_to_dims(sc, dims);

                        new_len = vdims_dims(v)[0];
                        for (i = 1; i < vdims_rank(v); i++)
                            new_len *= vdims_dims(v)[i];
                        if ((new_len < 0) ||
                                ((new_len + offset) > vector_length(orig)))
                        {
                            liberate(sc, v);
                            return(out_of_range(sc, sc->subvector_symbol, small_int(2), dims,
                                        wrap_string(sc, "a subvector has to fit in the original vector", 45)));
                        }
                        vdims_original(v) = orig;
                    }

                    if (is_normal_vector(orig))
                        mark_function[T_VECTOR] = mark_vector_possibly_shared;
                    else mark_function[type(orig)] = mark_int_or_float_vector_possibly_shared; /* I think this works for byte-vectors also */

                    new_cell(sc, x, (typeflag(orig) & (~T_COLLECTED)) | T_SUBVECTOR | T_SAFE_PROCEDURE);

                    vector_block(x) = mallocate_vector(sc, 0);
                    vector_set_dimension_info(x, v);
                    if (!v) subvector_set_vector(x, orig);
                    vector_length(x) = new_len;                 /* might be less than original length */
                    if ((new_len == 0) && (is_normal_vector(orig))) set_has_simple_elements(x);
                    vector_getter(x) = vector_getter(orig);
                    vector_setter(x) = vector_setter(orig);

                    if (is_int_vector(orig))
                        int_vector_ints(x) = (s7_int *)(int_vector_ints(orig) + offset);
                    else
                    {
                        if (is_float_vector(orig))
                            float_vector_floats(x) = (s7_double *)(float_vector_floats(orig) + offset);
                        else
                        {
                            if (is_normal_vector(x))
                                vector_elements(x) = (s7_pointer *)(vector_elements(orig) + offset);
                            else byte_vector_bytes(x) = (uint8_t *)(byte_vector_bytes(orig) + offset);
                        }
                    }

                    add_multivector(sc, x);
                    return(x);
                }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r12
movq %rdi, %rbx
movq 0x8(%rsi), %r14
movzbl (%r14), %eax
leaq 0xb7097(%rip), %rcx     # 0x119c20
cmpb $0x0, (%rax,%rcx)
je 0x62bfb
movq 0x8(%r14), %r13
movq 0x10(%r12), %rsi
movq 0x10(%rsi), %rcx
movq 0x110(%rbx), %rdx
cmpq %rdx, %rcx
je 0x62c15
movq 0x8(%rcx), %rcx
cmpb $0xb, (%rcx)
jne 0x62c6d
movq 0x8(%rcx), %r9
testq %r9, %r9
setns %dil
cmpq %r13, %r9
setl %r8b
testb %r8b, %dil
jne 0x62c18
testq %r9, %r9
movq 0x1590(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xb2d87(%rip), %rdx     # 0x115968
leaq 0xb6e60(%rip), %rax     # 0x119a48
leaq 0xb6e51(%rip), %rdi     # 0x119a40
cmovsq %rax, %rdi
movq (%rdi), %r8
movq %rbx, %rdi
jmp 0x62c5a
movq 0x1590(%rbx), %rdx
pushq $0x15
popq %r8
pushq $0x1
popq %r9
movq %rbx, %rdi
movq %r14, %rsi
jmp 0x62cde
xorl %r9d, %r9d
movq 0x8(%rsi), %r15
movb (%r15), %bpl
cmpb $0xb, %bpl
jne 0x62c84
movq 0x8(%r15), %rbp
cmpq %r13, %rbp
jg 0x62c3b
cmpq 0x2a0(%rbx), %rbp
jle 0x62cf4
movq 0x1590(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xb2d13(%rip), %rdx     # 0x115960
movq 0xb6dec(%rip), %r8      # 0x119a40
movq %rbx, %rdi
movq %r15, %rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xcb8f
movq 0x1590(%rbx), %rdx
pushq $0xb
popq %r8
pushq $0x3
popq %r9
movq %rbx, %rdi
movq %rcx, %rsi
jmp 0x62cde
cmpq %rdx, %r15
je 0x62cc9
movq %rbx, %rdi
movq %r15, %rsi
movq %r9, (%rsp)
callq 0x2db34
testb %al, %al
je 0x62cc9
movq %r15, %rax
cmpb $0x1, %bpl
jne 0x62d92
movq 0x8(%rax), %rcx
cmpb $0xb, (%rcx)
jne 0x62d0a
movq 0x8(%rcx), %rcx
cmpq %r13, %rcx
jg 0x62d0a
testq %rcx, %rcx
js 0x62d0a
movq 0x10(%rax), %rax
movb (%rax), %bpl
jmp 0x62c9f
movq 0x1590(%rbx), %rdx
pushq $0x1
popq %r8
pushq $0x2
popq %r9
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xcd70
testq %rbp, %rbp
js 0x62d63
leaq (%r9,%rbp), %rcx
cmpq %r13, %rcx
jg 0x62d63
xorl %r12d, %r12d
jmp 0x62e2b
movq 0x1940(%rbx), %r15
movq 0x820(%rbx), %rax
movslq 0x7dc(%rbx), %rcx
movq (%rax,%rcx,8), %rax
incl %ecx
andl $0x7, %ecx
movl %ecx, 0x7dc(%rbx)
leaq 0x84ccf(%rip), %rcx     # 0xe7a04
movq %rcx, 0x10(%rax)
movq $0x54, 0x8(%rax)
movq 0x6d8(%rbx), %rcx
movq %rax, 0x8(%rcx)
movq 0x6d8(%rbx), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2cdc0
jmp 0x62f1d
testq %rbp, %rbp
movq 0x1590(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xb2be8(%rip), %rdx     # 0x115960
leaq 0xb6cc9(%rip), %rax     # 0x119a48
leaq 0xb6cba(%rip), %rcx     # 0x119a40
cmovsq %rax, %rcx
movq (%rcx), %r8
jmp 0x62c54
movq %rbx, %rdi
movq %r15, %rsi
callq 0x7b414
movq (%rsp), %r9
movq %rax, %r12
movq (%rax), %rax
movq 0x10(%r12), %rcx
movq (%rax), %rbp
pushq $0x1
popq %rdx
cmpq %rcx, %rdx
jge 0x62dc1
imulq (%rax,%rdx,8), %rbp
incq %rdx
jmp 0x62db2
testq %rbp, %rbp
js 0x62dd0
leaq (%r9,%rbp), %rax
cmpq 0x8(%r14), %rax
jle 0x62e23
movq %rbx, %rdi
movq %r12, %rsi
callq 0x9439
movq 0x1590(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xb2b73(%rip), %rdx     # 0x115960
movq 0x820(%rbx), %rax
movslq 0x7dc(%rbx), %rcx
movq (%rax,%rcx,8), %r8
leal 0x1(%rcx), %eax
andl $0x7, %eax
movl %eax, 0x7dc(%rbx)
leaq 0x84c47(%rip), %rax     # 0xe7a59
movq %rax, 0x10(%r8)
movq $0x2d, 0x8(%r8)
jmp 0x62c54
movq %r14, 0x20(%r12)
movb (%r14), %al
cmpb $0x15, %al
jne 0x62e3f
leaq 0x46a15(%rip), %rax     # 0xa984b
movq %rax, 0xb29db(%rip)     # 0x115818
jmp 0x62e54
movzbl %al, %eax
leaq 0xb2927(%rip), %rcx     # 0x115770
leaq 0x46a3e(%rip), %rdx     # 0xa988e
movq %rdx, (%rcx,%rax,8)
movq %r9, %r13
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x62e76
movq %rbx, %rdi
callq 0x9c27
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r15
movq $-0x20220001, %rax      # imm = 0xDFDDFFFF
andq (%r14), %rax
orq $0x20200000, %rax       # imm = 0x20200000
movq %rax, (%r15)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2e974
movq %rax, 0x18(%r15)
movq %r12, 0x20(%rax)
testq %r12, %r12
jne 0x62eb7
movq 0x18(%r15), %rax
movq %r14, 0x18(%rax)
movq %rbp, 0x8(%r15)
testq %rbp, %rbp
jne 0x62ecb
cmpb $0x15, (%r14)
jne 0x62ecb
orb $0x1, 0x7(%r15)
movq 0x20(%r14), %rax
movq %rax, 0x20(%r15)
movq 0x28(%r14), %rax
movq %rax, 0x28(%r15)
movzbl (%r14), %eax
cmpl $0x17, %eax
je 0x62ee9
cmpl $0x16, %eax
jne 0x62ef7
shlq $0x3, %r13
addq 0x10(%r14), %r13
movq %r13, 0x10(%r15)
jmp 0x62f0e
cmpb $0x15, (%r15)
movq 0x10(%r14), %rax
jne 0x62f07
leaq (%rax,%r13,8), %rax
jmp 0x62f0a
addq %r13, %rax
movq %rax, 0x10(%r15)
movq 0x790(%rbx), %rdi
movq %r15, %rsi
callq 0xb999
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq