// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xf8, %rsp
movq %rdi, 0xe8(%rsp)
movq %rsi, 0xe0(%rsp)
movq $0x0, 0xa8(%rsp)
movq 0xe0(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0xd8(%rsp)
movq 0xd8(%rsp), %rax
movzbl (%rax), %eax
movl %eax, %ecx
leaq 0x180435(%rip), %rax    # 0x21a750
testb $0x1, (%rax,%rcx)
jne 0x9a366
movq 0xe8(%rsp), %rdi
movq 0xd8(%rsp), %rsi
movq 0xe8(%rsp), %rax
movq 0x1590(%rax), %rdx
movq 0xe0(%rsp), %rcx
movl $0x15, %r8d
movl $0x1, %r9d
callq 0x13c50
movq %rax, 0xf0(%rsp)
jmp 0x9abc5
movq 0xd8(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0xb0(%rsp)
movq 0xe0(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movq 0xe8(%rsp), %rcx
cmpq 0x110(%rcx), %rax
je 0x9a4e3
movq 0xe0(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0xa0(%rsp)
movq 0xa0(%rsp), %rdi
callq 0x11340
testb $0x1, %al
jne 0x9a411
movq 0xe8(%rsp), %rdi
movq 0xa0(%rsp), %rsi
movq 0xe8(%rsp), %rax
movq 0x1590(%rax), %rdx
movq 0xe0(%rsp), %rcx
movl $0xb, %r8d
movl $0x3, %r9d
callq 0x13c50
movq %rax, 0xf0(%rsp)
jmp 0x9abc5
movq 0xa0(%rsp), %rdi
callq 0x10790
movq %rax, 0xa8(%rsp)
cmpq $0x0, 0xa8(%rsp)
jl 0x9a447
movq 0xa8(%rsp), %rax
cmpq 0xb0(%rsp), %rax
jl 0x9a4e1
movq 0xe8(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0xe8(%rsp), %rax
movq 0x1590(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x78(%rsp)
movq 0x17c025(%rip), %rax    # 0x216498
movq %rax, 0x80(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x88(%rsp)
cmpq $0x0, 0xa8(%rsp)
jge 0x9a4a4
movq 0x1800db(%rip), %rax    # 0x21a578
movq %rax, 0x68(%rsp)
jmp 0x9a4b0
movq 0x1800c5(%rip), %rax    # 0x21a570
movq %rax, 0x68(%rsp)
movq 0x88(%rsp), %rcx
movq 0x80(%rsp), %rdx
movq 0x78(%rsp), %rsi
movq 0x70(%rsp), %rdi
movq 0x68(%rsp), %r8
callq 0x13880
movq %rax, 0xf0(%rsp)
jmp 0x9abc5
jmp 0x9a4e3
movq 0xe0(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rax
movzbl (%rax), %eax
cmpl $0xb, %eax
jne 0x9a65a
movq 0xd0(%rsp), %rdi
callq 0x10790
movq %rax, 0xb8(%rsp)
movq 0xb8(%rsp), %rax
cmpq 0xb0(%rsp), %rax
jg 0x9a54f
movq 0xb8(%rsp), %rax
movq 0xe8(%rsp), %rcx
cmpq 0x2a0(%rcx), %rax
jle 0x9a592
movq 0xe8(%rsp), %rdi
movq 0xe8(%rsp), %rax
movq 0x1590(%rax), %rax
movq 0x8(%rax), %rsi
movq 0x17bf1f(%rip), %rdx    # 0x216490
movq 0xd0(%rsp), %rcx
movq 0x17fff0(%rip), %r8     # 0x21a570
callq 0x13880
movq %rax, 0xf0(%rsp)
jmp 0x9abc5
cmpq $0x0, 0xb8(%rsp)
jl 0x9a5bb
movq 0xb8(%rsp), %rax
addq 0xa8(%rsp), %rax
cmpq 0xb0(%rsp), %rax
jle 0x9a649
movq 0xe8(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0xe8(%rsp), %rax
movq 0x1590(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x50(%rsp)
movq 0x17bea9(%rip), %rax    # 0x216490
movq %rax, 0x58(%rsp)
movq 0xd0(%rsp), %rax
movq %rax, 0x60(%rsp)
cmpq $0x0, 0xb8(%rsp)
jge 0x9a612
movq 0x17ff6d(%rip), %rax    # 0x21a578
movq %rax, 0x40(%rsp)
jmp 0x9a61e
movq 0x17ff57(%rip), %rax    # 0x21a570
movq %rax, 0x40(%rsp)
movq 0x60(%rsp), %rcx
movq 0x58(%rsp), %rdx
movq 0x50(%rsp), %rsi
movq 0x48(%rsp), %rdi
movq 0x40(%rsp), %r8
callq 0x13880
movq %rax, 0xf0(%rsp)
jmp 0x9abc5
movq $0x0, 0xc0(%rsp)
jmp 0x9a935
movq 0xd0(%rsp), %rax
movq 0xe8(%rsp), %rcx
cmpq 0x110(%rcx), %rax
je 0x9a68c
movq 0xe8(%rsp), %rdi
movq 0xd0(%rsp), %rsi
callq 0x31a40
testb $0x1, %al
jne 0x9a6d1
movq 0xe8(%rsp), %rdi
movq 0xd0(%rsp), %rsi
movq 0xe8(%rsp), %rax
movq 0x1590(%rax), %rdx
movq 0xe0(%rsp), %rcx
movl $0x1, %r8d
movl $0x2, %r9d
callq 0x13c50
movq %rax, 0xf0(%rsp)
jmp 0x9abc5
movq 0xd0(%rsp), %rax
movq %rax, 0x98(%rsp)
movq 0x98(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x1, %eax
jne 0x9a7cc
movq 0x98(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x11340
testb $0x1, %al
jne 0x9a70c
jmp 0x9a73e
movq 0x98(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x10790
cmpq 0xb0(%rsp), %rax
jg 0x9a73e
movq 0x98(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x10790
cmpq $0x0, %rax
jge 0x9a7b1
movq 0xe8(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0xe8(%rsp), %rax
movq 0x1940(%rax), %rax
movq %rax, 0x38(%rsp)
movq 0xe8(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0xe8(%rsp), %rdi
leaq 0x159244(%rip), %rsi    # 0x1f39bf
movl $0x54, %edx
callq 0xb880
movq 0x28(%rsp), %rdi
movq %rax, %rsi
callq 0xc3820
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq %rax, %rdx
callq 0x2f940
movq %rax, 0xf0(%rsp)
jmp 0x9abc5
jmp 0x9a7b3
movq 0x98(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x98(%rsp)
jmp 0x9a6e1
movq 0xe8(%rsp), %rdi
movq 0xd0(%rsp), %rsi
callq 0xd9260
movq %rax, 0xc0(%rsp)
movq 0xc0(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq %rax, 0xb8(%rsp)
movq $0x1, 0x90(%rsp)
movq 0x90(%rsp), %rax
movq 0xc0(%rsp), %rcx
cmpq 0x10(%rcx), %rax
jge 0x9a85f
movq 0xc0(%rsp), %rax
movq (%rax), %rax
movq 0x90(%rsp), %rcx
movq (%rax,%rcx,8), %rax
imulq 0xb8(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0x90(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x90(%rsp)
jmp 0x9a80b
cmpq $0x0, 0xb8(%rsp)
jl 0x9a88c
movq 0xb8(%rsp), %rax
addq 0xa8(%rsp), %rax
movq 0xd8(%rsp), %rcx
cmpq 0x8(%rcx), %rax
jle 0x9a921
movq 0xe8(%rsp), %rdi
movq 0xc0(%rsp), %rsi
callq 0xb230
movq 0xe8(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0xe8(%rsp), %rax
movq 0x1590(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x17bbc3(%rip), %rax    # 0x216490
movq %rax, 0x18(%rsp)
movq 0xd0(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0xe8(%rsp), %rdi
leaq 0x159126(%rip), %rsi    # 0x1f3a14
movl $0x2d, %edx
callq 0xb880
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq %rax, %r8
callq 0x13880
movq %rax, 0xf0(%rsp)
jmp 0x9abc5
movq 0xd8(%rsp), %rcx
movq 0xc0(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0xd8(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x15, %eax
jne 0x9a955
leaq 0xd2ac4(%rip), %rax     # 0x16d410
movq %rax, 0x17b9f5(%rip)    # 0x216348
jmp 0x9a974
movq 0xd8(%rsp), %rax
movzbl (%rax), %eax
movl %eax, %ecx
leaq 0x17b937(%rip), %rax    # 0x2162a0
leaq 0xd2b40(%rip), %rdx     # 0x16d4b0
movq %rdx, (%rax,%rcx,8)
jmp 0x9a976
movq 0xe8(%rsp), %rax
movq 0x90(%rax), %rax
movq 0xe8(%rsp), %rcx
cmpq 0x98(%rcx), %rax
ja 0x9a9a3
movq 0xe8(%rsp), %rdi
callq 0xc670
movq 0xe8(%rsp), %rcx
movq 0x90(%rcx), %rax
movq %rax, %rdx
addq $-0x8, %rdx
movq %rdx, 0x90(%rcx)
movq -0x8(%rax), %rax
movq %rax, 0xc8(%rsp)
movq 0xd8(%rsp), %rax
movq (%rax), %rcx
andq $-0x20001, %rcx         # imm = 0xFFFDFFFF
orq $0x20000000, %rcx       # imm = 0x20000000
orq $0x200000, %rcx         # imm = 0x200000
movq 0xc8(%rsp), %rax
movq %rcx, (%rax)
movq 0xe8(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x33d80
movq %rax, %rcx
movq 0xc8(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0xc0(%rsp), %rcx
movq 0xc8(%rsp), %rax
movq 0x18(%rax), %rax
movq %rcx, 0x20(%rax)
cmpq $0x0, 0xc0(%rsp)
jne 0x9aa52
movq 0xd8(%rsp), %rcx
movq 0xc8(%rsp), %rax
movq 0x18(%rax), %rax
movq %rcx, 0x18(%rax)
movq 0xb8(%rsp), %rcx
movq 0xc8(%rsp), %rax
movq %rcx, 0x8(%rax)
cmpq $0x0, 0xb8(%rsp)
jne 0x9aa97
movq 0xd8(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x15, %eax
jne 0x9aa97
movq 0xc8(%rsp), %rax
movzwl 0x6(%rax), %ecx
orl $0x100, %ecx            # imm = 0x100
movw %cx, 0x6(%rax)
movq 0xd8(%rsp), %rax
movq 0x20(%rax), %rcx
movq 0xc8(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0xd8(%rsp), %rax
movq 0x28(%rax), %rcx
movq 0xc8(%rsp), %rax
movq %rcx, 0x28(%rax)
movq 0xd8(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x16, %eax
jne 0x9ab03
movq 0xd8(%rsp), %rax
movq 0x10(%rax), %rcx
movq 0xa8(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rcx
movq 0xc8(%rsp), %rax
movq %rcx, 0x10(%rax)
jmp 0x9ab99
movq 0xd8(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x17, %eax
jne 0x9ab3c
movq 0xd8(%rsp), %rax
movq 0x10(%rax), %rcx
movq 0xa8(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rcx
movq 0xc8(%rsp), %rax
movq %rcx, 0x10(%rax)
jmp 0x9ab97
movq 0xc8(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x15, %eax
jne 0x9ab75
movq 0xd8(%rsp), %rax
movq 0x10(%rax), %rcx
movq 0xa8(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rcx
movq 0xc8(%rsp), %rax
movq %rcx, 0x10(%rax)
jmp 0x9ab95
movq 0xd8(%rsp), %rax
movq 0x10(%rax), %rcx
addq 0xa8(%rsp), %rcx
movq 0xc8(%rsp), %rax
movq %rcx, 0x10(%rax)
jmp 0x9ab97
jmp 0x9ab99
movq 0xe8(%rsp), %rax
movq 0x790(%rax), %rdi
movq 0xc8(%rsp), %rsi
callq 0x11230
movq 0xc8(%rsp), %rax
movq %rax, 0xf0(%rsp)
movq 0xf0(%rsp), %rax
addq $0xf8, %rsp
retq
nopw %cs:(%rax,%rax)