// File: lvandeve[P]lodepng/lodepng.cpp
// Function: deflateFixed(LodePNGBitWriter*, Hash*, unsigned char const*, unsigned long, unsigned long, LodePNGCompressSettings const*, unsigned int)
static unsigned deflateFixed(LodePNGBitWriter* writer, Hash* hash,
                             const unsigned char* data,
                             size_t datapos, size_t dataend,
                             const LodePNGCompressSettings* settings, unsigned final) {
  HuffmanTree tree_ll; /*tree for literal values and length codes*/
  HuffmanTree tree_d; /*tree for distance codes*/

  unsigned BFINAL = final;
  unsigned error = 0;
  size_t i;

  HuffmanTree_init(&tree_ll);
  HuffmanTree_init(&tree_d);

  error = generateFixedLitLenTree(&tree_ll);
  if(!error) error = generateFixedDistanceTree(&tree_d);

  if(!error) {
    writeBits(writer, BFINAL, 1);
    writeBits(writer, 1, 1); /*first bit of BTYPE*/
    writeBits(writer, 0, 1); /*second bit of BTYPE*/

    if(settings->use_lz77) /*LZ77 encoded*/ {
      uivector lz77_encoded;
      uivector_init(&lz77_encoded);
      error = encodeLZ77(&lz77_encoded, hash, data, datapos, dataend, settings->windowsize,
                         settings->minmatch, settings->nicematch, settings->lazymatching);
      if(!error) writeLZ77data(writer, &lz77_encoded, &tree_ll, &tree_d);
      uivector_cleanup(&lz77_encoded);
    } else /*no LZ77, but still will be Huffman compressed*/ {
      for(i = datapos; i < dataend; ++i) {
        writeBitsReversed(writer, tree_ll.codes[data[i]], tree_ll.lengths[data[i]]);
      }
    }
    /*add END code*/
    if(!error) writeBitsReversed(writer,tree_ll.codes[256], tree_ll.lengths[256]);
  }

  /*cleanup*/
  HuffmanTree_cleanup(&tree_ll);
  HuffmanTree_cleanup(&tree_d);

  return error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movl 0x10(%rbp), %eax
movl %eax, -0x84(%rbp)
movl $0x0, -0x88(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x12d70
leaq -0x80(%rbp), %rdi
callq 0x12d70
leaq -0x58(%rbp), %rdi
callq 0x13780
movl %eax, -0x88(%rbp)
cmpl $0x0, -0x88(%rbp)
jne 0x146d2
leaq -0x80(%rbp), %rdi
callq 0x13890
movl %eax, -0x88(%rbp)
cmpl $0x0, -0x88(%rbp)
jne 0x1483c
movq -0x8(%rbp), %rdi
movl -0x84(%rbp), %esi
movl $0x1, %edx
callq 0x154e0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x154e0
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x154e0
movq -0x30(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x147ad
leaq -0xa8(%rbp), %rdi
callq 0x15660
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %rax
movl 0x8(%rax), %r9d
movq -0x30(%rbp), %rax
movl 0xc(%rax), %r11d
movq -0x30(%rbp), %rax
movl 0x10(%rax), %r10d
movq -0x30(%rbp), %rax
movl 0x14(%rax), %eax
leaq -0xa8(%rbp), %rdi
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
callq 0x15690
movl %eax, -0x88(%rbp)
cmpl $0x0, -0x88(%rbp)
jne 0x1479f
movq -0x8(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
leaq -0x58(%rbp), %rdx
leaq -0x80(%rbp), %rcx
callq 0x15d90
leaq -0xa8(%rbp), %rdi
callq 0x15f00
jmp 0x14812
movq -0x20(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x14810
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x90(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
movl (%rax,%rcx,4), %esi
movq -0x50(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x90(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, %edx
callq 0x15f50
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x147b8
jmp 0x14812
cmpl $0x0, -0x88(%rbp)
jne 0x1483a
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rax
movl 0x400(%rax), %esi
movq -0x50(%rbp), %rax
movl 0x400(%rax), %eax
movl %eax, %edx
callq 0x15f50
jmp 0x1483c
leaq -0x58(%rbp), %rdi
callq 0x13730
leaq -0x80(%rbp), %rdi
callq 0x13730
movl -0x88(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax)