// File: /workspace/github_c_makefile_star2_O2/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, %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 0x59a9
movq %r8, %r12
movl %esi, %r14d
movq %rdi, %rbx
movl %r9d, -0x34(%rbp)
cmpq $0x0, 0x40(%rdi)
je 0x57bc
movq %rbx, %rdi
callq 0x4f8c
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
pushq $0x1
popq %rdx
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 0x5845
movl $0x20100018, %eax       # imm = 0x20100018
btl %r14d, %eax
jae 0x59b8
movl $0x8, -0x30(%rbp)
pushq $0x8
popq %r13
movq 0x8(%rbx), %rdi
movl %r13d, %r13d
movq %r13, %rsi
callq 0x5060
cltq
addq %rax, 0x38(%rbx)
movl -0x34(%rbp), %eax
cmpl %eax, 0x68(%rbx)
cmovael %eax, %r12d
movq 0x8(%rbx), %rdi
movq %r12, %rsi
callq 0x5060
cltq
addq %rax, 0x38(%rbx)
movl 0x6c(%rbx), %ecx
leal 0x1(%rcx), %eax
movl %eax, 0x6c(%rbx)
cmpl 0x118(%rbx), %eax
jne 0x58e3
movq 0x100(%rbx), %rax
cmpq 0x110(%rbx), %rax
jae 0x58e3
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 0x58e3
movl %ecx, %esi
callq 0x22c0
movq %rax, 0x30(%rbx)
movl -0x34(%rbp), %eax
testl %r12d, %r12d
jne 0x59a9
andb -0x29(%rbp), %r15b
andb -0x2a(%rbp), %r15b
leaq -0x38(%rbp), %rax
andl $0x0, (%rax)
xorl %eax, %eax
testb %r15b, %r15b
cmovneq %r13, %rax
testq %r13, %r13
movq 0x10(%rbx), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
cmovneq %rax, %rsi
callq 0x5060
leaq 0x70(%rbx), %rdi
movq 0x18(%rbx), %rcx
pushq $0x4
popq %r12
pushq $0x1
popq %r13
movq %r12, %rsi
movq %r13, %rdx
callq 0x2390
movq 0x18(%rbx), %rcx
leaq -0x30(%rbp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x2390
movq 0x18(%rbx), %rcx
leaq -0x38(%rbp), %r15
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x2390
movq 0x18(%rbx), %rcx
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x2390
cmpl $0x1d, %r14d
ja 0x59ce
movl $0x20100018, %eax       # imm = 0x20100018
btl %r14d, %eax
jae 0x59ce
leaq 0xc0(%rbx), %rdi
movq 0x20(%rbx), %rcx
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
callq 0x2390
movl -0x30(%rbp), %r15d
addl %r15d, 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 0x5845
andl $0x0, -0x30(%rbp)
xorl %r13d, %r13d
jmp 0x5845
movl -0x30(%rbp), %r15d
pushq $0x78
popq %r14
movl %r15d, %r12d
subl $0x1, %r12d
jb 0x599d
movq 0x20(%rbx), %rsi
movl %r14d, %edi
callq 0x21c0
jmp 0x59d9