// File: /workspace/github_c_makefile_star2_O1/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 0xd627
movq %r14, %rdi
callq 0x930b6
movq 0xa8(%r14), %rcx
leaq 0x7(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x3, %rdx
cmpq %rdx, %rax
jge 0xd627
movq %r14, %rdi
xorl %esi, %esi
callq 0x928d3
movq 0x90(%r14), %rax
cmpq 0x98(%r14), %rax
ja 0xd63f
movq %r14, %rdi
callq 0xb389
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 0xd677
movq %r14, %rdi
callq 0xa305
jmp 0xd6df
cmpq $0x0, 0x838(%r14)
jne 0xd6bd
movl $0x2800, %edi           # imm = 0x2800
callq 0x9480
movq %rax, 0x838(%r14)
addq $0x28, %rax
movl $0xff, %ecx
movq %rax, -0x10(%rax)
movl $0x0, -0x20(%rax)
addq $0x28, %rax
decl %ecx
jne 0xd69b
movq $0x0, -0x10(%rax)
movl $0x0, -0x20(%rax)
movq 0x838(%r14), %rax
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 0x53c2c(%rip), %rax     # 0x61325
movq %rax, 0x20(%r15)
leaq 0x53c2a(%rip), %rax     # 0x6132e
movq %rax, 0x28(%r15)
movq 0x740(%r14), %rbx
movq 0x8(%rbx), %rsi
cmpq %rsi, 0x10(%rbx)
jne 0xd730
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 $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 0x93e0
movb $0x1, 0x218(%r14)
cmpq $0x3, %r13
jl 0xd92e
movl $0x2, %r15d
movq %r13, 0x8(%rsp)
movq %r12, 0x20(%rsp)
movq (%r12,%r15,8), %rbp
movzbl (%rbp), %eax
cmpl $0x1f, %eax
je 0xd7e5
cmpl $0x1, %eax
jne 0xd921
movq %rbx, %r12
movq 0x10(%rbp), %rax
movq 0x110(%r14), %rbx
cmpq %rbx, %rax
je 0xd84b
cmpb $0x1, (%rax)
jne 0xd7d5
cmpq %rbx, 0x10(%rax)
je 0xd88e
movq %r14, %rdi
movq %rbp, %rsi
callq 0x955f7
jmp 0xd904
movq 0x90(%r14), %rax
cmpq 0x98(%r14), %rax
ja 0xd7fd
movq %r14, %rdi
callq 0xb389
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 0xd921
movq 0x8(%rbp), %r13
movq 0x90(%r14), %rax
cmpq 0x98(%r14), %rax
ja 0xd867
movq %r14, %rdi
callq 0xb389
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 0xd8ff
movq 0x8(%rbp), %r13
movq 0x8(%rax), %rdx
movq 0x90(%r14), %rax
cmpq 0x98(%r14), %rax
ja 0xd8b8
movq %r14, %rdi
movq %rdx, 0x10(%rsp)
callq 0xb389
movq 0x10(%rsp), %rdx
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 %rdx, 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 %r13, 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 0xd799
movb $0x0, 0x218(%r14)
movq 0x18(%rsp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq