// File: /workspace/github_c_makefile_star2_O1/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 0xd28b8(%rip), %rcx     # 0x152c20
cmpb $0x0, (%rax,%rcx)
je 0x803a8
movq 0x8(%r14), %rbp
movq 0x10(%r12), %rax
movq 0x10(%rax), %rax
cmpq 0x110(%rbx), %rax
je 0x803d7
movq 0x8(%rax), %rsi
cmpb $0xb, (%rsi)
jne 0x803df
movq 0x8(%rsi), %r13
testq %r13, %r13
setns %al
cmpq %rbp, %r13
setl %cl
testb %cl, %al
je 0x80405
movb $0x1, %al
jmp 0x80471
movq 0x1590(%rbx), %rdx
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rcx
movl $0x15, %r8d
movl $0x1, %r9d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xf1ae
xorl %r13d, %r13d
jmp 0x80479
movq 0x1590(%rbx), %rdx
movq %rbx, %rdi
movq %r12, %rcx
movl $0xb, %r8d
movl $0x3, %r9d
callq 0xf1ae
movq %rax, %r15
xorl %r13d, %r13d
jmp 0x8046f
testq %r13, %r13
movq 0x1590(%rbx), %rax
movq 0x8(%rax), %rax
movq 0xce54e(%rip), %rcx     # 0x14e968
leaq 0xd2627(%rip), %rdx     # 0x152a48
leaq 0xd2618(%rip), %rdi     # 0x152a40
cmovsq %rdx, %rdi
movq (%rdi), %rdx
movq 0x1ee8(%rbx), %rdi
movq 0x10(%rdi), %rdi
movq %rax, 0x8(%rdi)
movq 0x10(%rdi), %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rax), %rax
movq %rsi, 0x8(%rax)
movq 0x10(%rax), %rax
movq %rdx, 0x8(%rax)
movq 0x1948(%rbx), %r15
movq 0x1ee8(%rbx), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3b366
xorl %eax, %eax
testb %al, %al
je 0x80858
movq %r13, (%rsp)
movq 0x10(%r12), %rax
movq 0x8(%rax), %r13
cmpb $0xb, (%r13)
jne 0x80501
movq 0x8(%r13), %r12
cmpq %rbp, %r12
jg 0x804a3
cmpq 0x2a0(%rbx), %r12
jle 0x8075b
movq 0x1590(%rbx), %rax
movq 0x8(%rax), %rax
movq 0xce4ab(%rip), %rcx     # 0x14e960
movq 0xd2584(%rip), %rdx     # 0x152a40
movq 0x1ee8(%rbx), %rsi
movq 0x10(%rsi), %rsi
movq %rax, 0x8(%rsi)
movq 0x10(%rsi), %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rax), %rax
movq %r13, 0x8(%rax)
movq 0x10(%rax), %rax
movq %rdx, 0x8(%rax)
movq 0x1948(%rbx), %r15
movq 0x1ee8(%rbx), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3b366
jmp 0x80858
cmpq 0x110(%rbx), %r13
je 0x805fc
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3c2fb
testb %al, %al
je 0x805fc
cmpb $0x1, (%r13)
jne 0x80556
movq %r13, %rax
movq 0x8(%rax), %rcx
cmpb $0xb, (%rcx)
jne 0x807bd
cmpq %rbp, 0x8(%rcx)
jg 0x807bd
cmpq $0x0, 0x8(%rcx)
js 0x807bd
movq 0x10(%rax), %rax
cmpb $0x1, (%rax)
je 0x8052b
movq %rbx, %rdi
movq %r13, %rsi
callq 0xa08b2
movq %rax, %rbp
movq (%rax), %rax
movq 0x10(%rbp), %rcx
movq (%rax), %r12
cmpq $0x2, %rcx
jl 0x80586
movl $0x1, %edx
imulq (%rax,%rdx,8), %r12
incq %rdx
cmpq %rdx, %rcx
jne 0x80579
testq %r12, %r12
js 0x8059c
movq (%rsp), %rax
addq %r12, %rax
cmpq 0x8(%r14), %rax
jle 0x8086a
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xa9a3
movq 0x1590(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xce3a7(%rip), %rdx     # 0x14e960
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 0xa43cb(%rip), %rax     # 0x1249a9
movq %rax, 0x10(%r8)
movq $0x2d, 0x8(%r8)
movq %rbx, %rdi
movq %r13, %rcx
callq 0xef7f
movq %rax, %r15
xorl %eax, %eax
jmp 0x80622
movq 0x1590(%rbx), %rdx
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rcx
movl $0x1, %r8d
movl $0x2, %r9d
callq 0xf1ae
movq %rax, %r15
xorl %eax, %eax
testb %al, %al
movq (%rsp), %r13
je 0x80858
movzbl (%r14), %eax
cmpq $0x15, %rax
jne 0x80648
leaq 0x5e934(%rip), %rax     # 0xdef73
movq %rax, 0xce1d2(%rip)     # 0x14e818
jmp 0x8065a
leaq 0xce121(%rip), %rcx     # 0x14e770
leaq 0x5e95b(%rip), %rdx     # 0xdefb1
movq %rdx, (%rcx,%rax,8)
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x80672
movq %rbx, %rdi
callq 0xb389
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)
cmpq $0x0, 0x838(%rbx)
jne 0x806e1
movl $0x2800, %edi           # imm = 0x2800
callq 0x9480
movq %rax, 0x838(%rbx)
addq $0x28, %rax
movl $0xff, %ecx
movq %rax, -0x10(%rax)
movl $0x0, -0x20(%rax)
addq $0x28, %rax
decl %ecx
jne 0x806bf
movq $0x0, -0x10(%rax)
movl $0x0, -0x20(%rax)
movq 0x838(%rbx), %rax
movq 0x18(%rax), %rcx
movq %rcx, 0x838(%rbx)
movl $0x0, 0x8(%rax)
xorl %ecx, %ecx
movq %rcx, (%rax)
movq %rcx, 0x20(%rax)
movq %rax, 0x18(%r15)
movq %rbp, 0x20(%rax)
testq %rbp, %rbp
jne 0x80718
movq 0x18(%r15), %rax
movq %r14, 0x18(%rax)
movq %r12, 0x8(%r15)
testq %r12, %r12
jne 0x8072c
cmpb $0x15, (%r14)
jne 0x8072c
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 0x8074a
cmpl $0x16, %eax
jne 0x80777
shlq $0x3, %r13
addq 0x10(%r14), %r13
movq %r13, 0x10(%r15)
jmp 0x8081d
testq %r12, %r12
js 0x8078e
movq (%rsp), %rax
addq %r12, %rax
cmpq %rbp, %rax
jg 0x8078e
xorl %ebp, %ebp
movq (%rsp), %r13
jmp 0x8062e
cmpb $0x15, (%r15)
movq 0x10(%r14), %rax
jne 0x80816
leaq (%rax,%r13,8), %rax
jmp 0x80819
testq %r12, %r12
movq 0x1590(%rbx), %rax
movq 0x8(%rax), %rax
movq 0xce1bd(%rip), %rcx     # 0x14e960
leaq 0xd229e(%rip), %rdx     # 0x152a48
leaq 0xd228f(%rip), %rsi     # 0x152a40
cmovsq %rdx, %rsi
movq (%rsi), %rdx
jmp 0x804bc
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 0xa416c(%rip), %rcx     # 0x124954
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 0x3b366
jmp 0x80620
addq %r13, %rax
movq %rax, 0x10(%r15)
movq 0x790(%rbx), %rbx
movq 0x8(%rbx), %rsi
cmpq %rsi, 0x10(%rbx)
jne 0x80845
leaq (%rsi,%rsi), %rax
movq %rax, 0x8(%rbx)
movq (%rbx), %rdi
shlq $0x4, %rsi
callq 0x9510
movq %rax, (%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x10(%rbx)
movq %r15, (%rax,%rcx,8)
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, 0x20(%rbp)
movb $0x1, %al
jmp 0x80622