// File: /workspace/github_c_makefile_star2_O1/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 0x12683
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 0x129a8
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x12ba9
cmpq %r12, %r14
jae 0x1248c
cmpq %rbp, %r12
cmovbq %r12, %rbp
negq %rbp
leaq (%r12,%rbp), %rsi
movq %r13, %rdi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x12a84
incq %rbp
jne 0x12475
cmpq %r15, %r12
jae 0x12683
movl $0x0, 0x10(%rsp)
xorl %r8d, %r8d
xorl %r14d, %r14d
movl %r8d, 0x4(%rsp)
movl %r14d, 0x8(%rsp)
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x12a84
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 0x11c6f
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 0x12552
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 0x1259f
leaq -0x1(%r12), %rdx
movzbl -0x1(%r13,%r12), %edi
xorl %esi, %esi
movq 0x18(%rsp), %rcx
movl %r8d, 0x24(%rsp)
callq 0x1150d
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
jne 0x12677
cmpl $0x3, %ebp
jl 0x1261c
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
movl %r8d, %ecx
movl %r8d, %ebp
movl %r14d, %r8d
callq 0x11bfb
movl %r14d, %edi
movl %ebp, %esi
jmp 0x1262b
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 0x11bfb
movl %r14d, %edi
movl %ebp, %esi
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rcx
callq 0x1150d
movl $0x0, 0x10(%rsp)
cmpl $0x3, %r14d
jb 0x1266d
addq $-0x2, %r14
cmpq %r15, %r12
jae 0x126b4
incq %r12
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x12a84
decq %r14
jne 0x125f8
jmp 0x1266d
movw $0x1, 0x2(%rsp)
movzbl (%r13,%r12), %edi
xorl %esi, %esi
movq %r12, %rdx
movq 0x18(%rsp), %rcx
callq 0x1150d
movzwl 0x2(%rsp), %r14d
movl $0x0, 0x10(%rsp)
cmpq $0x2, %r14
jb 0x1266d
decq %r14
cmpq %r15, %r12
jae 0x12695
incq %r12
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x12a84
decq %r14
jne 0x1264f
movl 0x8(%rsp), %r14d
movl 0x4(%rsp), %r8d
incq %r12
cmpq %r15, %r12
jb 0x124a3
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4f32(%rip), %rdi      # 0x175ce
leaq 0x4cad(%rip), %rsi      # 0x17350
leaq 0x4f2e(%rip), %rcx      # 0x175d8
movl $0x272, %edx            # imm = 0x272
callq 0x3220
leaq 0x4f13(%rip), %rdi      # 0x175ce
leaq 0x4c8e(%rip), %rsi      # 0x17350
leaq 0x4f0f(%rip), %rcx      # 0x175d8
movl $0x259, %edx            # imm = 0x259
callq 0x3220
nop