// File: mhe[P]raytracerframework_cpp/lodepng.cpp
// Function: writeLZ77data(unsigned long*, ucvector*, uivector const*, HuffmanTree const*, HuffmanTree const*)
static void writeLZ77data(size_t* bp, ucvector* out, const uivector* lz77_encoded, const HuffmanTree* codes, const HuffmanTree* codesD)
{
  size_t i = 0;
  for(i = 0; i < lz77_encoded->size; i++)
  {
    unsigned val = lz77_encoded->data[i];
    addHuffmanSymbol(bp, out, HuffmanTree_getCode(codes, val), HuffmanTree_getLength(codes, val));
    if(val > 256) /*for a length code, 3 more things have to be added*/
    {
      unsigned length_index = val - FIRST_LENGTH_CODE_INDEX;
      unsigned n_length_extra_bits = LENGTHEXTRA[length_index];
      unsigned length_extra_bits = lz77_encoded->data[++i];
      
      unsigned distance_code = lz77_encoded->data[++i];
      
      unsigned distance_index = distance_code;
      unsigned n_distance_extra_bits = DISTANCEEXTRA[distance_index];
      unsigned distance_extra_bits = lz77_encoded->data[++i];
      
      addBitsToStream(bp, out, length_extra_bits, n_length_extra_bits);
      addHuffmanSymbol(bp, out, HuffmanTree_getCode(codesD, distance_code), HuffmanTree_getLength(codesD, distance_code));
      addBitsToStream(bp, out, distance_extra_bits, n_distance_extra_bits);
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x2e622
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x20(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x2e670
movl %eax, -0x54(%rbp)
movq -0x20(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x2e690
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
movl -0x54(%rbp), %edx
movl %eax, %ecx
callq 0x2e630
cmpl $0x100, -0x34(%rbp)     # imm = 0x100
jbe 0x2e60f
movl -0x34(%rbp), %eax
subl $0x101, %eax            # imm = 0x101
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl %eax, %ecx
leaq 0x1d3bd(%rip), %rax     # 0x4b8f0
movl (%rax,%rcx,4), %eax
movl %eax, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movl 0x4(%rax,%rcx,4), %eax
movl %eax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movl 0x4(%rax,%rcx,4), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movl %eax, %ecx
leaq 0x1d46b(%rip), %rax     # 0x4b9f0
movl (%rax,%rcx,4), %eax
movl %eax, -0x4c(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movl 0x4(%rax,%rcx,4), %eax
movl %eax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x40(%rbp), %edx
movl -0x3c(%rbp), %eax
movl %eax, %ecx
callq 0x2ea90
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x28(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x2e670
movl %eax, -0x6c(%rbp)
movq -0x28(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x2e690
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %rsi
movl -0x6c(%rbp), %edx
movl %eax, %ecx
callq 0x2e630
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x50(%rbp), %edx
movl -0x4c(%rbp), %eax
movl %eax, %ecx
callq 0x2ea90
jmp 0x2e611
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x2e4af
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)