// File: /workspace/github_c_makefile_star2_O3/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 %r8, 0x40(%rsp)
movq %rdx, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
cmpq $0xa, %rcx
jae 0x1504
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, 0x68(%rsp)
movq %r9, 0x18(%rsp)
movq 0x180(%rsp), %rax
movq %rax, 0x20(%rsp)
movl $0x1, %edi
movq %rcx, 0x10(%rsp)
movq %rcx, %rsi
callq 0x10e0
testq %rax, %rax
je 0x1a0b
movq %rax, %r11
decq 0x40(%rsp)
movq %rax, 0x28(%rsp)
je 0x18d1
movq 0x10(%rsp), %rbp
leaq -0x1(%rbp), %rbx
movl $0x1, %r14d
xorl %r15d, %r15d
leaq 0x88(%rsp), %r13
movq %rbx, 0x70(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x98(%rsp)
movq %r15, 0xa0(%rsp)
movq %rbp, 0xa8(%rsp)
cmpq %rbp, %r15
jae 0x19ae
movq %r14, 0x50(%rsp)
leaq 0x1(%r15), %rcx
movq %rbp, %rax
subq %rcx, %rax
cmpq $0x3ff, %rax            # imm = 0x3FF
movq %rcx, 0x58(%rsp)
ja 0x1615
movq %rcx, %r12
cmpq %rcx, %rbp
jbe 0x1717
movq %r15, 0x48(%rsp)
movq 0x58(%rsp), %r12
movq %r12, %r15
movsd 0x8a23(%rip), %xmm0     # 0xa008
movsd %xmm0, 0x8(%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x1a34
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
cmovaq %r15, %r12
minsd %xmm1, %xmm0
incq %r15
cmpq %r15, %rbp
jne 0x15e5
jmp 0x1709
movq %r15, 0x48(%rsp)
movq %rcx, %r12
movsd 0x89e3(%rip), %xmm0     # 0xa008
movq %rbp, 0x60(%rsp)
movq %rcx, %rsi
movq %rbp, 0x78(%rsp)
movsd %xmm0, 0x80(%rsp)
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
mulq %rcx
movq %rdx, %r15
shrq $0x3, %r15
movq %rsi, 0x8(%rsp)
leaq (%rsi,%r15), %rbp
xorl %r14d, %r14d
leaq 0x1(%r14), %rbx
movq %rbp, 0xb0(%rsp,%r14,8)
movq %rbp, %rdi
movq %r13, %rsi
callq 0x1a34
movsd %xmm0, 0x100(%rsp,%r14,8)
addq %r15, %rbp
movq %rbx, %r14
cmpq $0x9, %rbx
jne 0x165b
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 0x1698
ucomisd 0x80(%rsp), %xmm0
movq 0x78(%rsp), %rbp
movq 0x8(%rsp), %rsi
ja 0x1709
testq %rax, %rax
je 0x16e2
movq 0xa8(%rsp,%rax,8), %rsi
cmpq $0x8, %rax
je 0x16ef
movq 0xb8(%rsp,%rax,8), %rcx
movq %rcx, 0x60(%rsp)
movq 0xb0(%rsp,%rax,8), %r12
movq 0x60(%rsp), %rax
subq %rsi, %rax
cmpq $0x9, %rax
ja 0x1632
movq 0x48(%rsp), %r15
cmpq %r15, %r12
jbe 0x19ec
cmpq %rbp, %r12
jae 0x19cd
movq 0x30(%rsp), %r14
movq %r14, %rdi
movq 0x38(%rsp), %rbx
movq %rbx, %rsi
movq %r15, %rdx
movq %r12, %rcx
movl $0x2, %r8d
callq 0x2468
movsd %xmm0, 0x8(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %rbp, %rcx
movl $0x2, %r8d
callq 0x2468
addsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %rbp, %rcx
movl $0x2, %r8d
callq 0x2468
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x17c5
cmpq 0x58(%rsp), %r12
je 0x17c5
movq 0x20(%rsp), %rax
movq (%rax), %rsi
leaq -0x1(%rsi), %rax
testq %rax, %rsi
jne 0x17de
testq %rsi, %rsi
je 0x17e8
movq 0x18(%rsp), %rbx
movq (%rbx), %rdi
shlq $0x4, %rsi
callq 0x1150
movq 0x20(%rsp), %rcx
movq (%rcx), %rsi
jmp 0x17f9
movq 0x28(%rsp), %r11
movb $0x1, (%r11,%r15)
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq 0x50(%rsp), %r14
jmp 0x184d
movq 0x18(%rsp), %rax
movq (%rax), %rax
jmp 0x17fc
movl $0x8, %edi
callq 0x1130
xorl %esi, %esi
movq 0x18(%rsp), %rbx
movq %rax, (%rbx)
movq %r12, (%rax,%rsi,8)
movq 0x20(%rsp), %rsi
movq (%rsi), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rsi)
leaq -0x1(%rcx), %rdx
cmpq $-0x3, %rdx
ja 0x1840
xorl %edx, %edx
cmpq %r12, (%rax,%rdx,8)
ja 0x1837
incq %rdx
cmpq %rdx, %rcx
jne 0x181b
jmp 0x1840
movq -0x8(%rax,%rcx,8), %rsi
movq %rsi, (%rax,%rcx,8)
decq %rcx
cmpq %rdx, %rcx
ja 0x182b
movq %r12, (%rax,%rdx,8)
movq 0x50(%rsp), %r14
incq %r14
movq 0x28(%rsp), %r11
movq 0x20(%rsp), %rcx
movq (%rcx), %rcx
movb $0x1, %dl
xorl %edi, %edi
xorl %esi, %esi
movq 0x70(%rsp), %rbx
testq %rsi, %rsi
je 0x186c
movq -0x8(%rax,%rsi,8), %r8
jmp 0x186f
xorl %r8d, %r8d
movq %rbx, %r9
cmpq %rsi, %rcx
je 0x187b
movq (%rax,%rsi,8), %r9
incq %rsi
cmpb $0x0, (%r11,%r8)
jne 0x1890
movq %r9, %r10
subq %r8, %r10
cmpq %rdi, %r10
ja 0x1897
cmpq %rcx, %rsi
jbe 0x1860
jmp 0x18a9
xorl %edx, %edx
movq %r8, %r15
movq %r9, %rbp
movq %r10, %rdi
cmpq %rcx, %rsi
jbe 0x1860
jmp 0x18ba
testb $0x1, %dl
jne 0x18d1
movq %rbp, %r10
subq %r15, %r10
movq %r15, %r8
movq %rbp, %r9
cmpq $0xa, %r10
jb 0x18d1
movq %r9, %rbp
movq %r8, %r15
cmpq %r14, 0x40(%rsp)
jae 0x1568
movq 0x68(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x18f4
movq %r11, %rdi
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1030
movq 0x20(%rsp), %rax
movq (%rax), %r14
xorl %ebx, %ebx
movl $0x0, %eax
testq %r14, %r14
movq 0x10(%rsp), %rcx
je 0x1988
movq 0x18(%rsp), %rax
movq (%rax), %r15
xorl %eax, %eax
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %ebx, %ebx
movq 0x38(%rsp), %rdx
cmpw $0x0, (%rdx,%r13,2)
je 0x1938
movq 0x30(%rsp), %rdx
movzwl (%rdx,%r13,2), %ebp
jmp 0x193d
movl $0x1, %ebp
cmpq (%r15,%rbx,8), %r13
jne 0x197d
leaq -0x1(%rbx), %rcx
testq %rcx, %rbx
jne 0x196c
testq %rbx, %rbx
je 0x1962
movq %rbx, %rsi
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x1150
jmp 0x196c
movl $0x8, %edi
callq 0x1130
movq 0x10(%rsp), %rcx
movq %r12, (%rax,%rbx,8)
incq %rbx
cmpq %r14, %rbx
je 0x1991
addq %rbp, %r12
incq %r13
cmpq %r13, %rcx
jne 0x191f
cmpq %r14, %rbx
jne 0x1a15
xorl %edx, %edx
testq %r14, %r14
sete %dl
movq %rax, %rdi
movq %r14, %rsi
callq 0x11b0
movq 0x28(%rsp), %r11
jmp 0x18db
leaq 0x865b(%rip), %rdi      # 0xa010
leaq 0x8662(%rip), %rsi      # 0xa01e
leaq 0x866b(%rip), %rcx      # 0xa02e
movl $0xfc, %edx
callq 0x10b0
leaq 0x86ef(%rip), %rdi      # 0xa0c3
leaq 0x8643(%rip), %rsi      # 0xa01e
leaq 0x864c(%rip), %rcx      # 0xa02e
movl $0x100, %edx            # imm = 0x100
callq 0x10b0
leaq 0x86c1(%rip), %rdi      # 0xa0b4
leaq 0x8624(%rip), %rsi      # 0xa01e
leaq 0x862d(%rip), %rcx      # 0xa02e
movl $0xff, %edx
callq 0x10b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1180
leaq 0x86b5(%rip), %rdi      # 0xa0d1
leaq 0x85fb(%rip), %rsi      # 0xa01e
leaq 0x872f(%rip), %rcx      # 0xa159
movl $0xac, %edx
callq 0x10b0