// File: /workspace/github_c_makefile_star2_O3/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 0x5f2e1
movq %rsi, %rcx
movq 0x8(%rsi), %rsi
cmpb $0x13, (%rsi)
jne 0x5f2f0
movq 0x10(%rsi), %r13
testq %r13, %r13
je 0x5f313
cmpb $0x0, (%r13)
je 0x5f31b
xorl %r15d, %r15d
cmpb $0x0, 0x1(%r13,%r15)
leaq 0x1(%r15), %r15
jne 0x5f2d3
jmp 0x5f31e
leaq 0xac201(%rip), %r13     # 0x10b4e9
movl $0x6, %r15d
jmp 0x5f31e
movq 0xf40(%rbx), %rdx
movq %rbx, %rdi
movl $0x13, %r8d
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x95069
xorl %r15d, %r15d
xorl %r13d, %r13d
jmp 0x5f31e
xorl %r15d, %r15d
leaq 0xa8(%r15), %rsi
movq %rbx, %rdi
callq 0x9357
movq %rax, 0x10(%rsp)
movq (%rax), %r14
leaq 0x88(%r14), %r12
movb $0x7b, 0x88(%r14)
testq %r15, %r15
jle 0x5f35b
leaq 0x89(%r14), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x83e0
leaq 0x30(%r14), %rax
movq %rax, 0x8(%rsp)
leaq 0x60(%r14), %rax
movq %rax, (%rsp)
leaq (%r12,%r15), %rdi
movw $0x2d7d, 0x1(%r12,%r15) # imm = 0x2D7D
movl 0x220(%rbx), %ecx
leal 0x1(%rcx), %eax
movl %eax, 0x220(%rbx)
movb $0x0, 0xb4f(%rbx)
xorl %r13d, %r13d
leaq 0xb71a8(%rip), %rsi     # 0x116540
movabsq $-0x3333333333333333, %r8 # imm = 0xCCCCCCCCCCCCCCCD
movq %rcx, %rax
mulq %r8
shrq $0x3, %rdx
leaq (%rdx,%rdx), %rax
leaq (%rax,%rax,4), %rax
movq %rcx, %r9
subq %rax, %r9
movb (%rsi,%r9), %al
movb %al, 0xb4e(%rbx,%r13)
decq %r13
cmpq $0x9, %rcx
movq %rdx, %rcx
ja 0x5f3a2
movl $0x1, %edx
subq %r13, %rdx
addq $0x3, %rdi
leaq (%rbx,%r13), %rsi
addq $0xb4f, %rsi            # imm = 0xB4F
callq 0x83e0
subq %r13, %r15
leaq 0x1(%r15), %rax
addq $0x3, %r15
movq $0x0, 0x18(%rsp)
cmpq $0x6, %rax
jg 0x5f421
leaq 0x18(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x83e0
movq (%r13), %rbp
jmp 0x5f459
movq 0x88(%r14), %rbp
leaq 0x20(%rsp), %r13
movq $0x0, (%r13)
leaq 0x90(%r14), %rsi
cmpq $0x10, %r15
movl $0x10, %edx
cmovbq %r15, %rdx
addq $-0x8, %rdx
movq %r13, %rdi
callq 0x83e0
addq (%r13), %rbp
movabsq $0x4000000001000001, %rsi # imm = 0x4000000001000001
movabsq $-0x7fecfd2d94c4151b, %rcx # imm = 0x801302D26B3BEAE5
movq %rbp, %rax
mulq %rcx
shrq $0xe, %rdx
imulq $0x7fed, %rdx, %rax     # imm = 0x7FED
movq %rbp, %r13
subq %rax, %r13
leaq 0x12(%rsi), %rax
movq %rax, (%r14)
movq %r15, 0x8(%r14)
movq %r12, 0x10(%r14)
movq %rbp, 0x18(%r14)
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x5f4bc
movq %rbx, %rdi
movq %rsi, %r15
callq 0xa550
movq %r15, %rsi
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r15
movq $0x2000000a, (%r15)     # imm = 0x2000000A
movq %r14, 0x8(%r15)
movq (%rsp), %rax
movq %rax, 0x20(%r14)
movq 0x128(%rbx), %rax
movq %rax, 0x10(%r15)
movq 0x110(%rbx), %rax
movq %rax, 0x18(%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%r15)
movq 0x8(%r15), %rax
movq 0x20(%rax), %rax
movl $0x0, 0xc(%rax)
movq 0x8(%r15), %rax
movq 0x20(%rax), %rax
movq $0x0, 0x10(%rax)
movq 0x8(%r15), %rax
movq 0x10(%rsp), %rcx
movq %rcx, 0x28(%rax)
movq %rsi, 0x30(%r14)
movq %r15, 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 0x8(%rsp), %rcx
movq %rcx, (%rax,%r13,8)
movq %rbp, 0x48(%r14)
movl 0x8(%r14), %eax
movl %eax, 0x5c(%r14)
movq 0x10(%r14), %rax
movq %rax, 0x50(%r14)
movq 0x778(%rbx), %rbx
movq (%rbx), %rax
movq 0x10(%rbx), %rsi
cmpq 0x8(%rbx), %rsi
jne 0x5f59a
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)
leaq 0x2f655(%rip), %rax     # 0x8ec02
movq %rax, 0xe720c(%rip)     # 0x1467c0
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq