// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xc8, %rsp
movq %rdi, 0xc0(%rsp)
movq %rsi, 0xb8(%rsp)
movq %rdx, 0xb0(%rsp)
movq 0xb8(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0xa0(%rsp)
cmpq $0x100, 0xa0(%rsp) # imm = 0x100
jle 0x10b4a
cmpq $0x40, 0xb0(%rsp)
jge 0x10b48
movq $0x100, 0xa0(%rsp) # imm = 0x100
jmp 0x10b66
cmpq $0x100, 0xa0(%rsp) # imm = 0x100
jge 0x10b64
movq $0x100, 0xa0(%rsp) # imm = 0x100
jmp 0x10b66
movq 0xc0(%rsp), %rax
movq 0x90(%rax), %rax
movq 0xc0(%rsp), %rcx
movq 0x88(%rcx), %rcx
subq %rcx, %rax
sarq $0x3, %rax
movq %rax, 0x30(%rsp)
movq 0xc0(%rsp), %rax
movq 0xa8(%rax), %rax
movl $0x8, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq 0x30(%rsp), %rax
cmpq %rcx, %rax
jge 0x10c11
movq 0xc0(%rsp), %rdi
callq 0xc1d50
movq %rax, 0x80(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0xc0(%rsp), %rax
movq 0xa8(%rax), %rax
movl $0x8, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq 0x28(%rsp), %rax
cmpq %rcx, %rax
jge 0x10c0f
movq 0xc0(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xc0f40
jmp 0x10c11
movq 0xc0(%rsp), %rdi
movq 0xa0(%rsp), %rsi
callq 0x34da0
movq %rax, 0x98(%rsp)
movq 0x98(%rsp), %rax
movq $0x1e, (%rax)
movq 0xb0(%rsp), %rcx
movq 0x98(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x98(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x90(%rsp)
movq 0xb8(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x88(%rsp)
cmpq $0x0, 0xa0(%rsp)
jle 0x10cec
movq 0x90(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0xa0(%rsp), %rax
movq 0xb8(%rsp), %rcx
cmpq 0x8(%rcx), %rax
jle 0x10cc7
movq 0xb8(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x10cd4
movq 0xa0(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rdx
shlq $0x3, %rdx
callq 0x93e0
movq 0xc0(%rsp), %rdi
xorl %esi, %esi
callq 0xa180
movq $0x2, 0xa8(%rsp)
movq 0xa8(%rsp), %rax
cmpq 0xb0(%rsp), %rax
jge 0x10ff8
movq 0x88(%rsp), %rax
movq 0xa8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x1, %eax
jne 0x10fa5
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movq 0xc0(%rsp), %rcx
cmpq 0x110(%rcx), %rax
jne 0x10e2a
movq 0x78(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x68(%rsp)
movq 0xc0(%rsp), %rax
movq 0x110(%rax), %rax
movq %rax, 0x60(%rsp)
movq 0xc0(%rsp), %rax
movq 0x90(%rax), %rax
movq 0xc0(%rsp), %rcx
cmpq 0x98(%rcx), %rax
ja 0x10db4
movq 0xc0(%rsp), %rdi
callq 0xc670
movq 0xc0(%rsp), %rcx
movq 0x90(%rcx), %rax
movq %rax, %rdx
addq $-0x8, %rdx
movq %rdx, 0x90(%rcx)
movq -0x8(%rax), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rax
movq $0x200001, (%rax)       # imm = 0x200001
movq 0x68(%rsp), %rcx
movq 0x70(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x60(%rsp), %rcx
movq 0x70(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x70(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x58(%rsp), %rdx
movq 0x90(%rsp), %rax
movq 0xa8(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x10f7d
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movzbl (%rax), %eax
cmpl $0x1, %eax
jne 0x10f52
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movq 0xc0(%rsp), %rcx
cmpq 0x110(%rcx), %rax
jne 0x10f52
movq 0xc0(%rsp), %rax
movq %rax, (%rsp)
movq 0x78(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x48(%rsp)
movq 0xc0(%rsp), %rax
movq 0x110(%rax), %rax
movq %rax, 0x40(%rsp)
movq 0xc0(%rsp), %rax
movq 0x90(%rax), %rax
movq 0xc0(%rsp), %rcx
cmpq 0x98(%rcx), %rax
ja 0x10ece
movq 0xc0(%rsp), %rdi
callq 0xc670
movq 0xc0(%rsp), %rcx
movq 0x90(%rcx), %rax
movq %rax, %rdx
addq $-0x8, %rdx
movq %rdx, 0x90(%rcx)
movq -0x8(%rax), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
movq $0x200001, (%rax)       # imm = 0x200001
movq 0x8(%rsp), %rsi
movq (%rsp), %rdi
movq 0x48(%rsp), %rcx
movq 0x50(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x40(%rsp), %rcx
movq 0x50(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x50(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rdx
callq 0xd9f0
movq %rax, %rdx
movq 0x90(%rsp), %rax
movq 0xa8(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x10f7b
movq 0xc0(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0xc5ed0
movq %rax, %rdx
movq 0x90(%rsp), %rax
movq 0xa8(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x10f7d
movq 0x78(%rsp), %rax
movq (%rax), %rcx
andq $-0x20001, %rcx         # imm = 0xFFFDFFFF
movq 0x90(%rsp), %rax
movq 0xa8(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, (%rax)
jmp 0x10fdd
movq 0x78(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x1f, %eax
jne 0x10fdb
movq 0xc0(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0xc6590
movq %rax, %rdx
movq 0x90(%rsp), %rax
movq 0xa8(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x10fdd
jmp 0x10fdf
movq 0xa8(%rsp), %rax
addq $0x4, %rax
movq %rax, 0xa8(%rsp)
jmp 0x10d07
movq 0xc0(%rsp), %rdi
movl $0x1, %esi
callq 0xa180
movq 0x98(%rsp), %rax
addq $0xc8, %rsp
retq
nopw (%rax,%rax)