// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, -0x48(%rbp)
movq %rcx, -0x50(%rbp)
cmpq $0x0, 0x8(%rdx)
je 0x22ceb
movq %rsi, %r12
movq %rdi, %r13
xorl %ecx, %ecx
movq %rdx, -0x38(%rbp)
movq (%rdx), %rax
movq %rcx, -0x30(%rbp)
movl (%rax,%rcx,4), %ebx
movq -0x50(%rbp), %rax
movq 0x30(%rax), %rax
movl (%rax,%rbx,4), %r14d
testq %r14, %r14
je 0x22be5
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax,%rbx,4), %r15d
decq %r14
xorl %edx, %edx
btl %r14d, %r15d
setb %dl
movq %r13, %rdi
movq %r12, %rsi
callq 0x2267c
testq %r14, %r14
jne 0x22bc9
cmpl $0x101, %ebx            # imm = 0x101
jb 0x22cd6
addl $0xfffffeff, %ebx       # imm = 0xFFFFFEFF
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movl 0x8(%rax,%rcx,4), %esi
leaq 0xde33(%rip), %rdx      # 0x30a40
movq %rsi, -0x60(%rbp)
movl (%rdx,%rsi,4), %edx
movq %rdx, -0x58(%rbp)
movl 0xc(%rax,%rcx,4), %ecx
movl %ecx, -0x3c(%rbp)
leaq -0x1c(%rbx), %rcx
cmpq $-0x14, %rcx
jb 0x22c5b
leaq 0xdd10(%rip), %rcx      # 0x30940
movl (%rcx,%rbx,4), %ebx
movq -0x30(%rbp), %rcx
movl 0x4(%rax,%rcx,4), %r14d
xorl %r15d, %r15d
xorl %edx, %edx
btl %r15d, %r14d
setb %dl
movq %r13, %rdi
movq %r12, %rsi
callq 0x2267c
incq %r15
cmpq %r15, %rbx
jne 0x22c3f
movq -0x48(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x60(%rbp), %r15
movl (%rax,%r15,4), %ebx
testq %rbx, %rbx
je 0x22c98
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax,%r15,4), %r14d
decq %rbx
xorl %edx, %edx
btl %ebx, %r14d
setb %dl
movq %r13, %rdi
movq %r12, %rsi
callq 0x2267c
testq %rbx, %rbx
jne 0x22c7c
movq -0x30(%rbp), %rcx
addq $0x3, %rcx
cmpl $0x4, %r15d
jae 0x22cac
movq -0x38(%rbp), %rdx
jmp 0x22cde
movq %rcx, -0x30(%rbp)
xorl %ebx, %ebx
movq -0x58(%rbp), %r15
movl -0x3c(%rbp), %r14d
xorl %edx, %edx
btl %ebx, %r14d
setb %dl
movq %r13, %rdi
movq %r12, %rsi
callq 0x2267c
incq %rbx
cmpq %rbx, %r15
jne 0x22cba
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rcx
incq %rcx
cmpq 0x8(%rdx), %rcx
jb 0x22ba2
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq