// File: /workspace/github_c_makefile_star2_O0/bluecmd[P]fst-example/gtkwave/fstapi.c
// Function: fstReaderRecreateHierFile
static int fstReaderRecreateHierFile(struct fstReaderContext *xc)
{
int pass_status = 1;

if(!xc->fh)
        {
        off_t offs_cache = ftello(xc->f);
        char *fnam = (char *)malloc(strlen(xc->filename) + 6 + 16 + 32 + 1);
        unsigned char *mem = (unsigned char *)malloc(FST_GZIO_LEN);
        off_t hl, uclen;
        off_t clen = 0;
        gzFile zhandle = NULL;
        int zfd;
        int htyp = FST_BL_SKIP;

        /* can't handle both set at once should never happen in a real file */
        if(!xc->contains_hier_section_lz4 && xc->contains_hier_section)
                {
                htyp = FST_BL_HIER;
                }
        else
        if(xc->contains_hier_section_lz4 && !xc->contains_hier_section)
                {
                htyp = xc->contains_hier_section_lz4duo ? FST_BL_HIER_LZ4DUO : FST_BL_HIER_LZ4;
                }

        sprintf(fnam, "%s.hier_%d_%p", xc->filename, getpid(), (void *)xc);
        fstReaderFseeko(xc, xc->f, xc->hier_pos, SEEK_SET);
        uclen = fstReaderUint64(xc->f);
#ifndef __MINGW32__
        fflush(xc->f);
#endif
        if(htyp == FST_BL_HIER)
                {
                fstReaderFseeko(xc, xc->f, xc->hier_pos, SEEK_SET);
                uclen = fstReaderUint64(xc->f);
#ifndef __MINGW32__
                fflush(xc->f);
#endif
                zfd = dup(fileno(xc->f));
                zhandle = gzdopen(zfd, "rb");
                if(!zhandle)
                        {
                        close(zfd);
                        free(mem);
                        free(fnam);
                        return(0);
                        }
                }
        else
        if((htyp == FST_BL_HIER_LZ4) || (htyp == FST_BL_HIER_LZ4DUO))
                {
                fstReaderFseeko(xc, xc->f, xc->hier_pos - 8, SEEK_SET); /* get section len */
                clen =  fstReaderUint64(xc->f) - 16;
                uclen = fstReaderUint64(xc->f);
#ifndef __MINGW32__
                fflush(xc->f);
#endif
                }

#ifndef __MINGW32__
        xc->fh = fopen(fnam, "w+b");
        if(!xc->fh)
#endif
                {
                xc->fh = tmpfile_open(&xc->fh_nam);
                free(fnam); fnam = NULL;
                if(!xc->fh)
                        {
                        tmpfile_close(&xc->fh, &xc->fh_nam);
                        free(mem);
                        return(0);
                        }
                }

#ifndef __MINGW32__
        if(fnam) unlink(fnam);
#endif

        if(htyp == FST_BL_HIER)
                {
                for(hl = 0; hl < uclen; hl += FST_GZIO_LEN)
                        {
                        size_t len = ((uclen - hl) > FST_GZIO_LEN) ? FST_GZIO_LEN : (uclen - hl);
                        size_t gzreadlen = gzread(zhandle, mem, len); /* rc should equal len... */
                        size_t fwlen;

                        if(gzreadlen != len)
                                {
                                pass_status = 0;
                                break;
                                }

                        fwlen = fstFwrite(mem, len, 1, xc->fh);
                        if(fwlen != 1)
                                {
                                pass_status = 0;
                                break;
                                }
                        }
                gzclose(zhandle);
                }
        else
        if(htyp == FST_BL_HIER_LZ4DUO)
                {
                unsigned char *lz4_cmem  = (unsigned char *)malloc(clen);
                unsigned char *lz4_ucmem = (unsigned char *)malloc(uclen);
                unsigned char *lz4_ucmem2;
                uint64_t uclen2;
                int skiplen2 = 0;

                fstFread(lz4_cmem, clen, 1, xc->f);

                uclen2 = fstGetVarint64(lz4_cmem, &skiplen2);
                lz4_ucmem2 = (unsigned char *)malloc(uclen2);
                pass_status = (uclen2 == (uint64_t)LZ4_decompress_safe_partial ((char *)lz4_cmem + skiplen2, (char *)lz4_ucmem2, clen - skiplen2, uclen2, uclen2));
                if(pass_status)
                        {
                        pass_status = (uclen == LZ4_decompress_safe_partial ((char *)lz4_ucmem2, (char *)lz4_ucmem, uclen2, uclen, uclen));

                        if(fstFwrite(lz4_ucmem, uclen, 1, xc->fh) != 1)
                                {
                                pass_status = 0;
                                }
                        }

                free(lz4_ucmem2);
                free(lz4_ucmem);
                free(lz4_cmem);
                }
        else
        if(htyp == FST_BL_HIER_LZ4)
                {
                unsigned char *lz4_cmem  = (unsigned char *)malloc(clen);
                unsigned char *lz4_ucmem = (unsigned char *)malloc(uclen);

                fstFread(lz4_cmem, clen, 1, xc->f);
                pass_status = (uclen == LZ4_decompress_safe_partial ((char *)lz4_cmem, (char *)lz4_ucmem, clen, uclen, uclen));

                if(fstFwrite(lz4_ucmem, uclen, 1, xc->fh) != 1)
                        {
                        pass_status = 0;
                        }

                free(lz4_ucmem);
                free(lz4_cmem);
                }
        else /* FST_BL_SKIP */
                {
                pass_status = 0;
                if(xc->fh)
                        {
                        fclose(xc->fh); xc->fh = NULL; /* needed in case .hier file is missing and there are no hier sections */
                        }
                }

        free(mem);
        free(fnam);

        fstReaderFseeko(xc, xc->f, offs_cache, SEEK_SET);
        }

return(pass_status);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x10(%rbp)
movl $0x1, -0x14(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0xb68c
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x20a0
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x180(%rax), %rdi
callq 0x2130
movq %rax, %rdi
addq $0x6, %rdi
addq $0x10, %rdi
addq $0x20, %rdi
addq $0x1, %rdi
callq 0x2280
movq %rax, -0x28(%rbp)
movl $0x8000, %edi           # imm = 0x8000
callq 0x2280
movq %rax, -0x30(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movl $0xff, -0x58(%rbp)
movq -0x10(%rbp), %rax
movb 0x7a(%rax), %al
shrb $0x6, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0xb0b7
movq -0x10(%rbp), %rax
movb 0x7a(%rax), %al
shrb $0x4, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0xb0b7
movl $0x4, -0x58(%rbp)
jmp 0xb103
movq -0x10(%rbp), %rax
movb 0x7a(%rax), %al
shrb $0x6, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0xb101
movq -0x10(%rbp), %rax
movb 0x7a(%rax), %al
shrb $0x4, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0xb101
movq -0x10(%rbp), %rax
movb 0x7a(%rax), %al
shrb $0x5, %al
andb $0x1, %al
movzbl %al, %edx
movl $0x6, %eax
movl $0x7, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x58(%rbp)
jmp 0xb103
movq -0x28(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rax
movq 0x180(%rax), %rax
movq %rax, -0xb0(%rbp)
callq 0x20f0
movq -0xb8(%rbp), %rdi
movq -0xb0(%rbp), %rdx
movl %eax, %ecx
movq -0x10(%rbp), %r8
leaq 0x203af(%rip), %rsi     # 0x2b4ef
movb $0x0, %al
callq 0x2370
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x190(%rax), %rdx
xorl %ecx, %ecx
callq 0xa3d0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0xd4c0
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2290
cmpl $0x4, -0x58(%rbp)
jne 0xb21b
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x190(%rax), %rdx
xorl %ecx, %ecx
callq 0xa3d0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0xd4c0
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2290
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2270
movl %eax, %edi
callq 0x2180
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %edi
leaq 0x20038(%rip), %rsi     # 0x2b21b
callq 0x2100
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0xb219
movl -0x54(%rbp), %edi
callq 0x21b0
movq -0x30(%rbp), %rdi
callq 0x2040
movq -0x28(%rbp), %rdi
callq 0x2040
movl $0x0, -0x4(%rbp)
jmp 0xb692
jmp 0xb27a
cmpl $0x6, -0x58(%rbp)
je 0xb227
cmpl $0x7, -0x58(%rbp)
jne 0xb278
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x190(%rax), %rdx
subq $0x8, %rdx
xorl %ecx, %ecx
callq 0xa3d0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0xd4c0
subq $0x10, %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0xd4c0
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2290
jmp 0xb27a
movq -0x28(%rbp), %rdi
leaq 0x1fc97(%rip), %rsi     # 0x2af1c
callq 0x2330
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0xb306
movq -0x10(%rbp), %rdi
addq $0x106a8, %rdi          # imm = 0x106A8
callq 0x4bd0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rdi
callq 0x2040
movq $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0xb304
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
movq -0x10(%rbp), %rsi
addq $0x106a8, %rsi          # imm = 0x106A8
callq 0x4df0
movq -0x30(%rbp), %rdi
callq 0x2040
movl $0x0, -0x4(%rbp)
jmp 0xb692
jmp 0xb306
cmpq $0x0, -0x28(%rbp)
je 0xb316
movq -0x28(%rbp), %rdi
callq 0x2070
cmpl $0x4, -0x58(%rbp)
jne 0xb3eb
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jge 0xb3dd
movq -0x40(%rbp), %rax
subq -0x38(%rbp), %rax
cmpq $0x8000, %rax           # imm = 0x8000
jle 0xb354
movl $0x8000, %eax           # imm = 0x8000
movq %rax, -0xc0(%rbp)
jmp 0xb363
movq -0x40(%rbp), %rax
subq -0x38(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x50(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x60(%rbp), %rax
movl %eax, %edx
callq 0x2210
cltq
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x60(%rbp), %rax
je 0xb39a
movl $0x0, -0x14(%rbp)
jmp 0xb3dd
movq -0x30(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0x1, %edx
callq 0x78b0
movq %rax, -0x70(%rbp)
cmpq $0x1, -0x70(%rbp)
je 0xb3c8
movl $0x0, -0x14(%rbp)
jmp 0xb3dd
jmp 0xb3ca
movq -0x38(%rbp), %rax
addq $0x8000, %rax           # imm = 0x8000
movq %rax, -0x38(%rbp)
jmp 0xb328
movq -0x50(%rbp), %rdi
callq 0x2030
jmp 0xb664
cmpl $0x7, -0x58(%rbp)
jne 0xb55e
movq -0x48(%rbp), %rdi
callq 0x2280
movq %rax, -0x78(%rbp)
movq -0x40(%rbp), %rdi
callq 0x2280
movq %rax, -0x80(%rbp)
movl $0x0, -0x94(%rbp)
movq -0x78(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movl $0x1, %edx
callq 0x7990
movq -0x78(%rbp), %rdi
leaq -0x94(%rbp), %rsi
callq 0xbc50
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rdi
callq 0x2280
movq %rax, -0x88(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x78(%rbp), %rdi
movslq -0x94(%rbp), %rax
addq %rax, %rdi
movq -0x88(%rbp), %rsi
movq -0x48(%rbp), %rax
movslq -0x94(%rbp), %rcx
subq %rcx, %rax
movl %eax, %edx
movq -0x90(%rbp), %rax
movl %eax, %ecx
movq -0x90(%rbp), %rax
movl %eax, %r8d
callq 0x1c7f0
movl %eax, %ecx
movq -0xc8(%rbp), %rax
movslq %ecx, %rcx
cmpq %rcx, %rax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0xb53b
movq -0x40(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x88(%rbp), %rdi
movq -0x80(%rbp), %rsi
movq -0x90(%rbp), %rax
movl %eax, %edx
movq -0x40(%rbp), %rax
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %eax, %r8d
callq 0x1c7f0
movl %eax, %ecx
movq -0xd0(%rbp), %rax
movslq %ecx, %rcx
cmpq %rcx, %rax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x14(%rbp)
movq -0x80(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0x1, %edx
callq 0x78b0
cmpq $0x1, %rax
je 0xb539
movl $0x0, -0x14(%rbp)
jmp 0xb53b
movq -0x88(%rbp), %rdi
callq 0x2040
movq -0x80(%rbp), %rdi
callq 0x2040
movq -0x78(%rbp), %rdi
callq 0x2040
jmp 0xb662
cmpl $0x6, -0x58(%rbp)
jne 0xb633
movq -0x48(%rbp), %rdi
callq 0x2280
movq %rax, -0xa0(%rbp)
movq -0x40(%rbp), %rdi
callq 0x2280
movq %rax, -0xa8(%rbp)
movq -0xa0(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movl $0x1, %edx
callq 0x7990
movq -0x40(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xa0(%rbp), %rdi
movq -0xa8(%rbp), %rsi
movq -0x48(%rbp), %rax
movl %eax, %edx
movq -0x40(%rbp), %rax
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %eax, %r8d
callq 0x1c7f0
movl %eax, %ecx
movq -0xd8(%rbp), %rax
movslq %ecx, %rcx
cmpq %rcx, %rax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x14(%rbp)
movq -0xa8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0x1, %edx
callq 0x78b0
cmpq $0x1, %rax
je 0xb619
movl $0x0, -0x14(%rbp)
movq -0xa8(%rbp), %rdi
callq 0x2040
movq -0xa0(%rbp), %rdi
callq 0x2040
jmp 0xb660
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xb65e
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x2110
movq -0x10(%rbp), %rax
movq $0x0, 0x8(%rax)
jmp 0xb660
jmp 0xb662
jmp 0xb664
movq -0x30(%rbp), %rdi
callq 0x2040
movq -0x28(%rbp), %rdi
callq 0x2040
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x20(%rbp), %rdx
xorl %ecx, %ecx
callq 0xa3d0
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nop