// File: /workspace/github_c_makefile_star2_O3/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 %r9d, -0x34(%rbp)
movl %ecx, %r13d
movl %edx, %r15d
movl %ecx, -0x30(%rbp)
testq %rdi, %rdi
sete %cl
testq %r8, %r8
sete %dl
xorl %eax, %eax
orb %cl, %dl
jne 0x8143
movq %r8, %r12
movl %esi, %r14d
movq %rdi, %rbx
cmpq $0x0, 0x40(%rdi)
je 0x7f43
movq %rbx, %rdi
callq 0x76df
movq 0x8(%rbx), %rsi
movl %r14d, %edi
callq 0x21c0
movq 0x8(%rbx), %rsi
movl %r15d, %edi
callq 0x21c0
movq %r12, %rdi
callq 0x2130
movslq %eax, %r15
movq 0x8(%rbx), %rcx
movl $0x1, %edx
movq %r12, %rdi
movq %r15, %rsi
callq 0x2390
movq 0x8(%rbx), %rsi
xorl %r12d, %r12d
xorl %edi, %edi
callq 0x21c0
addl $0x3, %r15d
movslq %r15d, %rax
addq %rax, 0x38(%rbx)
leal -0x5(%r14), %eax
cmpl $-0x2, %eax
setb %cl
cmpl $0x14, %r14d
setne %r15b
cmpl $0x1d, %r14d
setne %dl
movb %cl, -0x2a(%rbp)
movb %dl, -0x29(%rbp)
ja 0x7fd0
movl $0x20100018, %eax       # imm = 0x20100018
btl %r14d, %eax
jae 0x8152
movl $0x8, -0x30(%rbp)
movl $0x8, %r13d
movq 0x8(%rbx), %rdi
movl %r13d, %r13d
movq %r13, %rsi
callq 0x773d
cltq
addq %rax, 0x38(%rbx)
movl -0x34(%rbp), %eax
cmpl %eax, 0x68(%rbx)
cmovael %eax, %r12d
movq 0x8(%rbx), %rdi
movq %r12, %rsi
callq 0x773d
cltq
addq %rax, 0x38(%rbx)
movl 0x6c(%rbx), %ecx
leal 0x1(%rcx), %eax
movl %eax, 0x6c(%rbx)
cmpl 0x118(%rbx), %eax
jne 0x806e
movq 0x100(%rbx), %rax
cmpq 0x110(%rbx), %rax
jae 0x806e
addl $0xf4241, %ecx          # imm = 0xF4241
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 0x806e
movl %ecx, %esi
callq 0x22c0
movq %rax, 0x30(%rbx)
movl -0x34(%rbp), %eax
testl %r12d, %r12d
jne 0x8143
andb -0x29(%rbp), %r15b
xorl %r12d, %r12d
andb -0x2a(%rbp), %r15b
leaq -0x38(%rbp), %r15
movl $0x0, (%r15)
movl $0x0, %eax
cmovneq %r13, %rax
testq %r13, %r13
movq 0x10(%rbx), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
cmovneq %rax, %rsi
callq 0x773d
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 0x816b
movl $0x20100018, %eax       # imm = 0x20100018
btl %r14d, %eax
jae 0x816b
leaq 0xc0(%rbx), %rdi
movq 0x20(%rbx), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x2390
movl -0x30(%rbp), %r12d
addl %r12d, 0x70(%rbx)
movl 0x68(%rbx), %eax
incl %eax
movl %eax, 0x68(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x15, %r14d
jne 0x7fd0
movl $0x0, -0x30(%rbp)
xorl %r13d, %r13d
jmp 0x7fd0
movl -0x30(%rbp), %r14d
testl %r14d, %r14d
je 0x8137
movl %r14d, %r15d
movq 0x20(%rbx), %rsi
movl $0x78, %edi
callq 0x21c0
decl %r15d
jne 0x8177
movl %r14d, %r12d
jmp 0x8137