// File: /workspace/github_c_makefile_star2_O2/madler[P]pigz/zopfli/src/zopfli/deflate.c
// Function: ZopfliDeflatePart
void ZopfliDeflatePart(const ZopfliOptions* options, int btype, int final,
                       const unsigned char* in, size_t instart, size_t inend,
                       unsigned char* bp, unsigned char** out,
                       size_t* outsize) {
  size_t i;
  /* byte coordinates rather than lz77 index */
  size_t* splitpoints_uncompressed = 0;
  size_t npoints = 0;
  size_t* splitpoints = 0;
  double totalcost = 0;
  ZopfliLZ77Store lz77;

  /* If btype=2 is specified, it tries all block types. If a lesser btype is
  given, then however it forces that one. Neither of the lesser types needs
  block splitting as they have no dynamic huffman trees. */
  if (btype == 0) {
    AddNonCompressedBlock(options, final, in, instart, inend, bp, out, outsize);
    return;
  } else if (btype == 1) {
    ZopfliLZ77Store store;
    ZopfliBlockState s;
    ZopfliInitLZ77Store(in, &store);
    ZopfliInitBlockState(options, instart, inend, 1, &s);

    ZopfliLZ77OptimalFixed(&s, in, instart, inend, &store);
    AddLZ77Block(options, btype, final, &store, 0, store.size, 0,
                 bp, out, outsize);

    ZopfliCleanBlockState(&s);
    ZopfliCleanLZ77Store(&store);
    return;
  }


  if (options->blocksplitting) {
    ZopfliBlockSplit(options, in, instart, inend,
                     options->blocksplittingmax,
                     &splitpoints_uncompressed, &npoints);
    splitpoints = (size_t*)malloc(sizeof(*splitpoints) * npoints);
  }

  ZopfliInitLZ77Store(in, &lz77);

  for (i = 0; i <= npoints; i++) {
    size_t start = i == 0 ? instart : splitpoints_uncompressed[i - 1];
    size_t end = i == npoints ? inend : splitpoints_uncompressed[i];
    ZopfliBlockState s;
    ZopfliLZ77Store store;
    ZopfliInitLZ77Store(in, &store);
    ZopfliInitBlockState(options, start, end, 1, &s);
    ZopfliLZ77Optimal(&s, in, start, end, options->numiterations, &store);
    totalcost += ZopfliCalculateBlockSizeAutoType(&store, 0, store.size);

    ZopfliAppendLZ77Store(&store, &lz77);
    if (i < npoints) splitpoints[i] = lz77.size;

    ZopfliCleanBlockState(&s);
    ZopfliCleanLZ77Store(&store);
  }

  /* Second block splitting attempt */
  if (options->blocksplitting && npoints > 1) {
    size_t* splitpoints2 = 0;
    size_t npoints2 = 0;
    double totalcost2 = 0;

    ZopfliBlockSplitLZ77(options, &lz77,
                         options->blocksplittingmax, &splitpoints2, &npoints2);

    for (i = 0; i <= npoints2; i++) {
      size_t start = i == 0 ? 0 : splitpoints2[i - 1];
      size_t end = i == npoints2 ? lz77.size : splitpoints2[i];
      totalcost2 += ZopfliCalculateBlockSizeAutoType(&lz77, start, end);
    }

    if (totalcost2 < totalcost) {
      free(splitpoints);
      splitpoints = splitpoints2;
      npoints = npoints2;
    } else {
      free(splitpoints2);
    }
  }

  for (i = 0; i <= npoints; i++) {
    size_t start = i == 0 ? 0 : splitpoints[i - 1];
    size_t end = i == npoints ? lz77.size : splitpoints[i];
    AddLZ77BlockAutoType(options, i == npoints && final,
                         &lz77, start, end, 0,
                         bp, out, outsize);
  }

  ZopfliCleanLZ77Store(&lz77);
  free(splitpoints);
  free(splitpoints_uncompressed);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %r9, 0x30(%rsp)
movq %r8, 0x28(%rsp)
movq %rcx, %r15
movl %edx, 0x1c(%rsp)
movq 0x140(%rsp), %r8
andq $0x0, 0x48(%rsp)
andq $0x0, 0x38(%rsp)
cmpl $0x1, %esi
je 0xe5f6
testl %esi, %esi
jne 0xe691
subq $0x8, %rsp
movl 0x24(%rsp), %edi
movq %r15, %rsi
movq 0x30(%rsp), %rdx
movq 0x38(%rsp), %rcx
movq 0x150(%rsp), %r9
pushq 0x158(%rsp)
callq 0xebea
addq $0x118, %rsp            # imm = 0x118
jmp 0xebdf
movq %rdi, %rbp
leaq 0xa0(%rsp), %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x109e8
pushq $0x1
popq %rcx
leaq 0x58(%rsp), %r12
movq %rbp, %rdi
movq 0x28(%rsp), %rbx
movq %rbx, %rsi
movq %r15, %r14
movq 0x30(%rsp), %r15
movq %r15, %rdx
movq %r12, %r8
callq 0x11273
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movq %r15, %rcx
movq %r13, %r8
callq 0x1318b
movq 0x10(%r13), %r9
subq $0x8, %rsp
movq %rbp, %rdi
pushq $0x1
popq %rsi
movl 0x24(%rsp), %edx
movq %r13, %rcx
xorl %r8d, %r8d
pushq 0x158(%rsp)
pushq 0x158(%rsp)
pushq 0x158(%rsp)
callq 0xee08
addq $0x20, %rsp
movq %r12, %rdi
callq 0x112ba
movq %r13, %rdi
callq 0x10a05
jmp 0xebd8
cmpl $0x0, 0xc(%rdi)
movq %rdi, 0x10(%rsp)
je 0xe6d6
movslq 0x14(%rdi), %r8
subq $0x8, %rsp
leaq 0x40(%rsp), %rbx
leaq 0x50(%rsp), %r9
movq %r15, %rsi
movq 0x30(%rsp), %rdx
movq 0x38(%rsp), %rcx
pushq %rbx
callq 0x1058c
popq %rax
popq %rcx
movq (%rbx), %rdi
shlq $0x3, %rdi
callq 0x33d0
movq %rax, 0x20(%rsp)
jmp 0xe6df
movq $0x0, 0x20(%rsp)
leaq 0x58(%rsp), %rsi
movq %r15, %rdi
callq 0x109e8
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %r12d, %r12d
leaq 0xa0(%rsp), %r13
movq 0x38(%rsp), %rax
cmpq %rax, %r12
ja 0xe7ef
movq 0x28(%rsp), %r14
testq %r12, %r12
je 0xe723
movq 0x48(%rsp), %rcx
movq -0x8(%rcx,%r12,8), %r14
movq 0x30(%rsp), %rbx
cmpq %rax, %r12
je 0xe736
movq 0x48(%rsp), %rax
movq (%rax,%r12,8), %rbx
movq %r15, %rdi
movq %r13, %rsi
callq 0x109e8
movq %r15, %r13
movq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
pushq $0x1
popq %rcx
leaq 0xe8(%rsp), %rbp
movq %rbp, %r8
callq 0x11273
movl 0x8(%r15), %r8d
movq %r13, %r15
leaq 0xa0(%rsp), %r13
movq %rbp, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
movq %r13, %r9
callq 0x12240
movq 0xb0(%rsp), %rdx
movq %r13, %rdi
xorl %esi, %esi
callq 0xe4ef
movsd %xmm0, (%rsp)
movq %r13, %rdi
leaq 0x58(%rsp), %rsi
callq 0x11053
cmpq 0x38(%rsp), %r12
jae 0xe7c1
movq 0x68(%rsp), %rax
movq 0x20(%rsp), %rcx
movq %rax, (%rcx,%r12,8)
movsd 0x8(%rsp), %xmm0
addsd (%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x112ba
movq %r13, %rdi
callq 0x10a05
incq %r12
jmp 0xe701
cmpq $0x2, %rax
jb 0xe8ce
movq 0x10(%rsp), %rdi
cmpl $0x0, 0xc(%rdi)
je 0xe8ce
leaq 0xa0(%rsp), %rcx
andq $0x0, (%rcx)
leaq 0xe8(%rsp), %r8
andq $0x0, (%r8)
movslq 0x14(%rdi), %rdx
leaq 0x58(%rsp), %rbx
movq %rbx, %rsi
callq 0xffb4
xorpd %xmm1, %xmm1
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0xe8(%rsp), %r12
cmpq %r12, %r15
ja 0xe897
testq %r15, %r15
movsd %xmm1, (%rsp)
je 0xe861
movq 0xa0(%rsp), %rax
movq -0x8(%rax,%r14), %rsi
jmp 0xe863
xorl %esi, %esi
movq 0xa0(%rsp), %rax
addq %r14, %rax
cmpq %r12, %r15
leaq 0x68(%rsp), %rcx
cmoveq %rcx, %rax
movq (%rax), %rdx
movq %rbx, %rdi
callq 0xe4ef
movsd (%rsp), %xmm1
addsd %xmm0, %xmm1
incq %r15
addq $0x8, %r14
jmp 0xe83b
movsd 0x8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xe8c1
movq 0x20(%rsp), %rdi
callq 0x3050
movq 0xa0(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %r12, 0x38(%rsp)
jmp 0xe8ce
movq 0xa0(%rsp), %rdi
callq 0x3050
xorl %r13d, %r13d
pushq $0x1
popq %r14
pushq $0x2
popq %r12
movq 0x20(%rsp), %rdx
movq 0x38(%rsp), %rax
cmpq %rax, %r13
ja 0xebba
testq %r13, %r13
je 0xe8f7
movq -0x8(%rdx), %rbp
jmp 0xe8f9
xorl %ebp, %ebp
cmpl $0x0, 0x1c(%rsp)
setne %cl
movq %r13, (%rsp)
cmpq %rax, %r13
movq %rdx, 0x30(%rsp)
movq %rdx, %rax
leaq 0x68(%rsp), %rdx
cmoveq %rdx, %rax
sete %dl
movq (%rax), %r15
andb %cl, %dl
movzbl %dl, %ebx
leaq 0x58(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0xe0e6
movsd %xmm0, 0x28(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
movq %r15, %rdx
movl %r14d, %ecx
callq 0xe0e6
movsd %xmm0, 0x8(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
movq %r15, %rdx
movl %r12d, %ecx
callq 0xe0e6
cmpq $0x3e8, 0x68(%rsp)      # imm = 0x3E8
movl %r12d, %r13d
movl %r14d, %r12d
setb %r14b
movapd %xmm0, %xmm1
mulsd 0x7442(%rip), %xmm1     # 0x15dc8
ucomisd 0x8(%rsp), %xmm1
setae %al
cmpq %r15, %rbp
jne 0xe9f2
movl %ebx, %edi
movl %r12d, %esi
movq 0x140(%rsp), %r15
movq %r15, %rdx
movq 0x148(%rsp), %rbx
movq %rbx, %rcx
movq 0x150(%rsp), %r14
movq %r14, %r8
callq 0xfdeb
movl %r12d, %edi
movl %r13d, %esi
movq %r15, %rdx
movq %rbx, %rcx
movq %r14, %r8
callq 0xfdeb
xorl %edi, %edi
pushq $0x7
popq %rsi
movq %r15, %rdx
movq %rbx, %rcx
movq %r14, %r8
callq 0xfdeb
movl %r13d, %r12d
movq (%rsp), %r13
jmp 0xeba5
movsd %xmm0, 0x50(%rsp)
movl %ebx, 0x44(%rsp)
orb %al, %r14b
movq 0x70(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x109e8
testb %r14b, %r14b
je 0xea92
movq 0x78(%rsp), %rax
movq (%rax,%rbp,8), %r12
leaq 0x58(%rsp), %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x11093
leaq (%rax,%r12), %rbx
movq 0x10(%rsp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
pushq $0x1
popq %rcx
leaq 0xe8(%rsp), %r13
movq %r13, %r8
callq 0x11273
movq 0x70(%rsp), %rsi
movq %r13, %rdi
movq %r12, %rdx
movq %rbx, %rcx
leaq 0xa0(%rsp), %r12
movq %r12, %r8
callq 0x1318b
movq 0xb0(%rsp), %rdx
movq %r12, %rdi
xorl %esi, %esi
pushq $0x1
popq %rcx
callq 0xe0e6
movsd %xmm0, 0x8(%rsp)
movq %r13, %rdi
callq 0x112ba
movsd 0x28(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movsd 0x50(%rsp), %xmm1
jbe 0xeaee
ucomisd %xmm0, %xmm1
jbe 0xeaee
subq $0x8, %rsp
movq 0x18(%rsp), %rdi
xorl %esi, %esi
movl 0x4c(%rsp), %edx
leaq 0x60(%rsp), %rcx
movq %rbp, %r8
movq %r15, %r9
pushq 0x158(%rsp)
pushq 0x158(%rsp)
pushq 0x158(%rsp)
callq 0xee08
addq $0x20, %rsp
pushq $0x2
popq %r12
jmp 0xeb5d
ucomisd 0x8(%rsp), %xmm1
pushq $0x2
popq %r12
movl 0x44(%rsp), %edx
jbe 0xeb28
testb %r14b, %r14b
movq (%rsp), %r13
je 0xeb63
movq 0xb0(%rsp), %r9
subq $0x8, %rsp
movq 0x18(%rsp), %rdi
pushq $0x1
popq %rsi
leaq 0xa8(%rsp), %rcx
xorl %r8d, %r8d
jmp 0xeb7a
subq $0x8, %rsp
movq 0x18(%rsp), %rdi
movl %r12d, %esi
leaq 0x60(%rsp), %rcx
movq %rbp, %r8
movq %r15, %r9
pushq 0x158(%rsp)
pushq 0x158(%rsp)
pushq 0x158(%rsp)
callq 0xee08
addq $0x20, %rsp
movq (%rsp), %r13
jmp 0xeb98
subq $0x8, %rsp
movq 0x18(%rsp), %rdi
pushq $0x1
popq %rsi
leaq 0x60(%rsp), %rcx
movq %rbp, %r8
movq %r15, %r9
pushq 0x158(%rsp)
pushq 0x158(%rsp)
pushq 0x158(%rsp)
callq 0xee08
addq $0x20, %rsp
leaq 0xa0(%rsp), %rdi
callq 0x10a05
incq %r13
movq 0x30(%rsp), %rdx
addq $0x8, %rdx
pushq $0x1
popq %r14
jmp 0xe8de
leaq 0x58(%rsp), %rdi
callq 0x10a05
movq 0x20(%rsp), %rdi
callq 0x3050
movq 0x48(%rsp), %rdi
callq 0x3050
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq