// File: /workspace/github_c_makefile_star2_O3/madler[P]pigz/zopfli/src/zopfli/lz77.c
// Function: ZopfliLZ77Greedy
void ZopfliLZ77Greedy(ZopfliBlockState* s, const unsigned char* in,
                      size_t instart, size_t inend,
                      ZopfliLZ77Store* store, ZopfliHash* h) {
  size_t i = 0, j;
  unsigned short leng;
  unsigned short dist;
  int lengthscore;
  size_t windowstart = instart > ZOPFLI_WINDOW_SIZE
      ? instart - ZOPFLI_WINDOW_SIZE : 0;
  unsigned short dummysublen[259];

#ifdef ZOPFLI_LAZY_MATCHING
  /* Lazy matching. */
  unsigned prev_length = 0;
  unsigned prev_match = 0;
  int prevlengthscore;
  int match_available = 0;
#endif

  if (instart == inend) return;

  ZopfliResetHash(ZOPFLI_WINDOW_SIZE, h);
  ZopfliWarmupHash(in, windowstart, inend, h);
  for (i = windowstart; i < instart; i++) {
    ZopfliUpdateHash(in, i, inend, h);
  }

  for (i = instart; i < inend; i++) {
    ZopfliUpdateHash(in, i, inend, h);

    ZopfliFindLongestMatch(s, h, in, i, inend, ZOPFLI_MAX_MATCH, dummysublen,
                           &dist, &leng);
    lengthscore = GetLengthScore(leng, dist);

#ifdef ZOPFLI_LAZY_MATCHING
    /* Lazy matching. */
    prevlengthscore = GetLengthScore(prev_length, prev_match);
    if (match_available) {
      match_available = 0;
      if (lengthscore > prevlengthscore + 1) {
        ZopfliStoreLitLenDist(in[i - 1], 0, i - 1, store);
        if (lengthscore >= ZOPFLI_MIN_MATCH && leng < ZOPFLI_MAX_MATCH) {
          match_available = 1;
          prev_length = leng;
          prev_match = dist;
          continue;
        }
      } else {
        /* Add previous to output. */
        leng = prev_length;
        dist = prev_match;
        lengthscore = prevlengthscore;
        /* Add to output. */
        ZopfliVerifyLenDist(in, inend, i - 1, dist, leng);
        ZopfliStoreLitLenDist(leng, dist, i - 1, store);
        for (j = 2; j < leng; j++) {
          assert(i < inend);
          i++;
          ZopfliUpdateHash(in, i, inend, h);
        }
        continue;
      }
    }
    else if (lengthscore >= ZOPFLI_MIN_MATCH && leng < ZOPFLI_MAX_MATCH) {
      match_available = 1;
      prev_length = leng;
      prev_match = dist;
      continue;
    }
    /* End of lazy matching. */
#endif

    /* Add to output. */
    if (lengthscore >= ZOPFLI_MIN_MATCH) {
      ZopfliVerifyLenDist(in, inend, i, dist, leng);
      ZopfliStoreLitLenDist(leng, dist, i, store);
    } else {
      leng = 1;
      ZopfliStoreLitLenDist(in[i], 0, i, store);
    }
    for (j = 1; j < leng; j++) {
      assert(i < inend);
      i++;
      ZopfliUpdateHash(in, i, inend, h);
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movq %r8, 0x18(%rsp)
movq %rdi, 0x28(%rsp)
cmpq %rcx, %rdx
je 0x12bb4
movq %r9, %rbx
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %r13
xorl %r14d, %r14d
movq %rdx, %rax
subq $0x8000, %rax           # imm = 0x8000
cmovaeq %rax, %r14
movl $0x8000, %ebp           # imm = 0x8000
movl $0x8000, %edi           # imm = 0x8000
movq %r9, %rsi
callq 0x13440
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x1365e
cmpq %r12, %r14
jae 0x1299a
cmpq %rbp, %r12
cmovbq %r12, %rbp
negq %rbp
leaq (%r12,%rbp), %rsi
movq %r13, %rdi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x13539
incq %rbp
jne 0x12983
cmpq %r15, %r12
jae 0x12bb4
movl $0x0, 0x10(%rsp)
xorl %r8d, %r8d
xorl %eax, %eax
movl %r8d, 0x4(%rsp)
movl %eax, 0x8(%rsp)
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x13539
subq $0x8, %rsp
movl $0x102, %r9d            # imm = 0x102
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r12, %rcx
movq %r15, %r8
leaq 0xa(%rsp), %rax
pushq %rax
leaq 0x1e(%rsp), %rax
pushq %rax
leaq 0x48(%rsp), %rax
pushq %rax
callq 0x121c8
addq $0x20, %rsp
movzwl 0x2(%rsp), %r14d
movzwl 0xe(%rsp), %r8d
cmpl $0x401, %r8d            # imm = 0x401
movl %r14d, %ebp
adcl $-0x1, %ebp
cmpl $0x0, 0x10(%rsp)
je 0x12a5e
xorl %eax, %eax
movl 0x4(%rsp), %esi
cmpl $0x401, %esi            # imm = 0x401
setge %al
movl 0x8(%rsp), %edi
movl %edi, %ecx
subl %eax, %ecx
incl %ecx
cmpl %ecx, %ebp
jle 0x12a89
leaq -0x1(%r12), %rdx
movzbl -0x1(%r13,%r12), %edi
xorl %esi, %esi
movq 0x18(%rsp), %rcx
movl %r8d, 0x24(%rsp)
callq 0x11a5f
movl 0x24(%rsp), %r8d
cmpl $0x3, %ebp
setge %al
movzwl %r14w, %ecx
cmpl $0x102, %ecx            # imm = 0x102
setb %cl
movl $0x1, 0x10(%rsp)
testb %cl, %al
je 0x12b0d
movl %r14d, %eax
jmp 0x12ba8
movw %di, 0x2(%rsp)
movw %si, 0xe(%rsp)
leaq -0x1(%r12), %rdx
movq %rdx, 0x10(%rsp)
movl %esi, %ebp
movl $0xffff, %eax           # imm = 0xFFFF
andl %eax, %ebp
movl %edi, %r14d
andl %eax, %r14d
movq %r13, %rdi
movq %r15, %rsi
movl %ebp, %ecx
movl %r14d, %r8d
callq 0x12154
movl %r14d, %edi
movl %ebp, %esi
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rcx
callq 0x11a5f
cmpl $0x3, %r14d
jb 0x12b71
movl $0x0, 0x10(%rsp)
addq $-0x2, %r14
cmpq %r15, %r12
jae 0x12bc6
incq %r12
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x13539
decq %r14
jne 0x12ae6
jmp 0x12b9f
cmpl $0x2, %ebp
jle 0x12b7b
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
movl %r8d, %ecx
movl %r8d, %ebp
movl %r14d, %r8d
callq 0x12154
movl %r14d, %edi
movl %ebp, %esi
movq %r12, %rdx
movq 0x18(%rsp), %rcx
callq 0x11a5f
cmpw $0x2, %r14w
jb 0x12b71
movl $0x0, 0x10(%rsp)
decq %r14
cmpq %r15, %r12
jae 0x12be5
incq %r12
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x13539
decq %r14
jne 0x12b4d
jmp 0x12b9f
movl $0x0, 0x10(%rsp)
jmp 0x12b9f
movw $0x1, 0x2(%rsp)
movzbl (%r13,%r12), %edi
movl $0x0, 0x10(%rsp)
xorl %esi, %esi
movq %r12, %rdx
movq 0x18(%rsp), %rcx
callq 0x11a5f
movl 0x8(%rsp), %eax
movl 0x4(%rsp), %r8d
incq %r12
cmpq %r15, %r12
jb 0x129b0
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4a41(%rip), %rdi      # 0x1760e
leaq 0x47bc(%rip), %rsi      # 0x17390
leaq 0x4a3d(%rip), %rcx      # 0x17618
movl $0x259, %edx            # imm = 0x259
callq 0x3220
leaq 0x4a22(%rip), %rdi      # 0x1760e
leaq 0x479d(%rip), %rsi      # 0x17390
leaq 0x4a1e(%rip), %rcx      # 0x17618
movl $0x272, %edx            # imm = 0x272
callq 0x3220