// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %r9, 0x28(%rsp)
movq %r8, 0x40(%rsp)
movq %rdx, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
cmpq $0xa, %rcx
jae 0x12c9
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rcx, %rbx
movq %rdi, %r14
movq 0x180(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %rcx, %rdi
callq 0x1120
testq %rax, %rax
je 0x182a
movq %rax, %r11
xorl %eax, %eax
cmpq %rax, %rbx
je 0x1301
movb $0x0, (%r11,%rax)
incq %rax
jmp 0x12f2
movq %r14, 0x60(%rsp)
decq 0x40(%rsp)
leaq -0x1(%rbx), %r14
pushq $0x1
popq %rax
xorl %r15d, %r15d
leaq 0x88(%rsp), %rbp
movq %rbx, %r13
movq %rax, 0x48(%rsp)
movq %r11, 0x20(%rsp)
movq %rbx, 0x50(%rsp)
movq %r14, 0x68(%rsp)
movq 0x48(%rsp), %rax
cmpq %rax, 0x40(%rsp)
jb 0x165c
movq 0x30(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x90(%rsp)
movq %rbx, 0x98(%rsp)
movq %r15, 0xa0(%rsp)
movq %r13, 0xa8(%rsp)
cmpq %r13, %r15
jae 0x180b
movq %r15, 0x18(%rsp)
leaq 0x1(%r15), %r12
movq %r13, %rax
subq %r12, %rax
cmpq $0x3ff, %rax            # imm = 0x3FF
movq %r12, 0x70(%rsp)
ja 0x13d7
movsd 0x5c65(%rip), %xmm0     # 0x7008
movq %r12, %r15
cmpq %r15, %r13
je 0x14c5
movq %r15, %rdi
movq %rbp, %rsi
movsd %xmm0, 0x8(%rsp)
callq 0x1851
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
cmovaq %r15, %r12
minsd %xmm1, %xmm0
incq %r15
jmp 0x13a6
movq %r12, %rsi
movq %r13, 0x58(%rsp)
movsd 0x5c21(%rip), %xmm0     # 0x7008
movq 0x58(%rsp), %rax
subq %rsi, %rax
cmpq $0xa, %rax
jb 0x14c5
movsd %xmm0, 0x78(%rsp)
movq %r12, 0x8(%rsp)
movq %r13, %r12
xorl %edx, %edx
pushq $0xa
popq %rcx
divq %rcx
movq %rax, %r15
movq %rsi, 0x80(%rsp)
leaq (%rsi,%rax), %r13
xorl %ebx, %ebx
cmpq $0x9, %rbx
je 0x144e
leaq 0x1(%rbx), %r14
movq %r13, 0xb0(%rsp,%rbx,8)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x1851
movsd %xmm0, 0x100(%rsp,%rbx,8)
addq %r15, %r13
movq %r14, %rbx
jmp 0x1420
movsd 0x100(%rsp), %xmm0
pushq $0x1
popq %rcx
xorl %eax, %eax
movq %r12, %r13
movq 0x8(%rsp), %r12
movq 0x80(%rsp), %rsi
cmpq $0x9, %rcx
je 0x1490
movsd 0x100(%rsp,%rcx,8), %xmm1
ucomisd %xmm1, %xmm0
cmovaq %rcx, %rax
minsd %xmm0, %xmm1
incq %rcx
movapd %xmm1, %xmm0
jmp 0x146c
ucomisd 0x78(%rsp), %xmm0
ja 0x14c5
testq %rax, %rax
je 0x14ab
movq 0xa8(%rsp,%rax,8), %rsi
cmpq $0x8, %rax
je 0x14b8
movq 0xb8(%rsp,%rax,8), %rcx
movq %rcx, 0x58(%rsp)
movq 0xb0(%rsp,%rax,8), %r12
jmp 0x13e7
cmpq 0x18(%rsp), %r12
jbe 0x17cd
cmpq %r13, %r12
jae 0x17ec
movq 0x30(%rsp), %r14
movq %r14, %rdi
movq 0x38(%rsp), %rbx
movq %rbx, %rsi
movq 0x18(%rsp), %r15
movq %r15, %rdx
movq %r12, %rcx
callq 0x1893
movsd %xmm0, 0x8(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x1893
addsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %r13, %rcx
callq 0x1893
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x1571
cmpq 0x70(%rsp), %r12
je 0x1571
movq 0x10(%rsp), %rax
movq (%rax), %rsi
leaq -0x1(%rsi), %rax
testq %rax, %rsi
movq 0x28(%rsp), %rbx
jne 0x158a
testq %rsi, %rsi
je 0x158f
movq (%rbx), %rdi
shlq $0x4, %rsi
callq 0x1140
movq 0x10(%rsp), %rcx
movq (%rcx), %rsi
jmp 0x1599
movq 0x20(%rsp), %r11
movq 0x18(%rsp), %r15
movb $0x1, (%r11,%r15)
movq 0x28(%rsp), %rax
movq (%rax), %rax
jmp 0x15e9
movq (%rbx), %rax
jmp 0x159c
pushq $0x8
popq %rdi
callq 0x1120
xorl %esi, %esi
movq %rax, (%rbx)
movq %r12, (%rax,%rsi,8)
movq 0x10(%rsp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdx
incq %rdx
movq %rdx, (%rsi)
je 0x15da
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x15da
cmpq %r12, (%rax,%rdx,8)
ja 0x15d1
incq %rdx
jmp 0x15b5
movq -0x8(%rax,%rcx,8), %rsi
movq %rsi, (%rax,%rcx,8)
decq %rcx
cmpq %rdx, %rcx
ja 0x15c5
movq %r12, (%rax,%rdx,8)
incq 0x48(%rsp)
movq 0x20(%rsp), %r11
movq 0x18(%rsp), %r15
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
xorl %edx, %edx
xorl %esi, %esi
xorl %edi, %edi
movq 0x50(%rsp), %rbx
movq 0x68(%rsp), %r14
pushq $0x1
popq %r12
cmpq %rcx, %rdx
ja 0x1648
testq %rdx, %rdx
je 0x1616
movq -0x8(%rax,%rdx,8), %r8
jmp 0x1619
xorl %r8d, %r8d
movq %r14, %r9
cmpq %rdx, %rcx
je 0x1625
movq (%rax,%rdx,8), %r9
cmpb $0x0, (%r11,%r8)
jne 0x1643
movq %r9, %r10
subq %r8, %r10
cmpq %rdi, %r10
jbe 0x1643
movq %r8, %r15
movq %r9, %r13
movl %r12d, %esi
movq %r10, %rdi
incq %rdx
jmp 0x1605
testl %esi, %esi
je 0x165c
movq %r13, %rax
subq %r15, %rax
cmpq $0xa, %rax
jae 0x1334
movq 0x60(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x167f
movq %r11, %rdi
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1030
movq 0x10(%rsp), %rax
movq (%rax), %rax
xorl %r15d, %r15d
movl $0x0, %edi
testq %rax, %rax
movq %rax, 0x8(%rsp)
je 0x1718
movq 0x28(%rsp), %rax
movq (%rax), %r14
xorl %r15d, %r15d
pushq $0x1
popq %r13
xorl %r12d, %r12d
xorl %ebx, %ebx
xorl %edi, %edi
cmpq %r12, 0x50(%rsp)
je 0x1713
movq 0x38(%rsp), %rax
cmpw $0x0, (%rax,%r12,2)
movq %r13, %rbp
je 0x16d0
movq 0x30(%rsp), %rax
movzwl (%rax,%r12,2), %ebp
cmpq (%r14,%r15,8), %r12
jne 0x170b
leaq -0x1(%r15), %rax
testq %rax, %r15
jne 0x16fd
testq %r15, %r15
je 0x16f2
movq %r15, %rsi
shlq $0x4, %rsi
callq 0x1140
jmp 0x16fa
pushq $0x8
popq %rdi
callq 0x1120
movq %rax, %rdi
movq %rbx, (%rdi,%r15,8)
incq %r15
cmpq 0x8(%rsp), %r15
je 0x1721
addq %rbp, %rbx
incq %r12
jmp 0x16af
movq 0x8(%rsp), %rax
cmpq %rax, %r15
jne 0x1832
movq %rdi, %r13
movq 0xa8cd(%rip), %rbx      # 0xbff8
movq (%rbx), %rcx
leaq 0x5a8f(%rip), %rdi      # 0x71c4
pushq $0x14
popq %rsi
pushq $0x1
popq %rdx
callq 0x1180
leaq 0x5a92(%rip), %r15      # 0x71d9
xorl %r12d, %r12d
movq 0x8(%rsp), %r14
movq (%rbx), %rcx
cmpq %r12, %r14
je 0x176e
movl (%r13,%r12,8), %edx
movq %rcx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x10f0
incq %r12
jmp 0x174f
leaq 0x5a68(%rip), %rdi      # 0x71dd
pushq $0x5
popq %rsi
pushq $0x1
popq %rdx
callq 0x1180
leaq 0x5a5c(%rip), %r15      # 0x71e3
xorl %r12d, %r12d
movq (%rbx), %rcx
cmpq %r12, %r14
je 0x17a9
movl (%r13,%r12,8), %edx
movq %rcx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x10f0
incq %r12
jmp 0x178a
leaq 0x5e02(%rip), %rdi      # 0x75b2
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
callq 0x1180
movq %r13, %rdi
callq 0x1030
movq 0x20(%rsp), %r11
jmp 0x1666
leaq 0x58e0(%rip), %rdi      # 0x70b4
leaq 0x5843(%rip), %rsi      # 0x701e
leaq 0x584c(%rip), %rcx      # 0x702e
movl $0xff, %edx
callq 0x10b0
leaq 0x58d0(%rip), %rdi      # 0x70c3
leaq 0x5824(%rip), %rsi      # 0x701e
leaq 0x582d(%rip), %rcx      # 0x702e
movl $0x100, %edx            # imm = 0x100
callq 0x10b0
leaq 0x57fe(%rip), %rdi      # 0x7010
leaq 0x5805(%rip), %rsi      # 0x701e
leaq 0x580e(%rip), %rcx      # 0x702e
movl $0xfc, %edx
callq 0x10b0
pushq $-0x1
popq %rdi
callq 0x1170
leaq 0x5898(%rip), %rdi      # 0x70d1
leaq 0x57de(%rip), %rsi      # 0x701e
leaq 0x5912(%rip), %rcx      # 0x7159
movl $0xac, %edx
callq 0x10b0