// File: /workspace/github_c_makefile_star2_O1/bluecmd[P]fst-example/gtkwave/fstapi.c
// Function: fstWriterCreateVar
fstHandle fstWriterCreateVar(void *ctx, enum fstVarType vt, enum fstVarDir vd,
        uint32_t len, const char *nam, fstHandle aliasHandle)
{
struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
unsigned int i;
int nlen, is_real;

if(xc && nam)
        {
        if(xc->valpos_mem)
                {
                fstDestroyMmaps(xc, 0);
                }

        fputc(vt, xc->hier_handle);
        fputc(vd, xc->hier_handle);
        nlen = strlen(nam);
        fstFwrite(nam, nlen, 1, xc->hier_handle);
        fputc(0, xc->hier_handle);
        xc->hier_file_len += (nlen+3);

        if((vt == FST_VT_VCD_REAL) || (vt == FST_VT_VCD_REAL_PARAMETER) || (vt == FST_VT_VCD_REALTIME) || (vt == FST_VT_SV_SHORTREAL))
                {
                is_real = 1;
                len = 8; /* recast number of bytes to that of what a double is */
                }
                else
                {
                is_real = 0;
                if(vt == FST_VT_GEN_STRING)
                        {
                        len = 0;
                        }
                }

        xc->hier_file_len += fstWriterVarint(xc->hier_handle, len);

        if(aliasHandle > xc->maxhandle) aliasHandle = 0;
        xc->hier_file_len += fstWriterVarint(xc->hier_handle, aliasHandle);
        xc->numsigs++;
        if(xc->numsigs == xc->next_huge_break)
                {
                if(xc->fst_break_size < xc->fst_huge_break_size)
                        {
                        xc->next_huge_break += FST_ACTIVATE_HUGE_INC;
                        xc->fst_break_size += xc->fst_orig_break_size;
                        xc->fst_break_add_size += xc->fst_orig_break_add_size;

                        xc->vchg_alloc_siz = xc->fst_break_size + xc->fst_break_add_size;
                        if(xc->vchg_mem)
                                {
                                xc->vchg_mem = (unsigned char *)realloc(xc->vchg_mem, xc->vchg_alloc_siz);
                                }
                        }
                }

        if(!aliasHandle)
                {
                uint32_t zero = 0;

                if(len)
                        {
                        fstWriterVarint(xc->geom_handle, !is_real ? len : 0); /* geom section encodes reals as zero byte */
                        }
                        else
                        {
                        fstWriterVarint(xc->geom_handle, 0xFFFFFFFF);         /* geom section encodes zero len as 32b -1 */
                        }

                fstFwrite(&xc->maxvalpos, sizeof(uint32_t), 1, xc->valpos_handle);
                fstFwrite(&len, sizeof(uint32_t), 1, xc->valpos_handle);
                fstFwrite(&zero, sizeof(uint32_t), 1, xc->valpos_handle);
                fstFwrite(&zero, sizeof(uint32_t), 1, xc->valpos_handle);

                if(!is_real)
                        {
                        for(i=0;i<len;i++)
                                {
                                fputc('x', xc->curval_handle);
                                }
                        }
                        else
                        {
                        fstFwrite(&xc->nan, 8, 1, xc->curval_handle); /* initialize doubles to NaN rather than x */
                        }

                xc->maxvalpos+=len;
                xc->maxhandle++;
                return(xc->maxhandle);
                }
                else
                {
                return(aliasHandle);
                }
        }

return(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, -0x30(%rbp)
testq %rdi, %rdi
sete %al
testq %r8, %r8
sete %cl
xorl %r15d, %r15d
orb %al, %cl
jne 0x6740
movq %r8, %r13
movl %edx, %r12d
movl %esi, %r14d
movq %rdi, %rbx
movl %r9d, -0x34(%rbp)
cmpq $0x0, 0x40(%rdi)
je 0x6550
movq %rbx, %rdi
callq 0x5cdd
movq 0x8(%rbx), %rsi
movl %r14d, %edi
callq 0x21c0
movq 0x8(%rbx), %rsi
movl %r12d, %edi
callq 0x21c0
movq %r13, %rdi
callq 0x2130
movslq %eax, %r12
movq 0x8(%rbx), %rcx
movl $0x1, %edx
movq %r13, %rdi
movq %r12, %rsi
callq 0x2390
movq 0x8(%rbx), %rsi
xorl %r15d, %r15d
xorl %edi, %edi
callq 0x21c0
addl $0x3, %r12d
movslq %r12d, %rax
addq %rax, 0x38(%rbx)
leal -0x5(%r14), %eax
cmpl $-0x2, %eax
setb -0x2a(%rbp)
cmpl $0x14, %r14d
setne %r12b
cmpl $0x1d, %r14d
setne -0x29(%rbp)
ja 0x65d3
movl $0x20100018, %eax       # imm = 0x20100018
btl %r14d, %eax
jae 0x6752
movl $0x8, -0x30(%rbp)
movq 0x8(%rbx), %rdi
movl -0x30(%rbp), %r13d
movq %r13, %rsi
callq 0x5d3b
cltq
addq %rax, 0x38(%rbx)
movl -0x34(%rbp), %eax
cmpl %eax, 0x68(%rbx)
cmovael %eax, %r15d
movq 0x8(%rbx), %rdi
movq %r15, %rsi
callq 0x5d3b
cltq
addq %rax, 0x38(%rbx)
movl 0x6c(%rbx), %eax
movl 0x118(%rbx), %ecx
incl %eax
movl %eax, 0x6c(%rbx)
cmpl %ecx, %eax
jne 0x6673
movq 0x100(%rbx), %rax
cmpq 0x110(%rbx), %rax
jae 0x6673
addl $0xf4240, %ecx          # imm = 0xF4240
movl %ecx, 0x118(%rbx)
addq 0xf0(%rbx), %rax
movq %rax, 0x100(%rbx)
movq 0x30(%rbx), %rdi
movq 0x108(%rbx), %rcx
addq 0xf8(%rbx), %rcx
movq %rcx, 0x108(%rbx)
addq %rax, %rcx
movl %ecx, 0xa4(%rbx)
testq %rdi, %rdi
je 0x6673
movl %ecx, %esi
callq 0x22c0
movq %rax, 0x30(%rbx)
testl %r15d, %r15d
jne 0x6740
andb -0x29(%rbp), %r12b
xorl %eax, %eax
andb -0x2a(%rbp), %r12b
leaq -0x38(%rbp), %r15
movl $0x0, (%r15)
cmovneq %r13, %rax
testq %r13, %r13
movq 0x10(%rbx), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
cmovneq %rax, %rsi
callq 0x5d3b
leaq 0x70(%rbx), %rdi
movq 0x18(%rbx), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2390
movq 0x18(%rbx), %rcx
leaq -0x30(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x2390
movq 0x18(%rbx), %rcx
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
callq 0x2390
movq 0x18(%rbx), %rcx
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
callq 0x2390
cmpl $0x1d, %r14d
ja 0x6768
movl $0x20100018, %eax       # imm = 0x20100018
btl %r14d, %eax
jae 0x6768
leaq 0xc0(%rbx), %rdi
movq 0x20(%rbx), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x2390
movl -0x30(%rbp), %eax
addl %eax, 0x70(%rbx)
movl 0x68(%rbx), %r15d
incl %r15d
movl %r15d, 0x68(%rbx)
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x15, %r14d
jne 0x65d3
movl $0x0, -0x30(%rbp)
jmp 0x65d3
movl -0x30(%rbp), %r14d
testl %r14d, %r14d
je 0x672f
movq 0x20(%rbx), %rsi
movl $0x78, %edi
callq 0x21c0
decl %r14d
jne 0x6771
jmp 0x672f