// File: /workspace/github_c_makefile_star2_O1/madler[P]pigz/zopfli/src/zopfli/squeeze.c
// Function: ZopfliLZ77Optimal
void ZopfliLZ77Optimal(ZopfliBlockState *s,
                       const unsigned char* in, size_t instart, size_t inend,
                       int numiterations,
                       ZopfliLZ77Store* store) {
  /* Dist to get to here with smallest cost. */
  size_t blocksize = inend - instart;
  unsigned short* length_array =
      (unsigned short*)malloc(sizeof(unsigned short) * (blocksize + 1));
  unsigned short* path = 0;
  size_t pathsize = 0;
  ZopfliLZ77Store currentstore;
  ZopfliHash hash;
  ZopfliHash* h = &hash;
  SymbolStats stats, beststats, laststats;
  int i;
  float* costs = (float*)malloc(sizeof(float) * (blocksize + 1));
  double cost;
  double bestcost = ZOPFLI_LARGE_FLOAT;
  double lastcost = 0;
  /* Try randomizing the costs a bit once the size stabilizes. */
  RanState ran_state;
  int lastrandomstep = -1;

  if (!costs) exit(-1); /* Allocation failed. */
  if (!length_array) exit(-1); /* Allocation failed. */

  InitRanState(&ran_state);
  InitStats(&stats);
  ZopfliInitLZ77Store(in, &currentstore);
  ZopfliAllocHash(ZOPFLI_WINDOW_SIZE, h);

  /* Do regular deflate, then loop multiple shortest path runs, each time using
  the statistics of the previous run. */

  /* Initial run. */
  ZopfliLZ77Greedy(s, in, instart, inend, &currentstore, h);
  GetStatistics(&currentstore, &stats);

  /* Repeat statistics with each time the cost model from the previous stat
  run. */
  for (i = 0; i < numiterations; i++) {
    ZopfliCleanLZ77Store(&currentstore);
    ZopfliInitLZ77Store(in, &currentstore);
    LZ77OptimalRun(s, in, instart, inend, &path, &pathsize,
                   length_array, GetCostStat, (void*)&stats,
                   &currentstore, h, costs);
    cost = ZopfliCalculateBlockSize(&currentstore, 0, currentstore.size, 2);
    if (s->options->verbose_more || (s->options->verbose && cost < bestcost)) {
      fprintf(stderr, "Iteration %d: %d bit\n", i, (int) cost);
    }
    if (cost < bestcost) {
      /* Copy to the output store. */
      ZopfliCopyLZ77Store(&currentstore, store);
      CopyStats(&stats, &beststats);
      bestcost = cost;
    }
    CopyStats(&stats, &laststats);
    ClearStatFreqs(&stats);
    GetStatistics(&currentstore, &stats);
    if (lastrandomstep != -1) {
      /* This makes it converge slower but better. Do it only once the
      randomness kicks in so that if the user does few iterations, it gives a
      better result sooner. */
      AddWeighedStatFreqs(&stats, 1.0, &laststats, 0.5, &stats);
      CalculateStatistics(&stats);
    }
    if (i > 5 && cost == lastcost) {
      CopyStats(&beststats, &stats);
      RandomizeStatFreqs(&ran_state, &stats);
      CalculateStatistics(&stats);
      lastrandomstep = i;
    }
    lastcost = cost;
  }

  free(length_array);
  free(path);
  free(costs);
  ZopfliCleanLZ77Store(&currentstore);
  ZopfliCleanHash(h);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3d48, %rsp           # imm = 0x3D48
movq %r9, 0x70(%rsp)
movl %r8d, (%rsp)
movq %rsi, 0x50(%rsp)
movq %rdi, 0x48(%rsp)
movq %rcx, 0x60(%rsp)
movq %rcx, %rbx
movq %rdx, 0x58(%rsp)
subq %rdx, %rbx
leaq 0x2(,%rbx,2), %rdi
callq 0x33d0
movq %rax, 0x18(%rsp)
xorl %eax, %eax
movq %rax, 0x68(%rsp)
movq %rax, 0xa8(%rsp)
leaq 0x4(,%rbx,4), %rdi
callq 0x33d0
movq %rax, 0x40(%rsp)
testq %rax, %rax
je 0x131c8
cmpq $0x0, 0x18(%rsp)
je 0x131c8
movabsq $0x200000001, %rax      # imm = 0x200000001
movq %rax, 0xb0(%rsp)
leaq 0x148(%rsp), %r14
movl $0x1400, %edx           # imm = 0x1400
movq %r14, %rdi
xorl %esi, %esi
callq 0x3260
leaq 0xb8(%rsp), %r15
movq 0x50(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x11284
leaq 0x100(%rsp), %r12
movl $0x8000, %edi           # imm = 0x8000
movq %r12, %rsi
callq 0x12938
movq 0x48(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rbx
movq 0x58(%rsp), %rdx
movq 0x60(%rsp), %rcx
movq %r15, %r8
movq %r12, %r9
callq 0x12403
movq %r15, %rdi
movq %r14, %rsi
callq 0x131d2
cmpl $0x0, (%rsp)
jle 0x1317e
movl $0x900, %eax            # imm = 0x900
leaq 0x2948(%rsp), %rdx
leaq (%rdx,%rax), %rcx
movq %rcx, 0x38(%rsp)
leaq (%rbx,%rax), %r14
movl $0xa00, %ecx            # imm = 0xA00
leaq (%rdx,%rcx), %rsi
movq %rsi, 0x30(%rsp)
leaq (%rbx,%rcx), %r13
movl $0x1300, %esi           # imm = 0x1300
addq %rsi, %rdx
movq %rdx, 0x28(%rsp)
leaq (%rbx,%rsi), %rdx
movq %rdx, 0x8(%rsp)
leaq 0x1548(%rsp), %rdx
addq %rdx, %rax
movq %rax, 0x80(%rsp)
leaq (%rdx,%rcx), %rax
movq %rax, 0x78(%rsp)
addq %rdx, %rsi
movq %rsi, 0x88(%rsp)
movsd 0x42d8(%rip), %xmm0     # 0x17048
movsd %xmm0, 0x20(%rsp)
xorpd %xmm0, %xmm0
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
xorl %r12d, %r12d
movq %r14, 0x98(%rsp)
movq %r13, 0x90(%rsp)
movsd %xmm0, 0xa0(%rsp)
leaq 0xb8(%rsp), %r13
movq %r13, %rdi
callq 0x112a1
movq 0x50(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x11284
movq 0x48(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq 0x18(%rsp), %r10
movq 0x58(%rsp), %rdx
movq 0x60(%rsp), %rcx
leaq 0x68(%rsp), %r8
leaq 0xa8(%rsp), %r9
pushq 0x40(%rsp)
leaq 0x108(%rsp), %rax
pushq %rax
pushq %r13
pushq %rbx
leaq 0xd6f(%rip), %rax       # 0x13b6b
pushq %rax
pushq %r10
callq 0x1327b
addq $0x30, %rsp
movq 0xc8(%rsp), %rdx
movq %r13, %rdi
xorl %esi, %esi
movl $0x2, %ecx
callq 0xe95f
movapd %xmm0, %xmm1
movq (%r14), %rax
cmpl $0x0, 0x4(%rax)
movsd %xmm0, 0x10(%rsp)
jne 0x12e43
cmpl $0x0, (%rax)
je 0x12e68
movsd 0x20(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x12e68
movq 0xa1a6(%rip), %rax      # 0x1cff0
movq (%rax), %rdi
cvttsd2si %xmm1, %ecx
leaq 0x4aa8(%rip), %rsi      # 0x17900
movl %r12d, %edx
xorl %eax, %eax
callq 0x3340
movsd 0x10(%rsp), %xmm1
movsd 0x20(%rsp), %xmm0
ucomisd %xmm1, %xmm0
movq 0x98(%rsp), %r14
movq 0x90(%rsp), %r13
jbe 0x12eef
leaq 0xb8(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0x112e4
movl $0x900, %edx            # imm = 0x900
leaq 0x2948(%rsp), %rdi
movq %rbx, %rsi
callq 0x3360
movl $0x100, %edx            # imm = 0x100
movq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x3360
movl $0x900, %edx            # imm = 0x900
movq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x3360
movl $0x100, %edx            # imm = 0x100
movq 0x28(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x3360
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movl $0x900, %edx            # imm = 0x900
leaq 0x1548(%rsp), %rdi
movq %rbx, %rsi
callq 0x3360
movl $0x100, %edx            # imm = 0x100
movq 0x80(%rsp), %rdi
movq %r14, %rsi
callq 0x3360
movl $0x900, %edx            # imm = 0x900
movq 0x78(%rsp), %rdi
movq %r13, %rsi
callq 0x3360
movl $0x100, %edx            # imm = 0x100
movq 0x88(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x3360
movl $0xa00, %edx            # imm = 0xA00
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3260
leaq 0xb8(%rsp), %rdi
movq %rbx, %rsi
callq 0x131d2
cmpl $-0x1, 0x4(%rsp)
je 0x1309d
xorl %eax, %eax
movsd 0x20aa(%rip), %xmm3     # 0x15020
movapd 0x20b2(%rip), %xmm4     # 0x15030
movsd 0x494a(%rip), %xmm5     # 0x178d0
movsd 0x494a(%rip), %xmm6     # 0x178d8
movsd 0x148(%rsp,%rax,8), %xmm0
unpcklps %xmm3, %xmm0            # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
subpd %xmm4, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd 0x1548(%rsp,%rax,8), %xmm0
unpcklps %xmm3, %xmm0            # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
subpd %xmm4, %xmm0
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
addsd %xmm0, %xmm2
mulsd %xmm5, %xmm2
addsd %xmm1, %xmm2
cvttsd2si %xmm2, %rcx
movq %rcx, %rdx
sarq $0x3f, %rdx
subsd %xmm6, %xmm2
cvttsd2si %xmm2, %rsi
andq %rdx, %rsi
orq %rcx, %rsi
movq %rsi, 0x148(%rsp,%rax,8)
incq %rax
cmpq $0x120, %rax            # imm = 0x120
jne 0x12f8e
movl $0x120, %eax            # imm = 0x120
movsd 0x148(%rsp,%rax,8), %xmm0
unpcklps %xmm3, %xmm0            # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
subpd %xmm4, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd 0x1548(%rsp,%rax,8), %xmm0
unpcklps %xmm3, %xmm0            # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
subpd %xmm4, %xmm0
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
addsd %xmm0, %xmm2
mulsd %xmm5, %xmm2
addsd %xmm1, %xmm2
cvttsd2si %xmm2, %rcx
movq %rcx, %rdx
sarq $0x3f, %rdx
subsd %xmm6, %xmm2
cvttsd2si %xmm2, %rsi
andq %rdx, %rsi
orq %rcx, %rsi
movq %rsi, 0x148(%rsp,%rax,8)
incq %rax
cmpq $0x140, %rax            # imm = 0x140
jne 0x13001
movq $0x1, 0x948(%rsp)
movl $0x120, %esi            # imm = 0x120
movq %rbx, %rdi
movq %r13, %rdx
callq 0x11141
movl $0x20, %esi
movq %r14, %rdi
movq 0x8(%rsp), %rdx
callq 0x11141
cmpl $0x6, %r12d
movsd 0x10(%rsp), %xmm0
jb 0x13171
ucomisd 0xa0(%rsp), %xmm0
jne 0x13171
jp 0x13171
movl $0x900, %edx            # imm = 0x900
movq %rbx, %rdi
leaq 0x2948(%rsp), %rsi
callq 0x3360
movl $0x100, %edx            # imm = 0x100
movq %r14, %rdi
movq 0x38(%rsp), %rsi
callq 0x3360
movl $0x900, %edx            # imm = 0x900
movq %r13, %rdi
movq 0x30(%rsp), %rsi
callq 0x3360
movl $0x100, %edx            # imm = 0x100
movq 0x8(%rsp), %r15
movq %r15, %rdi
movq 0x28(%rsp), %rsi
callq 0x3360
leaq 0xb0(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
movl $0x120, %edx            # imm = 0x120
callq 0x13d26
movq %rbp, %rdi
movq %r14, %rsi
movl $0x20, %edx
callq 0x13d26
movq $0x1, 0x948(%rsp)
movl $0x120, %esi            # imm = 0x120
movq %rbx, %rdi
movq %r13, %rdx
callq 0x11141
movl $0x20, %esi
movq %r14, %rdi
movq %r15, %rdx
callq 0x11141
movsd 0x10(%rsp), %xmm0
movl %r12d, 0x4(%rsp)
incl %r12d
cmpl (%rsp), %r12d
jne 0x12d95
movq 0x18(%rsp), %rdi
callq 0x3050
movq 0x68(%rsp), %rdi
callq 0x3050
movq 0x40(%rsp), %rdi
callq 0x3050
leaq 0xb8(%rsp), %rdi
callq 0x112a1
leaq 0x100(%rsp), %rdi
callq 0x12a41
addq $0x3d48, %rsp           # imm = 0x3D48
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3540