// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x290, %rsp            # imm = 0x290
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
cmpq $0x8000, -0x18(%rbp)    # imm = 0x8000
jbe 0x189f8
movq -0x18(%rbp), %rax
subq $0x8000, %rax           # imm = 0x8000
movq %rax, -0x278(%rbp)
jmp 0x18a03
xorl %eax, %eax
movq %rax, -0x278(%rbp)
jmp 0x18a03
movq -0x278(%rbp), %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x264(%rbp)
movl $0x0, -0x268(%rbp)
movl $0x0, -0x270(%rbp)
movq -0x18(%rbp), %rax
cmpq -0x20(%rbp), %rax
jne 0x18a3b
jmp 0x18d96
movq -0x30(%rbp), %rsi
movl $0x8000, %edi           # imm = 0x8000
callq 0x19350
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x197f0
movq -0x50(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x18a93
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x19510
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x18a66
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x18d96
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x19510
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x20(%rbp), %r8
leaq -0x260(%rbp), %r11
movl $0x102, %r9d            # imm = 0x102
leaq -0x44(%rbp), %r10
leaq -0x42(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x17cf0
movzwl -0x42(%rbp), %edi
movzwl -0x44(%rbp), %esi
callq 0x18da0
movl %eax, -0x48(%rbp)
movl -0x264(%rbp), %edi
movl -0x268(%rbp), %esi
callq 0x18da0
movl %eax, -0x26c(%rbp)
cmpl $0x0, -0x270(%rbp)
je 0x18c7a
movl $0x0, -0x270(%rbp)
movl -0x48(%rbp), %eax
movl -0x26c(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jle 0x18ba7
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
subq $0x1, %rcx
movzbl (%rax,%rcx), %eax
movq -0x38(%rbp), %rdx
subq $0x1, %rdx
movq -0x28(%rbp), %rcx
xorl %esi, %esi
movzwl %ax, %edi
callq 0x16f50
cmpl $0x3, -0x48(%rbp)
jl 0x18ba2
movzwl -0x42(%rbp), %eax
cmpl $0x102, %eax            # imm = 0x102
jge 0x18ba2
movl $0x1, -0x270(%rbp)
movzwl -0x42(%rbp), %eax
movl %eax, -0x264(%rbp)
movzwl -0x44(%rbp), %eax
movl %eax, -0x268(%rbp)
jmp 0x18d85
jmp 0x18c78
movl -0x264(%rbp), %eax
movw %ax, -0x42(%rbp)
movl -0x268(%rbp), %eax
movw %ax, -0x44(%rbp)
movl -0x26c(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x38(%rbp), %rdx
subq $0x1, %rdx
movw -0x44(%rbp), %ax
movzwl %ax, %ecx
movzwl -0x42(%rbp), %r8d
callq 0x17bf0
movw -0x42(%rbp), %si
movw -0x44(%rbp), %ax
movq -0x38(%rbp), %rdx
subq $0x1, %rdx
movq -0x28(%rbp), %rcx
movzwl %si, %edi
movzwl %ax, %esi
callq 0x16f50
movq $0x2, -0x40(%rbp)
movq -0x40(%rbp), %rax
movzwl -0x42(%rbp), %ecx
cmpq %rcx, %rax
jae 0x18c73
movq -0x38(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x18c25
jmp 0x18c44
leaq 0x5aaf(%rip), %rdi      # 0x1e6db
leaq 0x582a(%rip), %rsi      # 0x1e45d
movl $0x259, %edx            # imm = 0x259
leaq 0x5aa6(%rip), %rcx      # 0x1e6e5
callq 0x3220
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x19510
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x18c0c
jmp 0x18d85
jmp 0x18cb0
cmpl $0x3, -0x48(%rbp)
jl 0x18cae
movzwl -0x42(%rbp), %eax
cmpl $0x102, %eax            # imm = 0x102
jge 0x18cae
movl $0x1, -0x270(%rbp)
movzwl -0x42(%rbp), %eax
movl %eax, -0x264(%rbp)
movzwl -0x44(%rbp), %eax
movl %eax, -0x268(%rbp)
jmp 0x18d85
jmp 0x18cb0
cmpl $0x3, -0x48(%rbp)
jl 0x18cf0
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x38(%rbp), %rdx
movw -0x44(%rbp), %ax
movzwl %ax, %ecx
movzwl -0x42(%rbp), %r8d
callq 0x17bf0
movw -0x42(%rbp), %si
movw -0x44(%rbp), %ax
movq -0x38(%rbp), %rdx
movq -0x28(%rbp), %rcx
movzwl %si, %edi
movzwl %ax, %esi
callq 0x16f50
jmp 0x18d14
movw $0x1, -0x42(%rbp)
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x38(%rbp), %rdx
movq -0x28(%rbp), %rcx
xorl %esi, %esi
movzwl %ax, %edi
callq 0x16f50
movq $0x1, -0x40(%rbp)
movq -0x40(%rbp), %rax
movzwl -0x42(%rbp), %ecx
cmpq %rcx, %rax
jae 0x18d83
movq -0x38(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x18d35
jmp 0x18d54
leaq 0x599f(%rip), %rdi      # 0x1e6db
leaq 0x571a(%rip), %rsi      # 0x1e45d
movl $0x272, %edx            # imm = 0x272
leaq 0x5996(%rip), %rcx      # 0x1e6e5
callq 0x3220
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x19510
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x18d1c
jmp 0x18d85
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x18a9b
addq $0x290, %rsp            # imm = 0x290
popq %rbp
retq
nop