// File: /workspace/github_c_makefile_star2_O2/BernardTatin[P]s7sh/s7.c
// Function: g_gensym
static s7_pointer g_gensym(s7_scheme *sc, s7_pointer args)
    {
#define H_gensym "(gensym (prefix \"gensym\")) returns a new, unused symbol"
#define Q_gensym s7_make_signature(sc, 2, sc->is_gensym_symbol, sc->is_string_symbol)

        const char *prefix;
        char *name, *p, *base;
        s7_int len, plen, nlen;
        uint32_t location;
        uint64_t hash;
        s7_pointer x, str, stc;
        block_t *b, *ib;

        /* get symbol name */
        if (is_not_null(args))
        {
            s7_pointer gname;
            gname = car(args);
            if (!is_string(gname))
                return(method_or_bust_one_arg(sc, gname, sc->gensym_symbol, args, T_STRING));
            prefix = string_value(gname);
            plen = safe_strlen(prefix);
        }
        else
        {
            prefix = "gensym";
            plen = 6;
        }
        len = plen + 32; /* why 32 -- we need room for the gensym_counter integer, but (length "9223372036854775807") = 19 */

        b = mallocate(sc, len + sizeof(block_t) + 2 * sizeof(s7_cell));
        /* only 16 of block_t size is actually needed here because only the ln.tag (symbol_tag2) field is used in the embedded block_t */
        base = (char *)block_data(b);
        str = (s7_cell *)base;
        stc = (s7_cell *)(base + sizeof(s7_cell));
        ib = (block_t *)(base + 2 * sizeof(s7_cell));
        name = (char *)(base + sizeof(block_t) + 2 * sizeof(s7_cell));

        name[0] = '{';
        if (plen > 0) memcpy((void *)(name + 1), prefix, plen);
        name[plen + 1] = '}';
        name[plen + 2] = '-'; /* {gensym}-nnn */

        p = pos_int_to_str(sc, sc->gensym_counter++, &len, '\0');
        memcpy((void *)(name + plen + 3), (void *)p, len);
        nlen = len + plen + 2;

        hash = raw_string_hash((const uint8_t *)name, nlen);
        location = hash % SYMBOL_TABLE_SIZE;

        /* make-string for symbol name */
#if S7_DEBUGGING
        typeflag(str) = 0; /* here and below, this is needed to avoid set_type check errors (mallocate above) */
#endif
        set_type(str, T_STRING | T_IMMUTABLE | T_UNHEAP);
        string_length(str) = nlen;
        string_value(str) = name;
        string_hash(str) = hash;

        /* allocate the symbol in the heap so GC'd when inaccessible */
        new_cell(sc, x, T_SYMBOL | T_GENSYM);
        symbol_set_name_cell(x, str);
        symbol_info(x) = ib;
        set_global_slot(x, sc->undefined);
        /* set_initial_slot(x, sc->undefined); */
        symbol_set_local_unchecked(x, 0LL, sc->nil);
        symbol_set_ctr(x, 0);
        symbol_set_tag(x, 0);
        symbol_set_tag2(x, 0);
        symbol_clear_type(x);
        gensym_block(x) = b;

        /* place new symbol in symbol-table, but using calloc so we can easily free it (remove it from the table) in GC sweep */
#if S7_DEBUGGING
        typeflag(stc) = 0;
#endif
        set_type(stc, T_PAIR | T_IMMUTABLE | T_UNHEAP);
        set_car(stc, x);
        set_cdr(stc, vector_element(sc->symbol_table, location));
        vector_element(sc->symbol_table, location) = stc;
        pair_set_raw_hash(stc, hash);
        pair_set_raw_len(stc, (uint32_t)string_length(str));
        pair_set_raw_name(stc, string_value(str));

        add_gensym(sc, x);
        return(x);
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
cmpq %rsi, 0x110(%rdi)
je 0x4c758
movq %rsi, %rcx
movq 0x8(%rsi), %rsi
cmpb $0x13, (%rsi)
jne 0x4c948
movq 0x10(%rsi), %r13
movq %r13, %rdi
callq 0x8d06
movq %rax, %r15
jmp 0x4c763
leaq 0x8ad2a(%rip), %r13     # 0xd7489
pushq $0x6
popq %r15
leaq 0x20(%r15), %rax
movq %rax, 0x20(%rsp)
leaq 0xa8(%r15), %rsi
movq %rbx, %rdi
callq 0x9037
movq %rax, 0x18(%rsp)
movq (%rax), %r14
leaq 0x88(%r14), %r12
movb $0x7b, 0x88(%r14)
testq %r15, %r15
jle 0x4c7a9
leaq 0x89(%r14), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x83e0
leaq 0x30(%r14), %rax
movq %rax, 0x10(%rsp)
leaq 0x60(%r14), %rax
movq %rax, 0x8(%rsp)
movw $0x2d7d, 0x89(%r14,%r15) # imm = 0x2D7D
movl 0x220(%rbx), %esi
leal 0x1(%rsi), %eax
movl %eax, 0x220(%rbx)
leaq 0x20(%rsp), %r13
movq %rbx, %rdi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x77c9e
leaq (%r12,%r15), %rdi
addq $0x3, %rdi
movq (%r13), %r13
movq %rax, %rsi
movq %r13, %rdx
callq 0x83e0
leaq (%r15,%r13), %rbp
addq $0x2, %rbp
movq %r12, %rdi
movq %rbp, %rsi
callq 0x8dae
movq %rax, %r15
movl $0x7fed, %ecx           # imm = 0x7FED
xorl %edx, %edx
divq %rcx
movq %rdx, %r13
movabsq $0x4000000001000001, %rax # imm = 0x4000000001000001
addq $0x12, %rax
movq %rax, (%r14)
movq %rbp, 0x8(%r14)
movq %r12, 0x10(%r14)
movq %r15, 0x18(%r14)
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x4c85d
movq %rbx, %rdi
callq 0x9c27
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r12
movq $0x2000000a, (%r12)     # imm = 0x2000000A
movq %r14, 0x8(%r12)
movq 0x8(%rsp), %rax
movq %rax, 0x20(%r14)
movq 0x128(%rbx), %rax
movq %rax, 0x10(%r12)
movq 0x110(%rbx), %rax
movq %rax, 0x18(%r12)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%r12)
movq 0x8(%r12), %rax
movq 0x20(%rax), %rax
andl $0x0, 0xc(%rax)
movq 0x8(%r12), %rax
movq 0x20(%rax), %rax
andq $0x0, 0x10(%rax)
movq 0x8(%r12), %rax
movq 0x18(%rsp), %rcx
movq %rcx, 0x28(%rax)
movabsq $0x4000000001000001, %rax # imm = 0x4000000001000001
movq %rax, 0x30(%r14)
movq %r12, 0x38(%r14)
movq 0x148(%rbx), %rax
movq 0x10(%rax), %rax
movq (%rax,%r13,8), %rax
movq %rax, 0x40(%r14)
movq 0x148(%rbx), %rax
movq 0x10(%rax), %rax
movq 0x10(%rsp), %rcx
movq %rcx, (%rax,%r13,8)
movq %r15, 0x48(%r14)
movl 0x8(%r14), %eax
movl %eax, 0x5c(%r14)
movq 0x10(%r14), %rax
movq %rax, 0x50(%r14)
movq 0x778(%rbx), %rdi
movq %r12, %rsi
callq 0xb999
leaq 0x26006(%rip), %rax     # 0x72935
movq %rax, 0xc8e8a(%rip)     # 0x1157c0
movq %r12, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xf40(%rbx), %rdx
pushq $0x13
popq %r8
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x77745