// File: /workspace/github_c_makefile_star2_O1/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, 0x18(%rsp)
movq %rdi, 0x20(%rsp)
cmpq %rcx, %rdx
je 0x7387
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
xorl %ebx, %ebx
movq %rdx, %rax
subq $0x8000, %rax           # imm = 0x8000
cmovaeq %rax, %rbx
movl $0x8000, %ebp           # imm = 0x8000
leaq 0x28(%rsp), %r13
movl $0x8000, %edi           # imm = 0x8000
movq %r13, %rsi
callq 0x4424
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0x4c16
cmpq %r15, %rbx
jae 0x7175
cmpq %rbp, %r15
cmovbq %r15, %rbp
negq %rbp
leaq 0x28(%rsp), %rbx
leaq (%r15,%rbp), %rsi
movq %r12, %rdi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x4af1
incq %rbp
jne 0x715e
cmpq %r14, %r15
jae 0x737d
movl $0x0, 0x10(%rsp)
leaq 0x28(%rsp), %r13
xorl %ebx, %ebx
xorl %eax, %eax
movl %ebx, 0x8(%rsp)
movl %eax, 0xc(%rsp)
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0x4af1
subq $0x8, %rsp
movl $0x102, %r9d            # imm = 0x102
movq 0x28(%rsp), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r8
leaq 0xe(%rsp), %rax
pushq %rax
leaq 0x26(%rsp), %rax
pushq %rax
leaq 0x88(%rsp), %rax
pushq %rax
callq 0x684e
addq $0x20, %rsp
movzwl 0x6(%rsp), %r13d
movzwl 0x16(%rsp), %ebx
cmpl $0x401, %ebx            # imm = 0x401
movl %r13d, %ebp
adcl $-0x1, %ebp
cmpl $0x0, 0x10(%rsp)
je 0x72cf
xorl %eax, %eax
movl 0x8(%rsp), %edi
cmpl $0x401, %edi            # imm = 0x401
setge %al
movl 0xc(%rsp), %esi
movl %esi, %ecx
subl %eax, %ecx
incl %ecx
cmpl %ecx, %ebp
jle 0x7255
movzbl -0x1(%r12,%r15), %edi
xorl %esi, %esi
movq 0x18(%rsp), %rdx
callq 0x673f
leal -0x3(%rbp), %eax
movl $0x1, 0x10(%rsp)
cmpl $0xff, %eax
jae 0x72f2
movl %r13d, %eax
leaq 0x28(%rsp), %r13
jmp 0x7371
movw %si, 0x6(%rsp)
movw %di, 0x16(%rsp)
leaq -0x1(%r15), %rdx
movl %edi, %r13d
movl $0xffff, %eax           # imm = 0xFFFF
andl %eax, %r13d
movl %esi, %ebx
andl %eax, %ebx
movq %r12, %rdi
movq %r14, %rsi
movl %r13d, %ecx
movl %ebx, %r8d
callq 0x67da
movl %ebx, %edi
movl %r13d, %esi
movq 0x18(%rsp), %rdx
callq 0x673f
movl $0x0, 0x10(%rsp)
cmpl $0x3, %ebx
jb 0x7311
addq $-0x2, %rbx
leaq 0x28(%rsp), %r13
cmpq %r14, %r15
jae 0x73b8
incq %r15
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0x4af1
decq %rbx
jne 0x72a8
jmp 0x7369
cmpl $0x3, %ebp
setge %al
movzwl %r13w, %ecx
cmpl $0x102, %ecx            # imm = 0x102
setb %cl
movl $0x1, 0x10(%rsp)
testb %cl, %al
jne 0x7248
cmpl $0x3, %ebp
jl 0x7318
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
movl %ebx, %ecx
movl %r13d, %r8d
callq 0x67da
movl %r13d, %edi
movl %ebx, %esi
jmp 0x7326
leaq 0x28(%rsp), %r13
jmp 0x7369
movw $0x1, 0x6(%rsp)
movzbl (%r12,%r15), %edi
xorl %esi, %esi
movq 0x18(%rsp), %rdx
callq 0x673f
leaq 0x28(%rsp), %r13
movzwl 0x6(%rsp), %ebx
movl $0x0, 0x10(%rsp)
cmpq $0x2, %rbx
jb 0x7369
decq %rbx
cmpq %r14, %r15
jae 0x7399
incq %r15
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0x4af1
decq %rbx
jne 0x734b
movl 0xc(%rsp), %eax
movl 0x8(%rsp), %ebx
incq %r15
cmpq %r14, %r15
jb 0x718f
leaq 0x28(%rsp), %rdi
callq 0x4aae
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3886(%rip), %rdi      # 0xac26
leaq 0x3682(%rip), %rsi      # 0xaa29
leaq 0x3882(%rip), %rcx      # 0xac30
movl $0x1b8, %edx            # imm = 0x1B8
callq 0x10b0
leaq 0x3867(%rip), %rdi      # 0xac26
leaq 0x3663(%rip), %rsi      # 0xaa29
leaq 0x3863(%rip), %rcx      # 0xac30
movl $0x19f, %edx            # imm = 0x19F
callq 0x10b0