// File: /workspace/github_c_makefile_star2_O1/bluecmd[P]fst-example/gtkwave/fstapi.c
// Function: fstWriterEmitSectionHeader
static void fstWriterEmitSectionHeader(void *ctx)
{
struct fstWriterContext *xc = (struct fstWriterContext *)ctx;

if(xc)
        {
        unsigned long destlen;
        unsigned char *dmem;
        int rc;

        destlen = xc->maxvalpos;
        dmem = (unsigned char *)malloc(compressBound(destlen));
        rc = compress2(dmem, &destlen, xc->curval_mem, xc->maxvalpos, 4); /* was 9...which caused performance drag on traces with many signals */

        fputc(FST_BL_SKIP, xc->handle);                 /* temporarily tag the section, use FST_BL_VCDATA on finalize */
        xc->section_start = ftello(xc->handle);
#ifdef FST_WRITER_PARALLEL
        if(xc->xc_parent) xc->xc_parent->section_start = xc->section_start;
#endif
        xc->section_header_only = 1;                    /* indicates truncate might be needed */
        fstWriterUint64(xc->handle, 0);                 /* placeholder = section length */
        fstWriterUint64(xc->handle, xc->is_initial_time ? xc->firsttime : xc->curtime);         /* begin time of section */
        fstWriterUint64(xc->handle, xc->curtime);       /* end time of section (placeholder) */
        fstWriterUint64(xc->handle, 0);                 /* placeholder = amount of buffer memory required in reader for full vc traversal */
        fstWriterVarint(xc->handle, xc->maxvalpos);     /* maxvalpos = length of uncompressed data */

        if((rc == Z_OK) && (destlen < xc->maxvalpos))
                {
                fstWriterVarint(xc->handle, destlen);   /* length of compressed data */
                }
                else
                {
                fstWriterVarint(xc->handle, xc->maxvalpos); /* length of (unable to be) compressed data */
                }
        fstWriterVarint(xc->handle, xc->maxhandle);     /* max handle associated with this data (in case of dynamic facility adds) */

        if((rc == Z_OK) && (destlen < xc->maxvalpos))
                {
                fstFwrite(dmem, destlen, 1, xc->handle);
                }
                else /* comparison between compressed / decompressed len tells if compressed */
                {
                fstFwrite(xc->curval_mem, xc->maxvalpos, 1, xc->handle);
                }

        free(dmem);
        }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %r14
movl 0x70(%rdi), %edi
leaq -0x30(%rbp), %r15
movq %rdi, (%r15)
callq 0x2290
movq %rax, %rdi
callq 0x2270
movq %rax, %rbx
movq 0x48(%r14), %rdx
movl 0x70(%r14), %ecx
movq %rax, %rdi
movq %r15, %rsi
movl $0x4, %r8d
callq 0x2300
movl %eax, %r15d
movq (%r14), %rsi
movl $0xff, %edi
callq 0x21c0
movq (%r14), %rdi
callq 0x20b0
movq %rax, 0xb0(%r14)
orb $0x10, 0xe9(%r14)
movq (%r14), %rcx
leaq -0x28(%rbp), %rdi
movq $0x0, (%rdi)
movl $0x8, %r12d
movl $0x8, %esi
movl $0x1, %edx
callq 0x2390
movq (%r14), %rcx
movb 0x74(%r14), %al
andb $0x2, %al
shrb %al
movzbl %al, %eax
movq 0x90(%r14,%rax,8), %rax
movb %al, -0x29(%rbp,%r12)
shrq $0x8, %rax
decq %r12
jne 0x74ec
leaq -0x28(%rbp), %rdi
movl $0x8, %r12d
movl $0x8, %esi
movl $0x1, %edx
callq 0x2390
movq (%r14), %rcx
movq 0x90(%r14), %rax
movb %al, -0x29(%rbp,%r12)
shrq $0x8, %rax
decq %r12
jne 0x751d
leaq -0x28(%rbp), %r12
movl $0x8, %esi
movl $0x1, %edx
movq %r12, %rdi
callq 0x2390
movq (%r14), %rcx
movq $0x0, (%r12)
leaq -0x28(%rbp), %rdi
movl $0x8, %esi
movl $0x1, %edx
callq 0x2390
movq (%r14), %rdi
movl 0x70(%r14), %esi
callq 0x5d3b
testl %r15d, %r15d
jne 0x7582
movq -0x30(%rbp), %rsi
movl 0x70(%r14), %eax
cmpq %rax, %rsi
jae 0x7582
movq (%r14), %rdi
jmp 0x7589
movq (%r14), %rdi
movl 0x70(%r14), %esi
callq 0x5d3b
movq (%r14), %rdi
movl 0x68(%r14), %esi
callq 0x5d3b
testl %r15d, %r15d
jne 0x75b9
movq -0x30(%rbp), %rsi
movl 0x70(%r14), %eax
cmpq %rax, %rsi
jae 0x75b9
movq (%r14), %rcx
movl $0x1, %edx
movq %rbx, %rdi
jmp 0x75c9
movq (%r14), %rcx
movq 0x48(%r14), %rdi
movl 0x70(%r14), %esi
movl $0x1, %edx
callq 0x2390
movq %rbx, %rdi
callq 0x2050
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq