// File: /workspace/github_c_makefile_star2_O0/bluecmd[P]fst-example/gtkwave/lz4.c
// Function: LZ4_compress_destSize_generic
static int LZ4_compress_destSize_generic(
                       void* const ctx,
                 const char* const src,
                       char* const dst,
                       int*  const srcSizePtr,
                 const int targetDstSize,
                 const tableType_t tableType)
{
    const BYTE* ip = (const BYTE*) src;
    const BYTE* base = (const BYTE*) src;
    const BYTE* lowLimit = (const BYTE*) src;
    const BYTE* anchor = ip;
    const BYTE* const iend = ip + *srcSizePtr;
    const BYTE* const mflimit = iend - MFLIMIT;
    const BYTE* const matchlimit = iend - LASTLITERALS;

    BYTE* op = (BYTE*) dst;
    BYTE* const oend = op + targetDstSize;
    BYTE* const oMaxLit = op + targetDstSize - 2 /* offset */ - 8 /* because 8+MINMATCH==MFLIMIT */ - 1 /* token */;
    BYTE* const oMaxMatch = op + targetDstSize - (LASTLITERALS + 1 /* token */);
    BYTE* const oMaxSeq = oMaxLit - 1 /* token */;

    U32 forwardH;


    /* Init conditions */
    if (targetDstSize < 1) return 0;                                     /* Impossible to store anything */
    if ((U32)*srcSizePtr > (U32)LZ4_MAX_INPUT_SIZE) return 0;            /* Unsupported input size, too large (or negative) */
    if ((tableType == byU16) && (*srcSizePtr>=LZ4_64Klimit)) return 0;   /* Size too large (not within 64K limit) */
    if (*srcSizePtr<LZ4_minLength) goto _last_literals;                  /* Input too small, no compression (all literals) */

    /* First Byte */
    *srcSizePtr = 0;
    LZ4_putPosition(ip, ctx, tableType, base);
    ip++; forwardH = LZ4_hashPosition(ip, tableType);

    /* Main Loop */
    for ( ; ; )
    {
        const BYTE* match;
        BYTE* token;
        {
            const BYTE* forwardIp = ip;
            unsigned step = 1;
            unsigned searchMatchNb = 1 << LZ4_skipTrigger;

            /* Find a match */
            do {
                U32 h = forwardH;
                ip = forwardIp;
                forwardIp += step;
                step = (searchMatchNb++ >> LZ4_skipTrigger);

                if (unlikely(forwardIp > mflimit))
                    goto _last_literals;

                match = LZ4_getPositionOnHash(h, ctx, tableType, base);
                forwardH = LZ4_hashPosition(forwardIp, tableType);
                LZ4_putPositionOnHash(ip, h, ctx, tableType, base);

            } while ( ((tableType==byU16) ? 0 : (match + MAX_DISTANCE < ip))
                || (LZ4_read32(match) != LZ4_read32(ip)) );
        }

        /* Catch up */
        while ((ip>anchor) && (match > lowLimit) && (unlikely(ip[-1]==match[-1]))) { ip--; match--; }

        {
            /* Encode Literal length */
            unsigned litLength = (unsigned)(ip - anchor);
            token = op++;
            if (op + ((litLength+240)/255) + litLength > oMaxLit)
            {
                /* Not enough space for a last match */
                op--;
                goto _last_literals;
            }
            if (litLength>=RUN_MASK)
            {
                unsigned len = litLength - RUN_MASK;
                *token=(RUN_MASK<<ML_BITS);
                for(; len >= 255 ; len-=255) *op++ = 255;
                *op++ = (BYTE)len;
            }
            else *token = (BYTE)(litLength<<ML_BITS);

            /* Copy Literals */
            LZ4_wildCopy(op, anchor, op+litLength);
            op += litLength;
        }

_next_match:
        /* Encode Offset */
        LZ4_writeLE16(op, (U16)(ip-match)); op+=2;

        /* Encode MatchLength */
        {
            size_t matchLength;

            matchLength = LZ4_count(ip+MINMATCH, match+MINMATCH, matchlimit);

            if (op + ((matchLength+240)/255) > oMaxMatch)
            {
                /* Match description too long : reduce it */
                matchLength = (15-1) + (oMaxMatch-op) * 255;
            }
            /*printf("offset %5i, matchLength%5i \n", (int)(ip-match), matchLength + MINMATCH);*/
            ip += MINMATCH + matchLength;

            if (matchLength>=ML_MASK)
            {
                *token += ML_MASK;
                matchLength -= ML_MASK;
                while (matchLength >= 255) { matchLength-=255; *op++ = 255; }
                *op++ = (BYTE)matchLength;
            }
            else *token += (BYTE)(matchLength);
        }

        anchor = ip;

        /* Test end of block */
        if (ip > mflimit) break;
        if (op > oMaxSeq) break;

        /* Fill table */
        LZ4_putPosition(ip-2, ctx, tableType, base);

        /* Test next position */
        match = LZ4_getPosition(ip, ctx, tableType, base);
        LZ4_putPosition(ip, ctx, tableType, base);
        if ( (match+MAX_DISTANCE>=ip)
            && (LZ4_read32(match)==LZ4_read32(ip)) )
        { token=op++; *token=0; goto _next_match; }

        /* Prepare next loop */
        forwardH = LZ4_hashPosition(++ip, tableType);
    }

_last_literals:
    /* Encode Last Literals */
    {
        size_t lastRunSize = (size_t)(iend - anchor);
        if (op + 1 /* token */ + ((lastRunSize+240)/255) /* litLength */ + lastRunSize /* literals */ > oend)
        {
            /* adapt lastRunSize to fill 'dst' */
            lastRunSize  = (oend-op) - 1;
            lastRunSize -= (lastRunSize+240)/255;
        }
        ip = anchor + lastRunSize;

        if (lastRunSize >= RUN_MASK)
        {
            size_t accumulator = lastRunSize - RUN_MASK;
            *op++ = RUN_MASK << ML_BITS;
            for(; accumulator >= 255 ; accumulator-=255) *op++ = 255;
            *op++ = (BYTE) accumulator;
        }
        else
        {
            *op++ = (BYTE)(lastRunSize<<ML_BITS);
        }
        memcpy(op, anchor, lastRunSize);
        op += lastRunSize;
    }

    /* End */
    *srcSizePtr = (int) (((const char*)ip)-src);
    return (int) (((char*)op)-dst);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movl %r9d, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rcx
movslq (%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
addq $-0xc, %rax
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
addq $-0x5, %rax
movq %rax, -0x68(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movslq -0x2c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
movslq -0x2c(%rbp), %rcx
addq %rcx, %rax
addq $-0x2, %rax
addq $-0x8, %rax
addq $-0x1, %rax
movq %rax, -0x80(%rbp)
movq -0x70(%rbp), %rax
movslq -0x2c(%rbp), %rcx
addq %rcx, %rax
addq $-0x6, %rax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x90(%rbp)
cmpl $0x1, -0x2c(%rbp)
jge 0x289f6
movl $0x0, -0x4(%rbp)
jmp 0x29134
movq -0x28(%rbp), %rax
cmpl $0x7e000000, (%rax)     # imm = 0x7E000000
jbe 0x28a0e
movl $0x0, -0x4(%rbp)
jmp 0x29134
cmpl $0x2, -0x30(%rbp)
jne 0x28a2c
movq -0x28(%rbp), %rax
cmpl $0x1000b, (%rax)        # imm = 0x1000B
jl 0x28a2c
movl $0x0, -0x4(%rbp)
jmp 0x29134
movq -0x28(%rbp), %rax
cmpl $0xd, (%rax)
jge 0x28a3a
jmp 0x28fb1
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x30(%rbp), %edx
movq -0x40(%rbp), %rcx
callq 0x17d10
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0x282d0
movl %eax, -0x94(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0xb0(%rbp)
movl $0x1, -0xb4(%rbp)
movl $0x40, -0xb8(%rbp)
movl -0x94(%rbp), %eax
movl %eax, -0xbc(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0xb4(%rbp), %ecx
movq -0xb0(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0xb0(%rbp)
movl -0xb8(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0xb8(%rbp)
shrl $0x6, %eax
movl %eax, -0xb4(%rbp)
movq -0xb0(%rbp), %rax
cmpq -0x60(%rbp), %rax
seta %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x28b0a
jmp 0x28fb1
movl -0xbc(%rbp), %edi
movq -0x10(%rbp), %rsi
movl -0x30(%rbp), %edx
movq -0x40(%rbp), %rcx
callq 0x28300
movq %rax, -0xa0(%rbp)
movq -0xb0(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0x282d0
movl %eax, -0x94(%rbp)
movq -0x38(%rbp), %rdi
movl -0xbc(%rbp), %esi
movq -0x10(%rbp), %rdx
movl -0x30(%rbp), %ecx
movq -0x40(%rbp), %r8
callq 0x28380
cmpl $0x2, -0x30(%rbp)
jne 0x28b6d
movb $0x1, %al
xorl %ecx, %ecx
testb $0x1, %cl
movb %al, -0xe1(%rbp)
jne 0x28bb7
jmp 0x28b89
movq -0xa0(%rbp), %rcx
addq $0xffff, %rcx           # imm = 0xFFFF
movb $0x1, %al
cmpq -0x38(%rbp), %rcx
movb %al, -0xe1(%rbp)
jb 0x28bb7
movq -0xa0(%rbp), %rdi
callq 0x28420
movl %eax, -0xe8(%rbp)
movq -0x38(%rbp), %rdi
callq 0x28420
movl %eax, %ecx
movl -0xe8(%rbp), %eax
cmpl %ecx, %eax
setne %al
movb %al, -0xe1(%rbp)
movb -0xe1(%rbp), %al
testb $0x1, %al
jne 0x28a95
jmp 0x28bc7
movq -0x38(%rbp), %rcx
xorl %eax, %eax
cmpq -0x50(%rbp), %rcx
movb %al, -0xe9(%rbp)
jbe 0x28c25
movq -0xa0(%rbp), %rcx
xorl %eax, %eax
cmpq -0x48(%rbp), %rcx
movb %al, -0xe9(%rbp)
jbe 0x28c25
movq -0x38(%rbp), %rax
movzbl -0x1(%rax), %eax
movq -0xa0(%rbp), %rcx
movzbl -0x1(%rcx), %ecx
cmpl %ecx, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
setne %al
movb %al, -0xe9(%rbp)
movb -0xe9(%rbp), %al
testb $0x1, %al
jne 0x28c31
jmp 0x28c54
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
movq -0xa0(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0xa0(%rbp)
jmp 0x28bc7
movq -0x38(%rbp), %rax
movq -0x50(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0xc0(%rbp)
movq -0x70(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x70(%rbp)
movq %rax, -0xa8(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0xf8(%rbp)
movl -0xc0(%rbp), %eax
addl $0xf0, %eax
movl $0xff, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
movq -0xf8(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movl -0xc0(%rbp), %ecx
addq %rcx, %rax
cmpq -0x80(%rbp), %rax
jbe 0x28cc8
movq -0x70(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x28fb1
cmpl $0xf, -0xc0(%rbp)
jb 0x28d36
movl -0xc0(%rbp), %eax
subl $0xf, %eax
movl %eax, -0xc4(%rbp)
movq -0xa8(%rbp), %rax
movb $-0x10, (%rax)
cmpl $0xff, -0xc4(%rbp)
jb 0x28d1b
movq -0x70(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x70(%rbp)
movb $-0x1, (%rax)
movl -0xc4(%rbp), %eax
subl $0xff, %eax
movl %eax, -0xc4(%rbp)
jmp 0x28cea
movl -0xc4(%rbp), %eax
movb %al, %cl
movq -0x70(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x70(%rbp)
movb %cl, (%rax)
jmp 0x28d4a
movl -0xc0(%rbp), %eax
shll $0x4, %eax
movb %al, %cl
movq -0xa8(%rbp), %rax
movb %cl, (%rax)
movq -0x70(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x70(%rbp), %rdx
movl -0xc0(%rbp), %eax
addq %rax, %rdx
callq 0x28440
movl -0xc0(%rbp), %ecx
movq -0x70(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
movq -0x38(%rbp), %rax
movq -0xa0(%rbp), %rcx
subq %rcx, %rax
movzwl %ax, %esi
callq 0x284b0
movq -0x70(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x70(%rbp)
movq -0x38(%rbp), %rdi
addq $0x4, %rdi
movq -0xa0(%rbp), %rsi
addq $0x4, %rsi
movq -0x68(%rbp), %rdx
callq 0x28510
movl %eax, %eax
movq %rax, -0xd0(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0xd0(%rbp), %rax
addq $0xf0, %rax
movl $0xff, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0x100(%rbp), %rax
addq %rcx, %rax
cmpq -0x88(%rbp), %rax
jbe 0x28e1a
movq -0x88(%rbp), %rax
movq -0x70(%rbp), %rcx
subq %rcx, %rax
imulq $0xff, %rax, %rax
addq $0xe, %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
addq $0x4, %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0xf, -0xd0(%rbp)
jb 0x28ea9
movq -0xa8(%rbp), %rax
movzbl (%rax), %ecx
addl $0xf, %ecx
movb %cl, (%rax)
movq -0xd0(%rbp), %rax
subq $0xf, %rax
movq %rax, -0xd0(%rbp)
cmpq $0xff, -0xd0(%rbp)
jb 0x28e8d
movq -0xd0(%rbp), %rax
subq $0xff, %rax
movq %rax, -0xd0(%rbp)
movq -0x70(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x70(%rbp)
movb $-0x1, (%rax)
jmp 0x28e58
movq -0xd0(%rbp), %rax
movb %al, %cl
movq -0x70(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x70(%rbp)
movb %cl, (%rax)
jmp 0x28ec1
movq -0xd0(%rbp), %rax
movzbl %al, %edx
movq -0xa8(%rbp), %rax
movzbl (%rax), %ecx
addl %edx, %ecx
movb %cl, (%rax)
movq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x60(%rbp), %rax
jbe 0x28ed8
jmp 0x28faf
movq -0x70(%rbp), %rax
cmpq -0x90(%rbp), %rax
jbe 0x28eea
jmp 0x28faf
movq -0x38(%rbp), %rdi
addq $-0x2, %rdi
movq -0x10(%rbp), %rsi
movl -0x30(%rbp), %edx
movq -0x40(%rbp), %rcx
callq 0x17d10
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x30(%rbp), %edx
movq -0x40(%rbp), %rcx
callq 0x286b0
movq %rax, -0xa0(%rbp)
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x30(%rbp), %edx
movq -0x40(%rbp), %rcx
callq 0x17d10
movq -0xa0(%rbp), %rax
addq $0xffff, %rax           # imm = 0xFFFF
cmpq -0x38(%rbp), %rax
jb 0x28f90
movq -0xa0(%rbp), %rdi
callq 0x28420
movl %eax, -0x104(%rbp)
movq -0x38(%rbp), %rdi
callq 0x28420
movl %eax, %ecx
movl -0x104(%rbp), %eax
cmpl %ecx, %eax
jne 0x28f90
movq -0x70(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x70(%rbp)
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movb $0x0, (%rax)
jmp 0x28d77
movq -0x38(%rbp), %rdi
addq $0x1, %rdi
movq %rdi, -0x38(%rbp)
movl -0x30(%rbp), %esi
callq 0x282d0
movl %eax, -0x94(%rbp)
jmp 0x28a76
jmp 0x28fb1
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0xd8(%rbp)
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x110(%rbp)
movq -0xd8(%rbp), %rax
addq $0xf0, %rax
movl $0xff, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0x110(%rbp), %rax
addq %rcx, %rax
addq -0xd8(%rbp), %rax
cmpq -0x78(%rbp), %rax
jbe 0x29044
movq -0x78(%rbp), %rax
movq -0x70(%rbp), %rcx
subq %rcx, %rax
subq $0x1, %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
addq $0xf0, %rax
movl $0xff, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0xd8(%rbp), %rax
subq %rcx, %rax
movq %rax, -0xd8(%rbp)
movq -0x50(%rbp), %rax
addq -0xd8(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0xf, -0xd8(%rbp)
jb 0x290d2
movq -0xd8(%rbp), %rax
subq $0xf, %rax
movq %rax, -0xe0(%rbp)
movq -0x70(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x70(%rbp)
movb $-0x10, (%rax)
cmpq $0xff, -0xe0(%rbp)
jb 0x290b6
movq -0x70(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x70(%rbp)
movb $-0x1, (%rax)
movq -0xe0(%rbp), %rax
subq $0xff, %rax
movq %rax, -0xe0(%rbp)
jmp 0x29081
movq -0xe0(%rbp), %rax
movb %al, %cl
movq -0x70(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x70(%rbp)
movb %cl, (%rax)
jmp 0x290f0
movq -0xd8(%rbp), %rax
shlq $0x4, %rax
movb %al, %cl
movq -0x70(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x70(%rbp)
movb %cl, (%rax)
movq -0x70(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0xd8(%rbp), %rdx
callq 0x2250
movq -0xd8(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x70(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq