// File: /workspace/github_c_makefile_star2_O3/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 0x74d6
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 0x4584
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0x4d9a
cmpq %r15, %rbx
jae 0x72a4
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 0x4c75
incq %rbp
jne 0x728d
cmpq %r14, %r15
jae 0x74cc
movl $0x0, 0x4(%rsp)
leaq 0x28(%rsp), %r13
xorl %ecx, %ecx
xorl %eax, %eax
movl %ecx, 0xc(%rsp)
movl %eax, 0x10(%rsp)
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0x4c75
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 0x12(%rsp), %rax
pushq %rax
leaq 0x26(%rsp), %rax
pushq %rax
leaq 0x88(%rsp), %rax
pushq %rax
callq 0x69f3
addq $0x20, %rsp
movzwl 0xa(%rsp), %ebp
movzwl 0x16(%rsp), %r13d
cmpl $0x401, %r13d           # imm = 0x401
movl %ebp, %ebx
adcl $-0x1, %ebx
cmpl $0x0, 0x4(%rsp)
je 0x7404
xorl %eax, %eax
movl 0xc(%rsp), %edi
cmpl $0x401, %edi            # imm = 0x401
setge %al
movl 0x10(%rsp), %esi
movl %esi, %ecx
subl %eax, %ecx
incl %ecx
cmpl %ecx, %ebx
jle 0x7386
movzbl -0x1(%r12,%r15), %edi
xorl %esi, %esi
movq 0x18(%rsp), %rdx
callq 0x68df
leal -0x3(%rbx), %eax
movl $0x1, 0x4(%rsp)
cmpl $0xff, %eax
jae 0x7426
movl %ebp, %eax
movl %r13d, %ecx
leaq 0x28(%rsp), %r13
jmp 0x74c0
movw %si, 0xa(%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 0x697f
movl %ebx, %edi
movl %r13d, %esi
movq 0x18(%rsp), %rdx
callq 0x68df
cmpl $0x3, %ebx
jb 0x7489
movl $0x0, 0x4(%rsp)
addq $-0x2, %rbx
leaq 0x28(%rsp), %r13
cmpq %r14, %r15
jae 0x74e8
incq %r15
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0x4c75
decq %rbx
jne 0x73dd
jmp 0x74b8
cmpl $0x3, %ebx
setge %al
movzwl %bp, %ecx
cmpl $0x102, %ecx            # imm = 0x102
setb %cl
movl $0x1, 0x4(%rsp)
testb %cl, %al
jne 0x7377
cmpl $0x2, %ebx
jle 0x7493
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
movl %r13d, %ecx
movl %ebp, %r8d
callq 0x697f
movl %ebp, %edi
movl %r13d, %esi
movq 0x18(%rsp), %rdx
callq 0x68df
movl $0x0, 0x4(%rsp)
cmpw $0x2, %bp
jb 0x74b3
leaq -0x1(%rbp), %rbx
leaq 0x28(%rsp), %r13
cmpq %r14, %r15
jae 0x7507
incq %r15
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0x4c75
decq %rbx
jne 0x7465
jmp 0x74b8
movl $0x0, 0x4(%rsp)
jmp 0x74b3
movw $0x1, 0xa(%rsp)
movzbl (%r12,%r15), %edi
movl $0x0, 0x4(%rsp)
xorl %esi, %esi
movq 0x18(%rsp), %rdx
callq 0x68df
leaq 0x28(%rsp), %r13
movl 0x10(%rsp), %eax
movl 0xc(%rsp), %ecx
incq %r15
cmpq %r14, %r15
jb 0x72be
leaq 0x28(%rsp), %rdi
callq 0x4c32
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3727(%rip), %rdi      # 0xac16
leaq 0x3523(%rip), %rsi      # 0xaa19
leaq 0x3723(%rip), %rcx      # 0xac20
movl $0x19f, %edx            # imm = 0x19F
callq 0x10b0
leaq 0x3708(%rip), %rdi      # 0xac16
leaq 0x3504(%rip), %rsi      # 0xaa19
leaq 0x3704(%rip), %rcx      # 0xac20
movl $0x1b8, %edx            # imm = 0x1B8
callq 0x10b0