// File: /workspace/github_c_makefile_star2_O0/imaya[P]zopfli-for-emscripten/blocksplitter.c
// Function: ZopfliBlockSplitLZ77
void ZopfliBlockSplitLZ77(const ZopfliOptions* options,
                          const unsigned short* litlens,
                          const unsigned short* dists,
                          size_t llsize, size_t maxblocks,
                          size_t** splitpoints, size_t* npoints) {
  size_t lstart, lend;
  size_t i;
  size_t llpos = 0;
  size_t numblocks = 1;
  unsigned char* done;
  double splitcost, origcost;

  if (llsize < 10) return;  /* This code fails on tiny files. */

  done = (unsigned char*)malloc(llsize);
  if (!done) exit(-1); /* Allocation failed. */
  for (i = 0; i < llsize; i++) done[i] = 0;

  lstart = 0;
  lend = llsize;
  for (;;) {
    SplitCostContext c;

    if (maxblocks > 0 && numblocks >= maxblocks) {
      break;
    }

    c.litlens = litlens;
    c.dists = dists;
    c.llsize = llsize;
    c.start = lstart;
    c.end = lend;
    assert(lstart < lend);
    llpos = FindMinimum(SplitCost, &c, lstart + 1, lend);

    assert(llpos > lstart);
    assert(llpos < lend);

    splitcost = EstimateCost(litlens, dists, lstart, llpos) +
        EstimateCost(litlens, dists, llpos, lend);
    origcost = EstimateCost(litlens, dists, lstart, lend);

    if (splitcost > origcost || llpos == lstart + 1 || llpos == lend) {
      done[lstart] = 1;
    } else {
      AddSorted(llpos, splitpoints, npoints);
      numblocks++;
    }

    if (!FindLargestSplittableBlock(
        llsize, done, *splitpoints, *npoints, &lstart, &lend)) {
      break;  /* No further split will probably reduce compression. */
    }

    if (lend - lstart < 10) {
      break;
    }
  }

  if (options->verbose) {
    PrintBlockSplitPoints(litlens, dists, llsize, *splitpoints, *npoints);
  }

  free(done);
}

// Assembly:
subq $0xa8, %rsp
movq 0xb0(%rsp), %rax
movq %rdi, 0xa0(%rsp)
movq %rsi, 0x98(%rsp)
movq %rdx, 0x90(%rsp)
movq %rcx, 0x88(%rsp)
movq %r8, 0x80(%rsp)
movq %r9, 0x78(%rsp)
movq $0x0, 0x58(%rsp)
movq $0x1, 0x50(%rsp)
cmpq $0xa, 0x88(%rsp)
jae 0x12ee
jmp 0x15d5
movq 0x88(%rsp), %rdi
callq 0x1120
movq %rax, 0x48(%rsp)
cmpq $0x0, 0x48(%rsp)
jne 0x1312
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1170
movq $0x0, 0x60(%rsp)
movq 0x60(%rsp), %rax
cmpq 0x88(%rsp), %rax
jae 0x1348
movq 0x48(%rsp), %rax
movq 0x60(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x60(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x60(%rsp)
jmp 0x131b
movq $0x0, 0x70(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x68(%rsp)
cmpq $0x0, 0x80(%rsp)
jbe 0x137d
movq 0x50(%rsp), %rax
cmpq 0x80(%rsp), %rax
jb 0x137d
jmp 0x158e
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x70(%rsp), %rax
cmpq 0x68(%rsp), %rax
jae 0x13c6
jmp 0x13e5
leaq 0xbc43(%rip), %rdi      # 0xd010
leaq 0xbc4a(%rip), %rsi      # 0xd01e
movl $0xfc, %edx
leaq 0xbc4e(%rip), %rcx      # 0xd02e
callq 0x10b0
movq 0x70(%rsp), %rdx
addq $0x1, %rdx
movq 0x68(%rsp), %rcx
leaq 0x536(%rip), %rdi       # 0x1930
leaq 0x10(%rsp), %rsi
callq 0x15e0
movq %rax, 0x58(%rsp)
movq 0x58(%rsp), %rax
cmpq 0x70(%rsp), %rax
jbe 0x1417
jmp 0x1436
leaq 0xbc96(%rip), %rdi      # 0xd0b4
leaq 0xbbf9(%rip), %rsi      # 0xd01e
movl $0xff, %edx
leaq 0xbbfd(%rip), %rcx      # 0xd02e
callq 0x10b0
movq 0x58(%rsp), %rax
cmpq 0x68(%rsp), %rax
jae 0x1444
jmp 0x1463
leaq 0xbc78(%rip), %rdi      # 0xd0c3
leaq 0xbbcc(%rip), %rsi      # 0xd01e
movl $0x100, %edx            # imm = 0x100
leaq 0xbbd0(%rip), %rcx      # 0xd02e
callq 0x10b0
movq 0x98(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x58(%rsp), %rcx
callq 0x19b0
movsd %xmm0, 0x8(%rsp)
movq 0x98(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq 0x68(%rsp), %rcx
callq 0x19b0
movaps %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x98(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x68(%rsp), %rcx
callq 0x19b0
movsd %xmm0, 0x38(%rsp)
movsd 0x40(%rsp), %xmm0
ucomisd 0x38(%rsp), %xmm0
ja 0x150c
movq 0x58(%rsp), %rax
movq 0x70(%rsp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
je 0x150c
movq 0x58(%rsp), %rax
cmpq 0x68(%rsp), %rax
jne 0x151c
movq 0x48(%rsp), %rax
movq 0x70(%rsp), %rcx
movb $0x1, (%rax,%rcx)
jmp 0x1541
movq 0x58(%rsp), %rdi
movq 0x78(%rsp), %rsi
movq 0xb0(%rsp), %rdx
callq 0x19f0
movq 0x50(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x50(%rsp)
movq 0x88(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0x78(%rsp), %rax
movq (%rax), %rdx
movq 0xb0(%rsp), %rax
movq (%rax), %rcx
leaq 0x70(%rsp), %r8
leaq 0x68(%rsp), %r9
callq 0x1b70
cmpl $0x0, %eax
jne 0x1577
jmp 0x158e
movq 0x68(%rsp), %rax
subq 0x70(%rsp), %rax
cmpq $0xa, %rax
jae 0x1589
jmp 0x158e
jmp 0x135e
movq 0xa0(%rsp), %rax
cmpl $0x0, (%rax)
je 0x15cb
movq 0x98(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq 0x88(%rsp), %rdx
movq 0x78(%rsp), %rax
movq (%rax), %rcx
movq 0xb0(%rsp), %rax
movq (%rax), %r8
callq 0x1c90
movq 0x48(%rsp), %rdi
callq 0x1030
addq $0xa8, %rsp
retq
nopl (%rax)