// File: /workspace/github_c_makefile_star2_O1/bluecmd[P]fst-example/gtkwave/fstapi.c
// Function: fstReaderIterateHier
struct fstHier *fstReaderIterateHier(void *ctx)
{
struct fstReaderContext *xc = (struct fstReaderContext *)ctx;
int isfeof;
fstHandle alias;
char *pnt;
int ch;

if(!xc) return(NULL);

if(!xc->fh)
        {
        if(!fstReaderRecreateHierFile(xc))
                {
                return(NULL);
                }
        }

if(xc->do_rewind)
        {
        xc->do_rewind = 0;
        xc->current_handle = 0;
        fstReaderFseeko(xc, xc->fh, 0, SEEK_SET);
        clearerr(xc->fh);
        }

if(!(isfeof=feof(xc->fh)))
        {
        int tag = fgetc(xc->fh);
        switch(tag)
                {
                case FST_ST_VCD_SCOPE:
                        xc->hier.htyp = FST_HT_SCOPE;
                        xc->hier.u.scope.typ = fgetc(xc->fh);
                        xc->hier.u.scope.name = pnt = xc->str_scope_nam;
                        while((ch = fgetc(xc->fh)))
                                {
                                *(pnt++) = ch;
                                }; /* scopename */
                        *pnt = 0;
                        xc->hier.u.scope.name_length = pnt - xc->hier.u.scope.name;

                        xc->hier.u.scope.component = pnt = xc->str_scope_comp;
                        while((ch = fgetc(xc->fh)))
                                {
                                *(pnt++) = ch;
                                }; /* scopecomp */
                        *pnt = 0;
                        xc->hier.u.scope.component_length = pnt - xc->hier.u.scope.component;
                        break;

                case FST_ST_VCD_UPSCOPE:
                        xc->hier.htyp = FST_HT_UPSCOPE;
                        break;

                case FST_ST_GEN_ATTRBEGIN:
                        xc->hier.htyp = FST_HT_ATTRBEGIN;
                        xc->hier.u.attr.typ = fgetc(xc->fh);
                        xc->hier.u.attr.subtype = fgetc(xc->fh);
                        xc->hier.u.attr.name = pnt = xc->str_scope_nam;
                        while((ch = fgetc(xc->fh)))
                                {
                                *(pnt++) = ch;
                                }; /* scopename */
                        *pnt = 0;
                        xc->hier.u.attr.name_length = pnt - xc->hier.u.scope.name;

                        xc->hier.u.attr.arg = fstReaderVarint64(xc->fh);

                        if(xc->hier.u.attr.typ == FST_AT_MISC)
                                {
                                if((xc->hier.u.attr.subtype == FST_MT_SOURCESTEM)||(xc->hier.u.attr.subtype == FST_MT_SOURCEISTEM))
                                        {
                                        int sidx_skiplen_dummy = 0;
                                        xc->hier.u.attr.arg_from_name = fstGetVarint64((unsigned char *)xc->str_scope_nam, &sidx_skiplen_dummy);
                                        }
                                }
                        break;

                case FST_ST_GEN_ATTREND:
                        xc->hier.htyp = FST_HT_ATTREND;
                        break;

                case FST_VT_VCD_EVENT:
                case FST_VT_VCD_INTEGER:
                case FST_VT_VCD_PARAMETER:
                case FST_VT_VCD_REAL:
                case FST_VT_VCD_REAL_PARAMETER:
                case FST_VT_VCD_REG:
                case FST_VT_VCD_SUPPLY0:
                case FST_VT_VCD_SUPPLY1:
                case FST_VT_VCD_TIME:
                case FST_VT_VCD_TRI:
                case FST_VT_VCD_TRIAND:
                case FST_VT_VCD_TRIOR:
                case FST_VT_VCD_TRIREG:
                case FST_VT_VCD_TRI0:
                case FST_VT_VCD_TRI1:
                case FST_VT_VCD_WAND:
                case FST_VT_VCD_WIRE:
                case FST_VT_VCD_WOR:
                case FST_VT_VCD_PORT:
                case FST_VT_VCD_SPARRAY:
                case FST_VT_VCD_REALTIME:
                case FST_VT_GEN_STRING:
                case FST_VT_SV_BIT:
                case FST_VT_SV_LOGIC:
                case FST_VT_SV_INT:
                case FST_VT_SV_SHORTINT:
                case FST_VT_SV_LONGINT:
                case FST_VT_SV_BYTE:
                case FST_VT_SV_ENUM:
                case FST_VT_SV_SHORTREAL:
                        xc->hier.htyp = FST_HT_VAR;
                        xc->hier.u.var.svt_workspace = FST_SVT_NONE;
                        xc->hier.u.var.sdt_workspace = FST_SDT_NONE;
                        xc->hier.u.var.sxt_workspace = 0;
                        xc->hier.u.var.typ = tag;
                        xc->hier.u.var.direction = fgetc(xc->fh);
                        xc->hier.u.var.name = pnt = xc->str_scope_nam;
                        while((ch = fgetc(xc->fh)))
                                {
                                *(pnt++) = ch;
                                }; /* varname */
                        *pnt = 0;
                        xc->hier.u.var.name_length = pnt - xc->hier.u.var.name;
                        xc->hier.u.var.length = fstReaderVarint32(xc->fh);
                        if(tag == FST_VT_VCD_PORT)
                                {
                                xc->hier.u.var.length -= 2; /* removal of delimiting spaces */
                                xc->hier.u.var.length /= 3; /* port -> signal size adjust */
                                }

                        alias = fstReaderVarint32(xc->fh);

                        if(!alias)
                                {
                                xc->current_handle++;
                                xc->hier.u.var.handle = xc->current_handle;
                                xc->hier.u.var.is_alias = 0;
                                }
                                else
                                {
                                xc->hier.u.var.handle = alias;
                                xc->hier.u.var.is_alias = 1;
                                }

                        break;

                default:
                        isfeof = 1;
                        break;
                }
        }

return(!isfeof ? &xc->hier : NULL);
}

