// File: /workspace/github_c_makefile_star2_O0/tditlu[P]shadetabler/src/lodepng/lodepng.c
// Function: inflateHuffmanBlock
static unsigned inflateHuffmanBlock(ucvector* out, LodePNGBitReader* reader,
                                    unsigned btype) {
  unsigned error = 0;
  HuffmanTree tree_ll; /*the huffman tree for literal and length codes*/
  HuffmanTree tree_d; /*the huffman tree for distance codes*/

  HuffmanTree_init(&tree_ll);
  HuffmanTree_init(&tree_d);

  if(btype == 1) error = getTreeInflateFixed(&tree_ll, &tree_d);
  else /*if(btype == 2)*/ error = getTreeInflateDynamic(&tree_ll, &tree_d, reader);

  while(!error) /*decode all symbols until end reached, breaks at end code*/ {
    /*code_ll is literal, length or end code*/
    unsigned code_ll;
    ensureBits25(reader, 20); /* up to 15 for the huffman symbol, up to 5 for the length extra bits */
    code_ll = huffmanDecodeSymbol(reader, &tree_ll);
    if(code_ll <= 255) /*literal symbol*/ {
      if(!ucvector_resize(out, out->size + 1)) ERROR_BREAK(83 /*alloc fail*/);
      out->data[out->size - 1] = (unsigned char)code_ll;
    } else if(code_ll >= FIRST_LENGTH_CODE_INDEX && code_ll <= LAST_LENGTH_CODE_INDEX) /*length code*/ {
      unsigned code_d, distance;
      unsigned numextrabits_l, numextrabits_d; /*extra bits for length and distance*/
      size_t start, backward, length;

      /*part 1: get length base*/
      length = LENGTHBASE[code_ll - FIRST_LENGTH_CODE_INDEX];

      /*part 2: get extra bits and add the value of that to length*/
      numextrabits_l = LENGTHEXTRA[code_ll - FIRST_LENGTH_CODE_INDEX];
      if(numextrabits_l != 0) {
        /* bits already ensured above */
        length += readBits(reader, numextrabits_l);
      }

      /*part 3: get distance code*/
      ensureBits32(reader, 28); /* up to 15 for the huffman symbol, up to 13 for the extra bits */
      code_d = huffmanDecodeSymbol(reader, &tree_d);
      if(code_d > 29) {
        if(code_d <= 31) {
          ERROR_BREAK(18); /*error: invalid distance code (30-31 are never used)*/
        } else /* if(code_d == INVALIDSYMBOL) */{
          ERROR_BREAK(16); /*error: tried to read disallowed huffman symbol*/
        }
      }
      distance = DISTANCEBASE[code_d];

      /*part 4: get extra bits from distance*/
      numextrabits_d = DISTANCEEXTRA[code_d];
      if(numextrabits_d != 0) {
        /* bits already ensured above */
        distance += readBits(reader, numextrabits_d);
      }

      /*part 5: fill in all the out[n] values based on the length and dist*/
      start = out->size;
      if(distance > start) ERROR_BREAK(52); /*too long backward distance*/
      backward = start - distance;

      if(!ucvector_resize(out, out->size + length)) ERROR_BREAK(83 /*alloc fail*/);
      if(distance < length) {
        size_t forward;
        lodepng_memcpy(out->data + start, out->data + backward, distance);
        start += distance;
        for(forward = distance; forward < length; ++forward) {
          out->data[start++] = out->data[backward++];
        }
      } else {
        lodepng_memcpy(out->data + start, out->data + backward, length);
      }
    } else if(code_ll == 256) {
      break; /*end code, break the loop*/
    } else /*if(code_ll == INVALIDSYMBOL)*/ {
      ERROR_BREAK(16); /*error: tried to read disallowed huffman symbol*/
    }
    /*check if any of the ensureBits above went out of bounds*/
    if(reader->bp > reader->bitsize) {
      /*return error code 10 or 11 depending on the situation that happened in huffmanDecodeSymbol
      (10=no endcode, 11=wrong jump outside of tree)*/
      /* TODO: revise error codes 10,11,50: the above comment is no longer valid */
      ERROR_BREAK(51); /*error, bit pointer jumps past memory*/
    }
  }

  HuffmanTree_cleanup(&tree_ll);
  HuffmanTree_cleanup(&tree_d);

  return error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x10b50
leaq -0x68(%rbp), %rdi
callq 0x10b50
cmpl $0x1, -0x14(%rbp)
jne 0x10797
leaq -0x40(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x10b90
movl %eax, -0x18(%rbp)
jmp 0x107ab
movq -0x10(%rbp), %rdx
leaq -0x40(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x10bd0
movl %eax, -0x18(%rbp)
jmp 0x107ad
cmpl $0x0, -0x18(%rbp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x107bf
jmp 0x10a99
movq -0x10(%rbp), %rdi
movl $0x14, %esi
callq 0x4290
movq -0x10(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x11110
movl %eax, -0x6c(%rbp)
cmpl $0xff, -0x6c(%rbp)
ja 0x1082c
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0x1, %rsi
callq 0x10ac0
cmpl $0x0, %eax
jne 0x1080c
movl $0x53, -0x18(%rbp)
jmp 0x10a99
movl -0x6c(%rbp), %eax
movb %al, %dl
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
movb %dl, (%rax,%rcx)
jmp 0x10a79
cmpl $0x101, -0x6c(%rbp)     # imm = 0x101
jb 0x10a63
cmpl $0x11d, -0x6c(%rbp)     # imm = 0x11D
ja 0x10a63
movl -0x6c(%rbp), %eax
subl $0x101, %eax            # imm = 0x101
movl %eax, %eax
movl %eax, %ecx
leaq 0xaa57(%rip), %rax      # 0x1b2b0
movl (%rax,%rcx,4), %eax
movq %rax, -0x98(%rbp)
movl -0x6c(%rbp), %eax
subl $0x101, %eax            # imm = 0x101
movl %eax, %eax
movl %eax, %ecx
leaq 0xaaba(%rip), %rax      # 0x1b330
movl (%rax,%rcx,4), %eax
movl %eax, -0x78(%rbp)
cmpl $0x0, -0x78(%rbp)
je 0x108a0
movq -0x10(%rbp), %rdi
movl -0x78(%rbp), %eax
movl %eax, %esi
callq 0x4650
movl %eax, %eax
addq -0x98(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rdi
movl $0x1c, %esi
callq 0x40b0
movq -0x10(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x11110
movl %eax, -0x70(%rbp)
cmpl $0x1d, -0x70(%rbp)
jbe 0x108e2
cmpl $0x1f, -0x70(%rbp)
ja 0x108d6
movl $0x12, -0x18(%rbp)
jmp 0x10a99
movl $0x10, -0x18(%rbp)
jmp 0x10a99
movl -0x70(%rbp), %eax
movl %eax, %ecx
leaq 0xaac2(%rip), %rax      # 0x1b3b0
movl (%rax,%rcx,4), %eax
movl %eax, -0x74(%rbp)
movl -0x70(%rbp), %eax
movl %eax, %ecx
leaq 0xab30(%rip), %rax      # 0x1b430
movl (%rax,%rcx,4), %eax
movl %eax, -0x7c(%rbp)
cmpl $0x0, -0x7c(%rbp)
je 0x10920
movq -0x10(%rbp), %rdi
movl -0x7c(%rbp), %eax
movl %eax, %esi
callq 0x4650
addl -0x74(%rbp), %eax
movl %eax, -0x74(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x88(%rbp)
movl -0x74(%rbp), %eax
cmpq -0x88(%rbp), %rax
jbe 0x10947
movl $0x34, -0x18(%rbp)
jmp 0x10a99
movq -0x88(%rbp), %rax
movl -0x74(%rbp), %ecx
subq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
addq -0x98(%rbp), %rsi
callq 0x10ac0
cmpl $0x0, %eax
jne 0x10984
movl $0x53, -0x18(%rbp)
jmp 0x10a99
movl -0x74(%rbp), %eax
cmpq -0x98(%rbp), %rax
jae 0x10a39
movq -0x8(%rbp), %rax
movq (%rax), %rdi
addq -0x88(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rsi
addq -0x90(%rbp), %rsi
movl -0x74(%rbp), %eax
movl %eax, %edx
callq 0x6440
movl -0x74(%rbp), %eax
addq -0x88(%rbp), %rax
movq %rax, -0x88(%rbp)
movl -0x74(%rbp), %eax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
cmpq -0x98(%rbp), %rax
jae 0x10a37
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x90(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x90(%rbp)
movb (%rax,%rcx), %dl
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x88(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x88(%rbp)
movb %dl, (%rax,%rcx)
movq -0xa0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa0(%rbp)
jmp 0x109d5
jmp 0x10a61
movq -0x8(%rbp), %rax
movq (%rax), %rdi
addq -0x88(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rsi
addq -0x90(%rbp), %rsi
movq -0x98(%rbp), %rdx
callq 0x6440
jmp 0x10a77
cmpl $0x100, -0x6c(%rbp)     # imm = 0x100
jne 0x10a6e
jmp 0x10a99
movl $0x10, -0x18(%rbp)
jmp 0x10a99
jmp 0x10a79
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jbe 0x10a94
movl $0x33, -0x18(%rbp)
jmp 0x10a99
jmp 0x107ad
leaq -0x40(%rbp), %rdi
callq 0x111f0
leaq -0x68(%rbp), %rdi
callq 0x111f0
movl -0x18(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopw (%rax,%rax)