// File: /workspace/github_c_makefile_star2_O3/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:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x9b1e
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
testq %rdi, %rdi
jne 0x9ad8
movq %rbx, %rdi
callq 0x958e
testl %eax, %eax
je 0x9b1e
movq 0x8(%rbx), %rdi
movb 0x294(%rbx), %al
testb $0x1, %al
je 0x9b15
andb $-0x2, %al
movb %al, 0x294(%rbx)
movl $0x0, 0x280(%rbx)
xorl %esi, %esi
xorl %edx, %edx
callq 0x2320
testl %eax, %eax
jns 0x9b08
orb $0x1, 0x697(%rbx)
movq 0x8(%rbx), %rdi
callq 0x2230
movq 0x8(%rbx), %rdi
callq 0x2220
testl %eax, %eax
je 0x9b2e
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rbx), %rdi
callq 0x21a0
movl %eax, %r14d
cmpl $0x1e, %eax
jae 0x9c12
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 0x9b96
movb %al, (%r15)
incq %r15
jmp 0x9b81
movb $0x0, (%r15)
subl 0x258(%rbx), %r15d
movl %r15d, 0x268(%rbx)
movq 0x8(%rbx), %rdi
callq 0x9de5
cmpl $0x12, %r14d
jne 0x9bc9
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 0x9de5
testl %eax, %eax
je 0x9beb
movl %eax, 0x264(%rbx)
orb $0x1, 0x26c(%rbx)
jmp 0x9c06
movl 0x280(%rbx), %eax
incl %eax
movl %eax, 0x280(%rbx)
movl %eax, 0x264(%rbx)
andb $-0x2, 0x26c(%rbx)
addq $0x248, %rbx            # imm = 0x248
jmp 0x9b20
addl $0xffffff04, %r14d      # imm = 0xFFFFFF04
cmpl $0x3, %r14d
ja 0x9b1e
leaq 0xa532(%rip), %rax      # 0x1415c
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 0x9c8c
movq %r14, %r15
movb %al, (%r15)
incq %r15
movq 0x8(%rbx), %rdi
callq 0x21a0
testl %eax, %eax
jne 0x9c79
movb $0x0, (%r15)
subl 0x258(%rbx), %r15d
movl %r15d, 0x270(%rbx)
movq 0x8(%rbx), %rdi
callq 0x9d9d
movq %rax, 0x260(%rbx)
cmpb $0x0, 0x250(%rbx)
jne 0x9c06
movb 0x251(%rbx), %al
andb $-0x2, %al
cmpb $0x4, %al
jne 0x9c06
xorl %eax, %eax
cmpb $0x0, (%r14,%rax)
leaq 0x1(%rax), %rax
js 0x9ccd
xorl %ecx, %ecx
movq %rcx, %rdx
shlq $0x7, %rdx
movzbl 0x294(%rbx,%rax), %ecx
andl $0x7f, %ecx
orq %rdx, %rcx
decq %rax
jne 0x9cda
movq %rcx, 0x268(%rbx)
jmp 0x9c06
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 0x9d39
movb %al, (%r14)
incq %r14
jmp 0x9d24
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 0x9d6e
movb %al, (%r14)
incq %r14
jmp 0x9d59
movb $0x0, (%r14)
subl 0x260(%rbx), %r14d
movl %r14d, 0x26c(%rbx)
jmp 0x9c06
movb $0x1, 0x248(%rbx)
jmp 0x9c06
movb $0x4, 0x248(%rbx)
jmp 0x9c06