// File: /workspace/github_c_makefile_star2_O1/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 %rdx, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
cmpq $0xa, %rcx
jae 0x14ef
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r9, %r15
movq %r8, %r12
movq %rcx, %r14
movq %rdi, 0x70(%rsp)
movq 0x180(%rsp), %rax
movq %rax, 0x18(%rsp)
movq %rcx, %rdi
callq 0x1120
testq %rax, %rax
je 0x1a14
movq %rax, %rbx
movq $0x0, 0x10(%rsp)
movq %rax, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x10c0
decq %r12
leaq -0x1(%r14), %rax
movq %rax, 0x58(%rsp)
movl $0x1, %ecx
leaq 0x88(%rsp), %r13
movq %r14, %rbp
movq %rbx, 0x30(%rsp)
movq %r15, 0x28(%rsp)
movq %r14, 0x38(%rsp)
movq %r12, 0x78(%rsp)
cmpq %rcx, %r12
jae 0x1570
xorl %eax, %eax
jmp 0x18d2
movq 0x48(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x90(%rsp)
movq %r14, 0x98(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq %rbp, 0xa8(%rsp)
cmpq %rbp, %rax
jae 0x19b7
movq %rcx, 0x40(%rsp)
leaq 0x1(%rax), %rcx
movq %rbp, %rax
subq %rcx, %rax
cmpq $0x3ff, %rax            # imm = 0x3FF
movq %rbp, 0x20(%rsp)
movq %rcx, 0x60(%rsp)
movq %rcx, %r12
ja 0x161d
cmpq %rcx, %rbp
jbe 0x1702
movq 0x60(%rsp), %r12
movq %r12, %r15
movsd 0x8a1b(%rip), %xmm0     # 0xa008
movsd %xmm0, 0x8(%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x1a3d
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
cmovaq %r15, %r12
minsd %xmm1, %xmm0
incq %r15
cmpq %r15, %rbp
jne 0x15ed
jmp 0x1702
movsd 0x89e3(%rip), %xmm0     # 0xa008
movq %rbp, 0x68(%rsp)
movq %rcx, %rsi
movsd %xmm0, 0x80(%rsp)
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
mulq %rcx
movq %rdx, %r15
shrq $0x3, %r15
movq %rsi, 0x8(%rsp)
leaq (%rsi,%r15), %r14
xorl %ebx, %ebx
leaq 0x1(%rbx), %rbp
movq %r14, 0xb0(%rsp,%rbx,8)
movq %r14, %rdi
movq %r13, %rsi
callq 0x1a3d
movsd %xmm0, 0x100(%rsp,%rbx,8)
addq %r15, %r14
movq %rbp, %rbx
cmpq $0x9, %rbp
jne 0x1655
movl $0x1, %ecx
movsd 0x100(%rsp), %xmm0
xorl %eax, %eax
movapd %xmm0, %xmm1
movsd 0x100(%rsp,%rcx,8), %xmm0
ucomisd %xmm0, %xmm1
cmovaq %rcx, %rax
minsd %xmm1, %xmm0
incq %rcx
cmpq $0x9, %rcx
jne 0x1691
ucomisd 0x80(%rsp), %xmm0
movq 0x20(%rsp), %rbp
movq 0x8(%rsp), %rsi
ja 0x1702
testq %rax, %rax
je 0x16d5
movq 0xa8(%rsp,%rax,8), %rsi
cmpq $0x8, %rax
je 0x16e8
movq 0xb8(%rsp,%rax,8), %rcx
movq %rcx, 0x68(%rsp)
movq 0xb0(%rsp,%rax,8), %r12
movq 0x68(%rsp), %rax
subq %rsi, %rax
cmpq $0x9, %rax
ja 0x162d
movq 0x10(%rsp), %rdx
cmpq %rdx, %r12
jbe 0x19f5
cmpq %rbp, %r12
jae 0x19d6
movq %rbp, %r15
movq 0x48(%rsp), %r14
movq %r14, %rdi
movq 0x50(%rsp), %rbx
movq %rbx, %rsi
movq %r12, %rcx
movl $0x2, %r8d
movq %rdx, %rbp
callq 0x2458
movsd %xmm0, 0x8(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r15, %rcx
movl $0x2, %r8d
callq 0x2458
addsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %r15, %rcx
movl $0x2, %r8d
callq 0x2458
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x17c3
cmpq 0x60(%rsp), %r12
je 0x17c3
movq 0x18(%rsp), %rax
movq (%rax), %rsi
leaq -0x1(%rsi), %rax
testq %rax, %rsi
movq 0x10(%rsp), %r11
movq 0x58(%rsp), %rbp
movq 0x28(%rsp), %r14
jne 0x17f0
testq %rsi, %rsi
je 0x17de
movq (%r14), %rdi
shlq $0x4, %rsi
callq 0x1140
jmp 0x17e8
movq 0x30(%rsp), %rbx
movq 0x10(%rsp), %r11
movb $0x1, (%rbx,%r11)
movq 0x58(%rsp), %rbp
movq 0x28(%rsp), %r14
jmp 0x1844
movl $0x8, %edi
callq 0x1120
movq %rax, (%r14)
movq 0x10(%rsp), %r11
movq (%r14), %rax
movq 0x18(%rsp), %rsi
movq (%rsi), %rcx
movq %r12, (%rax,%rcx,8)
movq (%rsi), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rsi)
leaq -0x1(%rcx), %rdx
cmpq $-0x3, %rdx
ja 0x183a
xorl %edx, %edx
cmpq %r12, (%rax,%rdx,8)
ja 0x1831
incq %rdx
cmpq %rdx, %rcx
jne 0x1815
jmp 0x183a
movq -0x8(%rax,%rcx,8), %rsi
movq %rsi, (%rax,%rcx,8)
decq %rcx
cmpq %rdx, %rcx
ja 0x1825
movq %r12, (%rax,%rdx,8)
incq 0x40(%rsp)
movq 0x30(%rsp), %rbx
movq (%r14), %rax
movq 0x18(%rsp), %rcx
movq (%rcx), %rcx
xorl %esi, %esi
xorl %edx, %edx
xorl %edi, %edi
movq 0x38(%rsp), %r14
movq 0x78(%rsp), %r12
testq %rdi, %rdi
je 0x186b
movq -0x8(%rax,%rdi,8), %r8
jmp 0x186e
xorl %r8d, %r8d
movq %rbp, %r9
cmpq %rdi, %rcx
je 0x187a
movq (%rax,%rdi,8), %r9
cmpb $0x0, (%rbx,%r8)
jne 0x189c
movq %r9, %r10
subq %r8, %r10
cmpq %rsi, %r10
jbe 0x189c
movl $0x1, %edx
movq %r8, %r11
movq %r9, 0x20(%rsp)
movq %r10, %rsi
incq %rdi
cmpq %rcx, %rdi
jbe 0x185f
testl %edx, %edx
movq %r11, 0x10(%rsp)
je 0x18c6
movq 0x20(%rsp), %rbp
movq %rbp, %rax
subq %r11, %rax
cmpq $0xa, %rax
setae %al
movq 0x40(%rsp), %rcx
jmp 0x18d2
xorl %eax, %eax
movq 0x40(%rsp), %rcx
movq 0x20(%rsp), %rbp
testb %al, %al
jne 0x1564
movq 0x70(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x18fd
movq %rbx, %rdi
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1030
movq 0x18(%rsp), %rax
movq (%rax), %r15
xorl %r14d, %r14d
movl $0x0, %eax
testq %r15, %r15
je 0x199d
movq 0x28(%rsp), %rax
movq (%rax), %r12
decq 0x38(%rsp)
xorl %eax, %eax
xorl %r13d, %r13d
xorl %ebp, %ebp
xorl %r14d, %r14d
movq 0x50(%rsp), %rcx
cmpw $0x0, (%rcx,%rbp,2)
je 0x1944
movq 0x48(%rsp), %rcx
movzwl (%rcx,%rbp,2), %ebx
jmp 0x1949
movl $0x1, %ebx
cmpq (%r12,%r14,8), %rbp
jne 0x1986
leaq -0x1(%r14), %rcx
testq %rcx, %r14
jne 0x1978
testq %r14, %r14
je 0x196e
movq %r14, %rsi
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x1140
jmp 0x1978
movl $0x8, %edi
callq 0x1120
movq %r13, (%rax,%r14,8)
incq %r14
movb $0x1, %cl
cmpq %r15, %r14
je 0x198b
addq %rbx, %r13
xorl %ecx, %ecx
testb %cl, %cl
jne 0x199d
leaq 0x1(%rbp), %rcx
cmpq %rbp, 0x38(%rsp)
movq %rcx, %rbp
jne 0x192d
cmpq %r15, %r14
jne 0x1a1e
movq %r14, %rdi
movq %rax, %rsi
callq 0x11a0
movq 0x30(%rsp), %rbx
jmp 0x18e4
leaq 0x8652(%rip), %rdi      # 0xa010
leaq 0x8659(%rip), %rsi      # 0xa01e
leaq 0x8662(%rip), %rcx      # 0xa02e
movl $0xfc, %edx
callq 0x10b0
leaq 0x86e6(%rip), %rdi      # 0xa0c3
leaq 0x863a(%rip), %rsi      # 0xa01e
leaq 0x8643(%rip), %rcx      # 0xa02e
movl $0x100, %edx            # imm = 0x100
callq 0x10b0
leaq 0x86b8(%rip), %rdi      # 0xa0b4
leaq 0x861b(%rip), %rsi      # 0xa01e
leaq 0x8624(%rip), %rcx      # 0xa02e
movl $0xff, %edx
callq 0x10b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1170
leaq 0x86ac(%rip), %rdi      # 0xa0d1
leaq 0x85f2(%rip), %rsi      # 0xa01e
leaq 0x8726(%rip), %rcx      # 0xa159
movl $0xac, %edx
callq 0x10b0