// File: /workspace/github_c_makefile_star2_O1/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 0x6412c
movq %rsi, %rcx
movq 0x8(%rsi), %rsi
movb (%rsi), %bpl
cmpb $0x13, %bpl
jne 0x6413b
movq 0x10(%rsi), %r13
testq %r13, %r13
je 0x64155
cmpb $0x0, (%r13)
je 0x64155
movq $-0x1, %r14
cmpb $0x0, 0x1(%r13,%r14)
leaq 0x1(%r14), %r14
jne 0x6411e
jmp 0x64158
leaq 0xb02a6(%rip), %r13     # 0x1143d9
movl $0x6, %r14d
jmp 0x64162
movq 0xf40(%rbx), %rdx
movq %rbx, %rdi
movl $0x13, %r8d
callq 0x9b739
movq %rax, %r12
jmp 0x64158
xorl %r14d, %r14d
cmpb $0x13, %bpl
jne 0x64402
leaq 0xa8(%r14), %rsi
movq %rbx, %rdi
callq 0xa305
movq %rax, 0x18(%rsp)
movq (%rax), %rbp
leaq 0x88(%rbp), %r12
movb $0x7b, 0x88(%rbp)
testq %r14, %r14
jle 0x6419e
leaq 0x89(%rbp), %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x93e0
leaq 0x30(%rbp), %rax
movq %rax, 0x10(%rsp)
leaq 0x60(%rbp), %rax
movq %rax, 0x8(%rsp)
leaq (%r12,%r14), %rdi
movw $0x2d7d, 0x1(%r12,%r14) # imm = 0x2D7D
movl 0x220(%rbx), %ecx
leal 0x1(%rcx), %eax
movl %eax, 0x220(%rbx)
movb $0x0, 0xb4f(%rbx)
xorl %r15d, %r15d
leaq 0xbb254(%rip), %rsi     # 0x11f430
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,%r15)
decq %r15
cmpq $0x9, %rcx
movq %rdx, %rcx
ja 0x641e6
movl $0x1, %edx
subq %r15, %rdx
addq $0x3, %rdi
leaq (%rbx,%r15), %rsi
addq $0xb4f, %rsi            # imm = 0xB4F
callq 0x93e0
subq %r15, %r14
leaq 0x1(%r14), %rax
addq $0x3, %r14
movq $0x0, (%rsp)
cmpq $0x6, %rax
jg 0x6425b
movq %rsp, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x93e0
jmp 0x6429b
movq 0x88(%rbp), %r15
movq %r15, (%rsp)
leaq 0x20(%rsp), %r13
movq $0x0, (%r13)
leaq 0x90(%rbp), %rsi
cmpq $0x10, %r14
movl $0x10, %edx
cmovlq %r14, %rdx
addq $-0x8, %rdx
movq %r13, %rdi
callq 0x93e0
addq (%r13), %r15
movq %r15, (%rsp)
movabsq $0x4000000001000001, %rsi # imm = 0x4000000001000001
movq (%rsp), %r15
movabsq $-0x7fecfd2d94c4151b, %rcx # imm = 0x801302D26B3BEAE5
movq %r15, %rax
mulq %rcx
shrq $0xe, %rdx
imulq $0x7fed, %rdx, %rax     # imm = 0x7FED
movq %r15, %r13
subq %rax, %r13
leaq 0x12(%rsi), %rax
movq %rax, (%rbp)
movq %r14, 0x8(%rbp)
movq %r12, 0x10(%rbp)
movq %r15, 0x18(%rbp)
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x642fc
movq %rbx, %rdi
movq %rsi, %r14
callq 0xb389
movq %r14, %rsi
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r12
movq $0x2000000a, (%r12)     # imm = 0x2000000A
movq %rbp, 0x8(%r12)
movq 0x8(%rsp), %rax
movq %rax, 0x20(%rbp)
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
movl $0x0, 0xc(%rax)
movq 0x8(%r12), %rax
movq 0x20(%rax), %rax
movq $0x0, 0x10(%rax)
movq 0x8(%r12), %rax
movq 0x18(%rsp), %rcx
movq %rcx, 0x28(%rax)
movq %rsi, 0x30(%rbp)
movq %r12, 0x38(%rbp)
movq 0x148(%rbx), %rax
movq 0x10(%rax), %rax
movq (%rax,%r13,8), %rax
movq %rax, 0x40(%rbp)
movq 0x148(%rbx), %rax
movq 0x10(%rax), %rax
movq 0x10(%rsp), %rcx
movq %rcx, (%rax,%r13,8)
movq %r15, 0x48(%rbp)
movl 0x8(%rbp), %eax
movl %eax, 0x5c(%rbp)
movq 0x10(%rbp), %rax
movq %rax, 0x50(%rbp)
movq 0x778(%rbx), %rbx
movq 0x8(%rbx), %rsi
cmpq %rsi, 0x10(%rbx)
jne 0x643e1
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 %r12, (%rax,%rcx,8)
leaq 0x30b8e(%rip), %rax     # 0x94f89
movq %rax, 0xea3be(%rip)     # 0x14e7c0
movq %r12, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq