// File: phillip-h[P]fractal-gen/lodepng.cpp
// Function: deflateFixed(ucvector*, unsigned long*, Hash*, unsigned char const*, unsigned long, unsigned long, LodePNGCompressSettings const*, unsigned int)
static unsigned deflateFixed(ucvector* out, size_t* bp, 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);

  generateFixedLitLenTree(&tree_ll);
  generateFixedDistanceTree(&tree_d);

  addBitToStream(bp, out, BFINAL);
  addBitToStream(bp, out, 1); /*first bit of BTYPE*/
  addBitToStream(bp, out, 0); /*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(bp, out, &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)
    {
      addHuffmanSymbol(bp, out, HuffmanTree_getCode(&tree_ll, data[i]), HuffmanTree_getLength(&tree_ll, data[i]));
    }
  }
  /*add END code*/
  if(!error) addHuffmanSymbol(bp, out, HuffmanTree_getCode(&tree_ll, 256), HuffmanTree_getLength(&tree_ll, 256));

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

  return error;
}

// Assembly:
subq $0xe8, %rsp
movl 0xf8(%rsp), %eax
movq 0xf0(%rsp), %rax
movq %rdi, 0xe0(%rsp)
movq %rsi, 0xd8(%rsp)
movq %rdx, 0xd0(%rsp)
movq %rcx, 0xc8(%rsp)
movq %r8, 0xc0(%rsp)
movq %r9, 0xb8(%rsp)
movl 0xf8(%rsp), %eax
movl %eax, 0x74(%rsp)
movl $0x0, 0x70(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x12420
leaq 0x78(%rsp), %rdi
callq 0x12420
leaq 0x98(%rsp), %rdi
callq 0x12cf0
leaq 0x78(%rsp), %rdi
callq 0x12e20
movq 0xd8(%rsp), %rax
movq (%rax), %rax
andq $0x7, %rax
cmpq $0x0, %rax
jne 0x13a3b
movq 0xe0(%rsp), %rdi
xorl %esi, %esi
callq 0x81d0
movl 0x74(%rsp), %esi
movq 0xd8(%rsp), %rax
movq (%rax), %rax
andq $0x7, %rax
movl %eax, %ecx
shll %cl, %esi
movq 0xe0(%rsp), %rax
movq (%rax), %rax
movq 0xe0(%rsp), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movq 0xd8(%rsp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq 0xd8(%rsp), %rax
movq (%rax), %rax
andq $0x7, %rax
cmpq $0x0, %rax
jne 0x13aac
movq 0xe0(%rsp), %rdi
xorl %esi, %esi
callq 0x81d0
movq 0xd8(%rsp), %rax
movq (%rax), %rax
andq $0x7, %rax
movl %eax, %ecx
movl $0x1, %esi
shll %cl, %esi
movq 0xe0(%rsp), %rax
movq (%rax), %rax
movq 0xe0(%rsp), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movq 0xd8(%rsp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq 0xd8(%rsp), %rax
movq (%rax), %rax
andq $0x7, %rax
cmpq $0x0, %rax
jne 0x13b1e
movq 0xe0(%rsp), %rdi
xorl %esi, %esi
callq 0x81d0
movq 0xd8(%rsp), %rax
movq (%rax), %rax
andq $0x7, %rax
movl %eax, %ecx
xorl %esi, %esi
shll %cl, %esi
movq 0xe0(%rsp), %rax
movq (%rax), %rax
movq 0xe0(%rsp), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movq 0xd8(%rsp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq 0xf0(%rsp), %rax
cmpl $0x0, 0x4(%rax)
je 0x13c2c
leaq 0x50(%rsp), %rdi
callq 0x13160
movq 0xd0(%rsp), %rsi
movq 0xc8(%rsp), %rdx
movq 0xc0(%rsp), %rcx
movq 0xb8(%rsp), %r8
movq 0xf0(%rsp), %rax
movl 0x8(%rax), %r9d
movq 0xf0(%rsp), %rax
movl 0xc(%rax), %r11d
movq 0xf0(%rsp), %rax
movl 0x10(%rax), %r10d
movq 0xf0(%rsp), %rax
movl 0x14(%rax), %eax
leaq 0x50(%rsp), %rdi
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
callq 0x14ba0
movl %eax, 0x70(%rsp)
cmpl $0x0, 0x70(%rsp)
jne 0x13c1d
movq 0xd8(%rsp), %rdi
movq 0xe0(%rsp), %rsi
leaq 0x50(%rsp), %rdx
leaq 0x98(%rsp), %rcx
leaq 0x78(%rsp), %r8
callq 0x15490
leaq 0x50(%rsp), %rdi
callq 0x13220
jmp 0x13cd0
movq 0xc0(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rax
cmpq 0xb8(%rsp), %rax
jae 0x13cce
movq 0xd8(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0xc8(%rsp), %rax
movq 0x68(%rsp), %rcx
movzbl (%rax,%rcx), %esi
leaq 0x98(%rsp), %rdi
callq 0x156d0
movl %eax, 0x4c(%rsp)
movq 0xc8(%rsp), %rax
movq 0x68(%rsp), %rcx
movzbl (%rax,%rcx), %esi
leaq 0x98(%rsp), %rdi
callq 0x156f0
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl 0x4c(%rsp), %edx
movl %eax, %ecx
callq 0x15690
movq 0x68(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x68(%rsp)
jmp 0x13c39
jmp 0x13cd0
cmpl $0x0, 0x70(%rsp)
jne 0x13d2e
movq 0xd8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x98(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x156d0
movl %eax, 0x34(%rsp)
leaq 0x98(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x156f0
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl 0x34(%rsp), %edx
movl %eax, %ecx
callq 0x15690
leaq 0x98(%rsp), %rdi
callq 0x12cc0
leaq 0x78(%rsp), %rdi
callq 0x12cc0
movl 0x70(%rsp), %eax
addq $0xe8, %rsp
retq
nopw %cs:(%rax,%rax)