// File: /workspace/github_c_makefile_star2_O1/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 $0x5a8, %rsp            # imm = 0x5A8
movq %r9, 0x40(%rsp)
movq %r8, 0x30(%rsp)
movq %rcx, %r13
movl %edx, 0x24(%rsp)
movq %rdi, %r12
movq 0x5e0(%rsp), %r8
xorl %eax, %eax
movq %rax, 0x38(%rsp)
movq %rax, 0x18(%rsp)
cmpl $0x1, %esi
je 0xef36
testl %esi, %esi
jne 0xefd5
subq $0x8, %rsp
movl 0x2c(%rsp), %edi
movq %r13, %rsi
movq 0x38(%rsp), %rdx
movq 0x48(%rsp), %rcx
movq 0x5f0(%rsp), %r9
pushq 0x5f8(%rsp)
callq 0xf567
addq $0x5b8, %rsp            # imm = 0x5B8
jmp 0xf55c
leaq 0x120(%rsp), %r15
movq %r13, %rdi
movq %r15, %rsi
callq 0x11284
leaq 0xa0(%rsp), %rbx
movq %r12, %rdi
movq 0x30(%rsp), %rbp
movq %rbp, %rsi
movq %r13, %r14
movq 0x40(%rsp), %r13
movq %r13, %rdx
movl $0x1, %ecx
movq %rbx, %r8
callq 0x11b91
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r13, %rcx
movq %r15, %r8
callq 0x13bdc
movq 0x10(%r15), %r9
subq $0x8, %rsp
movq %r12, %rdi
movl $0x1, %esi
movl 0x2c(%rsp), %edx
movq %r15, %rcx
xorl %r8d, %r8d
pushq 0x5f8(%rsp)
pushq 0x5f8(%rsp)
pushq 0x5f8(%rsp)
callq 0xf785
addq $0x20, %rsp
movq %rbx, %rdi
callq 0x11bdd
movq %r15, %rdi
callq 0x112a1
jmp 0xf555
cmpl $0x0, 0xc(%r12)
movq %r12, 0x8(%rsp)
je 0xf022
movslq 0x14(%r12), %r8
subq $0x8, %rsp
leaq 0x20(%rsp), %rbx
leaq 0x40(%rsp), %r9
movq %r12, %rdi
movq %r13, %rsi
movq 0x38(%rsp), %rdx
movq 0x48(%rsp), %rcx
pushq %rbx
callq 0x10dc2
addq $0x10, %rsp
movq (%rbx), %rdi
shlq $0x3, %rdi
callq 0x33d0
movq %rax, 0x28(%rsp)
jmp 0xf02b
movq $0x0, 0x28(%rsp)
leaq 0x58(%rsp), %rsi
movq %r13, %rdi
callq 0x11284
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
xorl %r12d, %r12d
movq 0x18(%rsp), %rax
leaq 0x120(%rsp), %r15
movq 0x30(%rsp), %r14
testq %r12, %r12
je 0xf065
movq 0x38(%rsp), %rcx
movq -0x8(%rcx,%r12,8), %r14
movq 0x40(%rsp), %rbx
cmpq %rax, %r12
je 0xf078
movq 0x38(%rsp), %rax
movq (%rax,%r12,8), %rbx
movq %r13, %rdi
movq %r15, %rsi
callq 0x11284
movq %r13, %r15
movq 0x8(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movl $0x1, %ecx
leaq 0xa0(%rsp), %rbp
movq %rbp, %r8
callq 0x11b91
movl 0x8(%r13), %r8d
movq %r15, %r13
leaq 0x120(%rsp), %r15
movq %rbp, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %rbx, %rcx
movq %r15, %r9
callq 0x12bf8
movq 0x130(%rsp), %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0xedab
movsd %xmm0, 0x10(%rsp)
movq %r15, %rdi
leaq 0x58(%rsp), %rsi
callq 0x11929
cmpq 0x18(%rsp), %r12
jae 0xf106
movq 0x68(%rsp), %rax
movq 0x28(%rsp), %rcx
movq %rax, (%rcx,%r12,8)
movsd (%rsp), %xmm0
addsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x11bdd
movq %r15, %rdi
callq 0x112a1
incq %r12
movq 0x18(%rsp), %rax
cmpq %rax, %r12
jbe 0xf051
cmpq $0x2, %rax
jb 0xf21c
movq 0x8(%rsp), %rdi
cmpl $0x0, 0xc(%rdi)
je 0xf21c
xorl %r15d, %r15d
leaq 0x120(%rsp), %rcx
movq %r15, (%rcx)
leaq 0xa0(%rsp), %r14
movq %r15, (%r14)
movslq 0x14(%rdi), %rdx
leaq 0x58(%rsp), %rbx
movq %rbx, %rsi
movq %r14, %r8
callq 0x108a4
movq (%r14), %r12
xorpd %xmm1, %xmm1
leaq 0x68(%rsp), %r14
testq %r15, %r15
movsd %xmm1, 0x10(%rsp)
je 0xf1a8
movq 0x120(%rsp), %rax
movq -0x8(%rax,%r15,8), %rsi
jmp 0xf1aa
xorl %esi, %esi
leaq (,%r15,8), %rax
addq 0x120(%rsp), %rax
cmpq %r12, %r15
cmoveq %r14, %rax
movq (%rax), %rdx
movq %rbx, %rdi
callq 0xedab
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
incq %r15
movq 0xa0(%rsp), %r12
cmpq %r12, %r15
jbe 0xf18e
movsd (%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xf20f
movq 0x28(%rsp), %rdi
callq 0x3050
movq 0x120(%rsp), %rax
movq %rax, 0x28(%rsp)
movq %r12, 0x18(%rsp)
jmp 0xf21c
movq 0x120(%rsp), %rdi
callq 0x3050
movq 0x18(%rsp), %rax
xorl %r13d, %r13d
movq 0x28(%rsp), %r14
testq %r13, %r13
je 0xf234
movq -0x8(%r14), %r15
jmp 0xf237
xorl %r15d, %r15d
cmpl $0x0, 0x24(%rsp)
setne %cl
cmpq %rax, %r13
movq %r14, %rax
leaq 0x68(%rsp), %rdx
cmoveq %rdx, %rax
sete %dl
movq (%rax), %rbp
andb %cl, %dl
movzbl %dl, %eax
movl %eax, 0x10(%rsp)
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x1196e
movq %rax, %rcx
movabsq $-0x7fff7fff7fff7fff, %rdx # imm = 0x8000800080008001
mulq %rdx
shrq $0xf, %rdx
movq %rcx, %rax
movabsq $-0x1000100010001, %rsi # imm = 0xFFFEFFFEFFFEFFFF
imulq %rsi, %rax
xorl %esi, %esi
movabsq $0x1000100010001, %rdi  # imm = 0x1000100010001
cmpq %rdi, %rax
seta %sil
addq %rdx, %rsi
leaq (%rsi,%rsi,4), %rax
shlq $0x3, %rcx
leaq (%rcx,%rax,8), %rax
movq %rax, %xmm0
punpckldq 0x5d5c(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x5d64(%rip), %xmm0     # 0x15030
movapd %xmm0, 0x40(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movl $0x1, %ecx
callq 0xe95f
movsd %xmm0, (%rsp)
movq %rbx, %rdi
movq %r15, %rsi
movq %rbp, %rdx
leaq 0x120(%rsp), %r12
movq %r12, %rcx
leaq 0xa0(%rsp), %r8
callq 0xeb42
cmpq $0x3e8, 0x68(%rsp)      # imm = 0x3E8
addsd 0x7a5c(%rip), %xmm0     # 0x16d78
setb %bl
movapd %xmm0, %xmm1
mulsd 0x7a55(%rip), %xmm1     # 0x16d80
ucomisd (%rsp), %xmm1
setae %al
cmpq %rbp, %r15
jne 0xf399
movl 0x10(%rsp), %edi
movl $0x1, %esi
movq 0x5e0(%rsp), %r12
movq %r12, %rdx
movq 0x5e8(%rsp), %rbx
movq %rbx, %rcx
movq 0x5f0(%rsp), %r15
movq %r15, %r8
callq 0x106e2
movl $0x1, %edi
movl $0x2, %esi
movq %r12, %rdx
movq %rbx, %rcx
movq %r15, %r8
callq 0x106e2
xorl %edi, %edi
movl $0x7, %esi
movq %r12, %rdx
movq %rbx, %rcx
movq %r15, %r8
callq 0x106e2
jmp 0xf522
movsd %xmm0, 0x30(%rsp)
orb %al, %bl
movq 0x70(%rsp), %rdi
movq %r12, %rsi
callq 0x11284
testb %bl, %bl
je 0xf43e
movq 0x78(%rsp), %rax
movq (%rax,%r15,8), %r12
leaq 0x58(%rsp), %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x1196e
leaq (%rax,%r12), %rdx
movq %rdx, (%rsp)
movq 0x8(%rsp), %rdi
movq %r12, %rsi
movl $0x1, %ecx
leaq 0xa0(%rsp), %r8
callq 0x11b91
movq 0x70(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
movq %r12, %rdx
movq (%rsp), %rcx
leaq 0x120(%rsp), %r12
movq %r12, %r8
callq 0x13bdc
movq 0x130(%rsp), %rdx
movq %r12, %rdi
xorl %esi, %esi
movl $0x1, %ecx
callq 0xe95f
movsd %xmm0, (%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x11bdd
movapd 0x40(%rsp), %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movsd (%rsp), %xmm1
ucomisd %xmm0, %xmm1
movsd 0x30(%rsp), %xmm1
jbe 0xf478
ucomisd %xmm0, %xmm1
jbe 0xf478
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
xorl %esi, %esi
movl 0x18(%rsp), %edx
jmp 0xf4e9
ucomisd (%rsp), %xmm1
movl 0x10(%rsp), %edx
jbe 0xf4cb
testb %bl, %bl
je 0xf4db
movq 0x130(%rsp), %r9
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
movl $0x1, %esi
leaq 0x128(%rsp), %rbx
movq %rbx, %rcx
xorl %r8d, %r8d
pushq 0x5f8(%rsp)
pushq 0x5f8(%rsp)
pushq 0x5f8(%rsp)
callq 0xf785
addq $0x20, %rsp
jmp 0xf51a
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
movl $0x2, %esi
jmp 0xf4e9
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
movl $0x1, %esi
leaq 0x60(%rsp), %rcx
movq %r15, %r8
movq %rbp, %r9
pushq 0x5f8(%rsp)
pushq 0x5f8(%rsp)
pushq 0x5f8(%rsp)
callq 0xf785
addq $0x20, %rsp
leaq 0x120(%rsp), %rbx
movq %rbx, %rdi
callq 0x112a1
incq %r13
movq 0x18(%rsp), %rax
addq $0x8, %r14
cmpq %rax, %r13
jbe 0xf229
leaq 0x58(%rsp), %rdi
callq 0x112a1
movq 0x28(%rsp), %rdi
callq 0x3050
movq 0x38(%rsp), %rdi
callq 0x3050
addq $0x5a8, %rsp            # imm = 0x5A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq