// File: /workspace/github_c_makefile_star2_O3/BernardTatin[P]s7sh/s7.c
// Function: copy_stack
static s7_pointer copy_stack(s7_scheme *sc, s7_pointer old_v, int64_t top)
    {
#define CC_INITIAL_STACK_SIZE 256 /* 128 is too small here */
        int64_t i, len;
        s7_pointer new_v;
        s7_pointer *nv, *ov;

        /* stacks can grow temporarily, so sc->stack_size grows, but we don't normally need all that
         *   leftover space here, so choose the original stack size if it's smaller.
         */
        len = vector_length(old_v);
        if (len > CC_INITIAL_STACK_SIZE)
        {
            if (top < CC_INITIAL_STACK_SIZE / 4)
                len = CC_INITIAL_STACK_SIZE;
        }
        else
        {
            if (len < CC_INITIAL_STACK_SIZE)
                len = CC_INITIAL_STACK_SIZE;
        }

        if ((int64_t)(sc->free_heap_top - sc->free_heap) < (int64_t)(sc->heap_size / 8))
        {
            int64_t freed_heap;
#if S7_DEBUGGING
            freed_heap = gc(sc, __func__, __LINE__);
#else
            freed_heap = gc(sc);
#endif
            if (freed_heap < (int64_t)(sc->heap_size / 8))
                resize_heap(sc);
        }

        new_v = make_simple_vector(sc, len);
        set_type(new_v, T_STACK);
        temp_stack_top(new_v) = top;
        nv = stack_elements(new_v);
        ov = stack_elements(old_v);
        if (len > 0)
            memcpy((void *)nv, (void *)ov, ((len > vector_length(old_v)) ? vector_length(old_v) : len) * sizeof(s7_pointer));

        s7_gc_on(sc, false);

        for (i = 2; i < top; i += 4)
        {
            s7_pointer p;
            p = ov[i];                               /* args */
            if (is_pair(p))                          /* args need not be a list (it can be a port or #f, etc) */
            {
                if (is_null(cdr(p)))
                    nv[i] = list_1(sc, car(p));
                else
                {
                    if ((is_pair(cdr(p))) && (is_null(cddr(p))))
                        nv[i] = list_2(sc, car(p), cadr(p));
                    else nv[i] = protected_list_copy(sc, p);  /* args (copy is needed -- see s7test.scm) */
                }
                set_type(nv[i], (typeflag(p) & (~T_COLLECTED))); /* carry over T_IMMUTABLE */
            }
            /* lst can be dotted or circular here.  The circular list only happens in a case like:
             *    (dynamic-wind (lambda () (eq? (let ((lst (cons 1 2))) (set-cdr! lst lst) lst) (call/cc (lambda (k) k)))) (lambda () #f) (lambda () #f))
             */
            else
            {
                if (is_counter(p))                   /* these can only occur in this context */
                    nv[i] = copy_counter(sc, p);
            }
        }
        s7_gc_on(sc, true);
        return(new_v);
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r13
movq %rsi, %r12
movq 0x8(%rsi), %rax
cmpq $0x40, %rdx
movl $0x100, %ecx            # imm = 0x100
movq %rax, %rbp
cmovlq %rcx, %rbp
cmpq $0x101, %rax            # imm = 0x101
cmovlq %rcx, %rbp
movq %rdi, %r14
movq 0x90(%rdi), %rax
subq 0x88(%rdi), %rax
movq 0xa8(%rdi), %rcx
sarq $0x3, %rax
leaq 0x7(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x3, %rdx
cmpq %rdx, %rax
jge 0xc86c
movq %r14, %rdi
callq 0x8cc3f
movq 0xa8(%r14), %rcx
leaq 0x7(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x3, %rdx
cmpq %rdx, %rax
jge 0xc86c
movq %r14, %rdi
xorl %esi, %esi
callq 0x8c4d4
movq 0x90(%r14), %rax
cmpq 0x98(%r14), %rax
ja 0xc88b
movq %r14, %rdi
callq 0xa550
movq 0x90(%r14), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%r14)
movq -0x8(%rax), %r15
movq $0x200015, (%r15)       # imm = 0x200015
movq %rbp, 0x8(%r15)
leaq (,%rbp,8), %rsi
testq %rsi, %rsi
jle 0xc8bc
movq %r14, %rdi
callq 0x9357
jmp 0xc922
movq 0x838(%r14), %rax
testq %rax, %rax
jne 0xc907
movl $0x2800, %edi           # imm = 0x2800
callq 0x8480
movq %rax, 0x838(%r14)
movq %rax, %rcx
addq $0x28, %rcx
movl $0xff, %edx
movq %rcx, -0x10(%rcx)
movl $0x0, -0x20(%rcx)
addq $0x28, %rcx
decl %edx
jne 0xc8e5
movq $0x0, -0x10(%rcx)
movl $0x0, -0x20(%rcx)
movq 0x18(%rax), %rcx
movq %rcx, 0x838(%r14)
movl $0x0, 0x8(%rax)
xorl %ecx, %ecx
movq %rcx, (%rax)
movq %rcx, 0x20(%rax)
movq %rax, 0x18(%r15)
movq (%rax), %rcx
movq %rcx, 0x10(%r15)
movq $0x0, 0x20(%rax)
leaq 0x4f90d(%rip), %rax     # 0x5c249
movq %rax, 0x20(%r15)
leaq 0x4f90b(%rip), %rax     # 0x5c252
movq %rax, 0x28(%r15)
movq 0x740(%r14), %rbx
movq (%rbx), %rax
movq 0x10(%rbx), %rsi
cmpq 0x8(%rbx), %rsi
jne 0xc97a
leaq (%rsi,%rsi), %rcx
movq %rcx, 0x8(%rbx)
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x8510
movq %rax, (%rbx)
movq 0x10(%rbx), %rsi
leaq 0x1(%rsi), %rcx
movq %rcx, 0x10(%rbx)
movq %r15, (%rax,%rsi,8)
movq $0x1e, (%r15)
movq %r13, 0x20(%r15)
movq %r15, 0x18(%rsp)
movq 0x10(%r15), %rbx
movq 0x8(%r12), %rdx
movq 0x10(%r12), %r12
cmpq %rdx, %rbp
cmovlq %rbp, %rdx
shlq $0x3, %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x83e0
movb $0x1, 0x218(%r14)
cmpq $0x3, %r13
jl 0xcb71
movl $0x2, %r15d
movq %r13, 0x8(%rsp)
movq %r12, 0x20(%rsp)
movq (%r12,%r15,8), %rbp
movzbl (%rbp), %eax
cmpl $0x1f, %eax
je 0xca28
cmpl $0x1, %eax
jne 0xcb64
movq %rbx, %r12
movq 0x10(%rbp), %rax
movq 0x110(%r14), %rbx
cmpq %rbx, %rax
je 0xca8e
cmpb $0x1, (%rax)
jne 0xca18
cmpq %rbx, 0x10(%rax)
je 0xcad1
movq %r14, %rdi
movq %rbp, %rsi
callq 0x8f27a
jmp 0xcb47
movq 0x90(%r14), %rax
cmpq 0x98(%r14), %rax
ja 0xca47
movq %r14, %rdi
callq 0xa550
movq 0x90(%r14), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%r14)
movq -0x8(%rax), %rax
movq $0x1f, (%rax)
movq 0x8(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq 0x10(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq 0x28(%rbp), %rcx
movq %rcx, 0x28(%rax)
movq 0x18(%rbp), %rcx
movq %rcx, 0x18(%rax)
movq 0x20(%rbp), %rcx
movq %rcx, 0x20(%rax)
movq %rax, (%rbx,%r15,8)
jmp 0xcb64
movq 0x8(%rbp), %r13
movq 0x90(%r14), %rax
cmpq 0x98(%r14), %rax
ja 0xcab1
movq %r14, %rdi
callq 0xa550
movq 0x90(%r14), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%r14)
movq -0x8(%rax), %rax
movq $0x200001, (%rax)       # imm = 0x200001
movq %r13, 0x8(%rax)
movq %rbx, 0x10(%rax)
jmp 0xcb42
movq 0x8(%rbp), %rdi
movq 0x8(%rax), %r13
movq 0x90(%r14), %rax
cmpq 0x98(%r14), %rax
ja 0xcb02
movq %rdi, 0x10(%rsp)
movq %r14, %rdi
callq 0xa550
movq 0x10(%rsp), %rdi
movq 0x90(%r14), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%r14)
movq -0x8(%rax), %rcx
movl $0x200001, %esi         # imm = 0x200001
movq %rsi, (%rcx)
movq %r13, 0x8(%rcx)
movq %rbx, 0x10(%rcx)
movq 0x90(%r14), %rax
leaq -0x8(%rax), %rdx
movq %rdx, 0x90(%r14)
movq -0x8(%rax), %rax
movq %rsi, (%rax)
movq %rdi, 0x8(%rax)
movq %rcx, 0x10(%rax)
movq 0x8(%rsp), %r13
movq %r12, %rbx
movq %rax, (%r12,%r15,8)
movq (%rbp), %rcx
movq $-0x20001, %rdx         # imm = 0xFFFDFFFF
andq %rdx, %rcx
movq %rcx, (%rax)
movq 0x20(%rsp), %r12
addq $0x4, %r15
cmpq %r13, %r15
jl 0xc9dc
movb $0x0, 0x218(%r14)
movq 0x18(%rsp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq