// File: /workspace/github_c_makefile_star2_O2/imaya[P]zopfli-for-emscripten/lz77.c
// Function: ZopfliLZ77Greedy
void ZopfliLZ77Greedy(ZopfliBlockState* s, const unsigned char* in,
                      size_t instart, size_t inend,
                      ZopfliLZ77Store* store) {
  size_t i = 0, j;
  unsigned short leng;
  unsigned short dist;
  int lengvalue;
  size_t windowstart = instart > ZOPFLI_WINDOW_SIZE
      ? instart - ZOPFLI_WINDOW_SIZE : 0;
  unsigned short dummysublen[259];

  ZopfliHash hash;
  ZopfliHash* h = &hash;

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

  if (instart == inend) return;

  ZopfliInitHash(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);
    lengvalue = GetLengthValue(leng, dist);

#ifdef ZOPFLI_LAZY_MATCHING
    /* Lazy matching. */
    prevlengvalue = GetLengthValue(prev_length, prev_match);
    if (match_available) {
      match_available = 0;
      if (lengvalue > prevlengvalue + 1) {
        ZopfliStoreLitLenDist(in[i - 1], 0, store);
        if (lengvalue >= ZOPFLI_MIN_MATCH && lengvalue < ZOPFLI_MAX_MATCH) {
          match_available = 1;
          prev_length = leng;
          prev_match = dist;
          continue;
        }
      } else {
        /* Add previous to output. */
        leng = prev_length;
        dist = prev_match;
        lengvalue = prevlengvalue;
        /* Add to output. */
        ZopfliVerifyLenDist(in, inend, i - 1, dist, leng);
        ZopfliStoreLitLenDist(leng, dist, store);
        for (j = 2; j < leng; j++) {
          assert(i < inend);
          i++;
          ZopfliUpdateHash(in, i, inend, h);
        }
        continue;
      }
    }
    else if (lengvalue >= 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 (lengvalue >= ZOPFLI_MIN_MATCH) {
      ZopfliVerifyLenDist(in, inend, i, dist, leng);
      ZopfliStoreLitLenDist(leng, dist, store);
    } else {
      leng = 1;
      ZopfliStoreLitLenDist(in[i], 0, store);
    }
    for (j = 1; j < leng; j++) {
      assert(i < inend);
      i++;
      ZopfliUpdateHash(in, i, inend, h);
    }
  }

  ZopfliCleanHash(h);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
movq %r8, 0x10(%rsp)
movq %rdi, 0x20(%rsp)
cmpq %rcx, %rdx
je 0x4fd0
movq %rcx, %r14
movq %rdx, %r13
movq %rsi, %r15
xorl %ebx, %ebx
movq %rdx, %rax
subq $0x8000, %rax           # imm = 0x8000
cmovaeq %rax, %rbx
leaq 0x28(%rsp), %r12
movl $0x8000, %edi           # imm = 0x8000
movq %r12, %rsi
callq 0x3ce8
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %r12, %rcx
callq 0x3f3c
cmpq %r13, %rbx
jae 0x4dc6
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %r12, %rcx
callq 0x3e2a
incq %rbx
jmp 0x4dab
xorl %ebx, %ebx
leaq 0x28(%rsp), %rbp
xorl %edx, %edx
xorl %ecx, %ecx
cmpq %r14, %r13
jae 0x4fc6
movl %edx, 0x8(%rsp)
movl %ebx, 0xc(%rsp)
movq %r15, %rdi
movq %r13, %rsi
movq %r14, %rdx
movl %ecx, %ebx
movq %rbp, %rcx
callq 0x3e2a
subq $0x8, %rsp
movl $0x102, %r9d            # imm = 0x102
movq 0x28(%rsp), %rdi
movq %rbp, %rsi
movq %r15, %rdx
movq %r13, %rcx
movq %r14, %r8
leaq 0xc(%rsp), %rax
pushq %rax
leaq 0x16(%rsp), %rax
pushq %rax
leaq 0x88(%rsp), %rax
pushq %rax
callq 0x453e
addq $0x20, %rsp
movzwl 0x4(%rsp), %r8d
movzwl 0x6(%rsp), %ecx
cmpl $0x401, %ecx            # imm = 0x401
movl %r8d, %r12d
adcl $-0x1, %r12d
testl %ebx, %ebx
je 0x4f21
xorl %eax, %eax
movl 0x8(%rsp), %edi
cmpl $0x401, %edi            # imm = 0x401
setge %al
movl 0xc(%rsp), %esi
movl %esi, %edx
subl %eax, %edx
incl %edx
cmpl %edx, %r12d
jle 0x4eac
movzbl -0x1(%r15,%r13), %edi
xorl %esi, %esi
movq 0x10(%rsp), %rdx
movl %r8d, 0x1c(%rsp)
movl %ecx, %ebx
callq 0x4443
movl %ebx, %ecx
movl 0x1c(%rsp), %r8d
leal -0x3(%r12), %eax
cmpl $0xff, %eax
jae 0x4f39
movl %r8d, %ebx
movl %ecx, %edx
movq %r13, %rax
pushq $0x1
popq %rcx
jmp 0x4fbb
movw %si, 0x4(%rsp)
movw %di, 0x6(%rsp)
leaq -0x1(%r13), %rdx
movl %edi, %r12d
movl $0xffff, %eax           # imm = 0xFFFF
andl %eax, %r12d
movl %esi, %ebx
andl %eax, %ebx
movq %r15, %rdi
movq %r14, %rsi
movl %r12d, %ecx
movl %ebx, %r8d
callq 0x44dc
movl %ebx, %edi
movl %r12d, %esi
movq 0x10(%rsp), %rdx
callq 0x4443
pushq $0x2
popq %r12
leaq (%r12,%r13), %rax
addq $-0x2, %rax
cmpq %rbx, %r12
jae 0x4fb1
cmpq %r14, %rax
jae 0x4fe2
leaq (%r12,%r13), %rsi
decq %rsi
movq %r15, %rdi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x3e2a
incq %r12
jmp 0x4eed
cmpl $0x3, %r12d
setge %al
cmpw $0x102, %r8w            # imm = 0x102
setb %dl
testb %dl, %al
jne 0x4e9c
cmpl $0x3, %r12d
jl 0x4f6a
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
movl %r8d, %ebx
movl %ecx, %r12d
callq 0x44dc
movl %ebx, %edi
movl %r12d, %esi
movq 0x10(%rsp), %rdx
callq 0x4443
movl %ebx, %ebx
pushq $0x1
popq %r12
jmp 0x4fa5
movw $0x1, 0x4(%rsp)
movzbl (%r15,%r13), %edi
xorl %esi, %esi
movq 0x10(%rsp), %rdx
callq 0x4443
pushq $0x1
popq %r12
movq %r12, %rbx
jmp 0x4fa5
cmpq %r14, %rax
jae 0x5001
leaq (%r12,%r13), %rsi
movq %r15, %rdi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x3e2a
incq %r12
leaq (%r12,%r13), %rax
decq %rax
cmpq %rbx, %r12
jb 0x4f8b
xorl %ecx, %ecx
movl 0xc(%rsp), %ebx
movl 0x8(%rsp), %edx
incq %rax
movq %rax, %r13
jmp 0x4dd1
leaq 0x28(%rsp), %rdi
callq 0x3de7
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2b27(%rip), %rdi      # 0x7b10
leaq 0x2923(%rip), %rsi      # 0x7913
leaq 0x2b23(%rip), %rcx      # 0x7b1a
movl $0x19f, %edx            # imm = 0x19F
callq 0x10b0
leaq 0x2b08(%rip), %rdi      # 0x7b10
leaq 0x2904(%rip), %rsi      # 0x7913
leaq 0x2b04(%rip), %rcx      # 0x7b1a
movl $0x1b8, %edx            # imm = 0x1B8
callq 0x10b0