// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rcx, %r10
movq %rdx, %r13
movq %rsi, -0x48(%rbp)
movl (%rcx), %eax
testl %r8d, %r8d
setle %cl
cmpl $0x7e000001, %eax       # imm = 0x7E000001
setae %dl
xorl %r12d, %r12d
orb %cl, %dl
jne 0x14ae0
cmpl $0x2, %r9d
sete %cl
cmpl $0x1000b, %eax          # imm = 0x1000B
setge %dl
testb %dl, %cl
jne 0x14ae0
movslq %eax, %rsi
movslq %r8d, %r8
movabsq $-0x7f7f7f7f7f7f7f7f, %rbx # imm = 0x8080808080808081
movq %r13, %r15
movq -0x48(%rbp), %r12
movq %r12, %r11
cmpl $0xd, %eax
movq %r10, -0xa0(%rbp)
jl 0x149fc
xorl %ecx, %ecx
cmpl $0x2, %r9d
sete %cl
movl $0x0, (%r10)
orl $0xc, %ecx
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
shll %cl, %ebx
movabsq $0xcf1bbcdcbb, %rdx     # imm = 0xCF1BBCDCBB
movq (%r12), %rax
imulq %rdx, %rax
movl $0x28, %r11d
subl %ecx, %r11d
movl %r11d, %ecx
shrq %cl, %rax
notl %ebx
andl %ebx, %eax
cmpl $0x2, %r9d
jne 0x14524
movw $0x0, (%rdi,%rax,2)
jmp 0x1452b
movl $0x0, (%rdi,%rax,4)
leaq (%r12,%rsi), %rax
addq $-0xc, %rax
movq %rax, -0x70(%rbp)
movq %rsi, -0x50(%rbp)
leaq -0x5(%r12,%rsi), %rax
movq %rax, -0xb8(%rbp)
leaq -0xb(%r13,%r8), %rax
movq %rax, -0x78(%rbp)
leaq -0x6(%r13,%r8), %rax
movq %rax, -0xb0(%rbp)
movq %r8, -0x90(%rbp)
leaq -0xc(%r13,%r8), %rax
movq %rax, -0xa8(%rbp)
leaq 0x1(%r12), %rax
movq %r13, %rsi
movq 0x1(%r12), %r15
movabsq $0xcf1bbcdcbb, %r13     # imm = 0xCF1BBCDCBB
imulq %r13, %r15
movq %r11, -0x68(%rbp)
movl %r11d, %ecx
shrq %cl, %r15
andl %ebx, %r15d
movq %rsi, -0x98(%rbp)
movq %r12, %r11
movl %r9d, -0x40(%rbp)
movq %rdi, -0x58(%rbp)
movl %ebx, -0x3c(%rbp)
movq %rsi, -0x30(%rbp)
movl $0x40, %esi
movl $0x1, %r10d
movq %r14, %rdx
movq -0x68(%rbp), %rcx
movl %r10d, %r8d
addq %rax, %r8
cmpq -0x70(%rbp), %r8
ja 0x1463a
movl %r15d, %r10d
cmpl $0x1, %r9d
jne 0x145dd
movl (%rdi,%r10,4), %edx
jmp 0x145e2
movzwl (%rdi,%r10,2), %edx
movq (%r8), %r15
imulq %r13, %r15
shrq %cl, %r15
addq %r12, %rdx
andl %ebx, %r15d
movl %eax, %r14d
subl %r12d, %r14d
cmpl $0x2, %r9d
jne 0x14605
movw %r14w, (%rdi,%r10,2)
jmp 0x14609
movl %r14d, (%rdi,%r10,4)
xorl %r10d, %r10d
cmpq -0x70(%rbp), %r8
ja 0x14645
cmpl $0x2, %r9d
je 0x14624
leaq 0xffff(%rdx), %r10
cmpq %rax, %r10
jb 0x1462c
movl (%rdx), %r10d
cmpl (%rax), %r10d
je 0x14642
movl %esi, %r10d
shrl $0x6, %r10d
incl %esi
movq %r8, %rax
jmp 0x145c2
movl $0x2, %r10d
jmp 0x1460c
xorl %r10d, %r10d
testl %r10d, %r10d
je 0x14656
movq %rdx, %r14
movq -0x30(%rbp), %rsi
jmp 0x149c6
movl %eax, %ecx
subl %r11d, %ecx
leal -0x10e(%rcx), %r10d
movl %eax, %edi
shlb $0x4, %dil
movl %r11d, %r8d
shlb $0x4, %r8b
subb %r8b, %dil
xorl %r9d, %r9d
movl %r10d, -0x38(%rbp)
movl %r10d, %ebx
movq %r9, %r13
movl %edi, %r8d
leaq (%rdx,%r9), %r14
leaq (%rax,%r9), %r12
cmpq %r11, %r12
jbe 0x146b3
cmpq -0x48(%rbp), %r14
jbe 0x146b3
movq %r11, %rsi
movb -0x1(%rax,%r13), %r11b
leal -0x1(%rbx), %r10d
leaq -0x1(%r13), %r9
leal -0x10(%r8), %edi
cmpb -0x1(%rdx,%r13), %r11b
movq %rsi, %r11
je 0x14679
subl %r11d, %eax
leal (%rax,%r13), %r9d
leaq (%rcx,%r13), %rax
leal 0xf0(%rax), %edx
movl $0x80808081, %esi       # imm = 0x80808081
imulq %rsi, %rdx
shrq $0x27, %rdx
movq -0x30(%rbp), %rsi
addq %rsi, %rdx
incq %rdx
addq %r9, %rdx
movl $0x2, %r10d
movq %rsi, %rdi
cmpq -0x78(%rbp), %rdx
ja 0x147b2
leaq 0x1(%rsi), %rdi
cmpl $0xf, %eax
jb 0x14790
addl $-0xf, %ecx
addq %r13, %rcx
movb $-0x10, (%rsi)
cmpl $0xfe, %ecx
jbe 0x14789
movl -0x38(%rbp), %eax
movl %eax, %ecx
addq %r13, %rcx
movq %rcx, -0x80(%rbp)
addl %eax, %r13d
movq %rdx, -0x88(%rbp)
movq %r13, %rdx
movl $0x80808081, %eax       # imm = 0x80808081
imulq %rax, %rdx
shrq $0x27, %rdx
incl %edx
movl $0xff, %esi
movq %r11, -0x38(%rbp)
movq %r9, -0x60(%rbp)
callq 0x2190
movq -0x88(%rbp), %rdx
movq -0x60(%rbp), %r9
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %r11
movl -0x80(%rbp), %eax
movl $0x80808081, %r8d       # imm = 0x80808081
imulq %r8, %rax
shrq $0x27, %rax
leaq (%rsi,%rax), %rdi
addq $0x2, %rdi
movl %ebx, %ecx
imulq %r8, %rcx
shrq $0x27, %rcx
movl %ecx, %eax
shll $0x8, %eax
subl %eax, %ecx
addl %r13d, %ecx
movb %cl, (%rdi)
incq %rdi
jmp 0x14793
movb %r8b, (%rsi)
addq %rdi, %r9
movq %r11, %rax
movq (%rax), %rcx
movq %rcx, (%rdi)
addq $0x8, %rdi
addq $0x8, %rax
cmpq %r9, %rdi
jb 0x14799
xorl %r10d, %r10d
movq %r9, %rdi
cmpq -0x78(%rbp), %rdx
jbe 0x147dc
movq %rdi, %rsi
movq %r12, %rax
movq -0x48(%rbp), %r12
movl -0x40(%rbp), %r9d
movq -0x58(%rbp), %rdi
movl -0x3c(%rbp), %ebx
movabsq $0xcf1bbcdcbb, %r13     # imm = 0xCF1BBCDCBB
jmp 0x149c6
movq %rsi, -0x30(%rbp)
movq %r12, %r11
movq -0x48(%rbp), %r12
movl %r11d, %eax
subl %r14d, %eax
movw %ax, (%rdi)
leaq 0x2(%rdi), %rbx
movq %r11, -0x38(%rbp)
movq %rdi, %r13
leaq 0x4(%r11), %rdi
leaq 0x4(%r14), %rsi
movq -0xb8(%rbp), %rdx
callq 0x143d2
movq %rbx, %rsi
movl %eax, %ecx
leaq 0xf0(%rcx), %rax
movabsq $0x101010101010102, %rdx # imm = 0x101010101010102
mulq %rdx
movq %r13, -0x60(%rbp)
leaq (%rdx,%r13), %rax
addq $0x2, %rax
movq -0xb0(%rbp), %rdi
movq %rdi, %rdx
subq %rbx, %rdx
movq %rdx, %rbx
shlq $0x8, %rbx
subq %rdx, %rbx
addq $0xe, %rbx
cmpq %rdi, %rax
cmovbeq %rcx, %rbx
cmpq $0xf, %rbx
jb 0x148d5
movq -0x30(%rbp), %rax
addb $0xf, (%rax)
leaq -0xf(%rbx), %rax
cmpq $0xff, %rax
jb 0x148c0
leaq -0x10e(%rbx), %rax
movabsq $-0x7f7f7f7f7f7f7f7f, %rcx # imm = 0x8080808080808081
mulq %rcx
movq %rdx, %r12
shrq $0x7, %r12
leaq 0x1(%r12), %rdx
movq %rsi, %rdi
movl $0xff, %esi
callq 0x2190
movq %r12, %rax
shlq $0x8, %rax
movq -0x60(%rbp), %rcx
leaq (%rcx,%r12), %rsi
addq $0x3, %rsi
subq %rax, %r12
leaq (%rbx,%r12), %rax
addq $-0x10e, %rax           # imm = 0xFEF2
movq -0x48(%rbp), %r12
movq -0x38(%rbp), %r11
movabsq $0xcf1bbcdcbb, %r13     # imm = 0xCF1BBCDCBB
movb %al, (%rsi)
incq %rsi
jmp 0x148e9
movq -0x30(%rbp), %rax
addb %bl, (%rax)
movq -0x38(%rbp), %r11
movabsq $0xcf1bbcdcbb, %r13     # imm = 0xCF1BBCDCBB
addq %rbx, %r11
addq $0x4, %r11
movl $0x3, %r10d
cmpq -0x70(%rbp), %r11
ja 0x149b3
cmpq -0xa8(%rbp), %rsi
movl -0x40(%rbp), %r9d
movq -0x58(%rbp), %rdi
movl -0x3c(%rbp), %ebx
ja 0x149c3
movq -0x2(%r11), %rax
imulq %r13, %rax
movq -0x68(%rbp), %rcx
shrq %cl, %rax
leaq -0x2(%r11), %rdx
andl %ebx, %eax
subl %r12d, %edx
cmpl $0x2, %r9d
jne 0x1493c
movw %dx, (%rdi,%rax,2)
jmp 0x1493f
movl %edx, (%rdi,%rax,4)
movq (%r11), %rax
imulq %r13, %rax
shrq %cl, %rax
andl %ebx, %eax
cmpl $0x1, %r9d
jne 0x14957
movl (%rdi,%rax,4), %r14d
jmp 0x1495c
movzwl (%rdi,%rax,2), %r14d
movl %r11d, %ecx
subl %r12d, %ecx
cmpl $0x2, %r9d
jne 0x1496e
movw %cx, (%rdi,%rax,2)
jmp 0x14971
movl %ecx, (%rdi,%rax,4)
addq %r12, %r14
leaq 0xffff(%r14), %rax
cmpq %r11, %rax
jb 0x14998
movl (%r14), %eax
cmpl (%r11), %eax
jne 0x14998
leaq 0x1(%rsi), %rdi
movb $0x0, (%rsi)
movq %rsi, -0x30(%rbp)
jmp 0x147e7
movq 0x1(%r11), %r15
imulq %r13, %r15
movq -0x68(%rbp), %rcx
shrq %cl, %r15
leaq 0x1(%r11), %rax
andl %ebx, %r15d
xorl %r10d, %r10d
jmp 0x149c6
movq %r11, %rax
movl -0x40(%rbp), %r9d
movq -0x58(%rbp), %rdi
movl -0x3c(%rbp), %ebx
jmp 0x149c6
movq %r11, %rax
testl %r10d, %r10d
je 0x145ac
addl $-0x2, %r10d
cmpl $0x1, %r10d
ja 0x14af5
movq -0x98(%rbp), %r13
movq %rsi, %r15
movq -0x50(%rbp), %rsi
movabsq $-0x7f7f7f7f7f7f7f7f, %rbx # imm = 0x8080808080808081
movq -0x90(%rbp), %r8
addq %r12, %rsi
addq %r13, %r8
subq %r11, %rsi
leaq 0xf0(%rsi), %rax
mulq %rbx
shrq $0x7, %rdx
leaq (%r15,%rdx), %rax
incq %rax
addq %rsi, %rax
cmpq %r8, %rax
jbe 0x14a40
movq %r15, %rcx
notq %rcx
leaq (%rcx,%r8), %rax
addq $0xf0, %rax
mulq %rbx
leaq (%rcx,%r8), %rsi
shrq $0x7, %rdx
subq %rdx, %rsi
leaq 0x1(%r15), %r12
leaq (%r11,%rsi), %r14
cmpq $0xf, %rsi
jb 0x14ab3
leaq -0xf(%rsi), %rax
movb $-0x10, (%r15)
cmpq $0xff, %rax
jb 0x14aaa
leaq -0x10e(%rsi), %rax
mulq %rbx
movq %rdx, %rbx
shrq $0x7, %rbx
leaq 0x1(%rbx), %rdx
movq %rsi, -0x50(%rbp)
movq %r12, %rdi
movl $0xff, %esi
movq %r11, %r12
callq 0x2190
movq %r12, %r11
movq -0x50(%rbp), %rsi
movq %rbx, %rax
shlq $0x8, %rax
leaq (%rbx,%r15), %r12
addq $0x2, %r12
subq %rax, %rbx
leaq (%rsi,%rbx), %rax
addq $-0x10e, %rax           # imm = 0xFEF2
movb %al, (%r12)
incq %r12
jmp 0x14abb
movl %esi, %eax
shlb $0x4, %al
movb %al, (%r15)
movq %rsi, %rbx
movq %r12, %rdi
movq %r11, %rsi
movq %rbx, %rdx
callq 0x2240
addl %ebx, %r12d
subl -0x48(%rbp), %r14d
movq -0xa0(%rbp), %rax
movl %r14d, (%rax)
subl %r13d, %r12d
movl %r12d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x14ae0