// File: drummyfish[P]flowchart/src/lodepng.cpp
// Function: deflateFixed(ucvector*, unsigned long*, Hash*, unsigned char const*, unsigned long, unsigned long, LodePNGCompressSettings const*, int)
static unsigned deflateFixed(ucvector* out, size_t* bp, Hash* hash,
                             const unsigned char* data,
                             size_t datapos, size_t dataend,
                             const LodePNGCompressSettings* settings, int 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);
    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:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
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 0x18(%rbp), %eax
movl %eax, -0x74(%rbp)
movl $0x0, -0x78(%rbp)
leaq -0x50(%rbp), %rdi
callq 0xd7d0
leaq -0x70(%rbp), %rdi
callq 0xd7d0
leaq -0x50(%rbp), %rdi
callq 0xdfa0
leaq -0x70(%rbp), %rdi
callq 0xe0b0
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl -0x74(%rbp), %eax
movzbl %al, %edx
callq 0xf710
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl $0x1, %edx
callq 0xf710
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
xorl %edx, %edx
callq 0xf710
movq 0x10(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0xea0f
leaq -0x98(%rbp), %rdi
callq 0xcea0
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
movq 0x10(%rbp), %rax
movl 0x8(%rax), %r9d
leaq -0x98(%rbp), %rdi
callq 0xf790
movl %eax, -0x78(%rbp)
cmpl $0x0, -0x78(%rbp)
jne 0xe9fe
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
leaq -0x98(%rbp), %rdx
leaq -0x50(%rbp), %rcx
leaq -0x70(%rbp), %r8
callq 0xfde0
leaq -0x98(%rbp), %rdi
callq 0xd080
jmp 0xea92
movq -0x28(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0xea90
movq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x20(%rbp), %rax
movq -0x80(%rbp), %rcx
movzbl (%rax,%rcx), %esi
leaq -0x50(%rbp), %rdi
callq 0xffd0
movl %eax, -0x9c(%rbp)
movq -0x20(%rbp), %rax
movq -0x80(%rbp), %rcx
movzbl (%rax,%rcx), %esi
leaq -0x50(%rbp), %rdi
callq 0xfff0
movq -0xb0(%rbp), %rdi
movq -0xa8(%rbp), %rsi
movl -0x9c(%rbp), %edx
movl %eax, %ecx
callq 0xff90
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0xea17
jmp 0xea92
cmpl $0x0, -0x78(%rbp)
jne 0xeaeb
movq -0x10(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq -0x50(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0xffd0
movl %eax, -0xb4(%rbp)
leaq -0x50(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0xfff0
movq -0xc8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
movl -0xb4(%rbp), %edx
movl %eax, %ecx
callq 0xff90
leaq -0x50(%rbp), %rdi
callq 0xdf60
leaq -0x70(%rbp), %rdi
callq 0xdf60
movl -0x78(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax)