// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/lzf_c.c
// Function: lzf_compress
unsigned int
lzf_compress (const void *const in_data, unsigned int in_len,
	      void *out_data, unsigned int out_len
#if LZF_STATE_ARG
              , LZF_STATE htab
#endif
              )
{
#if !LZF_STATE_ARG
  LZF_STATE htab;
#endif
  const u8 *ip = (const u8 *)in_data;
        u8 *op = (u8 *)out_data;
  const u8 *in_end  = ip + in_len;
        u8 *out_end = op + out_len;
  const u8 *ref;

  /* off requires a type wide enough to hold a general pointer difference.
   * ISO C doesn't have that (size_t might not be enough and ptrdiff_t only
   * works for differences within a single object). We also assume that no
   * no bit pattern traps. Since the only platform that is both non-POSIX
   * and fails to support both assumptions is windows 64 bit, we make a
   * special workaround for it.
   */
#if defined (WIN32) && defined (_M_X64)
  unsigned _int64 off; /* workaround for missing POSIX compliance */
#else
  unsigned long off;
#endif
  unsigned int hval;
  int lit;

  if (!in_len || !out_len)
    return 0;

#if INIT_HTAB
  memset (htab, 0, sizeof (htab));
#endif

  lit = 0; op++; /* start run */

  hval = FRST (ip);
  while (ip < in_end - 2)
    {
      LZF_HSLOT *hslot;

      hval = NEXT (hval, ip);
      hslot = htab + IDX (hval);
      ref = *hslot + LZF_HSLOT_BIAS; *hslot = ip - LZF_HSLOT_BIAS;

      if (1
#if INIT_HTAB
          && ref < ip /* the next test will actually take care of this, but this is faster */
#endif
          && (off = ip - ref - 1) < MAX_OFF
          && ref > (u8 *)in_data
          && ref[2] == ip[2]
#if STRICT_ALIGN
          && ((ref[1] << 8) | ref[0]) == ((ip[1] << 8) | ip[0])
#else
          && *(u16 *)ref == *(u16 *)ip
#endif
        )
        {
          /* match found at *ref++ */
          unsigned int len = 2;
          unsigned int maxlen = in_end - ip - len;
          maxlen = maxlen > MAX_REF ? MAX_REF : maxlen;

          if (expect_false (op + 3 + 1 >= out_end)) /* first a faster conservative test */
            if (op - !lit + 3 + 1 >= out_end) /* second the exact but rare test */
              return 0;

          op [- lit - 1] = lit - 1; /* stop run */
          op -= !lit; /* undo run if length is zero */

          for (;;)
            {
              if (expect_true (maxlen > 16))
                {
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;

                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;

                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;

                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                  len++; if (ref [len] != ip [len]) break;
                }

              do
                len++;
              while (len < maxlen && ref[len] == ip[len]);

              break;
            }

          len -= 2; /* len is now #octets - 1 */
          ip++;

          if (len < 7)
            {
              *op++ = (off >> 8) + (len << 5);
            }
          else
            {
              *op++ = (off >> 8) + (  7 << 5);
              *op++ = len - 7;
            }

          *op++ = off;

          lit = 0; op++; /* start run */

          ip += len + 1;

          if (expect_false (ip >= in_end - 2))
            break;

#if ULTRA_FAST || VERY_FAST
          --ip;
# if VERY_FAST && !ULTRA_FAST
          --ip;
# endif
          hval = FRST (ip);

          hval = NEXT (hval, ip);
          htab[IDX (hval)] = ip - LZF_HSLOT_BIAS;
          ip++;

# if VERY_FAST && !ULTRA_FAST
          hval = NEXT (hval, ip);
          htab[IDX (hval)] = ip - LZF_HSLOT_BIAS;
          ip++;
# endif
#else
          ip -= len + 1;

          do
            {
              hval = NEXT (hval, ip);
              htab[IDX (hval)] = ip - LZF_HSLOT_BIAS;
              ip++;
            }
          while (len--);
#endif
        }
      else
        {
          /* one more literal byte we must copy */
          if (expect_false (op >= out_end))
            return 0;

          lit++; *op++ = *ip++;

          if (expect_false (lit == MAX_LIT))
            {
              op [- lit - 1] = lit - 1; /* stop run */
              lit = 0; op++; /* start run */
            }
        }
    }

  if (op + 3 > out_end) /* at most 3 bytes can be missing here */
    return 0;

  while (ip < in_end)
    {
      lit++; *op++ = *ip++;

      if (expect_false (lit == MAX_LIT))
        {
          op [- lit - 1] = lit - 1; /* stop run */
          lit = 0; op++; /* start run */
        }
    }

  op [- lit - 1] = lit - 1; /* end run */
  op -= !lit; /* undo run if length is zero */

  return op - (u8 *)out_data;
}

// Assembly:
testl %esi, %esi
sete %al
testl %ecx, %ecx
sete %r8b
orb %al, %r8b
jne 0x32f9f
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3ff98, %rsp          # imm = 0x3FF98
movl %esi, %esi
addq %rdi, %rsi
movl %ecx, %eax
addq %rdx, %rax
leaq 0x1(%rdx), %r8
movzwl (%rdi), %ecx
rolw $0x8, %cx
leaq 0x1(%rdi), %r9
movq %r9, -0x78(%rsp)
movzwl %cx, %r14d
leaq -0x2(%rsi), %r9
xorl %r15d, %r15d
movl $0xffff, %r13d          # imm = 0xFFFF
movq %rdi, %rcx
movl %r15d, %r10d
movq %r8, %r12
cmpq %r9, %rcx
jae 0x32fa2
movl %r14d, %r8d
shll $0x8, %r8d
movzbl 0x2(%rcx), %ebp
orl %r8d, %ebp
imull $0xfffb, %ebp, %r8d     # imm = 0xFFFB
addl %r14d, %r8d
movzwl %r8w, %r8d
movl -0x70(%rsp,%r8,4), %r14d
movl %ecx, %r11d
subl %edi, %r11d
movl %r11d, -0x70(%rsp,%r8,4)
testq %r14, %r14
je 0x32e85
leaq (%rdi,%r14), %r8
movq %r8, %r15
notq %r15
addq %rcx, %r15
cmpq $0x1fff, %r15           # imm = 0x1FFF
ja 0x32e85
movb 0x2(%r8), %r11b
cmpb 0x2(%rcx), %r11b
jne 0x32e85
movzwl (%r8), %r11d
cmpw (%rcx), %r11w
jne 0x32e85
movl %esi, %ebx
subl %ecx, %ebx
addl $-0x2, %ebx
movl $0x108, %r11d           # imm = 0x108
cmpl %r11d, %ebx
movl $0x108, %ebp            # imm = 0x108
cmovbl %ebx, %ebp
leaq 0x4(%r12), %r11
cmpq %rax, %r11
jae 0x32f85
leal -0x1(%r10), %r11d
cmpl $0x1, %r10d
notl %r10d
movslq %r10d, %r10
movb %r11b, (%r12,%r10)
sbbq $0x0, %r12
movl $0x2, %r11d
cmpl $0x11, %ebx
jb 0x32e3f
movb 0x3(%r8), %r11b
movl $0x3, %r10d
cmpb 0x3(%rcx), %r11b
jne 0x32ec5
movb 0x4(%r8), %r11b
movl $0x4, %r10d
cmpb 0x4(%rcx), %r11b
jne 0x32ec5
movb 0x5(%r8), %r11b
movl $0x5, %r10d
cmpb 0x5(%rcx), %r11b
jne 0x32ec5
movb 0x6(%r8), %r11b
movl $0x6, %r10d
cmpb 0x6(%rcx), %r11b
jne 0x32ec5
movb 0x7(%r8), %r11b
movl $0x7, %r10d
cmpb 0x7(%rcx), %r11b
jne 0x32ec5
movb 0x8(%r8), %r11b
movl $0x8, %r10d
cmpb 0x8(%rcx), %r11b
jne 0x32ec5
movb 0x9(%r8), %r11b
movl $0x9, %r10d
cmpb 0x9(%rcx), %r11b
jne 0x32f61
movb 0xa(%r8), %r11b
movl $0xa, %r10d
cmpb 0xa(%rcx), %r11b
jne 0x32f61
movb 0xb(%r8), %r11b
movl $0xb, %r10d
cmpb 0xb(%rcx), %r11b
jne 0x32f61
movb 0xc(%r8), %r11b
movl $0xc, %r10d
cmpb 0xc(%rcx), %r11b
jne 0x32f61
movb 0xd(%r8), %r11b
movl $0xd, %r10d
cmpb 0xd(%rcx), %r11b
jne 0x32f61
movb 0xe(%r8), %r11b
movl $0xe, %r10d
cmpb 0xe(%rcx), %r11b
jne 0x32f61
movb 0xf(%r8), %r11b
movl $0xf, %r10d
cmpb 0xf(%rcx), %r11b
jne 0x32f61
movb 0x10(%r8), %r11b
movl $0x10, %r10d
cmpb 0x10(%rcx), %r11b
jne 0x32f61
movb 0x11(%r8), %r11b
movl $0x11, %r10d
cmpb 0x11(%rcx), %r11b
jne 0x32f61
movb 0x12(%r8), %r8b
movl $0x12, %r10d
movl %r10d, %r11d
cmpb 0x12(%rcx), %r8b
jne 0x32f61
movl %r11d, %ebx
movl %ebp, %r8d
orl $0x1, %r11d
cmpl %r11d, %ebp
movl %r11d, %r10d
cmoval %ebp, %r10d
movq %r8, %rbp
addq -0x78(%rsp), %r14
movq %rbx, %r8
incq %rbx
cmpq %rbp, %rbx
jae 0x32e74
movb (%r14,%r8), %r11b
cmpb 0x1(%rcx,%r8), %r11b
je 0x32e5b
movl %ebx, %r10d
decq %r8
incq %rcx
cmpl $0x6, %r8d
jbe 0x32ecc
jmp 0x32f64
cmpq %rax, %r12
jae 0x32fae
leal 0x1(%r10), %r15d
movb (%rcx), %r11b
incq %rcx
leaq 0x1(%r12), %r8
movb %r11b, (%r12)
movl %ebp, %r14d
cmpl $0x20, %r15d
jne 0x32c37
movb %r10b, -0x20(%r12)
addq $0x2, %r12
xorl %r15d, %r15d
movq %r12, %r8
movl %ebp, %r14d
jmp 0x32c37
leal -0x2(%r10), %r8d
incq %rcx
movl %r15d, %r11d
shrl $0x8, %r11d
shll $0x5, %r8d
orl %r11d, %r8d
movb %r8b, (%r12)
incq %r12
movq %rcx, %rbx
movl %r10d, %ecx
movq %r12, %r8
movb %r15b, (%r12)
addq $0x2, %r8
decl %ecx
addq %rbx, %rcx
cmpq %r9, %rcx
jae 0x33009
leaq -0x2(%rcx), %r11
movzbl -0x2(%rcx), %ebx
leaq -0x1(%rcx), %r10
movzbl -0x1(%rcx), %ebp
shll $0x10, %ebx
shll $0x8, %ebp
orl %ebx, %ebp
movzbl (%rcx), %ebx
orl %ebp, %ebx
subl %edi, %r11d
shrl $0x8, %ebp
imull $0xfffb, %ebx, %r14d    # imm = 0xFFFB
addl %ebp, %r14d
andl %r13d, %r14d
movl %r11d, -0x70(%rsp,%r14,4)
movl %ebx, %r11d
shll $0x8, %r11d
movzbl 0x1(%rcx), %r14d
orl %r11d, %r14d
subl %edi, %r10d
imull $0xfffb, %r14d, %r11d   # imm = 0xFFFB
addl %ebx, %r11d
andl %r13d, %r11d
movl %r10d, -0x70(%rsp,%r11,4)
xorl %r15d, %r15d
jmp 0x32c37
incq %rcx
movl %r15d, %r8d
shrl $0x8, %r8d
orb $-0x20, %r8b
movb %r8b, (%r12)
leal -0x9(%r10), %r8d
movb %r8b, 0x1(%r12)
addq $0x2, %r12
jmp 0x32ee1
cmpl $0x1, %r10d
movq %r12, %r11
sbbq $0x0, %r11
addq $0x4, %r11
cmpq %rax, %r11
jb 0x32cd7
jmp 0x32fae
xorl %eax, %eax
retq
movq %r12, %r8
leaq 0x3(%r8), %rdi
cmpq %rax, %rdi
jbe 0x32fb2
xorl %eax, %eax
jmp 0x32ff7
movl %r10d, %edi
movq %r8, %rax
cmpq %rsi, %rcx
jae 0x32fe4
leal 0x1(%rdi), %r10d
movb (%rcx), %r9b
incq %rcx
leaq 0x1(%rax), %r8
movb %r9b, (%rax)
cmpl $0x20, %r10d
jne 0x32fb2
movb %dil, -0x20(%rax)
addq $0x2, %rax
xorl %r10d, %r10d
movq %rax, %r8
jmp 0x32fb2
leal -0x1(%rdi), %ecx
cmpl $0x1, %edi
notl %edi
movslq %edi, %rsi
movb %cl, (%rax,%rsi)
sbbl $0x0, %eax
subl %edx, %eax
addq $0x3ff98, %rsp          # imm = 0x3FF98
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r10d, %r10d
jmp 0x32fa5
nop