// File: /workspace/github_c_makefile_star2_O3/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, %rbp
movl %edx, 0x24(%rsp)
movq %rdi, %r12
xorl %eax, %eax
movq %rax, 0x38(%rsp)
movq %rax, 0x18(%rsp)
cmpl $0x1, %esi
je 0xf379
testl %esi, %esi
jne 0xf415
subq $0x8, %rsp
movl 0x2c(%rsp), %edi
movq %rbp, %rsi
movq 0x38(%rsp), %rdx
movq 0x48(%rsp), %rcx
movq 0x5e8(%rsp), %r8
movq 0x5f0(%rsp), %r9
pushq 0x5f8(%rsp)
callq 0xf983
addq $0x5b8, %rsp            # imm = 0x5B8
jmp 0xf978
leaq 0x120(%rsp), %r15
movq %rbp, %rdi
movq %r15, %rsi
callq 0x117d8
leaq 0xa0(%rsp), %r14
movq %r12, %rdi
movq 0x30(%rsp), %r13
movq %r13, %rsi
movq 0x40(%rsp), %rbx
movq %rbx, %rdx
movl $0x1, %ecx
movq %r14, %r8
callq 0x120ea
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %rbx, %rcx
movq %r15, %r8
callq 0x1486a
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 0xfbae
addq $0x20, %rsp
movq %r14, %rdi
callq 0x12136
movq %r15, %rdi
callq 0x117f5
jmp 0xf971
cmpl $0x0, 0xc(%r12)
movq %r12, 0x10(%rsp)
je 0xf462
movslq 0x14(%r12), %r8
subq $0x8, %rsp
leaq 0x20(%rsp), %rbx
leaq 0x40(%rsp), %r9
movq %r12, %rdi
movq %rbp, %rsi
movq 0x38(%rsp), %rdx
movq 0x48(%rsp), %rcx
pushq %rbx
callq 0x112f3
addq $0x10, %rsp
movq (%rbx), %rdi
shlq $0x3, %rdi
callq 0x33e0
movq %rax, 0x28(%rsp)
jmp 0xf46b
movq $0x0, 0x28(%rsp)
leaq 0x58(%rsp), %rsi
movq %rbp, 0x50(%rsp)
movq %rbp, %rdi
callq 0x117d8
movq 0x18(%rsp), %r12
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
xorl %r13d, %r13d
leaq 0x120(%rsp), %rbp
movq 0x50(%rsp), %r15
movq 0x30(%rsp), %r14
testq %r13, %r13
je 0xf4af
movq 0x38(%rsp), %rax
movq -0x8(%rax,%r13,8), %r14
movq 0x40(%rsp), %rbx
cmpq %r12, %r13
je 0xf4c2
movq 0x38(%rsp), %rax
movq (%rax,%r13,8), %rbx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x117d8
movq 0x10(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movl $0x1, %ecx
movq %r14, 0x8(%rsp)
movq %rbp, %r14
leaq 0xa0(%rsp), %rbp
movq %rbp, %r8
callq 0x120ea
movl 0x8(%r12), %r8d
movq %rbp, %rdi
movq %r14, %rbp
movq %r15, %rsi
movq 0x8(%rsp), %rdx
movq %rbx, %rcx
movq %r14, %r9
callq 0x136ac
movq 0x130(%rsp), %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0xf1ee
movsd %xmm0, 0x8(%rsp)
movq %r14, %rdi
leaq 0x58(%rsp), %rsi
callq 0x11e70
cmpq 0x18(%rsp), %r13
jae 0xf550
movq 0x68(%rsp), %rax
movq 0x28(%rsp), %rcx
movq %rax, (%rcx,%r13,8)
movsd (%rsp), %xmm0
addsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x12136
movq %rbp, %rdi
callq 0x117f5
incq %r13
movq 0x18(%rsp), %r12
cmpq %r12, %r13
jbe 0xf49b
cmpq $0x2, %r12
jb 0xf66b
movq 0x10(%rsp), %rdi
cmpl $0x0, 0xc(%rdi)
je 0xf66b
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 0x10da0
xorpd %xmm1, %xmm1
movq (%r14), %r12
testq %r15, %r15
movsd %xmm1, 0x8(%rsp)
je 0xf5ed
movq 0x120(%rsp), %rax
movq -0x8(%rax,%r15,8), %rsi
jmp 0xf5ef
xorl %esi, %esi
leaq (,%r15,8), %rax
addq 0x120(%rsp), %rax
cmpq %r12, %r15
leaq 0x68(%rsp), %rcx
cmoveq %rcx, %rax
movq (%rax), %rdx
movq %rbx, %rdi
callq 0xf1ee
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
incq %r15
movq 0xa0(%rsp), %r12
cmpq %r12, %r15
jbe 0xf5d3
movsd (%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xf659
movq 0x28(%rsp), %rdi
callq 0x3050
movq 0x120(%rsp), %rax
movq %rax, 0x28(%rsp)
movq %r12, 0x18(%rsp)
jmp 0xf66b
movq 0x120(%rsp), %rdi
callq 0x3050
movq 0x18(%rsp), %r12
xorl %r13d, %r13d
movq 0x28(%rsp), %r14
testq %r13, %r13
je 0xf67e
movq -0x8(%r14), %r15
jmp 0xf681
xorl %r15d, %r15d
cmpl $0x0, 0x24(%rsp)
setne %al
cmpq %r12, %r13
movq %r14, %rcx
leaq 0x68(%rsp), %rdx
cmoveq %rdx, %rcx
sete %dl
movq (%rcx), %rbp
andb %al, %dl
movzbl %dl, %eax
movl %eax, 0x8(%rsp)
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x11eb5
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 0x5912(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x591a(%rip), %xmm0     # 0x15030
movapd %xmm0, 0x40(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movl $0x1, %ecx
callq 0xed1e
movsd %xmm0, (%rsp)
movq %rbx, %rdi
movq %r15, %rsi
movq %rbp, %rdx
leaq 0x120(%rsp), %r12
movq %r12, %rcx
leaq 0xa0(%rsp), %r8
callq 0xef0d
cmpq $0x3e8, 0x68(%rsp)      # imm = 0x3E8
addsd 0x765a(%rip), %xmm0     # 0x16dc0
setb %bl
movapd %xmm0, %xmm1
mulsd 0x7653(%rip), %xmm1     # 0x16dc8
ucomisd (%rsp), %xmm1
setae %al
cmpq %rbp, %r15
jne 0xf7e3
movl 0x8(%rsp), %edi
movl $0x1, %esi
movq 0x5e0(%rsp), %rbx
movq %rbx, %rdx
movq 0x5e8(%rsp), %r15
movq %r15, %rcx
movq 0x5f0(%rsp), %r12
movq %r12, %r8
callq 0x10bc4
movl $0x1, %edi
movl $0x2, %esi
movq %rbx, %rdx
movq %r15, %rcx
movq %r12, %r8
callq 0x10bc4
xorl %edi, %edi
movl $0x7, %esi
movq %rbx, %rdx
movq %r15, %rcx
movq %r12, %r8
callq 0x10bc4
jmp 0xf93e
movsd %xmm0, 0x30(%rsp)
orb %al, %bl
movq 0x70(%rsp), %rdi
movq %r12, %rsi
callq 0x117d8
testb %bl, %bl
je 0xf888
movq 0x78(%rsp), %rax
movq (%rax,%r15,8), %r12
leaq 0x58(%rsp), %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x11eb5
leaq (%rax,%r12), %rdx
movq %rdx, (%rsp)
movq 0x10(%rsp), %rdi
movq %r12, %rsi
movl $0x1, %ecx
leaq 0xa0(%rsp), %r8
callq 0x120ea
movq 0x70(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
movq %r12, %rdx
leaq 0x120(%rsp), %r12
movq (%rsp), %rcx
movq %r12, %r8
callq 0x1486a
movq 0x130(%rsp), %rdx
movq %r12, %rdi
xorl %esi, %esi
movl $0x1, %ecx
callq 0xed1e
movsd %xmm0, (%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x12136
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 0xf8c2
ucomisd %xmm0, %xmm1
jbe 0xf8c2
subq $0x8, %rsp
movq 0x18(%rsp), %rdi
xorl %esi, %esi
movl 0x10(%rsp), %edx
jmp 0xf90d
ucomisd (%rsp), %xmm1
movl 0x8(%rsp), %edx
jbe 0xf8ef
testb %bl, %bl
je 0xf8ff
movq 0x130(%rsp), %r9
subq $0x8, %rsp
movq 0x18(%rsp), %rdi
movl $0x1, %esi
movq %r12, %rcx
xorl %r8d, %r8d
jmp 0xf918
subq $0x8, %rsp
movq 0x18(%rsp), %rdi
movl $0x2, %esi
jmp 0xf90d
subq $0x8, %rsp
movq 0x18(%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 0xfbae
addq $0x20, %rsp
movq %r12, %rdi
callq 0x117f5
incq %r13
movq 0x18(%rsp), %r12
addq $0x8, %r14
cmpq %r12, %r13
jbe 0xf673
leaq 0x58(%rsp), %rdi
callq 0x117f5
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