// File: /workspace/github_c_makefile_star2_O2/BernardTatin[P]s7sh/s7.c
// Function: g_reverse
static s7_pointer g_reverse(s7_scheme *sc, s7_pointer args)
                {
#define H_reverse "(reverse lst) returns a list with the elements of lst in reverse order.  reverse \
                    also accepts a string or vector argument."
#define Q_reverse s7_make_signature(sc, 2, sc->is_sequence_symbol, sc->is_sequence_symbol)

                    s7_pointer p, np;

                    p = car(args);
                    sc->temp3 = p;
                    np = sc->nil;

                    switch (type(p))
                    {
                        case T_NIL:
                            return(sc->nil);

                        case T_PAIR:
                            return(s7_reverse(sc, p));

                        case T_STRING:
                            {
                                char *source, *dest, *end;
                                s7_int len;
                                len = string_length(p);
                                source = string_value(p);
                                end = (char *)(source + len);
                                np = make_empty_string(sc, len, '\0');
                                dest = (char *)(string_value(np) + len);
                                while (source < end) *(--dest) = *source++;
                            }
                            break;

                        case T_BYTE_VECTOR:
                            {
                                uint8_t *source, *dest, *end;
                                s7_int len;
                                len = byte_vector_length(p);
                                source = byte_vector_bytes(p);
                                end = (uint8_t *)(source + len);
                                np = make_simple_byte_vector(sc, len);
                                dest = (uint8_t *)(byte_vector_bytes(np) + len);
                                while (source < end) *(--dest) = *source++;
                            }
                            break;

                        case T_INT_VECTOR:
                            {
                                s7_int *source, *dest, *end;
                                s7_int len;
                                len = vector_length(p);
                                if (vector_rank(p) > 1)
                                    np = g_make_vector_1(sc, set_plist_2(sc, g_vector_dimensions(sc, set_plist_1(sc, p)), small_int(0)), sc->make_int_vector_symbol);
                                else np = make_simple_int_vector(sc, len);
                                source = int_vector_ints(p);
                                end = (s7_int *)(source + len);
                                dest = (s7_int *)(int_vector_ints(np) + len);
                                while (source < end) *(--dest) = *source++;
                            }
                            break;

                        case T_FLOAT_VECTOR:
                            {
                                s7_double *source, *dest, *end;
                                s7_int len;
                                len = vector_length(p);
                                if (vector_rank(p) > 1)
                                    np = g_make_vector_1(sc, set_plist_2(sc, g_vector_dimensions(sc, set_plist_1(sc, p)), real_zero), sc->make_float_vector_symbol);
                                else np = make_simple_float_vector(sc, len);
                                source = float_vector_floats(p);
                                end = (s7_double *)(source + len);
                                dest = (s7_double *)(float_vector_floats(np) + len);
                                while (source < end) *(--dest) = *source++;
                            }
                            break;

                        case T_VECTOR:
                            {
                                s7_pointer *source, *dest, *end;
                                s7_int len;
                                len = vector_length(p);
                                if (vector_rank(p) > 1)
                                    np = g_make_vector(sc, set_plist_1(sc, g_vector_dimensions(sc, set_plist_1(sc, p))));
                                else np = make_simple_vector(sc, len);
                                source = vector_elements(p);
                                end = (s7_pointer *)(source + len);
                                dest = (s7_pointer *)(vector_elements(np) + len);
                                while (source < end) *(--dest) = *source++;
                            }
                            break;

                        case T_HASH_TABLE:
                            return(hash_table_reverse(sc, p));

                        case T_C_OBJECT:
                            check_method(sc, p, sc->reverse_symbol, args);
                            if (c_object_reverse(sc, p))
                                return((*(c_object_reverse(sc, p)))(sc, args));
                            eval_error(sc, "attempt to reverse ~S?", 22, p);

                        case T_LET:
                            check_method(sc, p, sc->reverse_symbol, args);
                            return(s7_error(sc, sc->wrong_type_arg_symbol, set_elist_2(sc, wrap_string(sc, "can't reverse let: ~S", 21), p)));

                        default:
                            return(method_or_bust_with_type_one_arg(sc, p, sc->reverse_symbol, args, a_sequence_string));
                    }
                    return(np);
                }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r15
movq %rdi, %rbx
movq 0x8(%rsi), %r14
movq %r14, 0x508(%rdi)
movzbl (%r14), %eax
leal -0x13(%rax), %ecx
cmpl $0x9, %ecx
ja 0x60048
leaq 0x73bfd(%rip), %rax     # 0xd3c00
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq 0x8(%r14), %r12
movq 0x10(%r14), %r14
leaq (%r14,%r12), %r13
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0xd239
movq %rax, %r15
movq 0x10(%rax), %rax
addq %r12, %rax
decq %rax
cmpq %r13, %r14
jae 0x604a8
movb (%r14), %cl
incq %r14
movb %cl, (%rax)
decq %rax
jmp 0x60032
cmpl $0x1, %eax
je 0x6037d
cmpl $0x2, %eax
jne 0x60062
movq 0x110(%rbx), %r15
jmp 0x604a8
movq 0x1480(%rbx), %rdx
movq 0xb9ba0(%rip), %r8      # 0x119c10
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc736d
movq 0x8(%r14), %r12
movq 0x10(%r14), %r14
leaq (%r14,%r12), %r13
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2fe85
movq %rax, %r15
movq 0x10(%rax), %rax
addq %r12, %rax
decq %rax
cmpq %r13, %r14
jae 0x604a8
movb (%r14), %cl
incq %r14
movb %cl, (%rax)
decq %rax
jmp 0x600b0
movq 0x8(%r14), %r13
leaq 0x1(%r13), %rsi
movq %rbx, %rdi
callq 0x2a5ea
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
callq 0x89a9
movq %rax, (%rsp)
movq 0x10(%r14), %r14
xorl %ebp, %ebp
cmpq %r13, %rbp
jg 0x6011f
leaq (%r14,%rbp,8), %r12
movq (%r12), %r12
testq %r12, %r12
je 0x6011a
movq (%r12), %rcx
movq 0x20(%r12), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2a7e4
addq $0x18, %r12
jmp 0x600f7
incq %rbp
jmp 0x600ee
movq %rbx, %rdi
movq (%rsp), %rsi
callq 0x8b00
jmp 0x604a8
testb $0x40, 0x3(%r14)
je 0x60166
cmpb $0x1, 0x24c(%rbx)
jne 0x60166
movq %rbx, %rdi
movq %r14, %rsi
callq 0x88f3
movq 0x1480(%rbx), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x888f
cmpq 0x128(%rbx), %rax
jne 0x601e4
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 0x8774b(%rip), %rcx     # 0xe78dc
movq %rcx, 0x10(%rax)
movq $0x15, 0x8(%rax)
jmp 0x6047c
testb $0x40, 0x3(%r14)
je 0x6034b
cmpb $0x1, 0x24c(%rbx)
jne 0x6034b
movq %rbx, %rdi
movq %r14, %rsi
callq 0x88f3
movq 0x1480(%rbx), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x888f
cmpq 0x128(%rbx), %rax
je 0x6034b
movq %rax, %r12
movq %rbx, %rdi
movq %r15, %rsi
callq 0x35492
movq %rbx, %rdi
movq %r12, %rsi
movq %rax, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa34c
movq 0x8(%r14), %r12
movq 0x18(%r14), %rax
movq 0x20(%rax), %rax
testq %rax, %rax
je 0x60396
cmpq $0x2, 0x10(%rax)
jl 0x60396
movq 0x700(%rbx), %rax
movq %r14, 0x8(%rax)
movq 0x700(%rbx), %rsi
movq %rbx, %rdi
callq 0x2f66b
movq 0xb9a09(%rip), %rcx     # 0x119c58
movq 0x708(%rbx), %rdx
movq %rax, 0x8(%rdx)
movq 0x710(%rbx), %rax
movq %rcx, 0x8(%rax)
movq 0x708(%rbx), %rsi
movq 0x12d8(%rbx), %rdx
movq %rbx, %rdi
callq 0x2f867
jmp 0x603a1
movq 0x8(%r14), %r12
movq 0x18(%r14), %rax
movq 0x20(%rax), %rax
testq %rax, %rax
je 0x603d3
cmpq $0x2, 0x10(%rax)
jl 0x603d3
movq 0x700(%rbx), %rax
movq %r14, 0x8(%rax)
movq 0x700(%rbx), %rsi
movq %rbx, %rdi
callq 0x2f66b
movq 0x700(%rbx), %rcx
movq %rax, 0x8(%rcx)
movq 0x700(%rbx), %rsi
movq %rbx, %rdi
callq 0x2f65f
jmp 0x603de
movq 0x8(%r14), %r12
movq 0x18(%r14), %rax
movq 0x20(%rax), %rax
testq %rax, %rax
je 0x6040e
cmpq $0x2, 0x10(%rax)
jl 0x6040e
movq 0x700(%rbx), %rax
movq %r14, 0x8(%rax)
movq 0x700(%rbx), %rsi
movq %rbx, %rdi
callq 0x2f66b
movq 0xb5636(%rip), %rcx     # 0x115950
movq 0x708(%rbx), %rdx
movq %rax, 0x8(%rdx)
movq 0x710(%rbx), %rax
movq %rcx, 0x8(%rax)
movq 0x708(%rbx), %rsi
movq 0x12f0(%rbx), %rdx
movq %rbx, %rdi
callq 0x2f867
jmp 0x60419
movq 0x8d8(%rbx), %rax
movq 0x8(%r14), %rcx
movq (%rax,%rcx,8), %rax
movq 0x60(%rax), %rax
testq %rax, %rax
je 0x60445
movq %rbx, %rdi
movq %r15, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *%rax
movq %rbx, %rdi
movq %r14, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2d7a4
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2fd63
movq %rax, %r15
movq 0x10(%r14), %rax
leaq (%rax,%r12,8), %rcx
movq 0x10(%r15), %rdx
leaq (%rdx,%r12,8), %rdx
addq $-0x8, %rdx
cmpq %rcx, %rax
jae 0x604a8
movsd (%rax), %xmm0
addq $0x8, %rax
movsd %xmm0, (%rdx)
addq $-0x8, %rdx
jmp 0x603b8
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2f202
movq %rax, %r15
movq 0x10(%r14), %rax
leaq (%rax,%r12,8), %rcx
movq 0x10(%r15), %rdx
leaq (%rdx,%r12,8), %rdx
addq $-0x8, %rdx
cmpq %rcx, %rax
jae 0x604a8
movq (%rax), %rsi
addq $0x8, %rax
movq %rsi, (%rdx)
addq $-0x8, %rdx
jmp 0x603f5
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2fdf4
movq %rax, %r15
movq 0x10(%r14), %rax
leaq (%rax,%r12,8), %rcx
movq 0x10(%r15), %rdx
leaq (%rdx,%r12,8), %rdx
addq $-0x8, %rdx
cmpq %rcx, %rax
jae 0x604a8
movq (%rax), %rsi
addq $0x8, %rax
movq %rsi, (%rdx)
addq $-0x8, %rdx
jmp 0x60430
movq 0x1918(%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 0x87455(%rip), %rcx     # 0xe78c5
movq %rcx, 0x10(%rax)
movq $0x16, 0x8(%rax)
movq 0x6e0(%rbx), %rcx
movq %rax, 0x8(%rcx)
movq 0x6e0(%rbx), %rax
movq 0x10(%rax), %rax
movq %r14, 0x8(%rax)
movq 0x6e0(%rbx), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2cdc0
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq