// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x2d8, %rsp            # imm = 0x2D8
movq %rdi, 0x2d0(%rsp)
movq %rsi, 0x2c8(%rsp)
movq %rdx, 0x2c0(%rsp)
movq %rcx, 0x2b8(%rsp)
movq %r8, 0x2b0(%rsp)
movq $0x0, 0x2a8(%rsp)
cmpq $0x8000, 0x2c0(%rsp) # imm = 0x8000
jbe 0x8c0e
movq 0x2c0(%rsp), %rax
subq $0x8000, %rax           # imm = 0x8000
movq %rax, 0x18(%rsp)
jmp 0x8c17
xorl %eax, %eax
movq %rax, 0x18(%rsp)
jmp 0x8c17
movq 0x18(%rsp), %rax
movq %rax, 0x290(%rsp)
leaq 0x38(%rsp), %rax
movq %rax, 0x30(%rsp)
movl $0x0, 0x2c(%rsp)
movl $0x0, 0x28(%rsp)
movl $0x0, 0x20(%rsp)
movq 0x2c0(%rsp), %rax
cmpq 0x2b8(%rsp), %rax
jne 0x8c5d
jmp 0x9108
movq 0x30(%rsp), %rsi
movl $0x8000, %edi           # imm = 0x8000
callq 0x6a10
movq 0x2c8(%rsp), %rdi
movq 0x290(%rsp), %rsi
movq 0x2b8(%rsp), %rdx
movq 0x30(%rsp), %rcx
callq 0x6fc0
movq 0x290(%rsp), %rax
movq %rax, 0x2a8(%rsp)
movq 0x2a8(%rsp), %rax
cmpq 0x2c0(%rsp), %rax
jae 0x8ce8
movq 0x2c8(%rsp), %rdi
movq 0x2a8(%rsp), %rsi
movq 0x2b8(%rsp), %rdx
movq 0x30(%rsp), %rcx
callq 0x6c90
movq 0x2a8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x2a8(%rsp)
jmp 0x8c9e
movq 0x2c0(%rsp), %rax
movq %rax, 0x2a8(%rsp)
movq 0x2a8(%rsp), %rax
cmpq 0x2b8(%rsp), %rax
jae 0x90fe
movq 0x2c8(%rsp), %rdi
movq 0x2a8(%rsp), %rsi
movq 0x2b8(%rsp), %rdx
movq 0x30(%rsp), %rcx
callq 0x6c90
movq 0x2d0(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x2c8(%rsp), %rdx
movq 0x2a8(%rsp), %rcx
movq 0x2b8(%rsp), %r8
leaq 0x80(%rsp), %r11
movl $0x102, %r9d            # imm = 0x102
leaq 0x29c(%rsp), %r10
leaq 0x29e(%rsp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x7bb0
movzwl 0x29e(%rsp), %edi
movzwl 0x29c(%rsp), %esi
callq 0x9110
movl %eax, 0x298(%rsp)
movl 0x2c(%rsp), %edi
movl 0x28(%rsp), %esi
callq 0x9110
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x20(%rsp)
je 0x8f6c
movl $0x0, 0x20(%rsp)
movl 0x298(%rsp), %eax
movl 0x24(%rsp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jle 0x8e43
movq 0x2c8(%rsp), %rax
movq 0x2a8(%rsp), %rcx
subq $0x1, %rcx
movzbl (%rax,%rcx), %eax
movq 0x2b0(%rsp), %rdx
xorl %esi, %esi
movzwl %ax, %edi
callq 0x7960
cmpl $0x3, 0x298(%rsp)
jl 0x8e3e
cmpl $0x102, 0x298(%rsp) # imm = 0x102
jge 0x8e3e
movl $0x1, 0x20(%rsp)
movzwl 0x29e(%rsp), %eax
movl %eax, 0x2c(%rsp)
movzwl 0x29c(%rsp), %eax
movl %eax, 0x28(%rsp)
jmp 0x90e5
jmp 0x8f6a
movl 0x2c(%rsp), %eax
movw %ax, 0x29e(%rsp)
movl 0x28(%rsp), %eax
movw %ax, 0x29c(%rsp)
movl 0x24(%rsp), %eax
movl %eax, 0x298(%rsp)
movq 0x2c8(%rsp), %rdi
movq 0x2b8(%rsp), %rsi
movq 0x2a8(%rsp), %rdx
subq $0x1, %rdx
movw 0x29c(%rsp), %ax
movzwl %ax, %ecx
movzwl 0x29e(%rsp), %r8d
callq 0x7aa0
movw 0x29e(%rsp), %cx
movw 0x29c(%rsp), %ax
movq 0x2b0(%rsp), %rdx
movzwl %cx, %edi
movzwl %ax, %esi
callq 0x7960
movq $0x2, 0x2a0(%rsp)
movq 0x2a0(%rsp), %rax
movzwl 0x29e(%rsp), %ecx
cmpq %rcx, %rax
jae 0x8f65
movq 0x2a8(%rsp), %rax
cmpq 0x2b8(%rsp), %rax
jae 0x8ef7
jmp 0x8f16
leaq 0x4c26(%rip), %rdi      # 0xdb24
leaq 0x4a22(%rip), %rsi      # 0xd927
movl $0x19f, %edx            # imm = 0x19F
leaq 0x4c1d(%rip), %rcx      # 0xdb2e
callq 0x10b0
movq 0x2a8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x2a8(%rsp)
movq 0x2c8(%rsp), %rdi
movq 0x2a8(%rsp), %rsi
movq 0x2b8(%rsp), %rdx
movq 0x30(%rsp), %rcx
callq 0x6c90
movq 0x2a0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x2a0(%rsp)
jmp 0x8eca
jmp 0x90e5
jmp 0x8fac
cmpl $0x3, 0x298(%rsp)
jl 0x8faa
movzwl 0x29e(%rsp), %eax
cmpl $0x102, %eax            # imm = 0x102
jge 0x8faa
movl $0x1, 0x20(%rsp)
movzwl 0x29e(%rsp), %eax
movl %eax, 0x2c(%rsp)
movzwl 0x29c(%rsp), %eax
movl %eax, 0x28(%rsp)
jmp 0x90e5
jmp 0x8fac
cmpl $0x3, 0x298(%rsp)
jl 0x900c
movq 0x2c8(%rsp), %rdi
movq 0x2b8(%rsp), %rsi
movq 0x2a8(%rsp), %rdx
movw 0x29c(%rsp), %ax
movzwl %ax, %ecx
movzwl 0x29e(%rsp), %r8d
callq 0x7aa0
movw 0x29e(%rsp), %cx
movw 0x29c(%rsp), %ax
movq 0x2b0(%rsp), %rdx
movzwl %cx, %edi
movzwl %ax, %esi
callq 0x7960
jmp 0x903c
movw $0x1, 0x29e(%rsp)
movq 0x2c8(%rsp), %rax
movq 0x2a8(%rsp), %rcx
movzbl (%rax,%rcx), %eax
movq 0x2b0(%rsp), %rdx
xorl %esi, %esi
movzwl %ax, %edi
callq 0x7960
movq $0x1, 0x2a0(%rsp)
movq 0x2a0(%rsp), %rax
movzwl 0x29e(%rsp), %ecx
cmpq %rcx, %rax
jae 0x90e3
movq 0x2a8(%rsp), %rax
cmpq 0x2b8(%rsp), %rax
jae 0x9075
jmp 0x9094
leaq 0x4aa8(%rip), %rdi      # 0xdb24
leaq 0x48a4(%rip), %rsi      # 0xd927
movl $0x1b8, %edx            # imm = 0x1B8
leaq 0x4a9f(%rip), %rcx      # 0xdb2e
callq 0x10b0
movq 0x2a8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x2a8(%rsp)
movq 0x2c8(%rsp), %rdi
movq 0x2a8(%rsp), %rsi
movq 0x2b8(%rsp), %rdx
movq 0x30(%rsp), %rcx
callq 0x6c90
movq 0x2a0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x2a0(%rsp)
jmp 0x9048
jmp 0x90e5
movq 0x2a8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x2a8(%rsp)
jmp 0x8cf8
movq 0x30(%rsp), %rdi
callq 0x6c20
addq $0x2d8, %rsp            # imm = 0x2D8
retq