// File: /workspace/github_c_makefile_star2_O0/imaya[P]zopfli-for-emscripten/cache.c
// Function: ZopfliSublenToCache
void ZopfliSublenToCache(const unsigned short* sublen,
                         size_t pos, size_t length,
                         ZopfliLongestMatchCache* lmc) {
  size_t i;
  size_t j = 0;
  unsigned bestlength = 0;
  unsigned char* cache;

#if ZOPFLI_CACHE_LENGTH == 0
  return;
#endif

  cache = &lmc->sublen[ZOPFLI_CACHE_LENGTH * pos * 3];
  if (length < 3) return;
  for (i = 3; i <= length; i++) {
    if (i == length || sublen[i] != sublen[i + 1]) {
      cache[j * 3] = i - 3;
      cache[j * 3 + 1] = sublen[i] % 256;
      cache[j * 3 + 2] = (sublen[i] >> 8) % 256;
      bestlength = i;
      j++;
      if (j >= ZOPFLI_CACHE_LENGTH) break;
    }
  }
  if (j < ZOPFLI_CACHE_LENGTH) {
    assert(bestlength == length);
    cache[(ZOPFLI_CACHE_LENGTH - 1) * 3] = bestlength - 3;
  } else {
    assert(bestlength <= length);
  }
  assert(bestlength == ZopfliMaxCachedSublen(lmc, pos, length));
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movq $0x0, 0x18(%rsp)
movl $0x0, 0x14(%rsp)
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x38(%rsp), %rcx
shlq $0x3, %rcx
imulq $0x3, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x8(%rsp)
cmpq $0x3, 0x30(%rsp)
jae 0x2444
jmp 0x25e8
movq $0x3, 0x20(%rsp)
movq 0x20(%rsp), %rax
cmpq 0x30(%rsp), %rax
ja 0x252c
movq 0x20(%rsp), %rax
cmpq 0x30(%rsp), %rax
je 0x248e
movq 0x40(%rsp), %rax
movq 0x20(%rsp), %rcx
movzwl (%rax,%rcx,2), %eax
movq 0x40(%rsp), %rcx
movq 0x20(%rsp), %rdx
movzwl 0x2(%rcx,%rdx,2), %ecx
cmpl %ecx, %eax
je 0x2517
movq 0x20(%rsp), %rax
subq $0x3, %rax
movb %al, %dl
movq 0x8(%rsp), %rax
imulq $0x3, 0x18(%rsp), %rcx
movb %dl, (%rax,%rcx)
movq 0x40(%rsp), %rax
movq 0x20(%rsp), %rcx
movzwl (%rax,%rcx,2), %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movq 0x8(%rsp), %rax
imulq $0x3, 0x18(%rsp), %rcx
movb %dl, 0x1(%rax,%rcx)
movq 0x40(%rsp), %rax
movq 0x20(%rsp), %rcx
movzwl (%rax,%rcx,2), %eax
sarl $0x8, %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movq 0x8(%rsp), %rax
imulq $0x3, 0x18(%rsp), %rcx
movb %dl, 0x2(%rax,%rcx)
movq 0x20(%rsp), %rax
movl %eax, 0x14(%rsp)
movq 0x18(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x18(%rsp)
cmpq $0x8, 0x18(%rsp)
jb 0x2515
jmp 0x252c
jmp 0x2517
jmp 0x2519
movq 0x20(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x20(%rsp)
jmp 0x244d
cmpq $0x8, 0x18(%rsp)
jae 0x2573
movl 0x14(%rsp), %eax
cmpq 0x30(%rsp), %rax
jne 0x2541
jmp 0x2560
leaq 0xac9f(%rip), %rdi      # 0xd1e7
leaq 0xacad(%rip), %rsi      # 0xd1fc
movl $0x49, %edx
leaq 0xaca9(%rip), %rcx      # 0xd204
callq 0x10b0
movl 0x14(%rsp), %eax
subl $0x3, %eax
movb %al, %cl
movq 0x8(%rsp), %rax
movb %cl, 0x15(%rax)
jmp 0x25a1
movl 0x14(%rsp), %eax
cmpq 0x30(%rsp), %rax
ja 0x2580
jmp 0x259f
leaq 0xacd9(%rip), %rdi      # 0xd260
leaq 0xac6e(%rip), %rsi      # 0xd1fc
movl $0x4c, %edx
leaq 0xac6a(%rip), %rcx      # 0xd204
callq 0x10b0
jmp 0x25a1
movl 0x14(%rsp), %eax
movl %eax, 0x4(%rsp)
movq 0x28(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdx
callq 0x25f0
movl %eax, %ecx
movl 0x4(%rsp), %eax
cmpl %ecx, %eax
jne 0x25c9
jmp 0x25e8
leaq 0xaca5(%rip), %rdi      # 0xd275
leaq 0xac25(%rip), %rsi      # 0xd1fc
movl $0x4e, %edx
leaq 0xac21(%rip), %rcx      # 0xd204
callq 0x10b0
addq $0x48, %rsp
retq
nopl (%rax)