// File: /workspace/github_c_makefile_star2_O2/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
jne 0x11ac5
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r9, %rbx
movq %rcx, %r15
movq %rdx, %rbp
movq %rsi, %r12
xorl %r14d, %r14d
movq %rdx, %rax
subq $0x8000, %rax           # imm = 0x8000
cmovaeq %rax, %r14
movl $0x8000, %edi           # imm = 0x8000
movq %r9, %rsi
callq 0x12018
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x121f2
cmpq %rbp, %r14
jae 0x11b1a
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x120e0
incq %r14
jmp 0x11aff
xorl %r13d, %r13d
xorl %r9d, %r9d
xorl %ecx, %ecx
cmpq %r15, %rbp
jae 0x11ab3
movl %r9d, 0x10(%rsp)
movl %r13d, 0x14(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
movq %r15, %rdx
movl %ecx, %r13d
movq %rbx, %rcx
callq 0x120e0
subq $0x8, %rsp
movl $0x102, %r9d            # imm = 0x102
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %rbp, %rcx
movq %r15, %r8
leaq 0x14(%rsp), %rax
pushq %rax
leaq 0x1e(%rsp), %rax
pushq %rax
leaq 0x48(%rsp), %rax
pushq %rax
callq 0x11342
addq $0x20, %rsp
movzwl 0xc(%rsp), %r8d
movzwl 0xe(%rsp), %r9d
cmpl $0x401, %r9d            # imm = 0x401
movl %r8d, %r14d
adcl $-0x1, %r14d
testl %r13d, %r13d
je 0x11be0
xorl %eax, %eax
movl 0x10(%rsp), %r13d
cmpl $0x401, %r13d           # imm = 0x401
setge %al
movl 0x14(%rsp), %edi
movl %edi, %ecx
subl %eax, %ecx
incl %ecx
cmpl %ecx, %r14d
jle 0x11c06
leaq -0x1(%rbp), %rdx
movzbl -0x1(%r12,%rbp), %edi
xorl %esi, %esi
movq 0x18(%rsp), %rcx
movl %r8d, 0x20(%rsp)
movl %r9d, %r13d
callq 0x10c30
movl %r13d, %r9d
movl 0x20(%rsp), %r8d
cmpl $0x3, %r14d
setge %al
cmpw $0x102, %r8w            # imm = 0x102
setb %cl
testb %cl, %al
je 0x11c8d
movl %r8d, %r13d
movq %rbp, %rax
pushq $0x1
popq %rcx
jmp 0x11d22
movw %di, 0xc(%rsp)
movw %r13w, 0xe(%rsp)
leaq -0x1(%rbp), %rdx
movq %rdx, 0x20(%rsp)
movl $0xffff, %eax           # imm = 0xFFFF
andl %eax, %r13d
movl %edi, %r14d
andl %eax, %r14d
movq %r12, %rdi
movq %r15, %rsi
movl %r13d, %ecx
movl %r14d, %r8d
callq 0x112d8
movl %r14d, %edi
movl %r13d, %esi
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rcx
callq 0x10c30
pushq $0x2
popq %r13
leaq -0x2(,%r13), %rax
addq %rbp, %rax
cmpq %r14, %r13
jae 0x11d16
cmpq %r15, %rax
jae 0x11d4c
leaq -0x1(,%r13), %rsi
addq %rbp, %rsi
movq %r12, %rdi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x120e0
incq %r13
jmp 0x11c52
cmpl $0x3, %r14d
jl 0x11cc6
movq %r12, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movl %r9d, %ecx
movl %r8d, %r14d
movl %r9d, %r13d
callq 0x112d8
movl %r14d, %edi
movl %r13d, %esi
movq %rbp, %rdx
movq 0x18(%rsp), %rcx
callq 0x10c30
movl %r14d, %r14d
pushq $0x1
popq %r13
jmp 0x11d06
movw $0x1, 0xc(%rsp)
movzbl (%r12,%rbp), %edi
xorl %esi, %esi
movq %rbp, %rdx
movq 0x18(%rsp), %rcx
callq 0x10c30
pushq $0x1
popq %r13
movq %r13, %r14
jmp 0x11d06
cmpq %r15, %rax
jae 0x11d2d
movq %rbp, %rsi
addq %r13, %rsi
movq %r12, %rdi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x120e0
incq %r13
leaq -0x1(,%r13), %rax
addq %rbp, %rax
cmpq %r14, %r13
jb 0x11cea
xorl %ecx, %ecx
movl 0x14(%rsp), %r13d
movl 0x10(%rsp), %r9d
incq %rax
movq %rax, %rbp
jmp 0x11b22
leaq 0x48da(%rip), %rdi      # 0x1660e
leaq 0x4655(%rip), %rsi      # 0x16390
leaq 0x48d6(%rip), %rcx      # 0x16618
movl $0x272, %edx            # imm = 0x272
callq 0x3220
leaq 0x48bb(%rip), %rdi      # 0x1660e
leaq 0x4636(%rip), %rsi      # 0x16390
leaq 0x48b7(%rip), %rcx      # 0x16618
movl $0x259, %edx            # imm = 0x259
callq 0x3220
nop