// File: mhe[P]raytracerframework_cpp/lodepng.cpp
// Function: deflateFixed(ucvector*, unsigned char const*, unsigned long, LodeZlib_DeflateSettings const*)
static unsigned deflateFixed(ucvector* out, const unsigned char* data, size_t datasize, const LodeZlib_DeflateSettings* settings)
{
  HuffmanTree codes; /*tree for literal values and length codes*/
  HuffmanTree codesD; /*tree for distance codes*/
  
  unsigned BFINAL = 1; /*make only one block... the first and final one*/
  unsigned error = 0;
  size_t i, bp = 0; /*the bit pointer*/
  
  HuffmanTree_init(&codes);
  HuffmanTree_init(&codesD);
  
  generateFixedTree(&codes);
  generateDistanceTree(&codesD);
  
  addBitToStream(&bp, out, BFINAL);
  addBitToStream(&bp, out, 1); /*first bit of BTYPE*/
  addBitToStream(&bp, out, 0); /*second bit of BTYPE*/
  
  if(settings->useLZ77) /*LZ77 encoded*/
  {
    uivector lz77_encoded;
    uivector_init(&lz77_encoded);
    error = encodeLZ77(&lz77_encoded, data, datasize, settings->windowSize);
    if(!error) writeLZ77data(&bp, out, &lz77_encoded, &codes, &codesD);
    uivector_cleanup(&lz77_encoded);
  }
  else /*no LZ77, but still will be Huffman compressed*/
  {
    for(i = 0; i < datasize; i++) addHuffmanSymbol(&bp, out, HuffmanTree_getCode(&codes, data[i]), HuffmanTree_getLength(&codes, data[i]));
  }
  if(!error) addHuffmanSymbol(&bp, out, HuffmanTree_getCode(&codes, 256), HuffmanTree_getLength(&codes, 256)); /*"end" code*/
  
  /*cleanup*/
  HuffmanTree_cleanup(&codes);
  HuffmanTree_cleanup(&codesD);
  
  return error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x1, -0xc4(%rbp)
movl $0x0, -0xc8(%rbp)
movq $0x0, -0xd8(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x2cf70
leaq -0xc0(%rbp), %rdi
callq 0x2cf70
leaq -0x70(%rbp), %rdi
callq 0x2d6d0
leaq -0xc0(%rbp), %rdi
callq 0x2d7e0
movq -0x8(%rbp), %rsi
movl -0xc4(%rbp), %eax
leaq -0xd8(%rbp), %rdi
movzbl %al, %edx
callq 0x2df00
movq -0x8(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
movl $0x1, %edx
callq 0x2df00
movq -0x8(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
xorl %edx, %edx
callq 0x2df00
movq -0x20(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x24847
leaq -0xf0(%rbp), %rdi
callq 0x2d6a0
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rax
movl 0x8(%rax), %ecx
leaq -0xf0(%rbp), %rdi
callq 0x2df80
movl %eax, -0xc8(%rbp)
cmpl $0x0, -0xc8(%rbp)
jne 0x24836
movq -0x8(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
leaq -0xf0(%rbp), %rdx
leaq -0x70(%rbp), %rcx
leaq -0xc0(%rbp), %r8
callq 0x2e480
leaq -0xf0(%rbp), %rdi
callq 0x2d9b0
jmp 0x248d1
movq $0x0, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x248cf
movq -0x8(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x10(%rbp), %rax
movq -0xd0(%rbp), %rcx
movzbl (%rax,%rcx), %esi
leaq -0x70(%rbp), %rdi
callq 0x2e670
movl %eax, -0xf4(%rbp)
movq -0x10(%rbp), %rax
movq -0xd0(%rbp), %rcx
movzbl (%rax,%rcx), %esi
leaq -0x70(%rbp), %rdi
callq 0x2e690
movq -0x100(%rbp), %rsi
movl -0xf4(%rbp), %edx
movl %eax, %ecx
leaq -0xd8(%rbp), %rdi
callq 0x2e630
movq -0xd0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xd0(%rbp)
jmp 0x24852
jmp 0x248d1
cmpl $0x0, -0xc8(%rbp)
jne 0x24922
movq -0x8(%rbp), %rax
movq %rax, -0x110(%rbp)
leaq -0x70(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x2e670
movl %eax, -0x104(%rbp)
leaq -0x70(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x2e690
movq -0x110(%rbp), %rsi
movl -0x104(%rbp), %edx
movl %eax, %ecx
leaq -0xd8(%rbp), %rdi
callq 0x2e630
leaq -0x70(%rbp), %rdi
callq 0x2d540
leaq -0xc0(%rbp), %rdi
callq 0x2d540
movl -0xc8(%rbp), %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopw %cs:(%rax,%rax)