// File: /workspace/github_c_makefile_star2_O0/imaya[P]zopfli-for-emscripten/squeeze.c
// Function: GetBestLengths
static double GetBestLengths(ZopfliBlockState *s,
                             const unsigned char* in,
                             size_t instart, size_t inend,
                             CostModelFun* costmodel, void* costcontext,
                             unsigned short* length_array) {
  /* Best cost to get here so far. */
  size_t blocksize = inend - instart;
  float* costs;
  size_t i = 0, k;
  unsigned short leng;
  unsigned short dist;
  unsigned short sublen[259];
  size_t windowstart = instart > ZOPFLI_WINDOW_SIZE
      ? instart - ZOPFLI_WINDOW_SIZE : 0;
  ZopfliHash hash;
  ZopfliHash* h = &hash;
  double result;
  double mincost = GetCostModelMinCost(costmodel, costcontext);

  if (instart == inend) return 0;

  costs = (float*)malloc(sizeof(float) * (blocksize + 1));
  if (!costs) exit(-1); /* Allocation failed. */

  ZopfliInitHash(ZOPFLI_WINDOW_SIZE, h);
  ZopfliWarmupHash(in, windowstart, inend, h);
  for (i = windowstart; i < instart; i++) {
    ZopfliUpdateHash(in, i, inend, h);
  }

  for (i = 1; i < blocksize + 1; i++) costs[i] = ZOPFLI_LARGE_FLOAT;
  costs[0] = 0;  /* Because it's the start. */
  length_array[0] = 0;

  for (i = instart; i < inend; i++) {
    size_t j = i - instart;  /* Index in the costs array and length_array. */
    ZopfliUpdateHash(in, i, inend, h);

#ifdef ZOPFLI_SHORTCUT_LONG_REPETITIONS
    /* If we're in a long repetition of the same character and have more than
    ZOPFLI_MAX_MATCH characters before and after our position. */
    if (h->same[i & ZOPFLI_WINDOW_MASK] > ZOPFLI_MAX_MATCH * 2
        && i > instart + ZOPFLI_MAX_MATCH + 1
        && i + ZOPFLI_MAX_MATCH * 2 + 1 < inend
        && h->same[(i - ZOPFLI_MAX_MATCH) & ZOPFLI_WINDOW_MASK]
            > ZOPFLI_MAX_MATCH) {
      double symbolcost = costmodel(ZOPFLI_MAX_MATCH, 1, costcontext);
      /* Set the length to reach each one to ZOPFLI_MAX_MATCH, and the cost to
      the cost corresponding to that length. Doing this, we skip
      ZOPFLI_MAX_MATCH values to avoid calling ZopfliFindLongestMatch. */
      for (k = 0; k < ZOPFLI_MAX_MATCH; k++) {
        costs[j + ZOPFLI_MAX_MATCH] = costs[j] + symbolcost;
        length_array[j + ZOPFLI_MAX_MATCH] = ZOPFLI_MAX_MATCH;
        i++;
        j++;
        ZopfliUpdateHash(in, i, inend, h);
      }
    }
#endif

    ZopfliFindLongestMatch(s, h, in, i, inend, ZOPFLI_MAX_MATCH, sublen,
                           &dist, &leng);

    /* Literal. */
    if (i + 1 <= inend) {
      double newCost = costs[j] + costmodel(in[i], 0, costcontext);
      assert(newCost >= 0);
      if (newCost < costs[j + 1]) {
        costs[j + 1] = newCost;
        length_array[j + 1] = 1;
      }
    }
    /* Lengths. */
    for (k = 3; k <= leng && i + k <= inend; k++) {
      double newCost;

      /* Calling the cost model is expensive, avoid this if we are already at
      the minimum possible cost that it can return. */
     if (costs[j + k] - costs[j] <= mincost) continue;

      newCost = costs[j] + costmodel(k, sublen[k], costcontext);
      assert(newCost >= 0);
      if (newCost < costs[j + k]) {
        assert(k <= ZOPFLI_MAX_MATCH);
        costs[j + k] = newCost;
        length_array[j + k] = k;
      }
    }
  }

  assert(costs[blocksize] >= 0);
  result = costs[blocksize];

  ZopfliCleanHash(h);
  free(costs);

  return result;
}

