// File: /workspace/github_c_makefile_star2_O2/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 -0x28(%rbp), %r15
movq %rdi, (%r15)
callq 0x2290
movq %rax, %rdi
callq 0x2270
movq %rax, %rbx
movq 0x48(%r14), %rdx
movl 0x70(%r14), %ecx
pushq $0x4
popq %r8
movq %rax, %rdi
movq %r15, %rsi
callq 0x2300
movl %eax, %r12d
movq (%r14), %rsi
movl $0xff, %edi
callq 0x21c0
movq (%r14), %rdi
callq 0x20b0
movq %rax, 0xb0(%r14)
orb $0x10, 0xe9(%r14)
movq (%r14), %rdi
xorl %esi, %esi
callq 0x502a
movq (%r14), %rdi
movb 0x74(%r14), %al
andb $0x2, %al
shrb %al
movzbl %al, %eax
movq 0x90(%r14,%rax,8), %rsi
callq 0x502a
movq (%r14), %rdi
movq 0x90(%r14), %rsi
callq 0x502a
movq (%r14), %rdi
xorl %esi, %esi
callq 0x502a
movq (%r14), %rdi
movl 0x70(%r14), %esi
callq 0x5060
movl 0x70(%r14), %eax
movq (%r15), %rsi
cmpq %rax, %rsi
cmovaeq %rax, %rsi
testl %r12d, %r12d
cmovneq %rax, %rsi
movq (%r14), %rdi
callq 0x5060
movq (%r14), %rdi
movl 0x68(%r14), %esi
callq 0x5060
movl 0x70(%r14), %esi
testl %r12d, %r12d
jne 0x66f9
movq -0x28(%rbp), %rax
cmpq %rsi, %rax
jae 0x66f9
movq (%r14), %rcx
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %rax, %rsi
jmp 0x6703
movq (%r14), %rcx
movq 0x48(%r14), %rdi
pushq $0x1
popq %rdx
callq 0x2390
movq %rbx, %rdi
callq 0x2050
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq