// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
cmpq $0x0, 0x8(%rdi)
je 0x6c8e
pushq $0x1
popq %r12
jmp 0x7102
movq %rdi, %rbx
movq (%rdi), %rdi
callq 0x20b0
movq %rax, -0x48(%rbp)
movq 0x180(%rbx), %r14
movq %r14, %rdi
callq 0x2130
leaq 0x37(%rax), %rdi
callq 0x2270
movq %rax, %r15
movl $0x8000, %edi           # imm = 0x8000
callq 0x2270
movq %rax, -0x58(%rbp)
movzbl 0x7a(%rbx), %eax
movl %eax, %ecx
andl $0x50, %ecx
cmpl $0x10, %ecx
je 0x6ce7
cmpl $0x40, %ecx
jne 0x6ced
andb $0x20, %al
cmpb $0x1, %al
pushq $0x7
popq %r13
sbbl $0x0, %r13d
jmp 0x6cf3
pushq $0x4
popq %r13
jmp 0x6cf3
movl $0xff, %r13d
callq 0x20f0
leaq 0xbbdc(%rip), %rsi      # 0x128db
movq %r15, %rdi
movq %r14, %rdx
movl %eax, %ecx
movq %rbx, %r8
xorl %eax, %eax
callq 0x2370
movq (%rbx), %rsi
movq 0x190(%rbx), %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x6776
movq (%rbx), %rdi
callq 0x835d
movq %rax, %r14
movq (%rbx), %rdi
callq 0x2280
cmpl $0x4, %r13d
jne 0x6db2
movq %r15, -0x38(%rbp)
movq (%rbx), %rsi
movq 0x190(%rbx), %rdx
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x6776
movq (%rbx), %rdi
callq 0x835d
movq %rax, -0x60(%rbp)
movq (%rbx), %rdi
callq 0x2280
movq %rbx, %r15
movq (%rbx), %rdi
callq 0x2260
movl %eax, %edi
callq 0x2180
movl %eax, %r14d
leaq 0xb87e(%rip), %rsi      # 0x12607
movl %eax, %edi
callq 0x2100
movq %rax, -0x30(%rbp)
testq %rax, %rax
je 0x7000
movq $0x0, -0x40(%rbp)
movq %r15, %rbx
movq -0x38(%rbp), %r15
movq -0x60(%rbp), %r14
jmp 0x6e14
movl %r13d, %eax
andl $0xfe, %eax
cmpl $0x6, %eax
jne 0x6e04
movq (%rbx), %rsi
movq 0x190(%rbx), %rdx
addq $-0x8, %rdx
movq $0x0, -0x30(%rbp)
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x6776
movq (%rbx), %rdi
callq 0x835d
addq $-0x10, %rax
movq %rax, -0x40(%rbp)
movq (%rbx), %rdi
callq 0x835d
movq %rax, %r14
movq (%rbx), %rdi
callq 0x2280
jmp 0x6e14
movq $0x0, -0x30(%rbp)
movq $0x0, -0x40(%rbp)
leaq 0x8(%rbx), %r12
leaq 0xb4e9(%rip), %rsi      # 0x12308
movq %r15, %rdi
callq 0x2330
movq %r12, -0x50(%rbp)
movq %rax, (%r12)
testq %rax, %rax
je 0x6e43
testq %r15, %r15
je 0x6e73
movq %r15, %rdi
callq 0x2080
jmp 0x6e76
movq %r14, %r12
callq 0x21f0
movq %rax, %r14
andq $0x0, 0x106a8(%rbx)
movq %rax, 0x8(%rbx)
movq %r15, %rdi
callq 0x2050
testq %r14, %r14
je 0x7114
xorl %r15d, %r15d
movq %r12, %r14
jmp 0x6e76
xorl %r15d, %r15d
cmpl $0x4, %r13d
movq %rbx, -0x68(%rbp)
jne 0x6eff
movq %r15, -0x38(%rbp)
xorl %r13d, %r13d
movq %r14, %r15
movq -0x58(%rbp), %rbx
cmpq %r14, %r13
jge 0x701f
movq %r14, %r12
movl $0x8000, %eax           # imm = 0x8000
cmpq %rax, %r15
movl $0x8000, %r14d          # imm = 0x8000
cmovlq %r15, %r14
movq -0x30(%rbp), %rdi
movq %rbx, %rsi
movl %r14d, %edx
callq 0x2200
cltq
movq $0x0, -0x40(%rbp)
cmpq %rax, %r14
jne 0x7026
movq -0x50(%rbp), %rax
movq (%rax), %rcx
movq %rbx, %rdi
movq %r14, %rsi
pushq $0x1
popq %rdx
callq 0x2390
addq $0x8000, %r13           # imm = 0x8000
addq $-0x8000, %r15          # imm = 0x8000
cmpq $0x1, %rax
movq %r12, %r14
je 0x6e8e
jmp 0x7026
cmpb $0x6, %r13b
je 0x7040
movzbl %r13b, %eax
cmpl $0x7, %eax
jne 0x70c4
movq %r15, -0x38(%rbp)
movq -0x40(%rbp), %r12
movq %r12, %rdi
callq 0x2270
movq %rax, %r15
movq %r14, %rdi
callq 0x2270
movq %rax, -0x30(%rbp)
movq %r14, -0x60(%rbp)
leaq -0x6c(%rbp), %r14
andl $0x0, (%r14)
movq (%rbx), %rcx
movq %r15, %rbx
pushq $0x1
popq %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x20c0
movq %r15, %rdi
movq %r14, %rsi
callq 0x7463
movq %rax, %r13
movq %rax, %rdi
callq 0x2270
movq %rax, %r15
movslq (%r14), %rax
movq %rbx, %rdi
addq %rax, %rdi
subl %eax, %r12d
movq %r15, %rsi
movl %r12d, %edx
movl %r13d, %ecx
movl %r13d, %r8d
callq 0xe482
cltq
xorl %r12d, %r12d
cmpq %rax, %r13
jne 0x6fda
movq %r15, %rdi
movq -0x30(%rbp), %r12
movq %r12, %rsi
movl %r13d, %edx
movq -0x60(%rbp), %r13
movl %r13d, %ecx
movl %r13d, %r8d
callq 0xe482
movslq %eax, %r14
xorq %r13, %r14
movq -0x50(%rbp), %rax
movq (%rax), %rcx
pushq $0x1
popq %rdx
movq %r12, %rdi
movq %r13, %rsi
callq 0x2390
xorq $0x1, %rax
xorl %r12d, %r12d
orq %r14, %rax
sete %r12b
movq %r15, %rdi
callq 0x2050
movq -0x30(%rbp), %rdi
callq 0x2050
movq %rbx, %rdi
callq 0x2050
movq -0x48(%rbp), %r14
movq -0x38(%rbp), %r15
jmp 0x70e0
movl %r14d, %edi
callq 0x21b0
movq -0x58(%rbp), %rdi
callq 0x2050
movq -0x38(%rbp), %rdi
callq 0x2050
jmp 0x7102
pushq $0x1
popq %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rdi
callq 0x2040
movq -0x48(%rbp), %r14
movq -0x38(%rbp), %r15
movq -0x40(%rbp), %r12
jmp 0x70e0
movq -0x40(%rbp), %r13
movq %r13, %rdi
callq 0x2270
movq %rax, %r12
movq %rax, -0x30(%rbp)
movq %r14, %rdi
callq 0x2270
movq %r15, -0x38(%rbp)
movq %rax, %r15
movq (%rbx), %rcx
pushq $0x1
popq %rdx
movq %r12, %rdi
movq %r13, %rsi
callq 0x20c0
movq %r12, %rdi
movq %r15, %rsi
movl %r13d, %edx
movl %r14d, %ecx
movl %r14d, %r8d
callq 0xe482
movslq %eax, %r13
xorq %r14, %r13
movq 0x8(%rbx), %rcx
movq %r15, %rdi
movq %r14, %rsi
pushq $0x1
popq %rdx
callq 0x2390
xorq $0x1, %rax
xorl %r12d, %r12d
orq %r13, %rax
sete %r12b
movq %r15, %rdi
movq -0x38(%rbp), %r15
callq 0x2050
movq -0x30(%rbp), %rdi
callq 0x2050
jmp 0x70dc
movq -0x50(%rbp), %rbx
movq (%rbx), %rdi
xorl %r12d, %r12d
testq %rdi, %rdi
je 0x70dc
callq 0x2110
andq $0x0, (%rbx)
movq -0x48(%rbp), %r14
movq -0x58(%rbp), %rdi
callq 0x2050
movq %r15, %rdi
callq 0x2050
movq -0x68(%rbp), %rdi
movq (%rdi), %rsi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x6776
movl %r12d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $0x106a8, %rbx          # imm = 0x106A8
movq -0x50(%rbp), %rdi
movq %rbx, %rsi
callq 0x3811
movq -0x58(%rbp), %rdi
callq 0x2050
xorl %r12d, %r12d
jmp 0x7102