// Assembly:
testq %rdi, %rdi
je 0x80fd
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
cmpq $0x0, 0x8(%rdi)
jne 0x80ac
movq %rbx, %rdi
callq 0x7b43
testl %eax, %eax
je 0x81bd
movb 0x294(%rbx), %al
testb $0x1, %al
je 0x80e9
andb $-0x2, %al
movb %al, 0x294(%rbx)
movl $0x0, 0x280(%rbx)
movq 0x8(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2320
testl %eax, %eax
jns 0x80e0
orb $0x1, 0x697(%rbx)
movq 0x8(%rbx), %rdi
callq 0x2230
movq 0x8(%rbx), %rdi
callq 0x2220
testl %eax, %eax
je 0x8100
xorl %ecx, %ecx
jmp 0x81de
xorl %eax, %eax
retq
movq 0x8(%rbx), %rdi
callq 0x21a0
movl %eax, %r14d
cmpl $0x1e, %eax
jae 0x81f8
movb $0x2, 0x248(%rbx)
movw $0x0, 0x252(%rbx)
movl $0x0, 0x254(%rbx)
movb %r14b, 0x250(%rbx)
movq 0x8(%rbx), %rdi
callq 0x21a0
movb %al, 0x251(%rbx)
leaq 0x295(%rbx), %r15
movq %r15, 0x258(%rbx)
movq 0x8(%rbx), %rdi
callq 0x21a0
testl %eax, %eax
je 0x8168
movb %al, (%r15)
incq %r15
jmp 0x8153
movb $0x0, (%r15)
subl 0x258(%rbx), %r15d
movl %r15d, 0x268(%rbx)
movq 0x8(%rbx), %rdi
callq 0x83cd
cmpl $0x12, %r14d
jne 0x819b
addl $-0x2, %eax
movl $0xaaaaaaab, %ecx       # imm = 0xAAAAAAAB
imulq %rax, %rcx
shrq $0x21, %rcx
movl %ecx, %eax
movl %eax, 0x260(%rbx)
movq 0x8(%rbx), %rdi
callq 0x83cd
testl %eax, %eax
je 0x81c1
movl %eax, 0x264(%rbx)
orb $0x1, 0x26c(%rbx)
jmp 0x81dc
xorl %eax, %eax
jmp 0x81ed
movl 0x280(%rbx), %eax
incl %eax
movl %eax, 0x280(%rbx)
movl %eax, 0x264(%rbx)
andb $-0x2, 0x26c(%rbx)
movb $0x1, %cl
addq $0x248, %rbx            # imm = 0x248
xorl %eax, %eax
testb %cl, %cl
cmovneq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
addl $0xffffff04, %r14d      # imm = 0xFFFFFF04
cmpl $0x3, %r14d
ja 0x80f6
leaq 0xcf4c(%rip), %rax      # 0x1515c
movslq (%rax,%r14,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movb $0x3, 0x248(%rbx)
movq 0x8(%rbx), %rdi
callq 0x21a0
movb %al, 0x250(%rbx)
movq 0x8(%rbx), %rdi
callq 0x21a0
movb %al, 0x251(%rbx)
leaq 0x295(%rbx), %r14
movq %r14, 0x258(%rbx)
movq 0x8(%rbx), %rdi
callq 0x21a0
movq %r14, %r15
testl %eax, %eax
je 0x8272
movq %r14, %r15
movb %al, (%r15)
incq %r15
movq 0x8(%rbx), %rdi
callq 0x21a0
testl %eax, %eax
jne 0x825f
movb $0x0, (%r15)
subl 0x258(%rbx), %r15d
movl %r15d, 0x270(%rbx)
movq 0x8(%rbx), %rdi
callq 0x8385
movq %rax, 0x260(%rbx)
movb $0x1, %cl
cmpb $0x0, 0x250(%rbx)
jne 0x81de
movb 0x251(%rbx), %al
andb $-0x2, %al
cmpb $0x4, %al
jne 0x81de
xorl %eax, %eax
cmpb $0x0, (%r14,%rax)
leaq 0x1(%rax), %rax
js 0x82b5
xorl %edx, %edx
movq %rdx, %rsi
shlq $0x7, %rsi
movzbl 0x294(%rbx,%rax), %edx
andl $0x7f, %edx
orq %rsi, %rdx
decq %rax
jne 0x82c2
movq %rdx, 0x268(%rbx)
jmp 0x81de
movb $0x0, 0x248(%rbx)
movq 0x8(%rbx), %rdi
callq 0x21a0
movb %al, 0x250(%rbx)
leaq 0x295(%rbx), %r14
movq %r14, 0x258(%rbx)
movq 0x8(%rbx), %rdi
callq 0x21a0
testl %eax, %eax
je 0x8321
movb %al, (%r14)
incq %r14
jmp 0x830c
movb $0x0, (%r14)
subl 0x258(%rbx), %r14d
movl %r14d, 0x268(%rbx)
leaq 0x496(%rbx), %r14
movq %r14, 0x260(%rbx)
movq 0x8(%rbx), %rdi
callq 0x21a0
testl %eax, %eax
je 0x8356
movb %al, (%r14)
incq %r14
jmp 0x8341
movb $0x0, (%r14)
subl 0x260(%rbx), %r14d
movl %r14d, 0x26c(%rbx)
jmp 0x81dc
movb $0x1, 0x248(%rbx)
jmp 0x81dc
movb $0x4, 0x248(%rbx)
jmp 0x81dc