// File: /workspace/github_c_makefile_star2_O0/bluecmd[P]fst-example/gtkwave/fstapi.c
// Function: fstWriterEmitValueChange
void fstWriterEmitValueChange(void *ctx, fstHandle handle, const void *val)
{
struct fstWriterContext *xc = (struct fstWriterContext *)ctx;
const unsigned char *buf = (const unsigned char *)val;
uint32_t offs;
int len;

if(FST_LIKELY((xc) && (handle <= xc->maxhandle)))
        {
        uint32_t fpos;
        uint32_t *vm4ip;

        if(FST_UNLIKELY(!xc->valpos_mem))
                {
                xc->vc_emitted = 1;
                fstWriterCreateMmaps(xc);
                }

        handle--; /* move starting at 1 index to starting at 0 */
        vm4ip = &(xc->valpos_mem[4*handle]);

        len  = vm4ip[1];
        if(FST_LIKELY(len)) /* len of zero = variable length, use fstWriterEmitVariableLengthValueChange */
                {
                if(FST_LIKELY(!xc->is_initial_time))
                        {
                        fpos = xc->vchg_siz;

                        if(FST_UNLIKELY((fpos + len + 10) > xc->vchg_alloc_siz))
                                {
                                xc->vchg_alloc_siz += (xc->fst_break_add_size + len); /* +len added in the case of extremely long vectors and small break add sizes */
                                xc->vchg_mem = (unsigned char *)realloc(xc->vchg_mem, xc->vchg_alloc_siz);
                                if(FST_UNLIKELY(!xc->vchg_mem))
                                        {
                                        fprintf(stderr, FST_APIMESS "Could not realloc() in fstWriterEmitValueChange, exiting.\n");
                                        exit(255);
                                        }
                                }
#ifdef FST_REMOVE_DUPLICATE_VC
                        offs = vm4ip[0];

                        if(len != 1)
                                {
                                if((vm4ip[3]==xc->tchn_idx)&&(vm4ip[2]))
                                        {
                                        unsigned char *old_value = xc->vchg_mem + vm4ip[2] + 4; /* the +4 skips old vm4ip[2] value */
                                        while(*(old_value++) & 0x80) { /* skips over varint encoded "xc->tchn_idx - vm4ip[3]" */ }
                                        memcpy(old_value, buf, len); /* overlay new value */

                                        memcpy(xc->curval_mem + offs, buf, len);
                                        return;
                                        }
                                else
                                        {
                                        if(!memcmp(xc->curval_mem + offs, buf, len))
                                                {
                                                if(!xc->curtime)
                                                        {
                                                        int i;
                                                        for(i=0;i<len;i++)
                                                                {
                                                                if(buf[i]!='x') break;
                                                                }

                                                        if(i<len) return;
                                                        }
                                                        else
                                                        {
                                                        return;
                                                        }
                                                }
                                        }

                                memcpy(xc->curval_mem + offs, buf, len);
                                }
                                else
                                {
                                if((vm4ip[3]==xc->tchn_idx)&&(vm4ip[2]))
                                        {
                                        unsigned char *old_value = xc->vchg_mem + vm4ip[2] + 4; /* the +4 skips old vm4ip[2] value */
                                        while(*(old_value++) & 0x80) { /* skips over varint encoded "xc->tchn_idx - vm4ip[3]" */ }
                                        *old_value = *buf; /* overlay new value */

                                        *(xc->curval_mem + offs) = *buf;
                                        return;
                                        }
                                else
                                        {
                                        if((*(xc->curval_mem + offs)) == (*buf))
                                                {
                                                if(!xc->curtime)
                                                        {
                                                        if(*buf != 'x') return;
                                                        }
                                                        else
                                                        {
                                                        return;
                                                        }
                                                }
                                        }

                                *(xc->curval_mem + offs) = *buf;
                                }
#endif
                        xc->vchg_siz += fstWriterUint32WithVarint32(xc, &vm4ip[2], xc->tchn_idx - vm4ip[3], buf, len); /* do one fwrite op only */
                        vm4ip[3] = xc->tchn_idx;
                        vm4ip[2] = fpos;
                        }
                        else
                        {
                        offs = vm4ip[0];
                        memcpy(xc->curval_mem + offs, buf, len);
                        }
                }
        }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x20(%rbp)
movb %al, -0x41(%rbp)
je 0x613f
movl -0xc(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x68(%rcx), %eax
setbe %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x6349
movq -0x20(%rbp), %rax
cmpq $0x0, 0x40(%rax)
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x618f
movq -0x20(%rbp), %rax
movb 0x74(%rax), %cl
andb $-0x2, %cl
orb $0x1, %cl
movb %cl, 0x74(%rax)
movq -0x20(%rbp), %rdi
callq 0x9510
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
movl -0xc(%rbp), %ecx
shll $0x2, %ecx
movl %ecx, %ecx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x6347
movq -0x20(%rbp), %rax
movb 0x74(%rax), %al
shrb %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x6321
movq -0x20(%rbp), %rax
movl 0xa0(%rax), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
addl -0x30(%rbp), %eax
addl $0xa, %eax
movq -0x20(%rbp), %rcx
cmpl 0xa4(%rcx), %eax
seta %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x62c8
movq -0x20(%rbp), %rax
movq 0x108(%rax), %rdx
movslq -0x30(%rbp), %rax
addq %rax, %rdx
movq -0x20(%rbp), %rax
movl 0xa4(%rax), %ecx
addq %rdx, %rcx
movl %ecx, 0xa4(%rax)
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x20(%rbp), %rax
movl 0xa4(%rax), %eax
movl %eax, %esi
callq 0x22c0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x30(%rax)
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x62c6
movq 0x28d45(%rip), %rax     # 0x2eff0
movq (%rax), %rdi
leaq 0x24d0a(%rip), %rsi     # 0x2afbf
movb $0x0, %al
callq 0x2220
movl $0xff, %edi
callq 0x2380
jmp 0x62c8
movq -0x20(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq $0x8, %rsi
movq -0x20(%rbp), %rax
movl 0x8c(%rax), %edx
movq -0x40(%rbp), %rax
subl 0xc(%rax), %edx
movq -0x28(%rbp), %rcx
movl -0x30(%rbp), %r8d
callq 0x9740
movl %eax, %ecx
movq -0x20(%rbp), %rax
addl 0xa0(%rax), %ecx
movl %ecx, 0xa0(%rax)
movq -0x20(%rbp), %rax
movl 0x8c(%rax), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x34(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0x6345
movq -0x40(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movl -0x2c(%rbp), %eax
addq %rax, %rdi
movq -0x28(%rbp), %rsi
movslq -0x30(%rbp), %rdx
callq 0x2250
jmp 0x6347
jmp 0x6349
addq $0x50, %rsp
popq %rbp
retq
nop