// Assembly:
subq $0x328, %rsp            # imm = 0x328
movq 0x330(%rsp), %rax
movq %rdi, 0x318(%rsp)
movq %rsi, 0x310(%rsp)
movq %rdx, 0x308(%rsp)
movq %rcx, 0x300(%rsp)
movq %r8, 0x2f8(%rsp)
movq %r9, 0x2f0(%rsp)
movq 0x300(%rsp), %rax
subq 0x308(%rsp), %rax
movq %rax, 0x2e8(%rsp)
movq $0x0, 0x2d8(%rsp)
cmpq $0x8000, 0x308(%rsp) # imm = 0x8000
jbe 0x9f36
movq 0x308(%rsp), %rax
subq $0x8000, %rax           # imm = 0x8000
movq %rax, 0x30(%rsp)
jmp 0x9f3f
xorl %eax, %eax
movq %rax, 0x30(%rsp)
jmp 0x9f3f
movq 0x30(%rsp), %rax
movq %rax, 0xb8(%rsp)
leaq 0x70(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x2f8(%rsp), %rdi
movq 0x2f0(%rsp), %rsi
callq 0xacb0
movsd %xmm0, 0x58(%rsp)
movq 0x308(%rsp), %rax
cmpq 0x300(%rsp), %rax
jne 0x9f94
xorps %xmm0, %xmm0
movsd %xmm0, 0x320(%rsp)
jmp 0xa66f
movq 0x2e8(%rsp), %rdi
addq $0x1, %rdi
shlq $0x2, %rdi
callq 0x1120
movq %rax, 0x2e0(%rsp)
cmpq $0x0, 0x2e0(%rsp)
jne 0x9fc6
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1170
movq 0x68(%rsp), %rsi
movl $0x8000, %edi           # imm = 0x8000
callq 0x6a10
movq 0x310(%rsp), %rdi
movq 0xb8(%rsp), %rsi
movq 0x300(%rsp), %rdx
movq 0x68(%rsp), %rcx
callq 0x6fc0
movq 0xb8(%rsp), %rax
movq %rax, 0x2d8(%rsp)
movq 0x2d8(%rsp), %rax
cmpq 0x308(%rsp), %rax
jae 0xa051
movq 0x310(%rsp), %rdi
movq 0x2d8(%rsp), %rsi
movq 0x300(%rsp), %rdx
movq 0x68(%rsp), %rcx
callq 0x6c90
movq 0x2d8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x2d8(%rsp)
jmp 0xa007
movq $0x1, 0x2d8(%rsp)
movq 0x2d8(%rsp), %rax
movq 0x2e8(%rsp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jae 0xa0a9
movq 0x2e0(%rsp), %rax
movq 0x2d8(%rsp), %rcx
movss 0x3cd2(%rip), %xmm0     # 0xdd60
movss %xmm0, (%rax,%rcx,4)
movq 0x2d8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x2d8(%rsp)
jmp 0xa05d
movq 0x2e0(%rsp), %rax
xorps %xmm0, %xmm0
movss %xmm0, (%rax)
movq 0x330(%rsp), %rax
movw $0x0, (%rax)
movq 0x308(%rsp), %rax
movq %rax, 0x2d8(%rsp)
movq 0x2d8(%rsp), %rax
cmpq 0x300(%rsp), %rax
jae 0xa5ec
movq 0x2d8(%rsp), %rax
subq 0x308(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x310(%rsp), %rdi
movq 0x2d8(%rsp), %rsi
movq 0x300(%rsp), %rdx
movq 0x68(%rsp), %rcx
callq 0x6c90
movq 0x68(%rsp), %rax
movq 0x40(%rax), %rax
movq 0x2d8(%rsp), %rcx
andq $0x7fff, %rcx           # imm = 0x7FFF
movzwl (%rax,%rcx,2), %eax
cmpl $0x204, %eax            # imm = 0x204
jle 0xa2a7
movq 0x2d8(%rsp), %rax
movq 0x308(%rsp), %rcx
addq $0x102, %rcx            # imm = 0x102
addq $0x1, %rcx
cmpq %rcx, %rax
jbe 0xa2a7
movq 0x2d8(%rsp), %rax
addq $0x204, %rax            # imm = 0x204
addq $0x1, %rax
cmpq 0x300(%rsp), %rax
jae 0xa2a7
movq 0x68(%rsp), %rax
movq 0x40(%rax), %rax
movq 0x2d8(%rsp), %rcx
subq $0x102, %rcx            # imm = 0x102
andq $0x7fff, %rcx           # imm = 0x7FFF
movzwl (%rax,%rcx,2), %eax
cmpl $0x102, %eax            # imm = 0x102
jle 0xa2a7
movq 0x2f8(%rsp), %rax
movq 0x2f0(%rsp), %rdx
movl $0x102, %edi            # imm = 0x102
movl $0x1, %esi
callq *%rax
movsd %xmm0, 0x48(%rsp)
movq $0x0, 0x2d0(%rsp)
cmpq $0x102, 0x2d0(%rsp) # imm = 0x102
jae 0xa2a5
movq 0x2e0(%rsp), %rax
movq 0x50(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
addsd 0x48(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movq 0x2e0(%rsp), %rax
movq 0x50(%rsp), %rcx
movss %xmm0, 0x408(%rax,%rcx,4)
movq 0x330(%rsp), %rax
movq 0x50(%rsp), %rcx
movw $0x102, 0x204(%rax,%rcx,2) # imm = 0x102
movq 0x2d8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x2d8(%rsp)
movq 0x50(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x50(%rsp)
movq 0x310(%rsp), %rdi
movq 0x2d8(%rsp), %rsi
movq 0x300(%rsp), %rdx
movq 0x68(%rsp), %rcx
callq 0x6c90
movq 0x2d0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x2d0(%rsp)
jmp 0xa1e9
jmp 0xa2a7
movq 0x318(%rsp), %rdi
movq 0x68(%rsp), %rsi
movq 0x310(%rsp), %rdx
movq 0x2d8(%rsp), %rcx
movq 0x300(%rsp), %r8
leaq 0xc0(%rsp), %r11
movl $0x102, %r9d            # imm = 0x102
leaq 0x2cc(%rsp), %r10
leaq 0x2ce(%rsp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x7bb0
movq 0x2d8(%rsp), %rax
addq $0x1, %rax
cmpq 0x300(%rsp), %rax
ja 0xa3f4
movq 0x2e0(%rsp), %rax
movq 0x50(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x28(%rsp)
movq 0x2f8(%rsp), %rax
movq 0x310(%rsp), %rcx
movq 0x2d8(%rsp), %rdx
movzbl (%rcx,%rdx), %edi
movq 0x2f0(%rsp), %rdx
xorl %esi, %esi
callq *%rax
movaps %xmm0, %xmm1
movsd 0x28(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x40(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xa37f
jmp 0xa39e
leaq 0x3aad(%rip), %rdi      # 0xde33
leaq 0x39f1(%rip), %rsi      # 0xdd7e
movl $0x112, %edx            # imm = 0x112
leaq 0x3aa7(%rip), %rcx      # 0xde40
callq 0x10b0
movsd 0x40(%rsp), %xmm1
movq 0x2e0(%rsp), %rax
movq 0x50(%rsp), %rcx
movss 0x4(%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0xa3f2
movsd 0x40(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movq 0x2e0(%rsp), %rax
movq 0x50(%rsp), %rcx
movss %xmm0, 0x4(%rax,%rcx,4)
movq 0x330(%rsp), %rax
movq 0x50(%rsp), %rcx
movw $0x1, 0x2(%rax,%rcx,2)
jmp 0xa3f4
movq $0x3, 0x2d0(%rsp)
movq 0x2d0(%rsp), %rcx
movzwl 0x2ce(%rsp), %eax
movl %eax, %edx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, 0x27(%rsp)
ja 0xa43c
movq 0x2d8(%rsp), %rax
addq 0x2d0(%rsp), %rax
cmpq 0x300(%rsp), %rax
setbe %al
movb %al, 0x27(%rsp)
movb 0x27(%rsp), %al
testb $0x1, %al
jne 0xa449
jmp 0xa5d1
movq 0x2e0(%rsp), %rax
movq 0x50(%rsp), %rcx
addq 0x2d0(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
movq 0x2e0(%rsp), %rax
movq 0x50(%rsp), %rcx
subss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x58(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jb 0xa48a
jmp 0xa5b8
movq 0x2e0(%rsp), %rax
movq 0x50(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x2f8(%rsp), %rax
movq 0x2d0(%rsp), %rcx
movl %ecx, %edi
movq 0x2d0(%rsp), %rcx
movzwl 0xc0(%rsp,%rcx,2), %esi
movq 0x2f0(%rsp), %rdx
callq *%rax
movaps %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x38(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xa4f6
jmp 0xa515
leaq 0x3936(%rip), %rdi      # 0xde33
leaq 0x387a(%rip), %rsi      # 0xdd7e
movl $0x121, %edx            # imm = 0x121
leaq 0x3930(%rip), %rcx      # 0xde40
callq 0x10b0
movsd 0x38(%rsp), %xmm1
movq 0x2e0(%rsp), %rax
movq 0x50(%rsp), %rcx
addq 0x2d0(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0xa5b6
cmpq $0x102, 0x2d0(%rsp) # imm = 0x102
ja 0xa54f
jmp 0xa56e
leaq 0x3965(%rip), %rdi      # 0xdebb
leaq 0x3821(%rip), %rsi      # 0xdd7e
movl $0x123, %edx            # imm = 0x123
leaq 0x38d7(%rip), %rcx      # 0xde40
callq 0x10b0
movsd 0x38(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movq 0x2e0(%rsp), %rax
movq 0x50(%rsp), %rcx
addq 0x2d0(%rsp), %rcx
movss %xmm0, (%rax,%rcx,4)
movq 0x2d0(%rsp), %rax
movw %ax, %dx
movq 0x330(%rsp), %rax
movq 0x50(%rsp), %rcx
addq 0x2d0(%rsp), %rcx
movw %dx, (%rax,%rcx,2)
jmp 0xa5b8
movq 0x2d0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x2d0(%rsp)
jmp 0xa400
jmp 0xa5d3
movq 0x2d8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x2d8(%rsp)
jmp 0xa0d5
movq 0x2e0(%rsp), %rax
movq 0x2e8(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0xa60b
jmp 0xa62a
leaq 0x38bf(%rip), %rdi      # 0xded1
leaq 0x3765(%rip), %rsi      # 0xdd7e
movl $0x12a, %edx            # imm = 0x12A
leaq 0x381b(%rip), %rcx      # 0xde40
callq 0x10b0
movq 0x2e0(%rsp), %rax
movq 0x2e8(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x60(%rsp)
movq 0x68(%rsp), %rdi
callq 0x6c20
movq 0x2e0(%rsp), %rdi
callq 0x1030
movsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x320(%rsp)
movsd 0x320(%rsp), %xmm0
addq $0x328, %rsp            # imm = 0x328
retq