BrotliGetDictionary:
 5898|  3.91k|const BrotliDictionary* BrotliGetDictionary() {
 5899|  3.91k|  return &kBrotliDictionary;
 5900|  3.91k|}

BrotliDefaultAllocFunc:
   13|  57.9k|void* BrotliDefaultAllocFunc(void* opaque, size_t size) {
   14|  57.9k|  BROTLI_UNUSED(opaque);
  ------------------
  |  |  511|  57.9k|#define BROTLI_UNUSED(X) (void)(X)
  ------------------
   15|  57.9k|  return malloc(size);
   16|  57.9k|}
BrotliDefaultFreeFunc:
   19|  97.0k|void BrotliDefaultFreeFunc(void* opaque, void* address) {
   20|  97.0k|  BROTLI_UNUSED(opaque);
  ------------------
  |  |  511|  97.0k|#define BROTLI_UNUSED(X) (void)(X)
  ------------------
   21|  97.0k|  free(address);
   22|  97.0k|}

decode.c:BrotliUnalignedRead64:
  347|  65.9k|static BROTLI_INLINE uint64_t BrotliUnalignedRead64(const void* p) {
  348|  65.9k|  return *(const uint64_t*)p;
  349|  65.9k|}
decode.c:BrotliUnalignedRead32:
  343|  71.8k|static BROTLI_INLINE uint32_t BrotliUnalignedRead32(const void* p) {
  344|  71.8k|  return *(const uint32_t*)p;
  345|  71.8k|}

BrotliGetTransforms:
  173|  3.91k|const BrotliTransforms* BrotliGetTransforms(void) {
  174|  3.91k|  return &kBrotliTransforms;
  175|  3.91k|}
BrotliTransformDictionaryWord:
  237|  26.6k|    const BrotliTransforms* transforms, int transform_idx) {
  238|  26.6k|  int idx = 0;
  239|  26.6k|  const uint8_t* prefix = BROTLI_TRANSFORM_PREFIX(transforms, transform_idx);
  ------------------
  |  |   70|  26.6k|#define BROTLI_TRANSFORM_PREFIX(T, I) (&(T)->prefix_suffix[ \
  |  |   71|  26.6k|    (T)->prefix_suffix_map[BROTLI_TRANSFORM_PREFIX_ID(T, I)]])
  |  |  ------------------
  |  |  |  |   65|  26.6k|#define BROTLI_TRANSFORM_PREFIX_ID(T, I) ((T)->transforms[((I) * 3) + 0])
  |  |  ------------------
  ------------------
  240|  26.6k|  uint8_t type = BROTLI_TRANSFORM_TYPE(transforms, transform_idx);
  ------------------
  |  |   66|  26.6k|#define BROTLI_TRANSFORM_TYPE(T, I)      ((T)->transforms[((I) * 3) + 1])
  ------------------
  241|  26.6k|  const uint8_t* suffix = BROTLI_TRANSFORM_SUFFIX(transforms, transform_idx);
  ------------------
  |  |   72|  26.6k|#define BROTLI_TRANSFORM_SUFFIX(T, I) (&(T)->prefix_suffix[ \
  |  |   73|  26.6k|    (T)->prefix_suffix_map[BROTLI_TRANSFORM_SUFFIX_ID(T, I)]])
  |  |  ------------------
  |  |  |  |   67|  26.6k|#define BROTLI_TRANSFORM_SUFFIX_ID(T, I) ((T)->transforms[((I) * 3) + 2])
  |  |  ------------------
  ------------------
  242|  26.6k|  {
  243|  26.6k|    int prefix_len = *prefix++;
  244|  38.7k|    while (prefix_len--) { dst[idx++] = *prefix++; }
  ------------------
  |  Branch (244:12): [True: 12.1k, False: 26.6k]
  ------------------
  245|  26.6k|  }
  246|  26.6k|  {
  247|  26.6k|    const int t = type;
  248|  26.6k|    int i = 0;
  249|  26.6k|    if (t <= BROTLI_TRANSFORM_OMIT_LAST_9) {
  ------------------
  |  Branch (249:9): [True: 18.7k, False: 7.87k]
  ------------------
  250|  18.7k|      len -= t;
  251|  18.7k|    } else if (t >= BROTLI_TRANSFORM_OMIT_FIRST_1
  ------------------
  |  Branch (251:16): [True: 1.96k, False: 5.90k]
  ------------------
  252|  1.96k|        && t <= BROTLI_TRANSFORM_OMIT_FIRST_9) {
  ------------------
  |  Branch (252:12): [True: 1.96k, False: 0]
  ------------------
  253|  1.96k|      int skip = t - (BROTLI_TRANSFORM_OMIT_FIRST_1 - 1);
  254|  1.96k|      word += skip;
  255|  1.96k|      len -= skip;
  256|  1.96k|    }
  257|   208k|    while (i < len) { dst[idx++] = word[i++]; }
  ------------------
  |  Branch (257:12): [True: 181k, False: 26.6k]
  ------------------
  258|  26.6k|    if (t == BROTLI_TRANSFORM_UPPERCASE_FIRST) {
  ------------------
  |  Branch (258:9): [True: 4.85k, False: 21.7k]
  ------------------
  259|  4.85k|      ToUpperCase(&dst[idx - len]);
  260|  21.7k|    } else if (t == BROTLI_TRANSFORM_UPPERCASE_ALL) {
  ------------------
  |  Branch (260:16): [True: 1.05k, False: 20.7k]
  ------------------
  261|  1.05k|      uint8_t* uppercase = &dst[idx - len];
  262|  9.89k|      while (len > 0) {
  ------------------
  |  Branch (262:14): [True: 8.84k, False: 1.05k]
  ------------------
  263|  8.84k|        int step = ToUpperCase(uppercase);
  264|  8.84k|        uppercase += step;
  265|  8.84k|        len -= step;
  266|  8.84k|      }
  267|  20.7k|    } else if (t == BROTLI_TRANSFORM_SHIFT_FIRST) {
  ------------------
  |  Branch (267:16): [True: 0, False: 20.7k]
  ------------------
  268|      0|      uint16_t param = (uint16_t)(transforms->params[transform_idx * 2]
  269|      0|          + (transforms->params[transform_idx * 2 + 1] << 8u));
  270|      0|      Shift(&dst[idx - len], len, param);
  271|  20.7k|    } else if (t == BROTLI_TRANSFORM_SHIFT_ALL) {
  ------------------
  |  Branch (271:16): [True: 0, False: 20.7k]
  ------------------
  272|      0|      uint16_t param = (uint16_t)(transforms->params[transform_idx * 2]
  273|      0|          + (transforms->params[transform_idx * 2 + 1] << 8u));
  274|      0|      uint8_t* shift = &dst[idx - len];
  275|      0|      while (len > 0) {
  ------------------
  |  Branch (275:14): [True: 0, False: 0]
  ------------------
  276|      0|        int step = Shift(shift, len, param);
  277|      0|        shift += step;
  278|      0|        len -= step;
  279|      0|      }
  280|      0|    }
  281|  26.6k|  }
  282|  26.6k|  {
  283|  26.6k|    int suffix_len = *suffix++;
  284|  78.9k|    while (suffix_len--) { dst[idx++] = *suffix++; }
  ------------------
  |  Branch (284:12): [True: 52.3k, False: 26.6k]
  ------------------
  285|  26.6k|    return idx;
  286|  26.6k|  }
  287|  26.6k|}
transform.c:ToUpperCase:
  177|  13.7k|static int ToUpperCase(uint8_t* p) {
  178|  13.7k|  if (p[0] < 0xC0) {
  ------------------
  |  Branch (178:7): [True: 11.9k, False: 1.71k]
  ------------------
  179|  11.9k|    if (p[0] >= 'a' && p[0] <= 'z') {
  ------------------
  |  Branch (179:9): [True: 9.12k, False: 2.86k]
  |  Branch (179:24): [True: 8.71k, False: 411]
  ------------------
  180|  8.71k|      p[0] ^= 32;
  181|  8.71k|    }
  182|  11.9k|    return 1;
  183|  11.9k|  }
  184|       |  /* An overly simplified uppercasing model for UTF-8. */
  185|  1.71k|  if (p[0] < 0xE0) {
  ------------------
  |  Branch (185:7): [True: 986, False: 731]
  ------------------
  186|    986|    p[1] ^= 32;
  187|    986|    return 2;
  188|    986|  }
  189|       |  /* An arbitrary transform for three byte characters. */
  190|    731|  p[2] ^= 5;
  191|    731|  return 3;
  192|  1.71k|}

BrotliInitBitReader:
   29|  3.91k|void BrotliInitBitReader(BrotliBitReader* const br) {
   30|  3.91k|  br->val_ = 0;
   31|  3.91k|  br->bit_pos_ = sizeof(br->val_) << 3;
   32|  3.91k|}
BrotliWarmupBitReader:
   34|  78.0k|BROTLI_BOOL BrotliWarmupBitReader(BrotliBitReader* const br) {
   35|  78.0k|  size_t aligned_read_mask = (sizeof(br->val_) >> 1) - 1;
   36|       |  /* Fixing alignment after unaligned BrotliFillWindow would result accumulator
   37|       |     overflow. If unalignment is caused by BrotliSafeReadBits, then there is
   38|       |     enough space in accumulator to fix alignment. */
   39|  78.0k|  if (!BROTLI_ALIGNED_READ) {
  ------------------
  |  |  287|  78.0k|#define BROTLI_ALIGNED_READ (!!0)
  ------------------
  |  Branch (39:7): [True: 78.0k, Folded]
  ------------------
   40|  78.0k|    aligned_read_mask = 0;
   41|  78.0k|  }
   42|  78.0k|  if (BrotliGetAvailableBits(br) == 0) {
  ------------------
  |  Branch (42:7): [True: 23.8k, False: 54.2k]
  ------------------
   43|  23.8k|    if (!BrotliPullByte(br)) {
  ------------------
  |  Branch (43:9): [True: 211, False: 23.6k]
  ------------------
   44|    211|      return BROTLI_FALSE;
  ------------------
  |  |   53|    211|#define BROTLI_FALSE 0
  ------------------
   45|    211|    }
   46|  23.8k|  }
   47|       |
   48|  77.8k|  while ((((size_t)br->next_in) & aligned_read_mask) != 0) {
  ------------------
  |  Branch (48:10): [True: 0, False: 77.8k]
  ------------------
   49|      0|    if (!BrotliPullByte(br)) {
  ------------------
  |  Branch (49:9): [True: 0, False: 0]
  ------------------
   50|       |      /* If we consumed all the input, we don't care about the alignment. */
   51|      0|      return BROTLI_TRUE;
  ------------------
  |  |   51|      0|#define BROTLI_TRUE 1
  ------------------
   52|      0|    }
   53|      0|  }
   54|  77.8k|  return BROTLI_TRUE;
  ------------------
  |  |   51|  77.8k|#define BROTLI_TRUE 1
  ------------------
   55|  77.8k|}

decode.c:BrotliBitReaderUnload:
  223|   142k|static BROTLI_INLINE void BrotliBitReaderUnload(BrotliBitReader* br) {
  224|   142k|  uint32_t unused_bytes = BrotliGetAvailableBits(br) >> 3;
  225|   142k|  uint32_t unused_bits = unused_bytes << 3;
  226|   142k|  br->avail_in += unused_bytes;
  227|   142k|  br->next_in -= unused_bytes;
  228|   142k|  if (unused_bits == sizeof(br->val_) << 3) {
  ------------------
  |  Branch (228:7): [True: 2.24k, False: 140k]
  ------------------
  229|  2.24k|    br->val_ = 0;
  230|   140k|  } else {
  231|   140k|    br->val_ <<= unused_bits;
  232|   140k|  }
  233|   142k|  br->bit_pos_ += unused_bits;
  234|   142k|}
decode.c:BrotliTakeBits:
  239|  88.6M|  BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
  240|  88.6M|  *val = (uint32_t)BrotliGetBitsUnmasked(br) & BitMask(n_bits);
  241|  88.6M|  BROTLI_LOG(("[BrotliTakeBits]  %d %d %d val: %6x\n",
  242|  88.6M|      (int)br->avail_in, (int)br->bit_pos_, (int)n_bits, (int)*val));
  243|  88.6M|  BrotliDropBits(br, n_bits);
  244|  88.6M|}
decode.c:BrotliGetBitsUnmasked:
  184|  2.15G|    BrotliBitReader* const br) {
  185|  2.15G|  return br->val_ >> br->bit_pos_;
  186|  2.15G|}
decode.c:BrotliDropBits:
  219|  2.06G|    BrotliBitReader* const br, uint32_t n_bits) {
  220|  2.06G|  br->bit_pos_ += n_bits;
  221|  2.06G|}
decode.c:BrotliSafeReadBits:
  292|  1.13M|    BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
  293|  1.13M|  BROTLI_DCHECK(n_bits <= 24);
  294|  2.00M|  while (BrotliGetAvailableBits(br) < n_bits) {
  ------------------
  |  Branch (294:10): [True: 866k, False: 1.13M]
  ------------------
  295|   866k|    if (!BrotliPullByte(br)) {
  ------------------
  |  Branch (295:9): [True: 1.17k, False: 865k]
  ------------------
  296|  1.17k|      return BROTLI_FALSE;
  ------------------
  |  |   53|  1.17k|#define BROTLI_FALSE 0
  ------------------
  297|  1.17k|    }
  298|   866k|  }
  299|  1.13M|  BrotliTakeBits(br, n_bits, val);
  300|  1.13M|  return BROTLI_TRUE;
  ------------------
  |  |   51|  1.13M|#define BROTLI_TRUE 1
  ------------------
  301|  1.13M|}
decode.c:BrotliPullByte:
  165|   445M|static BROTLI_INLINE BROTLI_BOOL BrotliPullByte(BrotliBitReader* const br) {
  166|   445M|  if (br->avail_in == 0) {
  ------------------
  |  Branch (166:7): [True: 444M, False: 1.05M]
  ------------------
  167|   444M|    return BROTLI_FALSE;
  ------------------
  |  |   53|   444M|#define BROTLI_FALSE 0
  ------------------
  168|   444M|  }
  169|  1.05M|  br->val_ >>= 8;
  170|  1.05M|#if (BROTLI_64_BITS)
  171|  1.05M|  br->val_ |= ((uint64_t)*br->next_in) << 56;
  172|       |#else
  173|       |  br->val_ |= ((uint32_t)*br->next_in) << 24;
  174|       |#endif
  175|  1.05M|  br->bit_pos_ -= 8;
  176|  1.05M|  --br->avail_in;
  177|  1.05M|  ++br->next_in;
  178|  1.05M|  return BROTLI_TRUE;
  ------------------
  |  |   51|  1.05M|#define BROTLI_TRUE 1
  ------------------
  179|   445M|}
decode.c:BrotliJumpToByteBoundary:
  322|  4.45k|static BROTLI_INLINE BROTLI_BOOL BrotliJumpToByteBoundary(BrotliBitReader* br) {
  323|  4.45k|  uint32_t pad_bits_count = BrotliGetAvailableBits(br) & 0x7;
  324|  4.45k|  uint32_t pad_bits = 0;
  325|  4.45k|  if (pad_bits_count != 0) {
  ------------------
  |  Branch (325:7): [True: 3.72k, False: 732]
  ------------------
  326|  3.72k|    BrotliTakeBits(br, pad_bits_count, &pad_bits);
  327|  3.72k|  }
  328|  4.45k|  return TO_BROTLI_BOOL(pad_bits == 0);
  ------------------
  |  |   55|  4.45k|#define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE)
  |  |  ------------------
  |  |  |  |   51|  4.39k|#define BROTLI_TRUE 1
  |  |  ------------------
  |  |               #define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE)
  |  |  ------------------
  |  |  |  |   53|     58|#define BROTLI_FALSE 0
  |  |  ------------------
  |  |  |  Branch (55:28): [True: 4.39k, False: 58]
  |  |  ------------------
  ------------------
  329|  4.45k|}
decode.c:BrotliSafeGetBits:
  207|  1.42G|    BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
  208|  1.42G|  while (BrotliGetAvailableBits(br) < n_bits) {
  ------------------
  |  Branch (208:10): [True: 444M, False: 979M]
  ------------------
  209|   444M|    if (!BrotliPullByte(br)) {
  ------------------
  |  Branch (209:9): [True: 444M, False: 185k]
  ------------------
  210|   444M|      return BROTLI_FALSE;
  ------------------
  |  |   53|   444M|#define BROTLI_FALSE 0
  ------------------
  211|   444M|    }
  212|   444M|  }
  213|   979M|  *val = (uint32_t)BrotliGetBitsUnmasked(br) & BitMask(n_bits);
  214|   979M|  return BROTLI_TRUE;
  ------------------
  |  |   51|   979M|#define BROTLI_TRUE 1
  ------------------
  215|  1.42G|}
decode.c:BrotliCheckInputAmount:
   99|   586M|    BrotliBitReader* const br, size_t num) {
  100|   586M|  return TO_BROTLI_BOOL(br->avail_in >= num);
  ------------------
  |  |   55|   586M|#define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE)
  |  |  ------------------
  |  |  |  |   51|   586M|#define BROTLI_TRUE 1
  |  |  ------------------
  |  |               #define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE)
  |  |  ------------------
  |  |  |  |   53|   100k|#define BROTLI_FALSE 0
  |  |  ------------------
  |  |  |  Branch (55:28): [True: 586M, False: 100k]
  |  |  ------------------
  ------------------
  101|   586M|}
decode.c:BrotliFillBitWindow16:
  159|   131k|static BROTLI_INLINE void BrotliFillBitWindow16(BrotliBitReader* const br) {
  160|   131k|  BrotliFillBitWindow(br, 17);
  161|   131k|}
decode.c:BrotliFillBitWindow:
  108|   762M|    BrotliBitReader* const br, uint32_t n_bits) {
  109|   762M|#if (BROTLI_64_BITS)
  110|   762M|  if (!BROTLI_ALIGNED_READ && BROTLI_IS_CONSTANT(n_bits) && (n_bits <= 8)) {
  ------------------
  |  |  287|  1.52G|#define BROTLI_ALIGNED_READ (!!0)
  ------------------
                if (!BROTLI_ALIGNED_READ && BROTLI_IS_CONSTANT(n_bits) && (n_bits <= 8)) {
  ------------------
  |  |  459|  1.52G|#define BROTLI_IS_CONSTANT(x) (!!__builtin_constant_p(x))
  |  |  ------------------
  |  |  |  Branch (459:31): [True: 674M, False: 87.4M]
  |  |  ------------------
  ------------------
  |  Branch (110:7): [True: 762M, Folded]
  |  Branch (110:61): [True: 543M, False: 131M]
  ------------------
  111|   543M|    if (br->bit_pos_ >= 56) {
  ------------------
  |  Branch (111:9): [True: 6.06k, False: 543M]
  ------------------
  112|  6.06k|      br->val_ >>= 56;
  113|  6.06k|      br->bit_pos_ ^= 56;  /* here same as -= 56 because of the if condition */
  114|  6.06k|      br->val_ |= BROTLI_UNALIGNED_LOAD64LE(br->next_in) << 8;
  ------------------
  |  |  386|  6.06k|#define BROTLI_UNALIGNED_LOAD64LE BrotliUnalignedRead64
  ------------------
  115|  6.06k|      br->avail_in -= 7;
  116|  6.06k|      br->next_in += 7;
  117|  6.06k|    }
  118|   543M|  } else if (
  119|   219M|      !BROTLI_ALIGNED_READ && BROTLI_IS_CONSTANT(n_bits) && (n_bits <= 16)) {
  ------------------
  |  |  287|   438M|#define BROTLI_ALIGNED_READ (!!0)
  ------------------
                    !BROTLI_ALIGNED_READ && BROTLI_IS_CONSTANT(n_bits) && (n_bits <= 16)) {
  ------------------
  |  |  459|   438M|#define BROTLI_IS_CONSTANT(x) (!!__builtin_constant_p(x))
  |  |  ------------------
  |  |  |  Branch (459:31): [True: 131M, False: 87.4M]
  |  |  ------------------
  ------------------
  |  Branch (119:7): [True: 219M, Folded]
  |  Branch (119:61): [True: 131M, False: 131k]
  ------------------
  120|   131M|    if (br->bit_pos_ >= 48) {
  ------------------
  |  Branch (120:9): [True: 59.9k, False: 131M]
  ------------------
  121|  59.9k|      br->val_ >>= 48;
  122|  59.9k|      br->bit_pos_ ^= 48;  /* here same as -= 48 because of the if condition */
  123|  59.9k|      br->val_ |= BROTLI_UNALIGNED_LOAD64LE(br->next_in) << 16;
  ------------------
  |  |  386|  59.9k|#define BROTLI_UNALIGNED_LOAD64LE BrotliUnalignedRead64
  ------------------
  124|  59.9k|      br->avail_in -= 6;
  125|  59.9k|      br->next_in += 6;
  126|  59.9k|    }
  127|   131M|  } else {
  128|  87.6M|    if (br->bit_pos_ >= 32) {
  ------------------
  |  Branch (128:9): [True: 71.8k, False: 87.5M]
  ------------------
  129|  71.8k|      br->val_ >>= 32;
  130|  71.8k|      br->bit_pos_ ^= 32;  /* here same as -= 32 because of the if condition */
  131|  71.8k|      br->val_ |= ((uint64_t)BROTLI_UNALIGNED_LOAD32LE(br->next_in)) << 32;
  ------------------
  |  |  385|  71.8k|#define BROTLI_UNALIGNED_LOAD32LE BrotliUnalignedRead32
  ------------------
  132|  71.8k|      br->avail_in -= BROTLI_SHORT_FILL_BIT_WINDOW_READ;
  ------------------
  |  |   22|  71.8k|#define BROTLI_SHORT_FILL_BIT_WINDOW_READ (sizeof(brotli_reg_t) >> 1)
  ------------------
  133|  71.8k|      br->next_in += BROTLI_SHORT_FILL_BIT_WINDOW_READ;
  ------------------
  |  |   22|  71.8k|#define BROTLI_SHORT_FILL_BIT_WINDOW_READ (sizeof(brotli_reg_t) >> 1)
  ------------------
  134|  71.8k|    }
  135|  87.6M|  }
  136|       |#else
  137|       |  if (!BROTLI_ALIGNED_READ && BROTLI_IS_CONSTANT(n_bits) && (n_bits <= 8)) {
  138|       |    if (br->bit_pos_ >= 24) {
  139|       |      br->val_ >>= 24;
  140|       |      br->bit_pos_ ^= 24;  /* here same as -= 24 because of the if condition */
  141|       |      br->val_ |= BROTLI_UNALIGNED_LOAD32LE(br->next_in) << 8;
  142|       |      br->avail_in -= 3;
  143|       |      br->next_in += 3;
  144|       |    }
  145|       |  } else {
  146|       |    if (br->bit_pos_ >= 16) {
  147|       |      br->val_ >>= 16;
  148|       |      br->bit_pos_ ^= 16;  /* here same as -= 16 because of the if condition */
  149|       |      br->val_ |= ((uint32_t)BROTLI_UNALIGNED_LOAD16LE(br->next_in)) << 16;
  150|       |      br->avail_in -= BROTLI_SHORT_FILL_BIT_WINDOW_READ;
  151|       |      br->next_in += BROTLI_SHORT_FILL_BIT_WINDOW_READ;
  152|       |    }
  153|       |  }
  154|       |#endif
  155|   762M|}
decode.c:BrotliGetRemainingBytes:
   90|  4.55k|static BROTLI_INLINE size_t BrotliGetRemainingBytes(BrotliBitReader* br) {
   91|  4.55k|  static const size_t kCap = (size_t)1 << BROTLI_LARGE_MAX_WBITS;
  ------------------
  |  |   57|  4.55k|#define BROTLI_LARGE_MAX_WBITS 30
  ------------------
   92|  4.55k|  if (br->avail_in > kCap) return kCap;
  ------------------
  |  Branch (92:7): [True: 0, False: 4.55k]
  ------------------
   93|  4.55k|  return br->avail_in + (BrotliGetAvailableBits(br) >> 3);
   94|  4.55k|}
decode.c:BrotliCopyBytes:
  335|  4.55k|                                          BrotliBitReader* br, size_t num) {
  336|  5.72k|  while (BrotliGetAvailableBits(br) >= 8 && num > 0) {
  ------------------
  |  Branch (336:10): [True: 1.92k, False: 3.79k]
  |  Branch (336:45): [True: 1.16k, False: 759]
  ------------------
  337|  1.16k|    *dest = (uint8_t)BrotliGetBitsUnmasked(br);
  338|  1.16k|    BrotliDropBits(br, 8);
  339|  1.16k|    ++dest;
  340|  1.16k|    --num;
  341|  1.16k|  }
  342|  4.55k|  memcpy(dest, br->next_in, num);
  343|  4.55k|  br->avail_in -= num;
  344|  4.55k|  br->next_in += num;
  345|  4.55k|}
decode.c:BitMask:
   26|  1.62G|static BROTLI_INLINE uint32_t BitMask(uint32_t n) {
   27|  1.62G|  if (BROTLI_IS_CONSTANT(n) || BROTLI_HAS_UBFX) {
  ------------------
  |  |  459|  3.24G|#define BROTLI_IS_CONSTANT(x) (!!__builtin_constant_p(x))
  |  |  ------------------
  |  |  |  Branch (459:31): [True: 1.52G, False: 100M]
  |  |  ------------------
  ------------------
                if (BROTLI_IS_CONSTANT(n) || BROTLI_HAS_UBFX) {
  ------------------
  |  |  467|   100M|#define BROTLI_HAS_UBFX (!!0)
  |  |  ------------------
  |  |  |  Branch (467:25): [Folded, False: 0]
  |  |  ------------------
  ------------------
   28|       |    /* Masking with this expression turns to a single
   29|       |       "Unsigned Bit Field Extract" UBFX instruction on ARM. */
   30|  1.52G|    return ~((0xFFFFFFFFu) << n);
   31|  1.52G|  } else {
   32|   100M|    return kBrotliBitMask[n];
   33|   100M|  }
   34|  1.62G|}
decode.c:BrotliReadBits24:
  250|  86.1M|    BrotliBitReader* const br, uint32_t n_bits) {
  251|  86.1M|  BROTLI_DCHECK(n_bits <= 24);
  252|  86.1M|  if (BROTLI_64_BITS || (n_bits <= 16)) {
  ------------------
  |  |  235|   172M|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 86.1M, Folded]
  |  |  ------------------
  ------------------
  |  Branch (252:25): [True: 0, False: 0]
  ------------------
  253|  86.1M|    uint32_t val;
  254|  86.1M|    BrotliFillBitWindow(br, n_bits);
  255|  86.1M|    BrotliTakeBits(br, n_bits, &val);
  256|  86.1M|    return val;
  257|  86.1M|  } else {
  258|      0|    uint32_t low_val;
  259|      0|    uint32_t high_val;
  260|      0|    BrotliFillBitWindow(br, 16);
  261|      0|    BrotliTakeBits(br, 16, &low_val);
  262|      0|    BrotliFillBitWindow(br, 8);
  263|      0|    BrotliTakeBits(br, n_bits - 16, &high_val);
  264|      0|    return low_val | (high_val << 16);
  265|      0|  }
  266|  86.1M|}
decode.c:BrotliBitReaderSaveState:
   67|   258M|    BrotliBitReader* const from, BrotliBitReaderState* to) {
   68|   258M|  to->val_ = from->val_;
   69|   258M|  to->bit_pos_ = from->bit_pos_;
   70|   258M|  to->next_in = from->next_in;
   71|   258M|  to->avail_in = from->avail_in;
   72|   258M|}
decode.c:BrotliBitReaderRestoreState:
   75|    751|    BrotliBitReader* const to, BrotliBitReaderState* from) {
   76|    751|  to->val_ = from->val_;
   77|    751|  to->bit_pos_ = from->bit_pos_;
   78|    751|  to->next_in = from->next_in;
   79|    751|  to->avail_in = from->avail_in;
   80|    751|}
decode.c:BrotliGetBits:
  199|   543M|    BrotliBitReader* const br, uint32_t n_bits) {
  200|   543M|  BrotliFillBitWindow(br, n_bits);
  201|   543M|  return (uint32_t)BrotliGetBitsUnmasked(br) & BitMask(n_bits);
  202|   543M|}
decode.c:BrotliGet16BitsUnmasked:
  191|   131M|    BrotliBitReader* const br) {
  192|   131M|  BrotliFillBitWindow(br, 16);
  193|   131M|  return (uint32_t)BrotliGetBitsUnmasked(br);
  194|   131M|}
decode.c:BrotliReadBits32:
  270|  1.37M|    BrotliBitReader* const br, uint32_t n_bits) {
  271|  1.37M|  BROTLI_DCHECK(n_bits <= 32);
  272|  1.37M|  if (BROTLI_64_BITS || (n_bits <= 16)) {
  ------------------
  |  |  235|  2.75M|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 1.37M, Folded]
  |  |  ------------------
  ------------------
  |  Branch (272:25): [True: 0, False: 0]
  ------------------
  273|  1.37M|    uint32_t val;
  274|  1.37M|    BrotliFillBitWindow(br, n_bits);
  275|  1.37M|    BrotliTakeBits(br, n_bits, &val);
  276|  1.37M|    return val;
  277|  1.37M|  } else {
  278|      0|    uint32_t low_val;
  279|      0|    uint32_t high_val;
  280|      0|    BrotliFillBitWindow(br, 16);
  281|      0|    BrotliTakeBits(br, 16, &low_val);
  282|      0|    BrotliFillBitWindow(br, 16);
  283|      0|    BrotliTakeBits(br, n_bits - 16, &high_val);
  284|      0|    return low_val | (high_val << 16);
  285|      0|  }
  286|  1.37M|}
decode.c:BrotliSafeReadBits32:
  305|  4.24k|    BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
  306|  4.24k|  BROTLI_DCHECK(n_bits <= 32);
  307|  4.24k|  if (BROTLI_64_BITS || (n_bits <= 24)) {
  ------------------
  |  |  235|  8.49k|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 4.24k, Folded]
  |  |  ------------------
  ------------------
  |  Branch (307:25): [True: 0, False: 0]
  ------------------
  308|  4.34k|    while (BrotliGetAvailableBits(br) < n_bits) {
  ------------------
  |  Branch (308:12): [True: 323, False: 4.02k]
  ------------------
  309|    323|      if (!BrotliPullByte(br)) {
  ------------------
  |  Branch (309:11): [True: 225, False: 98]
  ------------------
  310|    225|        return BROTLI_FALSE;
  ------------------
  |  |   53|    225|#define BROTLI_FALSE 0
  ------------------
  311|    225|      }
  312|    323|    }
  313|  4.02k|    BrotliTakeBits(br, n_bits, val);
  314|  4.02k|    return BROTLI_TRUE;
  ------------------
  |  |   51|  4.02k|#define BROTLI_TRUE 1
  ------------------
  315|  4.24k|  } else {
  316|      0|    return BrotliSafeReadBits32Slow(br, n_bits, val);
  317|      0|  }
  318|  4.24k|}
decode.c:BrotliGetAvailableBits:
   83|  1.87G|    const BrotliBitReader* br) {
   84|  1.87G|  return (BROTLI_64_BITS ? 64 : 32) - br->bit_pos_;
  ------------------
  |  |  235|  1.87G|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 1.87G, Folded]
  |  |  ------------------
  ------------------
   85|  1.87G|}
bit_reader.c:BrotliGetAvailableBits:
   83|  78.0k|    const BrotliBitReader* br) {
   84|  78.0k|  return (BROTLI_64_BITS ? 64 : 32) - br->bit_pos_;
  ------------------
  |  |  235|  78.0k|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 78.0k, Folded]
  |  |  ------------------
  ------------------
   85|  78.0k|}
bit_reader.c:BrotliPullByte:
  165|  23.8k|static BROTLI_INLINE BROTLI_BOOL BrotliPullByte(BrotliBitReader* const br) {
  166|  23.8k|  if (br->avail_in == 0) {
  ------------------
  |  Branch (166:7): [True: 211, False: 23.6k]
  ------------------
  167|    211|    return BROTLI_FALSE;
  ------------------
  |  |   53|    211|#define BROTLI_FALSE 0
  ------------------
  168|    211|  }
  169|  23.6k|  br->val_ >>= 8;
  170|  23.6k|#if (BROTLI_64_BITS)
  171|  23.6k|  br->val_ |= ((uint64_t)*br->next_in) << 56;
  172|       |#else
  173|       |  br->val_ |= ((uint32_t)*br->next_in) << 24;
  174|       |#endif
  175|  23.6k|  br->bit_pos_ -= 8;
  176|  23.6k|  --br->avail_in;
  177|  23.6k|  ++br->next_in;
  178|  23.6k|  return BROTLI_TRUE;
  ------------------
  |  |   51|  23.6k|#define BROTLI_TRUE 1
  ------------------
  179|  23.8k|}

BrotliDecoderCreateInstance:
   78|  3.91k|    brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque) {
   79|  3.91k|  BrotliDecoderState* state = 0;
  ------------------
  |  |  342|  3.91k|#define BrotliDecoderState BrotliDecoderStateInternal
  ------------------
   80|  3.91k|  if (!alloc_func && !free_func) {
  ------------------
  |  Branch (80:7): [True: 3.91k, False: 0]
  |  Branch (80:22): [True: 3.91k, False: 0]
  ------------------
   81|  3.91k|    state = (BrotliDecoderState*)malloc(sizeof(BrotliDecoderState));
   82|  3.91k|  } else if (alloc_func && free_func) {
  ------------------
  |  Branch (82:14): [True: 0, False: 0]
  |  Branch (82:28): [True: 0, False: 0]
  ------------------
   83|      0|    state = (BrotliDecoderState*)alloc_func(opaque, sizeof(BrotliDecoderState));
   84|      0|  }
   85|  3.91k|  if (state == 0) {
  ------------------
  |  Branch (85:7): [True: 0, False: 3.91k]
  ------------------
   86|      0|    BROTLI_DUMP();
  ------------------
  |  |  485|      0|#define BROTLI_DUMP() (void)(0)
  ------------------
   87|      0|    return 0;
   88|      0|  }
   89|  3.91k|  if (!BrotliDecoderStateInit(state, alloc_func, free_func, opaque)) {
  ------------------
  |  Branch (89:7): [True: 0, False: 3.91k]
  ------------------
   90|      0|    BROTLI_DUMP();
  ------------------
  |  |  485|      0|#define BROTLI_DUMP() (void)(0)
  ------------------
   91|      0|    if (!alloc_func && !free_func) {
  ------------------
  |  Branch (91:9): [True: 0, False: 0]
  |  Branch (91:24): [True: 0, False: 0]
  ------------------
   92|      0|      free(state);
   93|      0|    } else if (alloc_func && free_func) {
  ------------------
  |  Branch (93:16): [True: 0, False: 0]
  |  Branch (93:30): [True: 0, False: 0]
  ------------------
   94|      0|      free_func(opaque, state);
   95|      0|    }
   96|      0|    return 0;
   97|      0|  }
   98|  3.91k|  return state;
   99|  3.91k|}
BrotliDecoderDestroyInstance:
  102|  3.91k|void BrotliDecoderDestroyInstance(BrotliDecoderState* state) {
  103|  3.91k|  if (!state) {
  ------------------
  |  Branch (103:7): [True: 0, False: 3.91k]
  ------------------
  104|      0|    return;
  105|  3.91k|  } else {
  106|  3.91k|    brotli_free_func free_func = state->free_func;
  107|  3.91k|    void* opaque = state->memory_manager_opaque;
  108|  3.91k|    BrotliDecoderStateCleanup(state);
  109|  3.91k|    free_func(opaque, state);
  110|  3.91k|  }
  111|  3.91k|}
BrotliDecoderDecompressStream:
 2071|   145k|    size_t* available_out, uint8_t** next_out, size_t* total_out) {
 2072|   145k|  BrotliDecoderErrorCode result = BROTLI_DECODER_SUCCESS;
 2073|   145k|  BrotliBitReader* br = &s->br;
 2074|       |  /* Ensure that |total_out| is set, even if no data will ever be pushed out. */
 2075|   145k|  if (total_out) {
  ------------------
  |  Branch (2075:7): [True: 0, False: 145k]
  ------------------
 2076|      0|    *total_out = s->partial_pos_out;
 2077|      0|  }
 2078|       |  /* Do not try to process further in a case of unrecoverable error. */
 2079|   145k|  if ((int)s->error_code < 0) {
  ------------------
  |  Branch (2079:7): [True: 0, False: 145k]
  ------------------
 2080|      0|    return BROTLI_DECODER_RESULT_ERROR;
 2081|      0|  }
 2082|   145k|  if (*available_out && (!next_out || !*next_out)) {
  ------------------
  |  Branch (2082:7): [True: 0, False: 145k]
  |  Branch (2082:26): [True: 0, False: 0]
  |  Branch (2082:39): [True: 0, False: 0]
  ------------------
 2083|      0|    return SaveErrorCode(
 2084|      0|        s, BROTLI_FAILURE(BROTLI_DECODER_ERROR_INVALID_ARGUMENTS));
  ------------------
  |  |   31|      0|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|      0|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 2085|      0|  }
 2086|   145k|  if (!*available_out) next_out = 0;
  ------------------
  |  Branch (2086:7): [True: 145k, False: 0]
  ------------------
 2087|   145k|  if (s->buffer_length == 0) {  /* Just connect bit reader to input stream. */
  ------------------
  |  Branch (2087:7): [True: 145k, False: 0]
  ------------------
 2088|   145k|    br->avail_in = *available_in;
 2089|   145k|    br->next_in = *next_in;
 2090|   145k|  } else {
 2091|       |    /* At least one byte of input is required. More than one byte of input may
 2092|       |       be required to complete the transaction -> reading more data must be
 2093|       |       done in a loop -> do it in a main loop. */
 2094|      0|    result = BROTLI_DECODER_NEEDS_MORE_INPUT;
 2095|      0|    br->next_in = &s->buffer.u8[0];
 2096|      0|  }
 2097|       |  /* State machine */
 2098|   625k|  for (;;) {
 2099|   625k|    if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (2099:9): [True: 145k, False: 480k]
  ------------------
 2100|       |      /* Error, needs more input/output. */
 2101|   145k|      if (result == BROTLI_DECODER_NEEDS_MORE_INPUT) {
  ------------------
  |  Branch (2101:11): [True: 2.44k, False: 142k]
  ------------------
 2102|  2.44k|        if (s->ringbuffer != 0) {  /* Pro-actively push output. */
  ------------------
  |  Branch (2102:13): [True: 1.39k, False: 1.04k]
  ------------------
 2103|  1.39k|          BrotliDecoderErrorCode intermediate_result = WriteRingBuffer(s,
 2104|  1.39k|              available_out, next_out, total_out, BROTLI_TRUE);
  ------------------
  |  |   51|  1.39k|#define BROTLI_TRUE 1
  ------------------
 2105|       |          /* WriteRingBuffer checks s->meta_block_remaining_len validity. */
 2106|  1.39k|          if ((int)intermediate_result < 0) {
  ------------------
  |  Branch (2106:15): [True: 8, False: 1.38k]
  ------------------
 2107|      8|            result = intermediate_result;
 2108|      8|            break;
 2109|      8|          }
 2110|  1.39k|        }
 2111|  2.43k|        if (s->buffer_length != 0) {  /* Used with internal buffer. */
  ------------------
  |  Branch (2111:13): [True: 0, False: 2.43k]
  ------------------
 2112|      0|          if (br->avail_in == 0) {
  ------------------
  |  Branch (2112:15): [True: 0, False: 0]
  ------------------
 2113|       |            /* Successfully finished read transaction.
 2114|       |               Accumulator contains less than 8 bits, because internal buffer
 2115|       |               is expanded byte-by-byte until it is enough to complete read. */
 2116|      0|            s->buffer_length = 0;
 2117|       |            /* Switch to input stream and restart. */
 2118|      0|            result = BROTLI_DECODER_SUCCESS;
 2119|      0|            br->avail_in = *available_in;
 2120|      0|            br->next_in = *next_in;
 2121|      0|            continue;
 2122|      0|          } else if (*available_in != 0) {
  ------------------
  |  Branch (2122:22): [True: 0, False: 0]
  ------------------
 2123|       |            /* Not enough data in buffer, but can take one more byte from
 2124|       |               input stream. */
 2125|      0|            result = BROTLI_DECODER_SUCCESS;
 2126|      0|            s->buffer.u8[s->buffer_length] = **next_in;
 2127|      0|            s->buffer_length++;
 2128|      0|            br->avail_in = s->buffer_length;
 2129|      0|            (*next_in)++;
 2130|      0|            (*available_in)--;
 2131|       |            /* Retry with more data in buffer. */
 2132|      0|            continue;
 2133|      0|          }
 2134|       |          /* Can't finish reading and no more input. */
 2135|      0|          break;
 2136|  2.43k|        } else {  /* Input stream doesn't contain enough input. */
 2137|       |          /* Copy tail to internal buffer and return. */
 2138|  2.43k|          *next_in = br->next_in;
 2139|  2.43k|          *available_in = br->avail_in;
 2140|  2.48k|          while (*available_in) {
  ------------------
  |  Branch (2140:18): [True: 55, False: 2.43k]
  ------------------
 2141|     55|            s->buffer.u8[s->buffer_length] = **next_in;
 2142|     55|            s->buffer_length++;
 2143|     55|            (*next_in)++;
 2144|     55|            (*available_in)--;
 2145|     55|          }
 2146|  2.43k|          break;
 2147|  2.43k|        }
 2148|       |        /* Unreachable. */
 2149|  2.43k|      }
 2150|       |
 2151|       |      /* Fail or needs more output. */
 2152|       |
 2153|   142k|      if (s->buffer_length != 0) {
  ------------------
  |  Branch (2153:11): [True: 0, False: 142k]
  ------------------
 2154|       |        /* Just consumed the buffered input and produced some output. Otherwise
 2155|       |           it would result in "needs more input". Reset internal buffer. */
 2156|      0|        s->buffer_length = 0;
 2157|   142k|      } else {
 2158|       |        /* Using input stream in last iteration. When decoder switches to input
 2159|       |           stream it has less than 8 bits in accumulator, so it is safe to
 2160|       |           return unused accumulator bits there. */
 2161|   142k|        BrotliBitReaderUnload(br);
 2162|   142k|        *available_in = br->avail_in;
 2163|   142k|        *next_in = br->next_in;
 2164|   142k|      }
 2165|   142k|      break;
 2166|   145k|    }
 2167|   480k|    switch (s->state) {
  ------------------
  |  Branch (2167:13): [True: 480k, False: 0]
  ------------------
 2168|  3.91k|      case BROTLI_STATE_UNINITED:
  ------------------
  |  Branch (2168:7): [True: 3.91k, False: 476k]
  ------------------
 2169|       |        /* Prepare to the first read. */
 2170|  3.91k|        if (!BrotliWarmupBitReader(br)) {
  ------------------
  |  Branch (2170:13): [True: 171, False: 3.73k]
  ------------------
 2171|    171|          result = BROTLI_DECODER_NEEDS_MORE_INPUT;
 2172|    171|          break;
 2173|    171|        }
 2174|       |        /* Decode window size. */
 2175|  3.73k|        result = DecodeWindowBits(s, br);  /* Reads 1..8 bits. */
 2176|  3.73k|        if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (2176:13): [True: 1, False: 3.73k]
  ------------------
 2177|      1|          break;
 2178|      1|        }
 2179|  3.73k|        if (s->large_window) {
  ------------------
  |  Branch (2179:13): [True: 0, False: 3.73k]
  ------------------
 2180|      0|          s->state = BROTLI_STATE_LARGE_WINDOW_BITS;
 2181|      0|          break;
 2182|      0|        }
 2183|  3.73k|        s->state = BROTLI_STATE_INITIALIZE;
 2184|  3.73k|        break;
 2185|       |
 2186|      0|      case BROTLI_STATE_LARGE_WINDOW_BITS:
  ------------------
  |  Branch (2186:7): [True: 0, False: 480k]
  ------------------
 2187|      0|        if (!BrotliSafeReadBits(br, 6, &s->window_bits)) {
  ------------------
  |  Branch (2187:13): [True: 0, False: 0]
  ------------------
 2188|      0|          result = BROTLI_DECODER_NEEDS_MORE_INPUT;
 2189|      0|          break;
 2190|      0|        }
 2191|      0|        if (s->window_bits < BROTLI_LARGE_MIN_WBITS ||
  ------------------
  |  |   51|      0|#define BROTLI_LARGE_MIN_WBITS 10
  ------------------
  |  Branch (2191:13): [True: 0, False: 0]
  ------------------
 2192|      0|            s->window_bits > BROTLI_LARGE_MAX_WBITS) {
  ------------------
  |  |   57|      0|#define BROTLI_LARGE_MAX_WBITS 30
  ------------------
  |  Branch (2192:13): [True: 0, False: 0]
  ------------------
 2193|      0|          result = BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS);
  ------------------
  |  |   31|      0|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|      0|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 2194|      0|          break;
 2195|      0|        }
 2196|      0|        s->state = BROTLI_STATE_INITIALIZE;
 2197|       |      /* Fall through. */
 2198|       |
 2199|  3.73k|      case BROTLI_STATE_INITIALIZE:
  ------------------
  |  Branch (2199:7): [True: 3.73k, False: 476k]
  ------------------
 2200|  3.73k|        BROTLI_LOG_UINT(s->window_bits);
 2201|       |        /* Maximum distance, see section 9.1. of the spec. */
 2202|  3.73k|        s->max_backward_distance = (1 << s->window_bits) - BROTLI_WINDOW_GAP;
  ------------------
  |  |  102|  3.73k|#define BROTLI_WINDOW_GAP 16
  ------------------
 2203|       |
 2204|       |        /* Allocate memory for both block_type_trees and block_len_trees. */
 2205|  3.73k|        s->block_type_trees = (HuffmanCode*)BROTLI_DECODER_ALLOC(s,
  ------------------
  |  |  354|  3.73k|#define BROTLI_DECODER_ALLOC(S, L) S->alloc_func(S->memory_manager_opaque, L)
  ------------------
 2206|  3.73k|            sizeof(HuffmanCode) * 3 *
 2207|  3.73k|                (BROTLI_HUFFMAN_MAX_SIZE_258 + BROTLI_HUFFMAN_MAX_SIZE_26));
 2208|  3.73k|        if (s->block_type_trees == 0) {
  ------------------
  |  Branch (2208:13): [True: 0, False: 3.73k]
  ------------------
 2209|      0|          result = BROTLI_FAILURE(BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES);
  ------------------
  |  |   31|      0|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|      0|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 2210|      0|          break;
 2211|      0|        }
 2212|  3.73k|        s->block_len_trees =
 2213|  3.73k|            s->block_type_trees + 3 * BROTLI_HUFFMAN_MAX_SIZE_258;
  ------------------
  |  |   24|  3.73k|#define BROTLI_HUFFMAN_MAX_SIZE_258 632
  ------------------
 2214|       |
 2215|  3.73k|        s->state = BROTLI_STATE_METABLOCK_BEGIN;
 2216|       |      /* Fall through. */
 2217|       |
 2218|  13.8k|      case BROTLI_STATE_METABLOCK_BEGIN:
  ------------------
  |  Branch (2218:7): [True: 10.0k, False: 469k]
  ------------------
 2219|  13.8k|        BrotliDecoderStateMetablockBegin(s);
 2220|  13.8k|        BROTLI_LOG_UINT(s->pos);
 2221|  13.8k|        s->state = BROTLI_STATE_METABLOCK_HEADER;
 2222|       |      /* Fall through. */
 2223|       |
 2224|  13.8k|      case BROTLI_STATE_METABLOCK_HEADER:
  ------------------
  |  Branch (2224:7): [True: 0, False: 480k]
  ------------------
 2225|  13.8k|        result = DecodeMetaBlockLength(s, br);  /* Reads 2 - 31 bits. */
 2226|  13.8k|        if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (2226:13): [True: 204, False: 13.6k]
  ------------------
 2227|    204|          break;
 2228|    204|        }
 2229|  13.6k|        BROTLI_LOG_UINT(s->is_last_metablock);
 2230|  13.6k|        BROTLI_LOG_UINT(s->meta_block_remaining_len);
 2231|  13.6k|        BROTLI_LOG_UINT(s->is_metadata);
 2232|  13.6k|        BROTLI_LOG_UINT(s->is_uncompressed);
 2233|  13.6k|        if (s->is_metadata || s->is_uncompressed) {
  ------------------
  |  Branch (2233:13): [True: 2.62k, False: 10.9k]
  |  Branch (2233:31): [True: 1.62k, False: 9.35k]
  ------------------
 2234|  4.25k|          if (!BrotliJumpToByteBoundary(br)) {
  ------------------
  |  Branch (2234:15): [True: 27, False: 4.22k]
  ------------------
 2235|     27|            result = BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_PADDING_1);
  ------------------
  |  |   31|     27|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|     27|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 2236|     27|            break;
 2237|     27|          }
 2238|  4.25k|        }
 2239|  13.5k|        if (s->is_metadata) {
  ------------------
  |  Branch (2239:13): [True: 2.61k, False: 10.9k]
  ------------------
 2240|  2.61k|          s->state = BROTLI_STATE_METADATA;
 2241|  2.61k|          break;
 2242|  2.61k|        }
 2243|  10.9k|        if (s->meta_block_remaining_len == 0) {
  ------------------
  |  Branch (2243:13): [True: 135, False: 10.8k]
  ------------------
 2244|    135|          s->state = BROTLI_STATE_METABLOCK_DONE;
 2245|    135|          break;
 2246|    135|        }
 2247|  10.8k|        BrotliCalculateRingBufferSize(s);
 2248|  10.8k|        if (s->is_uncompressed) {
  ------------------
  |  Branch (2248:13): [True: 1.61k, False: 9.21k]
  ------------------
 2249|  1.61k|          s->state = BROTLI_STATE_UNCOMPRESSED;
 2250|  1.61k|          break;
 2251|  1.61k|        }
 2252|  9.21k|        s->state = BROTLI_STATE_BEFORE_COMPRESSED_METABLOCK_HEADER;
 2253|       |      /* Fall through. */
 2254|       |
 2255|  9.21k|      case BROTLI_STATE_BEFORE_COMPRESSED_METABLOCK_HEADER: {
  ------------------
  |  Branch (2255:7): [True: 0, False: 480k]
  ------------------
 2256|  9.21k|        BrotliMetablockHeaderArena* h = &s->arena.header;
 2257|  9.21k|        s->loop_counter = 0;
 2258|       |        /* Initialize compressed metablock header arena. */
 2259|  9.21k|        h->sub_loop_counter = 0;
 2260|       |        /* Make small negative indexes addressable. */
 2261|  9.21k|        h->symbol_lists =
 2262|  9.21k|            &h->symbols_lists_array[BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1];
  ------------------
  |  |   19|  9.21k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH 15
  ------------------
 2263|  9.21k|        h->substate_huffman = BROTLI_STATE_HUFFMAN_NONE;
 2264|  9.21k|        h->substate_tree_group = BROTLI_STATE_TREE_GROUP_NONE;
 2265|  9.21k|        h->substate_context_map = BROTLI_STATE_CONTEXT_MAP_NONE;
 2266|  9.21k|        s->state = BROTLI_STATE_HUFFMAN_CODE_0;
 2267|  9.21k|      }
 2268|       |      /* Fall through. */
 2269|       |
 2270|  35.8k|      case BROTLI_STATE_HUFFMAN_CODE_0:
  ------------------
  |  Branch (2270:7): [True: 26.6k, False: 453k]
  ------------------
 2271|  35.8k|        if (s->loop_counter >= 3) {
  ------------------
  |  Branch (2271:13): [True: 8.82k, False: 27.0k]
  ------------------
 2272|  8.82k|          s->state = BROTLI_STATE_METABLOCK_HEADER_2;
 2273|  8.82k|          break;
 2274|  8.82k|        }
 2275|       |        /* Reads 1..11 bits. */
 2276|  27.0k|        result = DecodeVarLenUint8(s, br, &s->num_block_types[s->loop_counter]);
 2277|  27.0k|        if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (2277:13): [True: 33, False: 27.0k]
  ------------------
 2278|     33|          break;
 2279|     33|        }
 2280|  27.0k|        s->num_block_types[s->loop_counter]++;
 2281|  27.0k|        BROTLI_LOG_UINT(s->num_block_types[s->loop_counter]);
 2282|  27.0k|        if (s->num_block_types[s->loop_counter] < 2) {
  ------------------
  |  Branch (2282:13): [True: 23.8k, False: 3.16k]
  ------------------
 2283|  23.8k|          s->loop_counter++;
 2284|  23.8k|          break;
 2285|  23.8k|        }
 2286|  3.16k|        s->state = BROTLI_STATE_HUFFMAN_CODE_1;
 2287|       |      /* Fall through. */
 2288|       |
 2289|  3.16k|      case BROTLI_STATE_HUFFMAN_CODE_1: {
  ------------------
  |  Branch (2289:7): [True: 0, False: 480k]
  ------------------
 2290|  3.16k|        uint32_t alphabet_size = s->num_block_types[s->loop_counter] + 2;
 2291|  3.16k|        int tree_offset = s->loop_counter * BROTLI_HUFFMAN_MAX_SIZE_258;
  ------------------
  |  |   24|  3.16k|#define BROTLI_HUFFMAN_MAX_SIZE_258 632
  ------------------
 2292|  3.16k|        result = ReadHuffmanCode(alphabet_size, alphabet_size,
 2293|  3.16k|            &s->block_type_trees[tree_offset], NULL, s);
 2294|  3.16k|        if (result != BROTLI_DECODER_SUCCESS) break;
  ------------------
  |  Branch (2294:13): [True: 202, False: 2.95k]
  ------------------
 2295|  2.95k|        s->state = BROTLI_STATE_HUFFMAN_CODE_2;
 2296|  2.95k|      }
 2297|       |      /* Fall through. */
 2298|       |
 2299|  2.95k|      case BROTLI_STATE_HUFFMAN_CODE_2: {
  ------------------
  |  Branch (2299:7): [True: 0, False: 480k]
  ------------------
 2300|  2.95k|        uint32_t alphabet_size = BROTLI_NUM_BLOCK_LEN_SYMBOLS;
  ------------------
  |  |   28|  2.95k|#define BROTLI_NUM_BLOCK_LEN_SYMBOLS 26
  ------------------
 2301|  2.95k|        int tree_offset = s->loop_counter * BROTLI_HUFFMAN_MAX_SIZE_26;
  ------------------
  |  |   22|  2.95k|#define BROTLI_HUFFMAN_MAX_SIZE_26 396
  ------------------
 2302|  2.95k|        result = ReadHuffmanCode(alphabet_size, alphabet_size,
 2303|  2.95k|            &s->block_len_trees[tree_offset], NULL, s);
 2304|  2.95k|        if (result != BROTLI_DECODER_SUCCESS) break;
  ------------------
  |  Branch (2304:13): [True: 114, False: 2.84k]
  ------------------
 2305|  2.84k|        s->state = BROTLI_STATE_HUFFMAN_CODE_3;
 2306|  2.84k|      }
 2307|       |      /* Fall through. */
 2308|       |
 2309|  2.84k|      case BROTLI_STATE_HUFFMAN_CODE_3: {
  ------------------
  |  Branch (2309:7): [True: 0, False: 480k]
  ------------------
 2310|  2.84k|        int tree_offset = s->loop_counter * BROTLI_HUFFMAN_MAX_SIZE_26;
  ------------------
  |  |   22|  2.84k|#define BROTLI_HUFFMAN_MAX_SIZE_26 396
  ------------------
 2311|  2.84k|        if (!SafeReadBlockLength(s, &s->block_length[s->loop_counter],
  ------------------
  |  Branch (2311:13): [True: 43, False: 2.80k]
  ------------------
 2312|  2.84k|            &s->block_len_trees[tree_offset], br)) {
 2313|     43|          result = BROTLI_DECODER_NEEDS_MORE_INPUT;
 2314|     43|          break;
 2315|     43|        }
 2316|  2.80k|        BROTLI_LOG_UINT(s->block_length[s->loop_counter]);
 2317|  2.80k|        s->loop_counter++;
 2318|  2.80k|        s->state = BROTLI_STATE_HUFFMAN_CODE_0;
 2319|  2.80k|        break;
 2320|  2.84k|      }
 2321|       |
 2322|  4.55k|      case BROTLI_STATE_UNCOMPRESSED: {
  ------------------
  |  Branch (2322:7): [True: 4.55k, False: 475k]
  ------------------
 2323|  4.55k|        result = CopyUncompressedBlockToOutput(
 2324|  4.55k|            available_out, next_out, total_out, s);
 2325|  4.55k|        if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (2325:13): [True: 3.15k, False: 1.39k]
  ------------------
 2326|  3.15k|          break;
 2327|  3.15k|        }
 2328|  1.39k|        s->state = BROTLI_STATE_METABLOCK_DONE;
 2329|  1.39k|        break;
 2330|  4.55k|      }
 2331|       |
 2332|  2.61k|      case BROTLI_STATE_METADATA:
  ------------------
  |  Branch (2332:7): [True: 2.61k, False: 477k]
  ------------------
 2333|   783k|        for (; s->meta_block_remaining_len > 0; --s->meta_block_remaining_len) {
  ------------------
  |  Branch (2333:16): [True: 780k, False: 2.55k]
  ------------------
 2334|   780k|          uint32_t bits;
 2335|       |          /* Read one byte and ignore it. */
 2336|   780k|          if (!BrotliSafeReadBits(br, 8, &bits)) {
  ------------------
  |  Branch (2336:15): [True: 54, False: 780k]
  ------------------
 2337|     54|            result = BROTLI_DECODER_NEEDS_MORE_INPUT;
 2338|     54|            break;
 2339|     54|          }
 2340|   780k|        }
 2341|  2.61k|        if (result == BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (2341:13): [True: 2.55k, False: 54]
  ------------------
 2342|  2.55k|          s->state = BROTLI_STATE_METABLOCK_DONE;
 2343|  2.55k|        }
 2344|  2.61k|        break;
 2345|       |
 2346|  8.82k|      case BROTLI_STATE_METABLOCK_HEADER_2: {
  ------------------
  |  Branch (2346:7): [True: 8.82k, False: 471k]
  ------------------
 2347|  8.82k|        uint32_t bits;
 2348|  8.82k|        if (!BrotliSafeReadBits(br, 6, &bits)) {
  ------------------
  |  Branch (2348:13): [True: 38, False: 8.78k]
  ------------------
 2349|     38|          result = BROTLI_DECODER_NEEDS_MORE_INPUT;
 2350|     38|          break;
 2351|     38|        }
 2352|  8.78k|        s->distance_postfix_bits = bits & BitMask(2);
 2353|  8.78k|        bits >>= 2;
 2354|  8.78k|        s->num_direct_distance_codes = bits << s->distance_postfix_bits;
 2355|  8.78k|        BROTLI_LOG_UINT(s->num_direct_distance_codes);
 2356|  8.78k|        BROTLI_LOG_UINT(s->distance_postfix_bits);
 2357|  8.78k|        s->context_modes =
 2358|  8.78k|            (uint8_t*)BROTLI_DECODER_ALLOC(s, (size_t)s->num_block_types[0]);
  ------------------
  |  |  354|  8.78k|#define BROTLI_DECODER_ALLOC(S, L) S->alloc_func(S->memory_manager_opaque, L)
  ------------------
 2359|  8.78k|        if (s->context_modes == 0) {
  ------------------
  |  Branch (2359:13): [True: 0, False: 8.78k]
  ------------------
 2360|      0|          result = BROTLI_FAILURE(BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES);
  ------------------
  |  |   31|      0|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|      0|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 2361|      0|          break;
 2362|      0|        }
 2363|  8.78k|        s->loop_counter = 0;
 2364|  8.78k|        s->state = BROTLI_STATE_CONTEXT_MODES;
 2365|  8.78k|      }
 2366|       |      /* Fall through. */
 2367|       |
 2368|  8.78k|      case BROTLI_STATE_CONTEXT_MODES:
  ------------------
  |  Branch (2368:7): [True: 0, False: 480k]
  ------------------
 2369|  8.78k|        result = ReadContextModes(s);
 2370|  8.78k|        if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (2370:13): [True: 25, False: 8.76k]
  ------------------
 2371|     25|          break;
 2372|     25|        }
 2373|  8.76k|        s->state = BROTLI_STATE_CONTEXT_MAP_1;
 2374|       |      /* Fall through. */
 2375|       |
 2376|  8.76k|      case BROTLI_STATE_CONTEXT_MAP_1:
  ------------------
  |  Branch (2376:7): [True: 0, False: 480k]
  ------------------
 2377|  8.76k|        result = DecodeContextMap(
 2378|  8.76k|            s->num_block_types[0] << BROTLI_LITERAL_CONTEXT_BITS,
  ------------------
  |  |   94|  8.76k|#define BROTLI_LITERAL_CONTEXT_BITS 6
  ------------------
 2379|  8.76k|            &s->num_literal_htrees, &s->context_map, s);
 2380|  8.76k|        if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (2380:13): [True: 166, False: 8.59k]
  ------------------
 2381|    166|          break;
 2382|    166|        }
 2383|  8.59k|        DetectTrivialLiteralBlockTypes(s);
 2384|  8.59k|        s->state = BROTLI_STATE_CONTEXT_MAP_2;
 2385|       |      /* Fall through. */
 2386|       |
 2387|  8.59k|      case BROTLI_STATE_CONTEXT_MAP_2: {
  ------------------
  |  Branch (2387:7): [True: 0, False: 480k]
  ------------------
 2388|  8.59k|        uint32_t npostfix = s->distance_postfix_bits;
 2389|  8.59k|        uint32_t ndirect = s->num_direct_distance_codes;
 2390|  8.59k|        uint32_t distance_alphabet_size_max = BROTLI_DISTANCE_ALPHABET_SIZE(
  ------------------
  |  |   69|  8.59k|#define BROTLI_DISTANCE_ALPHABET_SIZE(NPOSTFIX, NDIRECT, MAXNBITS) ( \
  |  |   70|  8.59k|    BROTLI_NUM_DISTANCE_SHORT_CODES + (NDIRECT) +                    \
  |  |  ------------------
  |  |  |  |   60|  8.59k|#define BROTLI_NUM_DISTANCE_SHORT_CODES 16
  |  |  ------------------
  |  |   71|  8.59k|    ((MAXNBITS) << ((NPOSTFIX) + 1)))
  ------------------
 2391|  8.59k|            npostfix, ndirect, BROTLI_MAX_DISTANCE_BITS);
 2392|  8.59k|        uint32_t distance_alphabet_size_limit = distance_alphabet_size_max;
 2393|  8.59k|        BROTLI_BOOL allocation_success = BROTLI_TRUE;
  ------------------
  |  |   49|  8.59k|#define BROTLI_BOOL int
  ------------------
                      BROTLI_BOOL allocation_success = BROTLI_TRUE;
  ------------------
  |  |   51|  8.59k|#define BROTLI_TRUE 1
  ------------------
 2394|  8.59k|        if (s->large_window) {
  ------------------
  |  Branch (2394:13): [True: 0, False: 8.59k]
  ------------------
 2395|      0|          BrotliDistanceCodeLimit limit = BrotliCalculateDistanceCodeLimit(
 2396|      0|              BROTLI_MAX_ALLOWED_DISTANCE, npostfix, ndirect);
  ------------------
  |  |   86|      0|#define BROTLI_MAX_ALLOWED_DISTANCE 0x7FFFFFFC
  ------------------
 2397|      0|          distance_alphabet_size_max = BROTLI_DISTANCE_ALPHABET_SIZE(
  ------------------
  |  |   69|      0|#define BROTLI_DISTANCE_ALPHABET_SIZE(NPOSTFIX, NDIRECT, MAXNBITS) ( \
  |  |   70|      0|    BROTLI_NUM_DISTANCE_SHORT_CODES + (NDIRECT) +                    \
  |  |  ------------------
  |  |  |  |   60|      0|#define BROTLI_NUM_DISTANCE_SHORT_CODES 16
  |  |  ------------------
  |  |   71|      0|    ((MAXNBITS) << ((NPOSTFIX) + 1)))
  ------------------
 2398|      0|              npostfix, ndirect, BROTLI_LARGE_MAX_DISTANCE_BITS);
 2399|      0|          distance_alphabet_size_limit = limit.max_alphabet_size;
 2400|      0|        }
 2401|  8.59k|        result = DecodeContextMap(
 2402|  8.59k|            s->num_block_types[2] << BROTLI_DISTANCE_CONTEXT_BITS,
  ------------------
  |  |   97|  8.59k|#define BROTLI_DISTANCE_CONTEXT_BITS 2
  ------------------
 2403|  8.59k|            &s->num_dist_htrees, &s->dist_context_map, s);
 2404|  8.59k|        if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (2404:13): [True: 118, False: 8.47k]
  ------------------
 2405|    118|          break;
 2406|    118|        }
 2407|  8.47k|        allocation_success &= BrotliDecoderHuffmanTreeGroupInit(
 2408|  8.47k|            s, &s->literal_hgroup, BROTLI_NUM_LITERAL_SYMBOLS,
  ------------------
  |  |   26|  8.47k|#define BROTLI_NUM_LITERAL_SYMBOLS 256
  ------------------
 2409|  8.47k|            BROTLI_NUM_LITERAL_SYMBOLS, s->num_literal_htrees);
  ------------------
  |  |   26|  8.47k|#define BROTLI_NUM_LITERAL_SYMBOLS 256
  ------------------
 2410|  8.47k|        allocation_success &= BrotliDecoderHuffmanTreeGroupInit(
 2411|  8.47k|            s, &s->insert_copy_hgroup, BROTLI_NUM_COMMAND_SYMBOLS,
  ------------------
  |  |   27|  8.47k|#define BROTLI_NUM_COMMAND_SYMBOLS 704
  ------------------
 2412|  8.47k|            BROTLI_NUM_COMMAND_SYMBOLS, s->num_block_types[1]);
  ------------------
  |  |   27|  8.47k|#define BROTLI_NUM_COMMAND_SYMBOLS 704
  ------------------
 2413|  8.47k|        allocation_success &= BrotliDecoderHuffmanTreeGroupInit(
 2414|  8.47k|            s, &s->distance_hgroup, distance_alphabet_size_max,
 2415|  8.47k|            distance_alphabet_size_limit, s->num_dist_htrees);
 2416|  8.47k|        if (!allocation_success) {
  ------------------
  |  Branch (2416:13): [True: 0, False: 8.47k]
  ------------------
 2417|      0|          return SaveErrorCode(s,
 2418|      0|              BROTLI_FAILURE(BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS));
  ------------------
  |  |   31|      0|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|      0|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 2419|      0|        }
 2420|  8.47k|        s->loop_counter = 0;
 2421|  8.47k|        s->state = BROTLI_STATE_TREE_GROUP;
 2422|  8.47k|      }
 2423|       |      /* Fall through. */
 2424|       |
 2425|  24.7k|      case BROTLI_STATE_TREE_GROUP: {
  ------------------
  |  Branch (2425:7): [True: 16.2k, False: 463k]
  ------------------
 2426|  24.7k|        HuffmanTreeGroup* hgroup = NULL;
 2427|  24.7k|        switch (s->loop_counter) {
 2428|  8.47k|          case 0: hgroup = &s->literal_hgroup; break;
  ------------------
  |  Branch (2428:11): [True: 8.47k, False: 16.2k]
  ------------------
 2429|  8.21k|          case 1: hgroup = &s->insert_copy_hgroup; break;
  ------------------
  |  Branch (2429:11): [True: 8.21k, False: 16.5k]
  ------------------
 2430|  8.07k|          case 2: hgroup = &s->distance_hgroup; break;
  ------------------
  |  Branch (2430:11): [True: 8.07k, False: 16.6k]
  ------------------
 2431|      0|          default: return SaveErrorCode(s, BROTLI_FAILURE(
  ------------------
  |  |   31|      0|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|      0|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
  |  Branch (2431:11): [True: 0, False: 24.7k]
  ------------------
 2432|      0|              BROTLI_DECODER_ERROR_UNREACHABLE));
 2433|  24.7k|        }
 2434|  24.7k|        result = HuffmanTreeGroupDecode(hgroup, s);
 2435|  24.7k|        if (result != BROTLI_DECODER_SUCCESS) break;
  ------------------
  |  Branch (2435:13): [True: 537, False: 24.2k]
  ------------------
 2436|  24.2k|        s->loop_counter++;
 2437|  24.2k|        if (s->loop_counter < 3) {
  ------------------
  |  Branch (2437:13): [True: 16.2k, False: 7.93k]
  ------------------
 2438|  16.2k|          break;
 2439|  16.2k|        }
 2440|  7.93k|        s->state = BROTLI_STATE_BEFORE_COMPRESSED_METABLOCK_BODY;
 2441|  7.93k|      }
 2442|       |      /* Fall through. */
 2443|       |
 2444|  7.93k|      case BROTLI_STATE_BEFORE_COMPRESSED_METABLOCK_BODY:
  ------------------
  |  Branch (2444:7): [True: 0, False: 480k]
  ------------------
 2445|  7.93k|        PrepareLiteralDecoding(s);
 2446|  7.93k|        s->dist_context_map_slice = s->dist_context_map;
 2447|  7.93k|        s->htree_command = s->insert_copy_hgroup.htrees[0];
 2448|  7.93k|        if (!BrotliEnsureRingBuffer(s)) {
  ------------------
  |  Branch (2448:13): [True: 0, False: 7.93k]
  ------------------
 2449|      0|          result = BROTLI_FAILURE(BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2);
  ------------------
  |  |   31|      0|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|      0|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 2450|      0|          break;
 2451|      0|        }
 2452|  7.93k|        CalculateDistanceLut(s);
 2453|  7.93k|        s->state = BROTLI_STATE_COMMAND_BEGIN;
 2454|       |      /* Fall through. */
 2455|       |
 2456|  23.0k|      case BROTLI_STATE_COMMAND_BEGIN:
  ------------------
  |  Branch (2456:7): [True: 15.0k, False: 464k]
  ------------------
 2457|       |      /* Fall through. */
 2458|  60.2k|      case BROTLI_STATE_COMMAND_INNER:
  ------------------
  |  Branch (2458:7): [True: 37.2k, False: 442k]
  ------------------
 2459|       |      /* Fall through. */
 2460|  78.9k|      case BROTLI_STATE_COMMAND_POST_DECODE_LITERALS:
  ------------------
  |  Branch (2460:7): [True: 18.7k, False: 461k]
  ------------------
 2461|       |      /* Fall through. */
 2462|   134k|      case BROTLI_STATE_COMMAND_POST_WRAP_COPY:
  ------------------
  |  Branch (2462:7): [True: 55.9k, False: 424k]
  ------------------
 2463|   134k|        result = ProcessCommands(s);
 2464|   134k|        if (result == BROTLI_DECODER_NEEDS_MORE_INPUT) {
  ------------------
  |  Branch (2464:13): [True: 100k, False: 34.8k]
  ------------------
 2465|   100k|          result = SafeProcessCommands(s);
 2466|   100k|        }
 2467|   134k|        break;
 2468|       |
 2469|   112k|      case BROTLI_STATE_COMMAND_INNER_WRITE:
  ------------------
  |  Branch (2469:7): [True: 112k, False: 367k]
  ------------------
 2470|       |      /* Fall through. */
 2471|   153k|      case BROTLI_STATE_COMMAND_POST_WRITE_1:
  ------------------
  |  Branch (2471:7): [True: 41.4k, False: 438k]
  ------------------
 2472|       |      /* Fall through. */
 2473|   265k|      case BROTLI_STATE_COMMAND_POST_WRITE_2:
  ------------------
  |  Branch (2473:7): [True: 112k, False: 368k]
  ------------------
 2474|   265k|        result = WriteRingBuffer(
 2475|   265k|            s, available_out, next_out, total_out, BROTLI_FALSE);
  ------------------
  |  |   53|   265k|#define BROTLI_FALSE 0
  ------------------
 2476|   265k|        if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (2476:13): [True: 138k, False: 127k]
  ------------------
 2477|   138k|          break;
 2478|   138k|        }
 2479|   127k|        WrapRingBuffer(s);
 2480|   127k|        if (s->ringbuffer_size == 1 << s->window_bits) {
  ------------------
  |  Branch (2480:13): [True: 127k, False: 23]
  ------------------
 2481|   127k|          s->max_distance = s->max_backward_distance;
 2482|   127k|        }
 2483|   127k|        if (s->state == BROTLI_STATE_COMMAND_POST_WRITE_1) {
  ------------------
  |  Branch (2483:13): [True: 15.0k, False: 112k]
  ------------------
 2484|  15.0k|          if (s->meta_block_remaining_len == 0) {
  ------------------
  |  Branch (2484:15): [True: 14, False: 15.0k]
  ------------------
 2485|       |            /* Next metablock, if any. */
 2486|     14|            s->state = BROTLI_STATE_METABLOCK_DONE;
 2487|  15.0k|          } else {
 2488|  15.0k|            s->state = BROTLI_STATE_COMMAND_BEGIN;
 2489|  15.0k|          }
 2490|  15.0k|          break;
 2491|   112k|        } else if (s->state == BROTLI_STATE_COMMAND_POST_WRITE_2) {
  ------------------
  |  Branch (2491:20): [True: 55.9k, False: 56.0k]
  ------------------
 2492|  55.9k|          s->state = BROTLI_STATE_COMMAND_POST_WRAP_COPY;
 2493|  56.0k|        } else {  /* BROTLI_STATE_COMMAND_INNER_WRITE */
 2494|  56.0k|          if (s->loop_counter == 0) {
  ------------------
  |  Branch (2494:15): [True: 18.8k, False: 37.2k]
  ------------------
 2495|  18.8k|            if (s->meta_block_remaining_len == 0) {
  ------------------
  |  Branch (2495:17): [True: 133, False: 18.7k]
  ------------------
 2496|    133|              s->state = BROTLI_STATE_METABLOCK_DONE;
 2497|  18.7k|            } else {
 2498|  18.7k|              s->state = BROTLI_STATE_COMMAND_POST_DECODE_LITERALS;
 2499|  18.7k|            }
 2500|  18.8k|            break;
 2501|  18.8k|          }
 2502|  37.2k|          s->state = BROTLI_STATE_COMMAND_INNER;
 2503|  37.2k|        }
 2504|  93.1k|        break;
 2505|       |
 2506|  93.1k|      case BROTLI_STATE_METABLOCK_DONE:
  ------------------
  |  Branch (2506:7): [True: 10.6k, False: 469k]
  ------------------
 2507|  10.6k|        if (s->meta_block_remaining_len < 0) {
  ------------------
  |  Branch (2507:13): [True: 340, False: 10.2k]
  ------------------
 2508|    340|          result = BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2);
  ------------------
  |  |   31|    340|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|    340|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 2509|    340|          break;
 2510|    340|        }
 2511|  10.2k|        BrotliDecoderStateCleanupAfterMetablock(s);
 2512|  10.2k|        if (!s->is_last_metablock) {
  ------------------
  |  Branch (2512:13): [True: 10.0k, False: 205]
  ------------------
 2513|  10.0k|          s->state = BROTLI_STATE_METABLOCK_BEGIN;
 2514|  10.0k|          break;
 2515|  10.0k|        }
 2516|    205|        if (!BrotliJumpToByteBoundary(br)) {
  ------------------
  |  Branch (2516:13): [True: 31, False: 174]
  ------------------
 2517|     31|          result = BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_PADDING_2);
  ------------------
  |  |   31|     31|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|     31|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 2518|     31|          break;
 2519|     31|        }
 2520|    174|        if (s->buffer_length == 0) {
  ------------------
  |  Branch (2520:13): [True: 174, False: 0]
  ------------------
 2521|    174|          BrotliBitReaderUnload(br);
 2522|    174|          *available_in = br->avail_in;
 2523|    174|          *next_in = br->next_in;
 2524|    174|        }
 2525|    174|        s->state = BROTLI_STATE_DONE;
 2526|       |      /* Fall through. */
 2527|       |
 2528|    188|      case BROTLI_STATE_DONE:
  ------------------
  |  Branch (2528:7): [True: 14, False: 480k]
  ------------------
 2529|    188|        if (s->ringbuffer != 0) {
  ------------------
  |  Branch (2529:13): [True: 33, False: 155]
  ------------------
 2530|     33|          result = WriteRingBuffer(
 2531|     33|              s, available_out, next_out, total_out, BROTLI_TRUE);
  ------------------
  |  |   51|     33|#define BROTLI_TRUE 1
  ------------------
 2532|     33|          if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (2532:15): [True: 19, False: 14]
  ------------------
 2533|     19|            break;
 2534|     19|          }
 2535|     33|        }
 2536|    169|        return SaveErrorCode(s, result);
 2537|   480k|    }
 2538|   480k|  }
 2539|   145k|  return SaveErrorCode(s, result);
 2540|   145k|}
BrotliDecoderTakeOutput:
 2551|   144k|const uint8_t* BrotliDecoderTakeOutput(BrotliDecoderState* s, size_t* size) {
 2552|   144k|  uint8_t* result = 0;
 2553|   144k|  size_t available_out = *size ? *size : 1u << 24;
  ------------------
  |  Branch (2553:26): [True: 0, False: 144k]
  ------------------
 2554|   144k|  size_t requested_out = available_out;
 2555|   144k|  BrotliDecoderErrorCode status;
 2556|   144k|  if ((s->ringbuffer == 0) || ((int)s->error_code < 0)) {
  ------------------
  |  Branch (2556:7): [True: 1.20k, False: 142k]
  |  Branch (2556:31): [True: 0, False: 142k]
  ------------------
 2557|  1.20k|    *size = 0;
 2558|  1.20k|    return 0;
 2559|  1.20k|  }
 2560|   142k|  WrapRingBuffer(s);
 2561|   142k|  status = WriteRingBuffer(s, &available_out, &result, 0, BROTLI_TRUE);
  ------------------
  |  |   51|   142k|#define BROTLI_TRUE 1
  ------------------
 2562|       |  /* Either WriteRingBuffer returns those "success" codes... */
 2563|   142k|  if (status == BROTLI_DECODER_SUCCESS ||
  ------------------
  |  Branch (2563:7): [True: 142k, False: 0]
  ------------------
 2564|   142k|      status == BROTLI_DECODER_NEEDS_MORE_OUTPUT) {
  ------------------
  |  Branch (2564:7): [True: 0, False: 0]
  ------------------
 2565|   142k|    *size = requested_out - available_out;
 2566|   142k|  } else {
 2567|       |    /* ... or stream is broken. Normally this should be caught by
 2568|       |       BrotliDecoderDecompressStream, this is just a safeguard. */
 2569|      0|    if ((int)status < 0) SaveErrorCode(s, status);
  ------------------
  |  Branch (2569:9): [True: 0, False: 0]
  ------------------
 2570|      0|    *size = 0;
 2571|      0|    result = 0;
 2572|      0|  }
 2573|   142k|  return result;
 2574|   144k|}
decode.c:SaveErrorCode:
  115|   145k|    BrotliDecoderState* s, BrotliDecoderErrorCode e) {
  116|   145k|  s->error_code = (int)e;
  117|   145k|  switch (e) {
  118|    169|    case BROTLI_DECODER_SUCCESS:
  ------------------
  |  Branch (118:5): [True: 169, False: 145k]
  ------------------
  119|    169|      return BROTLI_DECODER_RESULT_SUCCESS;
  120|       |
  121|  2.43k|    case BROTLI_DECODER_NEEDS_MORE_INPUT:
  ------------------
  |  Branch (121:5): [True: 2.43k, False: 142k]
  ------------------
  122|  2.43k|      return BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT;
  123|       |
  124|   141k|    case BROTLI_DECODER_NEEDS_MORE_OUTPUT:
  ------------------
  |  Branch (124:5): [True: 141k, False: 3.69k]
  ------------------
  125|   141k|      return BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT;
  126|       |
  127|  1.09k|    default:
  ------------------
  |  Branch (127:5): [True: 1.09k, False: 144k]
  ------------------
  128|  1.09k|      return BROTLI_DECODER_RESULT_ERROR;
  129|   145k|  }
  130|   145k|}
decode.c:WriteRingBuffer:
 1269|   415k|    size_t* total_out, BROTLI_BOOL force) {
 1270|   415k|  uint8_t* start =
 1271|   415k|      s->ringbuffer + (s->partial_pos_out & (size_t)s->ringbuffer_mask);
 1272|   415k|  size_t to_write = UnwrittenBytes(s, BROTLI_TRUE);
  ------------------
  |  |   51|   415k|#define BROTLI_TRUE 1
  ------------------
 1273|   415k|  size_t num_written = *available_out;
 1274|   415k|  if (num_written > to_write) {
  ------------------
  |  Branch (1274:7): [True: 142k, False: 273k]
  ------------------
 1275|   142k|    num_written = to_write;
 1276|   142k|  }
 1277|   415k|  if (s->meta_block_remaining_len < 0) {
  ------------------
  |  Branch (1277:7): [True: 123, False: 415k]
  ------------------
 1278|    123|    return BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1);
  ------------------
  |  |   31|    123|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|    123|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 1279|    123|  }
 1280|   415k|  if (next_out && !*next_out) {
  ------------------
  |  Branch (1280:7): [True: 142k, False: 272k]
  |  Branch (1280:19): [True: 142k, False: 0]
  ------------------
 1281|   142k|    *next_out = start;
 1282|   272k|  } else {
 1283|   272k|    if (next_out) {
  ------------------
  |  Branch (1283:9): [True: 0, False: 272k]
  ------------------
 1284|      0|      memcpy(*next_out, start, num_written);
 1285|      0|      *next_out += num_written;
 1286|      0|    }
 1287|   272k|  }
 1288|   415k|  *available_out -= num_written;
 1289|   415k|  BROTLI_LOG_UINT(to_write);
 1290|   415k|  BROTLI_LOG_UINT(num_written);
 1291|   415k|  s->partial_pos_out += num_written;
 1292|   415k|  if (total_out) {
  ------------------
  |  Branch (1292:7): [True: 0, False: 415k]
  ------------------
 1293|      0|    *total_out = s->partial_pos_out;
 1294|      0|  }
 1295|   415k|  if (num_written < to_write) {
  ------------------
  |  Branch (1295:7): [True: 142k, False: 273k]
  ------------------
 1296|   142k|    if (s->ringbuffer_size == (1 << s->window_bits) || force) {
  ------------------
  |  Branch (1296:9): [True: 142k, False: 803]
  |  Branch (1296:56): [True: 780, False: 23]
  ------------------
 1297|   142k|      return BROTLI_DECODER_NEEDS_MORE_OUTPUT;
 1298|   142k|    } else {
 1299|     23|      return BROTLI_DECODER_SUCCESS;
 1300|     23|    }
 1301|   142k|  }
 1302|       |  /* Wrap ring buffer only if it has reached its maximal size. */
 1303|   273k|  if (s->ringbuffer_size == (1 << s->window_bits) &&
  ------------------
  |  Branch (1303:7): [True: 272k, False: 864]
  ------------------
 1304|   272k|      s->pos >= s->ringbuffer_size) {
  ------------------
  |  Branch (1304:7): [True: 130k, False: 141k]
  ------------------
 1305|   130k|    s->pos -= s->ringbuffer_size;
 1306|   130k|    s->rb_roundtrips++;
 1307|   130k|    s->should_wrap_ringbuffer = (size_t)s->pos != 0 ? 1 : 0;
  ------------------
  |  Branch (1307:33): [True: 11.2k, False: 118k]
  ------------------
 1308|   130k|  }
 1309|   273k|  return BROTLI_DECODER_SUCCESS;
 1310|   415k|}
decode.c:DecodeWindowBits:
  135|  3.73k|                                               BrotliBitReader* br) {
  136|  3.73k|  uint32_t n;
  137|  3.73k|  BROTLI_BOOL large_window = s->large_window;
  ------------------
  |  |   49|  3.73k|#define BROTLI_BOOL int
  ------------------
  138|  3.73k|  s->large_window = BROTLI_FALSE;
  ------------------
  |  |   53|  3.73k|#define BROTLI_FALSE 0
  ------------------
  139|  3.73k|  BrotliTakeBits(br, 1, &n);
  140|  3.73k|  if (n == 0) {
  ------------------
  |  Branch (140:7): [True: 2.55k, False: 1.18k]
  ------------------
  141|  2.55k|    s->window_bits = 16;
  142|  2.55k|    return BROTLI_DECODER_SUCCESS;
  143|  2.55k|  }
  144|  1.18k|  BrotliTakeBits(br, 3, &n);
  145|  1.18k|  if (n != 0) {
  ------------------
  |  Branch (145:7): [True: 651, False: 531]
  ------------------
  146|    651|    s->window_bits = 17 + n;
  147|    651|    return BROTLI_DECODER_SUCCESS;
  148|    651|  }
  149|    531|  BrotliTakeBits(br, 3, &n);
  150|    531|  if (n == 1) {
  ------------------
  |  Branch (150:7): [True: 1, False: 530]
  ------------------
  151|      1|    if (large_window) {
  ------------------
  |  Branch (151:9): [True: 0, False: 1]
  ------------------
  152|      0|      BrotliTakeBits(br, 1, &n);
  153|      0|      if (n == 1) {
  ------------------
  |  Branch (153:11): [True: 0, False: 0]
  ------------------
  154|      0|        return BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS);
  ------------------
  |  |   31|      0|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|      0|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
  155|      0|      }
  156|      0|      s->large_window = BROTLI_TRUE;
  ------------------
  |  |   51|      0|#define BROTLI_TRUE 1
  ------------------
  157|      0|      return BROTLI_DECODER_SUCCESS;
  158|      1|    } else {
  159|      1|      return BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS);
  ------------------
  |  |   31|      1|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|      1|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
  160|      1|    }
  161|      1|  }
  162|    530|  if (n != 0) {
  ------------------
  |  Branch (162:7): [True: 504, False: 26]
  ------------------
  163|    504|    s->window_bits = 8 + n;
  164|    504|    return BROTLI_DECODER_SUCCESS;
  165|    504|  }
  166|     26|  s->window_bits = 17;
  167|     26|  return BROTLI_DECODER_SUCCESS;
  168|    530|}
decode.c:DecodeMetaBlockLength:
  226|  13.8k|    BrotliDecoderState* s, BrotliBitReader* br) {
  227|  13.8k|  uint32_t bits;
  228|  13.8k|  int i;
  229|  29.2k|  for (;;) {
  230|  29.2k|    switch (s->substate_metablock_header) {
  231|  13.8k|      case BROTLI_STATE_METABLOCK_HEADER_NONE:
  ------------------
  |  Branch (231:7): [True: 13.8k, False: 15.4k]
  ------------------
  232|  13.8k|        if (!BrotliSafeReadBits(br, 1, &bits)) {
  ------------------
  |  Branch (232:13): [True: 50, False: 13.7k]
  ------------------
  233|     50|          return BROTLI_DECODER_NEEDS_MORE_INPUT;
  234|     50|        }
  235|  13.7k|        s->is_last_metablock = bits ? 1 : 0;
  ------------------
  |  Branch (235:32): [True: 974, False: 12.7k]
  ------------------
  236|  13.7k|        s->meta_block_remaining_len = 0;
  237|  13.7k|        s->is_uncompressed = 0;
  238|  13.7k|        s->is_metadata = 0;
  239|  13.7k|        if (!s->is_last_metablock) {
  ------------------
  |  Branch (239:13): [True: 12.7k, False: 974]
  ------------------
  240|  12.7k|          s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_NIBBLES;
  241|  12.7k|          break;
  242|  12.7k|        }
  243|    974|        s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_EMPTY;
  244|       |      /* Fall through. */
  245|       |
  246|    974|      case BROTLI_STATE_METABLOCK_HEADER_EMPTY:
  ------------------
  |  Branch (246:7): [True: 0, False: 29.2k]
  ------------------
  247|    974|        if (!BrotliSafeReadBits(br, 1, &bits)) {
  ------------------
  |  Branch (247:13): [True: 9, False: 965]
  ------------------
  248|      9|          return BROTLI_DECODER_NEEDS_MORE_INPUT;
  249|      9|        }
  250|    965|        if (bits) {
  ------------------
  |  Branch (250:13): [True: 135, False: 830]
  ------------------
  251|    135|          s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_NONE;
  252|    135|          return BROTLI_DECODER_SUCCESS;
  253|    135|        }
  254|    830|        s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_NIBBLES;
  255|       |      /* Fall through. */
  256|       |
  257|  13.6k|      case BROTLI_STATE_METABLOCK_HEADER_NIBBLES:
  ------------------
  |  Branch (257:7): [True: 12.7k, False: 16.4k]
  ------------------
  258|  13.6k|        if (!BrotliSafeReadBits(br, 2, &bits)) {
  ------------------
  |  Branch (258:13): [True: 34, False: 13.5k]
  ------------------
  259|     34|          return BROTLI_DECODER_NEEDS_MORE_INPUT;
  260|     34|        }
  261|  13.5k|        s->size_nibbles = (uint8_t)(bits + 4);
  262|  13.5k|        s->loop_counter = 0;
  263|  13.5k|        if (bits == 3) {
  ------------------
  |  Branch (263:13): [True: 2.65k, False: 10.9k]
  ------------------
  264|  2.65k|          s->is_metadata = 1;
  265|  2.65k|          s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_RESERVED;
  266|  2.65k|          break;
  267|  2.65k|        }
  268|  10.9k|        s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_SIZE;
  269|       |      /* Fall through. */
  270|       |
  271|  10.9k|      case BROTLI_STATE_METABLOCK_HEADER_SIZE:
  ------------------
  |  Branch (271:7): [True: 0, False: 29.2k]
  ------------------
  272|  10.9k|        i = s->loop_counter;
  273|  55.7k|        for (; i < (int)s->size_nibbles; ++i) {
  ------------------
  |  Branch (273:16): [True: 44.8k, False: 10.8k]
  ------------------
  274|  44.8k|          if (!BrotliSafeReadBits(br, 4, &bits)) {
  ------------------
  |  Branch (274:15): [True: 75, False: 44.7k]
  ------------------
  275|     75|            s->loop_counter = i;
  276|     75|            return BROTLI_DECODER_NEEDS_MORE_INPUT;
  277|     75|          }
  278|  44.7k|          if (i + 1 == (int)s->size_nibbles && s->size_nibbles > 4 &&
  ------------------
  |  Branch (278:15): [True: 10.8k, False: 33.9k]
  |  Branch (278:48): [True: 880, False: 9.96k]
  ------------------
  279|    880|              bits == 0) {
  ------------------
  |  Branch (279:15): [True: 4, False: 876]
  ------------------
  280|      4|            return BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE);
  ------------------
  |  |   31|      4|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|      4|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
  281|      4|          }
  282|  44.7k|          s->meta_block_remaining_len |= (int)(bits << (i * 4));
  283|  44.7k|        }
  284|  10.8k|        s->substate_metablock_header =
  285|  10.8k|            BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSED;
  286|       |      /* Fall through. */
  287|       |
  288|  10.8k|      case BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSED:
  ------------------
  |  Branch (288:7): [True: 0, False: 29.2k]
  ------------------
  289|  10.8k|        if (!s->is_last_metablock) {
  ------------------
  |  Branch (289:13): [True: 10.1k, False: 710]
  ------------------
  290|  10.1k|          if (!BrotliSafeReadBits(br, 1, &bits)) {
  ------------------
  |  Branch (290:15): [True: 4, False: 10.1k]
  ------------------
  291|      4|            return BROTLI_DECODER_NEEDS_MORE_INPUT;
  292|      4|          }
  293|  10.1k|          s->is_uncompressed = bits ? 1 : 0;
  ------------------
  |  Branch (293:32): [True: 1.62k, False: 8.50k]
  ------------------
  294|  10.1k|        }
  295|  10.8k|        ++s->meta_block_remaining_len;
  296|  10.8k|        s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_NONE;
  297|  10.8k|        return BROTLI_DECODER_SUCCESS;
  298|       |
  299|  2.65k|      case BROTLI_STATE_METABLOCK_HEADER_RESERVED:
  ------------------
  |  Branch (299:7): [True: 2.65k, False: 26.5k]
  ------------------
  300|  2.65k|        if (!BrotliSafeReadBits(br, 1, &bits)) {
  ------------------
  |  Branch (300:13): [True: 2, False: 2.65k]
  ------------------
  301|      2|          return BROTLI_DECODER_NEEDS_MORE_INPUT;
  302|      2|        }
  303|  2.65k|        if (bits != 0) {
  ------------------
  |  Branch (303:13): [True: 6, False: 2.64k]
  ------------------
  304|      6|          return BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_RESERVED);
  ------------------
  |  |   31|      6|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|      6|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
  305|      6|        }
  306|  2.64k|        s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_BYTES;
  307|       |      /* Fall through. */
  308|       |
  309|  2.64k|      case BROTLI_STATE_METABLOCK_HEADER_BYTES:
  ------------------
  |  Branch (309:7): [True: 0, False: 29.2k]
  ------------------
  310|  2.64k|        if (!BrotliSafeReadBits(br, 2, &bits)) {
  ------------------
  |  Branch (310:13): [True: 3, False: 2.64k]
  ------------------
  311|      3|          return BROTLI_DECODER_NEEDS_MORE_INPUT;
  312|      3|        }
  313|  2.64k|        if (bits == 0) {
  ------------------
  |  Branch (313:13): [True: 1.70k, False: 942]
  ------------------
  314|  1.70k|          s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_NONE;
  315|  1.70k|          return BROTLI_DECODER_SUCCESS;
  316|  1.70k|        }
  317|    942|        s->size_nibbles = (uint8_t)bits;
  318|    942|        s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_METADATA;
  319|       |      /* Fall through. */
  320|       |
  321|    942|      case BROTLI_STATE_METABLOCK_HEADER_METADATA:
  ------------------
  |  Branch (321:7): [True: 0, False: 29.2k]
  ------------------
  322|    942|        i = s->loop_counter;
  323|  2.12k|        for (; i < (int)s->size_nibbles; ++i) {
  ------------------
  |  Branch (323:16): [True: 1.20k, False: 925]
  ------------------
  324|  1.20k|          if (!BrotliSafeReadBits(br, 8, &bits)) {
  ------------------
  |  Branch (324:15): [True: 15, False: 1.18k]
  ------------------
  325|     15|            s->loop_counter = i;
  326|     15|            return BROTLI_DECODER_NEEDS_MORE_INPUT;
  327|     15|          }
  328|  1.18k|          if (i + 1 == (int)s->size_nibbles && s->size_nibbles > 1 &&
  ------------------
  |  Branch (328:15): [True: 927, False: 258]
  |  Branch (328:48): [True: 222, False: 705]
  ------------------
  329|    222|              bits == 0) {
  ------------------
  |  Branch (329:15): [True: 2, False: 220]
  ------------------
  330|      2|            return BROTLI_FAILURE(
  ------------------
  |  |   31|      2|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|      2|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
  331|      2|                BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE);
  332|      2|          }
  333|  1.18k|          s->meta_block_remaining_len |= (int)(bits << (i * 8));
  334|  1.18k|        }
  335|    925|        ++s->meta_block_remaining_len;
  336|    925|        s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_NONE;
  337|    925|        return BROTLI_DECODER_SUCCESS;
  338|       |
  339|      0|      default:
  ------------------
  |  Branch (339:7): [True: 0, False: 29.2k]
  ------------------
  340|      0|        return
  341|      0|            BROTLI_FAILURE(BROTLI_DECODER_ERROR_UNREACHABLE);
  ------------------
  |  |   31|      0|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|      0|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
  342|  29.2k|    }
  343|  29.2k|  }
  344|  13.8k|}
decode.c:BrotliCalculateRingBufferSize:
 1413|  10.8k|    BrotliDecoderState* s) {
 1414|  10.8k|  int window_size = 1 << s->window_bits;
 1415|  10.8k|  int new_ringbuffer_size = window_size;
 1416|       |  /* We need at least 2 bytes of ring buffer size to get the last two
 1417|       |     bytes for context from there */
 1418|  10.8k|  int min_size = s->ringbuffer_size ? s->ringbuffer_size : 1024;
  ------------------
  |  Branch (1418:18): [True: 7.36k, False: 3.46k]
  ------------------
 1419|  10.8k|  int output_size;
 1420|       |
 1421|       |  /* If maximum is already reached, no further extension is retired. */
 1422|  10.8k|  if (s->ringbuffer_size == window_size) {
  ------------------
  |  Branch (1422:7): [True: 986, False: 9.84k]
  ------------------
 1423|    986|    return;
 1424|    986|  }
 1425|       |
 1426|       |  /* Metadata blocks does not touch ring buffer. */
 1427|  9.84k|  if (s->is_metadata) {
  ------------------
  |  Branch (1427:7): [True: 0, False: 9.84k]
  ------------------
 1428|      0|    return;
 1429|      0|  }
 1430|       |
 1431|  9.84k|  if (!s->ringbuffer) {
  ------------------
  |  Branch (1431:7): [True: 3.46k, False: 6.37k]
  ------------------
 1432|  3.46k|    output_size = 0;
 1433|  6.37k|  } else {
 1434|  6.37k|    output_size = s->pos;
 1435|  6.37k|  }
 1436|  9.84k|  output_size += s->meta_block_remaining_len;
 1437|  9.84k|  min_size = min_size < output_size ? output_size : min_size;
  ------------------
  |  Branch (1437:14): [True: 3.23k, False: 6.60k]
  ------------------
 1438|       |
 1439|  9.84k|  if (!!s->canny_ringbuffer_allocation) {
  ------------------
  |  Branch (1439:7): [True: 9.84k, False: 0]
  ------------------
 1440|       |    /* Reduce ring buffer size to save memory when server is unscrupulous.
 1441|       |       In worst case memory usage might be 1.5x bigger for a short period of
 1442|       |       ring buffer reallocation. */
 1443|  55.2k|    while ((new_ringbuffer_size >> 1) >= min_size) {
  ------------------
  |  Branch (1443:12): [True: 45.3k, False: 9.84k]
  ------------------
 1444|  45.3k|      new_ringbuffer_size >>= 1;
 1445|  45.3k|    }
 1446|  9.84k|  }
 1447|       |
 1448|  9.84k|  s->new_ringbuffer_size = new_ringbuffer_size;
 1449|  9.84k|}
decode.c:DecodeVarLenUint8:
  182|  44.4k|    BrotliDecoderState* s, BrotliBitReader* br, uint32_t* value) {
  183|  44.4k|  uint32_t bits;
  184|  44.4k|  switch (s->substate_decode_uint8) {
  185|  44.4k|    case BROTLI_STATE_DECODE_UINT8_NONE:
  ------------------
  |  Branch (185:5): [True: 44.4k, False: 0]
  ------------------
  186|  44.4k|      if (BROTLI_PREDICT_FALSE(!BrotliSafeReadBits(br, 1, &bits))) {
  ------------------
  |  |   83|  44.4k|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 23, False: 44.4k]
  |  |  ------------------
  ------------------
  187|     23|        return BROTLI_DECODER_NEEDS_MORE_INPUT;
  188|     23|      }
  189|  44.4k|      if (bits == 0) {
  ------------------
  |  Branch (189:11): [True: 39.4k, False: 4.94k]
  ------------------
  190|  39.4k|        *value = 0;
  191|  39.4k|        return BROTLI_DECODER_SUCCESS;
  192|  39.4k|      }
  193|       |    /* Fall through. */
  194|       |
  195|  4.94k|    case BROTLI_STATE_DECODE_UINT8_SHORT:
  ------------------
  |  Branch (195:5): [True: 0, False: 44.4k]
  ------------------
  196|  4.94k|      if (BROTLI_PREDICT_FALSE(!BrotliSafeReadBits(br, 3, &bits))) {
  ------------------
  |  |   83|  4.94k|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 24, False: 4.91k]
  |  |  ------------------
  ------------------
  197|     24|        s->substate_decode_uint8 = BROTLI_STATE_DECODE_UINT8_SHORT;
  198|     24|        return BROTLI_DECODER_NEEDS_MORE_INPUT;
  199|     24|      }
  200|  4.91k|      if (bits == 0) {
  ------------------
  |  Branch (200:11): [True: 1.94k, False: 2.97k]
  ------------------
  201|  1.94k|        *value = 1;
  202|  1.94k|        s->substate_decode_uint8 = BROTLI_STATE_DECODE_UINT8_NONE;
  203|  1.94k|        return BROTLI_DECODER_SUCCESS;
  204|  1.94k|      }
  205|       |      /* Use output value as a temporary storage. It MUST be persisted. */
  206|  2.97k|      *value = bits;
  207|       |    /* Fall through. */
  208|       |
  209|  2.97k|    case BROTLI_STATE_DECODE_UINT8_LONG:
  ------------------
  |  Branch (209:5): [True: 0, False: 44.4k]
  ------------------
  210|  2.97k|      if (BROTLI_PREDICT_FALSE(!BrotliSafeReadBits(br, *value, &bits))) {
  ------------------
  |  |   83|  2.97k|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 23, False: 2.94k]
  |  |  ------------------
  ------------------
  211|     23|        s->substate_decode_uint8 = BROTLI_STATE_DECODE_UINT8_LONG;
  212|     23|        return BROTLI_DECODER_NEEDS_MORE_INPUT;
  213|     23|      }
  214|  2.94k|      *value = (1U << *value) + bits;
  215|  2.94k|      s->substate_decode_uint8 = BROTLI_STATE_DECODE_UINT8_NONE;
  216|  2.94k|      return BROTLI_DECODER_SUCCESS;
  217|       |
  218|      0|    default:
  ------------------
  |  Branch (218:5): [True: 0, False: 44.4k]
  ------------------
  219|      0|      return
  220|      0|          BROTLI_FAILURE(BROTLI_DECODER_ERROR_UNREACHABLE);
  ------------------
  |  |   31|      0|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|      0|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
  221|  44.4k|  }
  222|  44.4k|}
decode.c:ReadHuffmanCode:
  752|  43.2k|                                              BrotliDecoderState* s) {
  753|  43.2k|  BrotliBitReader* br = &s->br;
  754|  43.2k|  BrotliMetablockHeaderArena* h = &s->arena.header;
  755|       |  /* State machine. */
  756|  49.5k|  for (;;) {
  757|  49.5k|    switch (h->substate_huffman) {
  758|  43.2k|      case BROTLI_STATE_HUFFMAN_NONE:
  ------------------
  |  Branch (758:7): [True: 43.2k, False: 6.29k]
  ------------------
  759|  43.2k|        if (!BrotliSafeReadBits(br, 2, &h->sub_loop_counter)) {
  ------------------
  |  Branch (759:13): [True: 91, False: 43.1k]
  ------------------
  760|     91|          return BROTLI_DECODER_NEEDS_MORE_INPUT;
  761|     91|        }
  762|  43.1k|        BROTLI_LOG_UINT(h->sub_loop_counter);
  763|       |        /* The value is used as follows:
  764|       |           1 for simple code;
  765|       |           0 for no skipping, 2 skips 2 code lengths, 3 skips 3 code lengths */
  766|  43.1k|        if (h->sub_loop_counter != 1) {
  ------------------
  |  Branch (766:13): [True: 6.29k, False: 36.9k]
  ------------------
  767|  6.29k|          h->space = 32;
  768|  6.29k|          h->repeat = 0;  /* num_codes */
  769|  6.29k|          memset(&h->code_length_histo[0], 0, sizeof(h->code_length_histo[0]) *
  770|  6.29k|              (BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH + 1));
  ------------------
  |  |   28|  6.29k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH 5
  ------------------
  771|  6.29k|          memset(&h->code_length_code_lengths[0], 0,
  772|  6.29k|              sizeof(h->code_length_code_lengths));
  773|  6.29k|          h->substate_huffman = BROTLI_STATE_HUFFMAN_COMPLEX;
  774|  6.29k|          continue;
  775|  6.29k|        }
  776|       |      /* Fall through. */
  777|       |
  778|  36.9k|      case BROTLI_STATE_HUFFMAN_SIMPLE_SIZE:
  ------------------
  |  Branch (778:7): [True: 0, False: 49.5k]
  ------------------
  779|       |        /* Read symbols, codes & code lengths directly. */
  780|  36.9k|        if (!BrotliSafeReadBits(br, 2, &h->symbol)) {  /* num_symbols */
  ------------------
  |  Branch (780:13): [True: 33, False: 36.8k]
  ------------------
  781|     33|          h->substate_huffman = BROTLI_STATE_HUFFMAN_SIMPLE_SIZE;
  782|     33|          return BROTLI_DECODER_NEEDS_MORE_INPUT;
  783|     33|        }
  784|  36.8k|        h->sub_loop_counter = 0;
  785|       |      /* Fall through. */
  786|       |
  787|  36.8k|      case BROTLI_STATE_HUFFMAN_SIMPLE_READ: {
  ------------------
  |  Branch (787:7): [True: 0, False: 49.5k]
  ------------------
  788|  36.8k|        BrotliDecoderErrorCode result =
  789|  36.8k|            ReadSimpleHuffmanSymbols(alphabet_size_max, alphabet_size_limit, s);
  790|  36.8k|        if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (790:13): [True: 117, False: 36.7k]
  ------------------
  791|    117|          return result;
  792|    117|        }
  793|  36.8k|      }
  794|       |      /* Fall through. */
  795|       |
  796|  36.7k|      case BROTLI_STATE_HUFFMAN_SIMPLE_BUILD: {
  ------------------
  |  Branch (796:7): [True: 0, False: 49.5k]
  ------------------
  797|  36.7k|        uint32_t table_size;
  798|  36.7k|        if (h->symbol == 3) {
  ------------------
  |  Branch (798:13): [True: 2.97k, False: 33.7k]
  ------------------
  799|  2.97k|          uint32_t bits;
  800|  2.97k|          if (!BrotliSafeReadBits(br, 1, &bits)) {
  ------------------
  |  Branch (800:15): [True: 4, False: 2.96k]
  ------------------
  801|      4|            h->substate_huffman = BROTLI_STATE_HUFFMAN_SIMPLE_BUILD;
  802|      4|            return BROTLI_DECODER_NEEDS_MORE_INPUT;
  803|      4|          }
  804|  2.96k|          h->symbol += bits;
  805|  2.96k|        }
  806|  36.7k|        BROTLI_LOG_UINT(h->symbol);
  807|  36.7k|        table_size = BrotliBuildSimpleHuffmanTable(
  808|  36.7k|            table, HUFFMAN_TABLE_BITS, h->symbols_lists_array, h->symbol);
  ------------------
  |  |   39|  36.7k|#define HUFFMAN_TABLE_BITS 8U
  ------------------
  809|  36.7k|        if (opt_table_size) {
  ------------------
  |  Branch (809:13): [True: 30.3k, False: 6.35k]
  ------------------
  810|  30.3k|          *opt_table_size = table_size;
  811|  30.3k|        }
  812|  36.7k|        h->substate_huffman = BROTLI_STATE_HUFFMAN_NONE;
  813|  36.7k|        return BROTLI_DECODER_SUCCESS;
  814|  36.7k|      }
  815|       |
  816|       |      /* Decode Huffman-coded code lengths. */
  817|  6.29k|      case BROTLI_STATE_HUFFMAN_COMPLEX: {
  ------------------
  |  Branch (817:7): [True: 6.29k, False: 43.2k]
  ------------------
  818|  6.29k|        uint32_t i;
  819|  6.29k|        BrotliDecoderErrorCode result = ReadCodeLengthCodeLengths(s);
  820|  6.29k|        if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (820:13): [True: 364, False: 5.92k]
  ------------------
  821|    364|          return result;
  822|    364|        }
  823|  5.92k|        BrotliBuildCodeLengthsHuffmanTable(h->table,
  824|  5.92k|                                           h->code_length_code_lengths,
  825|  5.92k|                                           h->code_length_histo);
  826|  5.92k|        memset(&h->code_length_histo[0], 0, sizeof(h->code_length_histo));
  827|   100k|        for (i = 0; i <= BROTLI_HUFFMAN_MAX_CODE_LENGTH; ++i) {
  ------------------
  |  |   19|   100k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH 15
  ------------------
  |  Branch (827:21): [True: 94.8k, False: 5.92k]
  ------------------
  828|  94.8k|          h->next_symbol[i] = (int)i - (BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1);
  ------------------
  |  |   19|  94.8k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH 15
  ------------------
  829|  94.8k|          h->symbol_lists[h->next_symbol[i]] = 0xFFFF;
  830|  94.8k|        }
  831|       |
  832|  5.92k|        h->symbol = 0;
  833|  5.92k|        h->prev_code_len = BROTLI_INITIAL_REPEATED_CODE_LENGTH;
  ------------------
  |  |   38|  5.92k|#define BROTLI_INITIAL_REPEATED_CODE_LENGTH 8
  ------------------
  834|  5.92k|        h->repeat = 0;
  835|  5.92k|        h->repeat_code_len = 0;
  836|  5.92k|        h->space = 32768;
  837|  5.92k|        h->substate_huffman = BROTLI_STATE_HUFFMAN_LENGTH_SYMBOLS;
  838|  5.92k|      }
  839|       |      /* Fall through. */
  840|       |
  841|  5.92k|      case BROTLI_STATE_HUFFMAN_LENGTH_SYMBOLS: {
  ------------------
  |  Branch (841:7): [True: 0, False: 49.5k]
  ------------------
  842|  5.92k|        uint32_t table_size;
  843|  5.92k|        BrotliDecoderErrorCode result = ReadSymbolCodeLengths(
  844|  5.92k|            alphabet_size_limit, s);
  845|  5.92k|        if (result == BROTLI_DECODER_NEEDS_MORE_INPUT) {
  ------------------
  |  Branch (845:13): [True: 687, False: 5.24k]
  ------------------
  846|    687|          result = SafeReadSymbolCodeLengths(alphabet_size_limit, s);
  847|    687|        }
  848|  5.92k|        if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (848:13): [True: 155, False: 5.77k]
  ------------------
  849|    155|          return result;
  850|    155|        }
  851|       |
  852|  5.77k|        if (h->space != 0) {
  ------------------
  |  Branch (852:13): [True: 157, False: 5.61k]
  ------------------
  853|    157|          BROTLI_LOG(("[ReadHuffmanCode] space = %d\n", (int)h->space));
  854|    157|          return BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE);
  ------------------
  |  |   31|    157|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|    157|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
  855|    157|        }
  856|  5.61k|        table_size = BrotliBuildHuffmanTable(
  857|  5.61k|            table, HUFFMAN_TABLE_BITS, h->symbol_lists, h->code_length_histo);
  ------------------
  |  |   39|  5.61k|#define HUFFMAN_TABLE_BITS 8U
  ------------------
  858|  5.61k|        if (opt_table_size) {
  ------------------
  |  Branch (858:13): [True: 4.53k, False: 1.08k]
  ------------------
  859|  4.53k|          *opt_table_size = table_size;
  860|  4.53k|        }
  861|  5.61k|        h->substate_huffman = BROTLI_STATE_HUFFMAN_NONE;
  862|  5.61k|        return BROTLI_DECODER_SUCCESS;
  863|  5.77k|      }
  864|       |
  865|      0|      default:
  ------------------
  |  Branch (865:7): [True: 0, False: 49.5k]
  ------------------
  866|      0|        return
  867|      0|            BROTLI_FAILURE(BROTLI_DECODER_ERROR_UNREACHABLE);
  ------------------
  |  |   31|      0|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|      0|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
  868|  49.5k|    }
  869|  49.5k|  }
  870|  43.2k|}
decode.c:ReadSimpleHuffmanSymbols:
  477|  36.8k|    BrotliDecoderState* s) {
  478|       |  /* max_bits == 1..11; symbol == 0..3; 1..44 bits will be read. */
  479|  36.8k|  BrotliBitReader* br = &s->br;
  480|  36.8k|  BrotliMetablockHeaderArena* h = &s->arena.header;
  481|  36.8k|  uint32_t max_bits = Log2Floor(alphabet_size_max - 1);
  482|  36.8k|  uint32_t i = h->sub_loop_counter;
  483|  36.8k|  uint32_t num_symbols = h->symbol;
  484|  95.9k|  while (i <= num_symbols) {
  ------------------
  |  Branch (484:10): [True: 59.1k, False: 36.7k]
  ------------------
  485|  59.1k|    uint32_t v;
  486|  59.1k|    if (BROTLI_PREDICT_FALSE(!BrotliSafeReadBits(br, max_bits, &v))) {
  ------------------
  |  |   83|  59.1k|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 80, False: 59.0k]
  |  |  ------------------
  ------------------
  487|     80|      h->sub_loop_counter = i;
  488|     80|      h->substate_huffman = BROTLI_STATE_HUFFMAN_SIMPLE_READ;
  489|     80|      return BROTLI_DECODER_NEEDS_MORE_INPUT;
  490|     80|    }
  491|  59.0k|    if (v >= alphabet_size_limit) {
  ------------------
  |  Branch (491:9): [True: 25, False: 59.0k]
  ------------------
  492|     25|      return
  493|     25|          BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET);
  ------------------
  |  |   31|     25|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|     25|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
  494|     25|    }
  495|  59.0k|    h->symbols_lists_array[i] = (uint16_t)v;
  496|  59.0k|    BROTLI_LOG_UINT(h->symbols_lists_array[i]);
  497|  59.0k|    ++i;
  498|  59.0k|  }
  499|       |
  500|  59.0k|  for (i = 0; i < num_symbols; ++i) {
  ------------------
  |  Branch (500:15): [True: 22.2k, False: 36.7k]
  ------------------
  501|  22.2k|    uint32_t k = i + 1;
  502|  56.5k|    for (; k <= num_symbols; ++k) {
  ------------------
  |  Branch (502:12): [True: 34.3k, False: 22.2k]
  ------------------
  503|  34.3k|      if (h->symbols_lists_array[i] == h->symbols_lists_array[k]) {
  ------------------
  |  Branch (503:11): [True: 12, False: 34.3k]
  ------------------
  504|     12|        return BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME);
  ------------------
  |  |   31|     12|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|     12|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
  505|     12|      }
  506|  34.3k|    }
  507|  22.2k|  }
  508|       |
  509|  36.7k|  return BROTLI_DECODER_SUCCESS;
  510|  36.7k|}
decode.c:Log2Floor:
  463|  36.8k|static BROTLI_INLINE uint32_t Log2Floor(uint32_t x) {
  464|  36.8k|  uint32_t result = 0;
  465|   311k|  while (x) {
  ------------------
  |  Branch (465:10): [True: 274k, False: 36.8k]
  ------------------
  466|   274k|    x >>= 1;
  467|   274k|    ++result;
  468|   274k|  }
  469|  36.8k|  return result;
  470|  36.8k|}
decode.c:ReadCodeLengthCodeLengths:
  692|  6.29k|static BrotliDecoderErrorCode ReadCodeLengthCodeLengths(BrotliDecoderState* s) {
  693|  6.29k|  BrotliBitReader* br = &s->br;
  694|  6.29k|  BrotliMetablockHeaderArena* h = &s->arena.header;
  695|  6.29k|  uint32_t num_codes = h->repeat;
  696|  6.29k|  unsigned space = h->space;
  697|  6.29k|  uint32_t i = h->sub_loop_counter;
  698|  51.4k|  for (; i < BROTLI_CODE_LENGTH_CODES; ++i) {
  ------------------
  |  |   36|  51.4k|#define BROTLI_CODE_LENGTH_CODES (BROTLI_REPEAT_ZERO_CODE_LENGTH + 1)
  |  |  ------------------
  |  |  |  |   35|  51.4k|#define BROTLI_REPEAT_ZERO_CODE_LENGTH 17
  |  |  ------------------
  ------------------
  |  Branch (698:10): [True: 51.0k, False: 374]
  ------------------
  699|  51.0k|    const uint8_t code_len_idx = kCodeLengthCodeOrder[i];
  700|  51.0k|    uint32_t ix;
  701|  51.0k|    uint32_t v;
  702|  51.0k|    if (BROTLI_PREDICT_FALSE(!BrotliSafeGetBits(br, 4, &ix))) {
  ------------------
  |  |   83|  51.0k|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 408, False: 50.6k]
  |  |  ------------------
  ------------------
  703|    408|      uint32_t available_bits = BrotliGetAvailableBits(br);
  704|    408|      if (available_bits != 0) {
  ------------------
  |  Branch (704:11): [True: 267, False: 141]
  ------------------
  705|    267|        ix = BrotliGetBitsUnmasked(br) & 0xF;
  706|    267|      } else {
  707|    141|        ix = 0;
  708|    141|      }
  709|    408|      if (kCodeLengthPrefixLength[ix] > available_bits) {
  ------------------
  |  Branch (709:11): [True: 235, False: 173]
  ------------------
  710|    235|        h->sub_loop_counter = i;
  711|    235|        h->repeat = num_codes;
  712|    235|        h->space = space;
  713|    235|        h->substate_huffman = BROTLI_STATE_HUFFMAN_COMPLEX;
  714|    235|        return BROTLI_DECODER_NEEDS_MORE_INPUT;
  715|    235|      }
  716|    408|    }
  717|  50.8k|    v = kCodeLengthPrefixValue[ix];
  718|  50.8k|    BrotliDropBits(br, kCodeLengthPrefixLength[ix]);
  719|  50.8k|    h->code_length_code_lengths[code_len_idx] = (uint8_t)v;
  720|  50.8k|    BROTLI_LOG_ARRAY_INDEX(h->code_length_code_lengths, code_len_idx);
  721|  50.8k|    if (v != 0) {
  ------------------
  |  Branch (721:9): [True: 31.6k, False: 19.1k]
  ------------------
  722|  31.6k|      space = space - (32U >> v);
  723|  31.6k|      ++num_codes;
  724|  31.6k|      ++h->code_length_histo[v];
  725|  31.6k|      if (space - 1U >= 32U) {
  ------------------
  |  Branch (725:11): [True: 5.68k, False: 25.9k]
  ------------------
  726|       |        /* space is 0 or wrapped around. */
  727|  5.68k|        break;
  728|  5.68k|      }
  729|  31.6k|    }
  730|  50.8k|  }
  731|  6.05k|  if (!(num_codes == 1 || space == 0)) {
  ------------------
  |  Branch (731:9): [True: 305, False: 5.75k]
  |  Branch (731:27): [True: 5.62k, False: 129]
  ------------------
  732|    129|    return BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_CL_SPACE);
  ------------------
  |  |   31|    129|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|    129|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
  733|    129|  }
  734|  5.92k|  return BROTLI_DECODER_SUCCESS;
  735|  6.05k|}
decode.c:ReadSymbolCodeLengths:
  594|  5.92k|    uint32_t alphabet_size, BrotliDecoderState* s) {
  595|  5.92k|  BrotliBitReader* br = &s->br;
  596|  5.92k|  BrotliMetablockHeaderArena* h = &s->arena.header;
  597|  5.92k|  uint32_t symbol = h->symbol;
  598|  5.92k|  uint32_t repeat = h->repeat;
  599|  5.92k|  uint32_t space = h->space;
  600|  5.92k|  uint32_t prev_code_len = h->prev_code_len;
  601|  5.92k|  uint32_t repeat_code_len = h->repeat_code_len;
  602|  5.92k|  uint16_t* symbol_lists = h->symbol_lists;
  603|  5.92k|  uint16_t* code_length_histo = h->code_length_histo;
  604|  5.92k|  int* next_symbol = h->next_symbol;
  605|  5.92k|  if (!BrotliWarmupBitReader(br)) {
  ------------------
  |  Branch (605:7): [True: 40, False: 5.88k]
  ------------------
  606|     40|    return BROTLI_DECODER_NEEDS_MORE_INPUT;
  607|     40|  }
  608|   137k|  while (symbol < alphabet_size && space > 0) {
  ------------------
  |  Branch (608:10): [True: 137k, False: 364]
  |  Branch (608:36): [True: 132k, False: 4.87k]
  ------------------
  609|   132k|    const HuffmanCode* p = h->table;
  610|   132k|    uint32_t code_len;
  611|   132k|    BROTLI_HC_MARK_TABLE_FOR_FAST_LOAD(p);
  612|   132k|    if (!BrotliCheckInputAmount(br, BROTLI_SHORT_FILL_BIT_WINDOW_READ)) {
  ------------------
  |  |   22|   132k|#define BROTLI_SHORT_FILL_BIT_WINDOW_READ (sizeof(brotli_reg_t) >> 1)
  ------------------
  |  Branch (612:9): [True: 647, False: 131k]
  ------------------
  613|    647|      h->symbol = symbol;
  614|    647|      h->repeat = repeat;
  615|    647|      h->prev_code_len = prev_code_len;
  616|    647|      h->repeat_code_len = repeat_code_len;
  617|    647|      h->space = space;
  618|    647|      return BROTLI_DECODER_NEEDS_MORE_INPUT;
  619|    647|    }
  620|   131k|    BrotliFillBitWindow16(br);
  621|   131k|    BROTLI_HC_ADJUST_TABLE_INDEX(p, BrotliGetBitsUnmasked(br) &
  ------------------
  |  |   67|   131k|#define BROTLI_HC_ADJUST_TABLE_INDEX(H, V) H += (V)
  ------------------
  622|   131k|        BitMask(BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH));
  623|   131k|    BrotliDropBits(br, BROTLI_HC_FAST_LOAD_BITS(p));  /* Use 1..5 bits. */
  ------------------
  |  |   70|   131k|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  624|   131k|    code_len = BROTLI_HC_FAST_LOAD_VALUE(p);  /* code_len == 0..17 */
  ------------------
  |  |   71|   131k|#define BROTLI_HC_FAST_LOAD_VALUE(H) (H->value)
  ------------------
  625|   131k|    if (code_len < BROTLI_REPEAT_PREVIOUS_CODE_LENGTH) {
  ------------------
  |  |   34|   131k|#define BROTLI_REPEAT_PREVIOUS_CODE_LENGTH 16
  ------------------
  |  Branch (625:9): [True: 126k, False: 5.11k]
  ------------------
  626|   126k|      ProcessSingleCodeLength(code_len, &symbol, &repeat, &space,
  627|   126k|          &prev_code_len, symbol_lists, code_length_histo, next_symbol);
  628|   126k|    } else {  /* code_len == 16..17, extra_bits == 2..3 */
  629|  5.11k|      uint32_t extra_bits =
  630|  5.11k|          (code_len == BROTLI_REPEAT_PREVIOUS_CODE_LENGTH) ? 2 : 3;
  ------------------
  |  |   34|  5.11k|#define BROTLI_REPEAT_PREVIOUS_CODE_LENGTH 16
  ------------------
  |  Branch (630:11): [True: 1.67k, False: 3.43k]
  ------------------
  631|  5.11k|      uint32_t repeat_delta =
  632|  5.11k|          (uint32_t)BrotliGetBitsUnmasked(br) & BitMask(extra_bits);
  633|  5.11k|      BrotliDropBits(br, extra_bits);
  634|  5.11k|      ProcessRepeatedCodeLength(code_len, repeat_delta, alphabet_size,
  635|  5.11k|          &symbol, &repeat, &space, &prev_code_len, &repeat_code_len,
  636|  5.11k|          symbol_lists, code_length_histo, next_symbol);
  637|  5.11k|    }
  638|   131k|  }
  639|  5.24k|  h->space = space;
  640|  5.24k|  return BROTLI_DECODER_SUCCESS;
  641|  5.88k|}
decode.c:ProcessSingleCodeLength:
  521|   147k|    uint16_t* code_length_histo, int* next_symbol) {
  522|   147k|  *repeat = 0;
  523|   147k|  if (code_len != 0) {  /* code_len == 1..15 */
  ------------------
  |  Branch (523:7): [True: 140k, False: 7.44k]
  ------------------
  524|   140k|    symbol_lists[next_symbol[code_len]] = (uint16_t)(*symbol);
  525|   140k|    next_symbol[code_len] = (int)(*symbol);
  526|   140k|    *prev_code_len = code_len;
  527|   140k|    *space -= 32768U >> code_len;
  528|   140k|    code_length_histo[code_len]++;
  529|   140k|    BROTLI_LOG(("[ReadHuffmanCode] code_length[%d] = %d\n",
  530|   140k|        (int)*symbol, (int)code_len));
  531|   140k|  }
  532|   147k|  (*symbol)++;
  533|   147k|}
decode.c:ProcessRepeatedCodeLength:
  549|  6.11k|    uint16_t* code_length_histo, int* next_symbol) {
  550|  6.11k|  uint32_t old_repeat;
  551|  6.11k|  uint32_t extra_bits = 3;  /* for BROTLI_REPEAT_ZERO_CODE_LENGTH */
  552|  6.11k|  uint32_t new_len = 0;  /* for BROTLI_REPEAT_ZERO_CODE_LENGTH */
  553|  6.11k|  if (code_len == BROTLI_REPEAT_PREVIOUS_CODE_LENGTH) {
  ------------------
  |  |   34|  6.11k|#define BROTLI_REPEAT_PREVIOUS_CODE_LENGTH 16
  ------------------
  |  Branch (553:7): [True: 2.49k, False: 3.61k]
  ------------------
  554|  2.49k|    new_len = *prev_code_len;
  555|  2.49k|    extra_bits = 2;
  556|  2.49k|  }
  557|  6.11k|  if (*repeat_code_len != new_len) {
  ------------------
  |  Branch (557:7): [True: 990, False: 5.12k]
  ------------------
  558|    990|    *repeat = 0;
  559|    990|    *repeat_code_len = new_len;
  560|    990|  }
  561|  6.11k|  old_repeat = *repeat;
  562|  6.11k|  if (*repeat > 0) {
  ------------------
  |  Branch (562:7): [True: 718, False: 5.39k]
  ------------------
  563|    718|    *repeat -= 2;
  564|    718|    *repeat <<= extra_bits;
  565|    718|  }
  566|  6.11k|  *repeat += repeat_delta + 3U;
  567|  6.11k|  repeat_delta = *repeat - old_repeat;
  568|  6.11k|  if (*symbol + repeat_delta > alphabet_size) {
  ------------------
  |  Branch (568:7): [True: 75, False: 6.03k]
  ------------------
  569|     75|    BROTLI_DUMP();
  ------------------
  |  |  485|     75|#define BROTLI_DUMP() (void)(0)
  ------------------
  570|     75|    *symbol = alphabet_size;
  571|     75|    *space = 0xFFFFF;
  572|     75|    return;
  573|     75|  }
  574|  6.03k|  BROTLI_LOG(("[ReadHuffmanCode] code_length[%d..%d] = %d\n",
  575|  6.03k|      (int)*symbol, (int)(*symbol + repeat_delta - 1), (int)*repeat_code_len));
  576|  6.03k|  if (*repeat_code_len != 0) {
  ------------------
  |  Branch (576:7): [True: 2.45k, False: 3.58k]
  ------------------
  577|  2.45k|    unsigned last = *symbol + repeat_delta;
  578|  2.45k|    int next = next_symbol[*repeat_code_len];
  579|  26.7k|    do {
  580|  26.7k|      symbol_lists[next] = (uint16_t)*symbol;
  581|  26.7k|      next = (int)*symbol;
  582|  26.7k|    } while (++(*symbol) != last);
  ------------------
  |  Branch (582:14): [True: 24.3k, False: 2.45k]
  ------------------
  583|  2.45k|    next_symbol[*repeat_code_len] = next;
  584|  2.45k|    *space -= repeat_delta << (15 - *repeat_code_len);
  585|  2.45k|    code_length_histo[*repeat_code_len] =
  586|  2.45k|        (uint16_t)(code_length_histo[*repeat_code_len] + repeat_delta);
  587|  3.58k|  } else {
  588|  3.58k|    *symbol += repeat_delta;
  589|  3.58k|  }
  590|  6.03k|}
decode.c:SafeReadSymbolCodeLengths:
  644|    687|    uint32_t alphabet_size, BrotliDecoderState* s) {
  645|    687|  BrotliBitReader* br = &s->br;
  646|    687|  BrotliMetablockHeaderArena* h = &s->arena.header;
  647|    687|  BROTLI_BOOL get_byte = BROTLI_FALSE;
  ------------------
  |  |   49|    687|#define BROTLI_BOOL int
  ------------------
                BROTLI_BOOL get_byte = BROTLI_FALSE;
  ------------------
  |  |   53|    687|#define BROTLI_FALSE 0
  ------------------
  648|  22.9k|  while (h->symbol < alphabet_size && h->space > 0) {
  ------------------
  |  Branch (648:10): [True: 22.8k, False: 142]
  |  Branch (648:39): [True: 22.4k, False: 390]
  ------------------
  649|  22.4k|    const HuffmanCode* p = h->table;
  650|  22.4k|    uint32_t code_len;
  651|  22.4k|    uint32_t available_bits;
  652|  22.4k|    uint32_t bits = 0;
  653|  22.4k|    BROTLI_HC_MARK_TABLE_FOR_FAST_LOAD(p);
  654|  22.4k|    if (get_byte && !BrotliPullByte(br)) return BROTLI_DECODER_NEEDS_MORE_INPUT;
  ------------------
  |  Branch (654:9): [True: 382, False: 22.0k]
  |  Branch (654:21): [True: 155, False: 227]
  ------------------
  655|  22.2k|    get_byte = BROTLI_FALSE;
  ------------------
  |  |   53|  22.2k|#define BROTLI_FALSE 0
  ------------------
  656|  22.2k|    available_bits = BrotliGetAvailableBits(br);
  657|  22.2k|    if (available_bits != 0) {
  ------------------
  |  Branch (657:9): [True: 19.7k, False: 2.48k]
  ------------------
  658|  19.7k|      bits = (uint32_t)BrotliGetBitsUnmasked(br);
  659|  19.7k|    }
  660|  22.2k|    BROTLI_HC_ADJUST_TABLE_INDEX(p,
  ------------------
  |  |   67|  22.2k|#define BROTLI_HC_ADJUST_TABLE_INDEX(H, V) H += (V)
  ------------------
  661|  22.2k|        bits & BitMask(BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH));
  662|  22.2k|    if (BROTLI_HC_FAST_LOAD_BITS(p) > available_bits) {
  ------------------
  |  |   70|  22.2k|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  |  Branch (662:9): [True: 301, False: 21.9k]
  ------------------
  663|    301|      get_byte = BROTLI_TRUE;
  ------------------
  |  |   51|    301|#define BROTLI_TRUE 1
  ------------------
  664|    301|      continue;
  665|    301|    }
  666|  21.9k|    code_len = BROTLI_HC_FAST_LOAD_VALUE(p);  /* code_len == 0..17 */
  ------------------
  |  |   71|  21.9k|#define BROTLI_HC_FAST_LOAD_VALUE(H) (H->value)
  ------------------
  667|  21.9k|    if (code_len < BROTLI_REPEAT_PREVIOUS_CODE_LENGTH) {
  ------------------
  |  |   34|  21.9k|#define BROTLI_REPEAT_PREVIOUS_CODE_LENGTH 16
  ------------------
  |  Branch (667:9): [True: 20.8k, False: 1.08k]
  ------------------
  668|  20.8k|      BrotliDropBits(br, BROTLI_HC_FAST_LOAD_BITS(p));
  ------------------
  |  |   70|  20.8k|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  669|  20.8k|      ProcessSingleCodeLength(code_len, &h->symbol, &h->repeat, &h->space,
  670|  20.8k|          &h->prev_code_len, h->symbol_lists, h->code_length_histo,
  671|  20.8k|          h->next_symbol);
  672|  20.8k|    } else {  /* code_len == 16..17, extra_bits == 2..3 */
  673|  1.08k|      uint32_t extra_bits = code_len - 14U;
  674|  1.08k|      uint32_t repeat_delta = (bits >> BROTLI_HC_FAST_LOAD_BITS(p)) &
  ------------------
  |  |   70|  1.08k|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  675|  1.08k|          BitMask(extra_bits);
  676|  1.08k|      if (available_bits < BROTLI_HC_FAST_LOAD_BITS(p) + extra_bits) {
  ------------------
  |  |   70|  1.08k|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  |  Branch (676:11): [True: 81, False: 1.00k]
  ------------------
  677|     81|        get_byte = BROTLI_TRUE;
  ------------------
  |  |   51|     81|#define BROTLI_TRUE 1
  ------------------
  678|     81|        continue;
  679|     81|      }
  680|  1.00k|      BrotliDropBits(br, BROTLI_HC_FAST_LOAD_BITS(p) + extra_bits);
  ------------------
  |  |   70|  1.00k|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  681|  1.00k|      ProcessRepeatedCodeLength(code_len, repeat_delta, alphabet_size,
  682|  1.00k|          &h->symbol, &h->repeat, &h->space, &h->prev_code_len,
  683|  1.00k|          &h->repeat_code_len, h->symbol_lists, h->code_length_histo,
  684|  1.00k|          h->next_symbol);
  685|  1.00k|    }
  686|  21.9k|  }
  687|    532|  return BROTLI_DECODER_SUCCESS;
  688|    687|}
decode.c:SafeReadBlockLength:
  886|  20.8k|    BrotliBitReader* br) {
  887|  20.8k|  uint32_t index;
  888|  20.8k|  if (s->substate_read_block_length == BROTLI_STATE_READ_BLOCK_LENGTH_NONE) {
  ------------------
  |  Branch (888:7): [True: 20.8k, False: 0]
  ------------------
  889|  20.8k|    if (!SafeReadSymbol(table, br, &index)) {
  ------------------
  |  Branch (889:9): [True: 50, False: 20.7k]
  ------------------
  890|     50|      return BROTLI_FALSE;
  ------------------
  |  |   53|     50|#define BROTLI_FALSE 0
  ------------------
  891|     50|    }
  892|  20.8k|  } else {
  893|      0|    index = s->block_length_index;
  894|      0|  }
  895|  20.7k|  {
  896|  20.7k|    uint32_t bits;
  897|  20.7k|    uint32_t nbits = _kBrotliPrefixCodeRanges[index].nbits;
  898|  20.7k|    uint32_t offset = _kBrotliPrefixCodeRanges[index].offset;
  899|  20.7k|    if (!BrotliSafeReadBits(br, nbits, &bits)) {
  ------------------
  |  Branch (899:9): [True: 288, False: 20.4k]
  ------------------
  900|    288|      s->block_length_index = index;
  901|    288|      s->substate_read_block_length = BROTLI_STATE_READ_BLOCK_LENGTH_SUFFIX;
  902|    288|      return BROTLI_FALSE;
  ------------------
  |  |   53|    288|#define BROTLI_FALSE 0
  ------------------
  903|    288|    }
  904|  20.4k|    *result = offset + bits;
  905|  20.4k|    s->substate_read_block_length = BROTLI_STATE_READ_BLOCK_LENGTH_NONE;
  906|  20.4k|    return BROTLI_TRUE;
  ------------------
  |  |   51|  20.4k|#define BROTLI_TRUE 1
  ------------------
  907|  20.7k|  }
  908|  20.7k|}
decode.c:SafeReadSymbol:
  416|  1.42G|    const HuffmanCode* table, BrotliBitReader* br, uint32_t* result) {
  417|  1.42G|  uint32_t val;
  418|  1.42G|  if (BROTLI_PREDICT_TRUE(BrotliSafeGetBits(br, 15, &val))) {
  ------------------
  |  |   82|  1.42G|#define BROTLI_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
  |  |  ------------------
  |  |  |  Branch (82:32): [True: 979M, False: 444M]
  |  |  ------------------
  ------------------
  419|   979M|    *result = DecodeSymbol(val, table, br);
  420|   979M|    return BROTLI_TRUE;
  ------------------
  |  |   51|   979M|#define BROTLI_TRUE 1
  ------------------
  421|   979M|  }
  422|   444M|  return SafeDecodeSymbol(table, br, result);
  423|  1.42G|}
decode.c:DecodeSymbol:
  352|  1.11G|                                           BrotliBitReader* br) {
  353|  1.11G|  BROTLI_HC_MARK_TABLE_FOR_FAST_LOAD(table);
  354|  1.11G|  BROTLI_HC_ADJUST_TABLE_INDEX(table, bits & HUFFMAN_TABLE_MASK);
  ------------------
  |  |   67|  1.11G|#define BROTLI_HC_ADJUST_TABLE_INDEX(H, V) H += (V)
  ------------------
  355|  1.11G|  if (BROTLI_HC_FAST_LOAD_BITS(table) > HUFFMAN_TABLE_BITS) {
  ------------------
  |  |   70|  1.11G|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
                if (BROTLI_HC_FAST_LOAD_BITS(table) > HUFFMAN_TABLE_BITS) {
  ------------------
  |  |   39|  1.11G|#define HUFFMAN_TABLE_BITS 8U
  ------------------
  |  Branch (355:7): [True: 12.9k, False: 1.11G]
  ------------------
  356|  12.9k|    uint32_t nbits = BROTLI_HC_FAST_LOAD_BITS(table) - HUFFMAN_TABLE_BITS;
  ------------------
  |  |   70|  12.9k|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
                  uint32_t nbits = BROTLI_HC_FAST_LOAD_BITS(table) - HUFFMAN_TABLE_BITS;
  ------------------
  |  |   39|  12.9k|#define HUFFMAN_TABLE_BITS 8U
  ------------------
  357|  12.9k|    BrotliDropBits(br, HUFFMAN_TABLE_BITS);
  ------------------
  |  |   39|  12.9k|#define HUFFMAN_TABLE_BITS 8U
  ------------------
  358|  12.9k|    BROTLI_HC_ADJUST_TABLE_INDEX(table,
  ------------------
  |  |   67|  12.9k|#define BROTLI_HC_ADJUST_TABLE_INDEX(H, V) H += (V)
  ------------------
  359|  12.9k|        BROTLI_HC_FAST_LOAD_VALUE(table) +
  360|  12.9k|        ((bits >> HUFFMAN_TABLE_BITS) & BitMask(nbits)));
  361|  12.9k|  }
  362|  1.11G|  BrotliDropBits(br, BROTLI_HC_FAST_LOAD_BITS(table));
  ------------------
  |  |   70|  1.11G|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  363|  1.11G|  return BROTLI_HC_FAST_LOAD_VALUE(table);
  ------------------
  |  |   71|  1.11G|#define BROTLI_HC_FAST_LOAD_VALUE(H) (H->value)
  ------------------
  364|  1.11G|}
decode.c:SafeDecodeSymbol:
  376|   444M|    const HuffmanCode* table, BrotliBitReader* br, uint32_t* result) {
  377|   444M|  uint32_t val;
  378|   444M|  uint32_t available_bits = BrotliGetAvailableBits(br);
  379|   444M|  BROTLI_HC_MARK_TABLE_FOR_FAST_LOAD(table);
  380|   444M|  if (available_bits == 0) {
  ------------------
  |  Branch (380:7): [True: 37.3M, False: 407M]
  ------------------
  381|  37.3M|    if (BROTLI_HC_FAST_LOAD_BITS(table) == 0) {
  ------------------
  |  |   70|  37.3M|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  |  Branch (381:9): [True: 37.3M, False: 119]
  ------------------
  382|  37.3M|      *result = BROTLI_HC_FAST_LOAD_VALUE(table);
  ------------------
  |  |   71|  37.3M|#define BROTLI_HC_FAST_LOAD_VALUE(H) (H->value)
  ------------------
  383|  37.3M|      return BROTLI_TRUE;
  ------------------
  |  |   51|  37.3M|#define BROTLI_TRUE 1
  ------------------
  384|  37.3M|    }
  385|    119|    return BROTLI_FALSE;  /* No valid bits at all. */
  ------------------
  |  |   53|    119|#define BROTLI_FALSE 0
  ------------------
  386|  37.3M|  }
  387|   407M|  val = (uint32_t)BrotliGetBitsUnmasked(br);
  388|   407M|  BROTLI_HC_ADJUST_TABLE_INDEX(table, val & HUFFMAN_TABLE_MASK);
  ------------------
  |  |   67|   407M|#define BROTLI_HC_ADJUST_TABLE_INDEX(H, V) H += (V)
  ------------------
  389|   407M|  if (BROTLI_HC_FAST_LOAD_BITS(table) <= HUFFMAN_TABLE_BITS) {
  ------------------
  |  |   70|   407M|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
                if (BROTLI_HC_FAST_LOAD_BITS(table) <= HUFFMAN_TABLE_BITS) {
  ------------------
  |  |   39|   407M|#define HUFFMAN_TABLE_BITS 8U
  ------------------
  |  Branch (389:7): [True: 407M, False: 49]
  ------------------
  390|   407M|    if (BROTLI_HC_FAST_LOAD_BITS(table) <= available_bits) {
  ------------------
  |  |   70|   407M|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  |  Branch (390:9): [True: 407M, False: 83]
  ------------------
  391|   407M|      BrotliDropBits(br, BROTLI_HC_FAST_LOAD_BITS(table));
  ------------------
  |  |   70|   407M|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  392|   407M|      *result = BROTLI_HC_FAST_LOAD_VALUE(table);
  ------------------
  |  |   71|   407M|#define BROTLI_HC_FAST_LOAD_VALUE(H) (H->value)
  ------------------
  393|   407M|      return BROTLI_TRUE;
  ------------------
  |  |   51|   407M|#define BROTLI_TRUE 1
  ------------------
  394|   407M|    } else {
  395|     83|      return BROTLI_FALSE;  /* Not enough bits for the first level. */
  ------------------
  |  |   53|     83|#define BROTLI_FALSE 0
  ------------------
  396|     83|    }
  397|   407M|  }
  398|     49|  if (available_bits <= HUFFMAN_TABLE_BITS) {
  ------------------
  |  |   39|     49|#define HUFFMAN_TABLE_BITS 8U
  ------------------
  |  Branch (398:7): [True: 34, False: 15]
  ------------------
  399|     34|    return BROTLI_FALSE;  /* Not enough bits to move to the second level. */
  ------------------
  |  |   53|     34|#define BROTLI_FALSE 0
  ------------------
  400|     34|  }
  401|       |
  402|       |  /* Speculatively drop HUFFMAN_TABLE_BITS. */
  403|     15|  val = (val & BitMask(BROTLI_HC_FAST_LOAD_BITS(table))) >> HUFFMAN_TABLE_BITS;
  ------------------
  |  |   70|     15|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
                val = (val & BitMask(BROTLI_HC_FAST_LOAD_BITS(table))) >> HUFFMAN_TABLE_BITS;
  ------------------
  |  |   39|     15|#define HUFFMAN_TABLE_BITS 8U
  ------------------
  404|     15|  available_bits -= HUFFMAN_TABLE_BITS;
  ------------------
  |  |   39|     15|#define HUFFMAN_TABLE_BITS 8U
  ------------------
  405|     15|  BROTLI_HC_ADJUST_TABLE_INDEX(table, BROTLI_HC_FAST_LOAD_VALUE(table) + val);
  ------------------
  |  |   67|     15|#define BROTLI_HC_ADJUST_TABLE_INDEX(H, V) H += (V)
  ------------------
  406|     15|  if (available_bits < BROTLI_HC_FAST_LOAD_BITS(table)) {
  ------------------
  |  |   70|     15|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  |  Branch (406:7): [True: 2, False: 13]
  ------------------
  407|      2|    return BROTLI_FALSE;  /* Not enough bits for the second level. */
  ------------------
  |  |   53|      2|#define BROTLI_FALSE 0
  ------------------
  408|      2|  }
  409|       |
  410|     13|  BrotliDropBits(br, HUFFMAN_TABLE_BITS + BROTLI_HC_FAST_LOAD_BITS(table));
  ------------------
  |  |   39|     13|#define HUFFMAN_TABLE_BITS 8U
  ------------------
                BrotliDropBits(br, HUFFMAN_TABLE_BITS + BROTLI_HC_FAST_LOAD_BITS(table));
  ------------------
  |  |   70|     13|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  411|     13|  *result = BROTLI_HC_FAST_LOAD_VALUE(table);
  ------------------
  |  |   71|     13|#define BROTLI_HC_FAST_LOAD_VALUE(H) (H->value)
  ------------------
  412|     13|  return BROTLI_TRUE;
  ------------------
  |  |   51|     13|#define BROTLI_TRUE 1
  ------------------
  413|     15|}
decode.c:CopyUncompressedBlockToOutput:
 1357|  4.55k|    BrotliDecoderState* s) {
 1358|       |  /* TODO: avoid allocation for single uncompressed block. */
 1359|  4.55k|  if (!BrotliEnsureRingBuffer(s)) {
  ------------------
  |  Branch (1359:7): [True: 0, False: 4.55k]
  ------------------
 1360|      0|    return BROTLI_FAILURE(BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1);
  ------------------
  |  |   31|      0|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|      0|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 1361|      0|  }
 1362|       |
 1363|       |  /* State machine */
 1364|  7.49k|  for (;;) {
 1365|  7.49k|    switch (s->substate_uncompressed) {
  ------------------
  |  Branch (1365:13): [True: 7.49k, False: 0]
  ------------------
 1366|  4.55k|      case BROTLI_STATE_UNCOMPRESSED_NONE: {
  ------------------
  |  Branch (1366:7): [True: 4.55k, False: 2.94k]
  ------------------
 1367|  4.55k|        int nbytes = (int)BrotliGetRemainingBytes(&s->br);
 1368|  4.55k|        if (nbytes > s->meta_block_remaining_len) {
  ------------------
  |  Branch (1368:13): [True: 1.39k, False: 3.16k]
  ------------------
 1369|  1.39k|          nbytes = s->meta_block_remaining_len;
 1370|  1.39k|        }
 1371|  4.55k|        if (s->pos + nbytes > s->ringbuffer_size) {
  ------------------
  |  Branch (1371:13): [True: 2.93k, False: 1.61k]
  ------------------
 1372|  2.93k|          nbytes = s->ringbuffer_size - s->pos;
 1373|  2.93k|        }
 1374|       |        /* Copy remaining bytes from s->br.buf_ to ring-buffer. */
 1375|  4.55k|        BrotliCopyBytes(&s->ringbuffer[s->pos], &s->br, (size_t)nbytes);
 1376|  4.55k|        s->pos += nbytes;
 1377|  4.55k|        s->meta_block_remaining_len -= nbytes;
 1378|  4.55k|        if (s->pos < 1 << s->window_bits) {
  ------------------
  |  Branch (1378:13): [True: 1.61k, False: 2.94k]
  ------------------
 1379|  1.61k|          if (s->meta_block_remaining_len == 0) {
  ------------------
  |  Branch (1379:15): [True: 1.39k, False: 217]
  ------------------
 1380|  1.39k|            return BROTLI_DECODER_SUCCESS;
 1381|  1.39k|          }
 1382|    217|          return BROTLI_DECODER_NEEDS_MORE_INPUT;
 1383|  1.61k|        }
 1384|  2.94k|        s->substate_uncompressed = BROTLI_STATE_UNCOMPRESSED_WRITE;
 1385|  2.94k|      }
 1386|       |      /* Fall through. */
 1387|       |
 1388|  5.88k|      case BROTLI_STATE_UNCOMPRESSED_WRITE: {
  ------------------
  |  Branch (1388:7): [True: 2.94k, False: 4.55k]
  ------------------
 1389|  5.88k|        BrotliDecoderErrorCode result;
 1390|  5.88k|        result = WriteRingBuffer(
 1391|  5.88k|            s, available_out, next_out, total_out, BROTLI_FALSE);
  ------------------
  |  |   53|  5.88k|#define BROTLI_FALSE 0
  ------------------
 1392|  5.88k|        if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (1392:13): [True: 2.94k, False: 2.94k]
  ------------------
 1393|  2.94k|          return result;
 1394|  2.94k|        }
 1395|  2.94k|        if (s->ringbuffer_size == 1 << s->window_bits) {
  ------------------
  |  Branch (1395:13): [True: 2.94k, False: 0]
  ------------------
 1396|  2.94k|          s->max_distance = s->max_backward_distance;
 1397|  2.94k|        }
 1398|  2.94k|        s->substate_uncompressed = BROTLI_STATE_UNCOMPRESSED_NONE;
 1399|  2.94k|        break;
 1400|  5.88k|      }
 1401|  7.49k|    }
 1402|  7.49k|  }
 1403|      0|  BROTLI_DCHECK(0);  /* Unreachable */
 1404|      0|}
decode.c:ReadContextModes:
 1452|  8.78k|static BrotliDecoderErrorCode ReadContextModes(BrotliDecoderState* s) {
 1453|  8.78k|  BrotliBitReader* br = &s->br;
 1454|  8.78k|  int i = s->loop_counter;
 1455|       |
 1456|  38.0k|  while (i < (int)s->num_block_types[0]) {
  ------------------
  |  Branch (1456:10): [True: 29.2k, False: 8.76k]
  ------------------
 1457|  29.2k|    uint32_t bits;
 1458|  29.2k|    if (!BrotliSafeReadBits(br, 2, &bits)) {
  ------------------
  |  Branch (1458:9): [True: 25, False: 29.2k]
  ------------------
 1459|     25|      s->loop_counter = i;
 1460|     25|      return BROTLI_DECODER_NEEDS_MORE_INPUT;
 1461|     25|    }
 1462|  29.2k|    s->context_modes[i] = (uint8_t)bits;
 1463|  29.2k|    BROTLI_LOG_ARRAY_INDEX(s->context_modes, i);
 1464|  29.2k|    i++;
 1465|  29.2k|  }
 1466|  8.76k|  return BROTLI_DECODER_SUCCESS;
 1467|  8.78k|}
decode.c:DecodeContextMap:
  994|  17.3k|                                               BrotliDecoderState* s) {
  995|  17.3k|  BrotliBitReader* br = &s->br;
  996|  17.3k|  BrotliDecoderErrorCode result = BROTLI_DECODER_SUCCESS;
  997|  17.3k|  BrotliMetablockHeaderArena* h = &s->arena.header;
  998|       |
  999|  17.3k|  switch ((int)h->substate_context_map) {
 1000|  17.3k|    case BROTLI_STATE_CONTEXT_MAP_NONE:
  ------------------
  |  Branch (1000:5): [True: 17.3k, False: 0]
  ------------------
 1001|  17.3k|      result = DecodeVarLenUint8(s, br, num_htrees);
 1002|  17.3k|      if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (1002:11): [True: 37, False: 17.3k]
  ------------------
 1003|     37|        return result;
 1004|     37|      }
 1005|  17.3k|      (*num_htrees)++;
 1006|  17.3k|      h->context_index = 0;
 1007|  17.3k|      BROTLI_LOG_UINT(context_map_size);
 1008|  17.3k|      BROTLI_LOG_UINT(*num_htrees);
 1009|  17.3k|      *context_map_arg =
 1010|  17.3k|          (uint8_t*)BROTLI_DECODER_ALLOC(s, (size_t)context_map_size);
  ------------------
  |  |  354|  17.3k|#define BROTLI_DECODER_ALLOC(S, L) S->alloc_func(S->memory_manager_opaque, L)
  ------------------
 1011|  17.3k|      if (*context_map_arg == 0) {
  ------------------
  |  Branch (1011:11): [True: 0, False: 17.3k]
  ------------------
 1012|      0|        return BROTLI_FAILURE(BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP);
  ------------------
  |  |   31|      0|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|      0|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 1013|      0|      }
 1014|  17.3k|      if (*num_htrees <= 1) {
  ------------------
  |  Branch (1014:11): [True: 15.5k, False: 1.73k]
  ------------------
 1015|  15.5k|        memset(*context_map_arg, 0, (size_t)context_map_size);
 1016|  15.5k|        return BROTLI_DECODER_SUCCESS;
 1017|  15.5k|      }
 1018|  1.73k|      h->substate_context_map = BROTLI_STATE_CONTEXT_MAP_READ_PREFIX;
 1019|       |    /* Fall through. */
 1020|       |
 1021|  1.73k|    case BROTLI_STATE_CONTEXT_MAP_READ_PREFIX: {
  ------------------
  |  Branch (1021:5): [True: 0, False: 17.3k]
  ------------------
 1022|  1.73k|      uint32_t bits;
 1023|       |      /* In next stage ReadHuffmanCode uses at least 4 bits, so it is safe
 1024|       |         to peek 4 bits ahead. */
 1025|  1.73k|      if (!BrotliSafeGetBits(br, 5, &bits)) {
  ------------------
  |  Branch (1025:11): [True: 27, False: 1.70k]
  ------------------
 1026|     27|        return BROTLI_DECODER_NEEDS_MORE_INPUT;
 1027|     27|      }
 1028|  1.70k|      if ((bits & 1) != 0) { /* Use RLE for zeros. */
  ------------------
  |  Branch (1028:11): [True: 228, False: 1.48k]
  ------------------
 1029|    228|        h->max_run_length_prefix = (bits >> 1) + 1;
 1030|    228|        BrotliDropBits(br, 5);
 1031|  1.48k|      } else {
 1032|  1.48k|        h->max_run_length_prefix = 0;
 1033|  1.48k|        BrotliDropBits(br, 1);
 1034|  1.48k|      }
 1035|  1.70k|      BROTLI_LOG_UINT(h->max_run_length_prefix);
 1036|  1.70k|      h->substate_context_map = BROTLI_STATE_CONTEXT_MAP_HUFFMAN;
 1037|  1.70k|    }
 1038|       |    /* Fall through. */
 1039|       |
 1040|  1.70k|    case BROTLI_STATE_CONTEXT_MAP_HUFFMAN: {
  ------------------
  |  Branch (1040:5): [True: 0, False: 17.3k]
  ------------------
 1041|  1.70k|      uint32_t alphabet_size = *num_htrees + h->max_run_length_prefix;
 1042|  1.70k|      result = ReadHuffmanCode(alphabet_size, alphabet_size,
 1043|  1.70k|                               h->context_map_table, NULL, s);
 1044|  1.70k|      if (result != BROTLI_DECODER_SUCCESS) return result;
  ------------------
  |  Branch (1044:11): [True: 68, False: 1.64k]
  ------------------
 1045|  1.64k|      h->code = 0xFFFF;
 1046|  1.64k|      h->substate_context_map = BROTLI_STATE_CONTEXT_MAP_DECODE;
 1047|  1.64k|    }
 1048|       |    /* Fall through. */
 1049|       |
 1050|  1.64k|    case BROTLI_STATE_CONTEXT_MAP_DECODE: {
  ------------------
  |  Branch (1050:5): [True: 0, False: 17.3k]
  ------------------
 1051|  1.64k|      uint32_t context_index = h->context_index;
 1052|  1.64k|      uint32_t max_run_length_prefix = h->max_run_length_prefix;
 1053|  1.64k|      uint8_t* context_map = *context_map_arg;
 1054|  1.64k|      uint32_t code = h->code;
 1055|  1.64k|      BROTLI_BOOL skip_preamble = (code != 0xFFFF);
  ------------------
  |  |   49|  1.64k|#define BROTLI_BOOL int
  ------------------
 1056|   302k|      while (context_index < context_map_size || skip_preamble) {
  ------------------
  |  Branch (1056:14): [True: 301k, False: 1.49k]
  |  Branch (1056:50): [True: 0, False: 1.49k]
  ------------------
 1057|   301k|        if (!skip_preamble) {
  ------------------
  |  Branch (1057:13): [True: 301k, False: 0]
  ------------------
 1058|   301k|          if (!SafeReadSymbol(h->context_map_table, br, &code)) {
  ------------------
  |  Branch (1058:15): [True: 44, False: 301k]
  ------------------
 1059|     44|            h->code = 0xFFFF;
 1060|     44|            h->context_index = context_index;
 1061|     44|            return BROTLI_DECODER_NEEDS_MORE_INPUT;
 1062|     44|          }
 1063|   301k|          BROTLI_LOG_UINT(code);
 1064|       |
 1065|   301k|          if (code == 0) {
  ------------------
  |  Branch (1065:15): [True: 26.5k, False: 274k]
  ------------------
 1066|  26.5k|            context_map[context_index++] = 0;
 1067|  26.5k|            continue;
 1068|  26.5k|          }
 1069|   274k|          if (code > max_run_length_prefix) {
  ------------------
  |  Branch (1069:15): [True: 271k, False: 3.04k]
  ------------------
 1070|   271k|            context_map[context_index++] =
 1071|   271k|                (uint8_t)(code - max_run_length_prefix);
 1072|   271k|            continue;
 1073|   271k|          }
 1074|   274k|        } else {
 1075|      0|          skip_preamble = BROTLI_FALSE;
  ------------------
  |  |   53|      0|#define BROTLI_FALSE 0
  ------------------
 1076|      0|        }
 1077|       |        /* RLE sub-stage. */
 1078|  3.04k|        {
 1079|  3.04k|          uint32_t reps;
 1080|  3.04k|          if (!BrotliSafeReadBits(br, code, &reps)) {
  ------------------
  |  Branch (1080:15): [True: 57, False: 2.98k]
  ------------------
 1081|     57|            h->code = code;
 1082|     57|            h->context_index = context_index;
 1083|     57|            return BROTLI_DECODER_NEEDS_MORE_INPUT;
 1084|     57|          }
 1085|  2.98k|          reps += 1U << code;
 1086|  2.98k|          BROTLI_LOG_UINT(reps);
 1087|  2.98k|          if (context_index + reps > context_map_size) {
  ------------------
  |  Branch (1087:15): [True: 41, False: 2.94k]
  ------------------
 1088|     41|            return
 1089|     41|                BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT);
  ------------------
  |  |   31|     41|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|     41|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 1090|     41|          }
 1091|   253k|          do {
 1092|   253k|            context_map[context_index++] = 0;
 1093|   253k|          } while (--reps);
  ------------------
  |  Branch (1093:20): [True: 250k, False: 2.94k]
  ------------------
 1094|  2.94k|        }
 1095|  2.94k|      }
 1096|  1.64k|    }
 1097|       |    /* Fall through. */
 1098|       |
 1099|  1.49k|    case BROTLI_STATE_CONTEXT_MAP_TRANSFORM: {
  ------------------
  |  Branch (1099:5): [True: 0, False: 17.3k]
  ------------------
 1100|  1.49k|      uint32_t bits;
 1101|  1.49k|      if (!BrotliSafeReadBits(br, 1, &bits)) {
  ------------------
  |  Branch (1101:11): [True: 10, False: 1.48k]
  ------------------
 1102|     10|        h->substate_context_map = BROTLI_STATE_CONTEXT_MAP_TRANSFORM;
 1103|     10|        return BROTLI_DECODER_NEEDS_MORE_INPUT;
 1104|     10|      }
 1105|  1.48k|      if (bits != 0) {
  ------------------
  |  Branch (1105:11): [True: 1.11k, False: 377]
  ------------------
 1106|  1.11k|        InverseMoveToFrontTransform(*context_map_arg, context_map_size, s);
 1107|  1.11k|      }
 1108|  1.48k|      h->substate_context_map = BROTLI_STATE_CONTEXT_MAP_NONE;
 1109|  1.48k|      return BROTLI_DECODER_SUCCESS;
 1110|  1.49k|    }
 1111|       |
 1112|      0|    default:
  ------------------
  |  Branch (1112:5): [True: 0, False: 17.3k]
  ------------------
 1113|      0|      return
 1114|      0|          BROTLI_FAILURE(BROTLI_DECODER_ERROR_UNREACHABLE);
  ------------------
  |  |   31|      0|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|      0|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 1115|  17.3k|  }
 1116|  17.3k|}
decode.c:InverseMoveToFrontTransform:
  925|  1.11k|    uint8_t* v, uint32_t v_len, BrotliDecoderState* state) {
  926|       |  /* Reinitialize elements that could have been changed. */
  927|  1.11k|  uint32_t i = 1;
  928|  1.11k|  uint32_t upper_bound = state->mtf_upper_bound;
  929|  1.11k|  uint32_t* mtf = &state->mtf[1];  /* Make mtf[-1] addressable. */
  930|  1.11k|  uint8_t* mtf_u8 = (uint8_t*)mtf;
  931|       |  /* Load endian-aware constant. */
  932|  1.11k|  const uint8_t b0123[4] = {0, 1, 2, 3};
  933|  1.11k|  uint32_t pattern;
  934|  1.11k|  memcpy(&pattern, &b0123, 4);
  935|       |
  936|       |  /* Initialize list using 4 consequent values pattern. */
  937|  1.11k|  mtf[0] = pattern;
  938|  19.3k|  do {
  939|  19.3k|    pattern += 0x04040404;  /* Advance all 4 values by 4. */
  940|  19.3k|    mtf[i] = pattern;
  941|  19.3k|    i++;
  942|  19.3k|  } while (i <= upper_bound);
  ------------------
  |  Branch (942:12): [True: 18.2k, False: 1.11k]
  ------------------
  943|       |
  944|       |  /* Transform the input. */
  945|  1.11k|  upper_bound = 0;
  946|   211k|  for (i = 0; i < v_len; ++i) {
  ------------------
  |  Branch (946:15): [True: 210k, False: 1.11k]
  ------------------
  947|   210k|    int index = v[i];
  948|   210k|    uint8_t value = mtf_u8[index];
  949|   210k|    upper_bound |= v[i];
  950|   210k|    v[i] = value;
  951|   210k|    mtf_u8[-1] = value;
  952|  2.69M|    do {
  953|  2.69M|      index--;
  954|  2.69M|      mtf_u8[index + 1] = mtf_u8[index];
  955|  2.69M|    } while (index >= 0);
  ------------------
  |  Branch (955:14): [True: 2.48M, False: 210k]
  ------------------
  956|   210k|  }
  957|       |  /* Remember amount of elements to be reinitialized. */
  958|  1.11k|  state->mtf_upper_bound = upper_bound >> 2;
  959|  1.11k|}
decode.c:DetectTrivialLiteralBlockTypes:
 1165|  8.59k|    BrotliDecoderState* s) {
 1166|  8.59k|  size_t i;
 1167|  77.3k|  for (i = 0; i < 8; ++i) s->trivial_literal_contexts[i] = 0;
  ------------------
  |  Branch (1167:15): [True: 68.7k, False: 8.59k]
  ------------------
 1168|  31.3k|  for (i = 0; i < s->num_block_types[0]; i++) {
  ------------------
  |  Branch (1168:15): [True: 22.7k, False: 8.59k]
  ------------------
 1169|  22.7k|    size_t offset = i << BROTLI_LITERAL_CONTEXT_BITS;
  ------------------
  |  |   94|  22.7k|#define BROTLI_LITERAL_CONTEXT_BITS 6
  ------------------
 1170|  22.7k|    size_t error = 0;
 1171|  22.7k|    size_t sample = s->context_map[offset];
 1172|  22.7k|    size_t j;
 1173|   387k|    for (j = 0; j < (1u << BROTLI_LITERAL_CONTEXT_BITS);) {
  ------------------
  |  |   94|   387k|#define BROTLI_LITERAL_CONTEXT_BITS 6
  ------------------
  |  Branch (1173:17): [True: 364k, False: 22.7k]
  ------------------
 1174|   364k|      BROTLI_REPEAT(4, error |= s->context_map[offset + j++] ^ sample;)
  ------------------
  |  |  505|   364k|#define BROTLI_REPEAT(N, X) {     \
  |  |  506|   364k|  if ((N & 1) != 0) {X;}          \
  |  |  ------------------
  |  |  |  Branch (506:7): [Folded, False: 364k]
  |  |  ------------------
  |  |  507|   364k|  if ((N & 2) != 0) {X; X;}       \
  |  |  ------------------
  |  |  |  Branch (507:7): [Folded, False: 364k]
  |  |  ------------------
  |  |  508|   364k|  if ((N & 4) != 0) {X; X; X; X;} \
  |  |  ------------------
  |  |  |  Branch (508:7): [True: 364k, Folded]
  |  |  ------------------
  |  |  509|   364k|}
  ------------------
 1175|   364k|    }
 1176|  22.7k|    if (error == 0) {
  ------------------
  |  Branch (1176:9): [True: 18.8k, False: 3.97k]
  ------------------
 1177|  18.8k|      s->trivial_literal_contexts[i >> 5] |= 1u << (i & 31);
 1178|  18.8k|    }
 1179|  22.7k|  }
 1180|  8.59k|}
decode.c:HuffmanTreeGroupDecode:
  963|  24.7k|    HuffmanTreeGroup* group, BrotliDecoderState* s) {
  964|  24.7k|  BrotliMetablockHeaderArena* h = &s->arena.header;
  965|  24.7k|  if (h->substate_tree_group != BROTLI_STATE_TREE_GROUP_LOOP) {
  ------------------
  |  Branch (965:7): [True: 24.7k, False: 0]
  ------------------
  966|  24.7k|    h->next = group->codes;
  967|  24.7k|    h->htree_index = 0;
  968|  24.7k|    h->substate_tree_group = BROTLI_STATE_TREE_GROUP_LOOP;
  969|  24.7k|  }
  970|  59.6k|  while (h->htree_index < group->num_htrees) {
  ------------------
  |  Branch (970:10): [True: 35.4k, False: 24.2k]
  ------------------
  971|  35.4k|    uint32_t table_size;
  972|  35.4k|    BrotliDecoderErrorCode result = ReadHuffmanCode(group->alphabet_size_max,
  973|  35.4k|        group->alphabet_size_limit, h->next, &table_size, s);
  974|  35.4k|    if (result != BROTLI_DECODER_SUCCESS) return result;
  ------------------
  |  Branch (974:9): [True: 537, False: 34.9k]
  ------------------
  975|  34.9k|    group->htrees[h->htree_index] = h->next;
  976|  34.9k|    h->next += table_size;
  977|  34.9k|    ++h->htree_index;
  978|  34.9k|  }
  979|  24.2k|  h->substate_tree_group = BROTLI_STATE_TREE_GROUP_NONE;
  980|  24.2k|  return BROTLI_DECODER_SUCCESS;
  981|  24.7k|}
decode.c:PrepareLiteralDecoding:
 1182|   102k|static BROTLI_INLINE void PrepareLiteralDecoding(BrotliDecoderState* s) {
 1183|   102k|  uint8_t context_mode;
 1184|   102k|  size_t trivial;
 1185|   102k|  uint32_t block_type = s->block_type_rb[1];
 1186|   102k|  uint32_t context_offset = block_type << BROTLI_LITERAL_CONTEXT_BITS;
  ------------------
  |  |   94|   102k|#define BROTLI_LITERAL_CONTEXT_BITS 6
  ------------------
 1187|   102k|  s->context_map_slice = s->context_map + context_offset;
 1188|   102k|  trivial = s->trivial_literal_contexts[block_type >> 5];
 1189|   102k|  s->trivial_literal_context = (trivial >> (block_type & 31)) & 1;
 1190|   102k|  s->literal_htree = s->literal_hgroup.htrees[s->context_map_slice[0]];
 1191|   102k|  context_mode = s->context_modes[block_type] & 3;
 1192|   102k|  s->context_lookup = BROTLI_CONTEXT_LUT(context_mode);
  ------------------
  |  |  108|   102k|#define BROTLI_CONTEXT_LUT(MODE) (&_kBrotliContextLookupTable[(MODE) << 9])
  ------------------
 1193|   102k|}
decode.c:BrotliEnsureRingBuffer:
 1327|  12.4k|    BrotliDecoderState* s) {
 1328|  12.4k|  uint8_t* old_ringbuffer = s->ringbuffer;
 1329|  12.4k|  if (s->ringbuffer_size == s->new_ringbuffer_size) {
  ------------------
  |  Branch (1329:7): [True: 9.84k, False: 2.65k]
  ------------------
 1330|  9.84k|    return BROTLI_TRUE;
  ------------------
  |  |   51|  9.84k|#define BROTLI_TRUE 1
  ------------------
 1331|  9.84k|  }
 1332|       |
 1333|  2.65k|  s->ringbuffer = (uint8_t*)BROTLI_DECODER_ALLOC(s,
  ------------------
  |  |  354|  2.65k|#define BROTLI_DECODER_ALLOC(S, L) S->alloc_func(S->memory_manager_opaque, L)
  ------------------
 1334|  2.65k|      (size_t)(s->new_ringbuffer_size) + kRingBufferWriteAheadSlack);
 1335|  2.65k|  if (s->ringbuffer == 0) {
  ------------------
  |  Branch (1335:7): [True: 0, False: 2.65k]
  ------------------
 1336|       |    /* Restore previous value. */
 1337|      0|    s->ringbuffer = old_ringbuffer;
 1338|      0|    return BROTLI_FALSE;
  ------------------
  |  |   53|      0|#define BROTLI_FALSE 0
  ------------------
 1339|      0|  }
 1340|  2.65k|  s->ringbuffer[s->new_ringbuffer_size - 2] = 0;
 1341|  2.65k|  s->ringbuffer[s->new_ringbuffer_size - 1] = 0;
 1342|       |
 1343|  2.65k|  if (!!old_ringbuffer) {
  ------------------
  |  Branch (1343:7): [True: 257, False: 2.39k]
  ------------------
 1344|    257|    memcpy(s->ringbuffer, old_ringbuffer, (size_t)s->pos);
 1345|    257|    BROTLI_DECODER_FREE(s, old_ringbuffer);
  ------------------
  |  |  356|    257|#define BROTLI_DECODER_FREE(S, X) {          \
  |  |  357|    257|  S->free_func(S->memory_manager_opaque, X); \
  |  |  358|    257|  X = NULL;                                  \
  |  |  359|    257|}
  ------------------
 1346|    257|  }
 1347|       |
 1348|  2.65k|  s->ringbuffer_size = s->new_ringbuffer_size;
 1349|  2.65k|  s->ringbuffer_mask = s->new_ringbuffer_size - 1;
 1350|  2.65k|  s->ringbuffer_end = s->ringbuffer + s->ringbuffer_size;
 1351|       |
 1352|  2.65k|  return BROTLI_TRUE;
  ------------------
  |  |   51|  2.65k|#define BROTLI_TRUE 1
  ------------------
 1353|  2.65k|}
decode.c:CalculateDistanceLut:
 1583|  7.93k|static void CalculateDistanceLut(BrotliDecoderState* s) {
 1584|  7.93k|  BrotliMetablockBodyArena* b = &s->arena.body;
 1585|  7.93k|  uint32_t npostfix = s->distance_postfix_bits;
 1586|  7.93k|  uint32_t ndirect = s->num_direct_distance_codes;
 1587|  7.93k|  uint32_t alphabet_size_limit = s->distance_hgroup.alphabet_size_limit;
 1588|  7.93k|  uint32_t postfix = 1u << npostfix;
 1589|  7.93k|  uint32_t j;
 1590|  7.93k|  uint32_t bits = 1;
 1591|  7.93k|  uint32_t half = 0;
 1592|       |
 1593|       |  /* Skip short codes. */
 1594|  7.93k|  uint32_t i = BROTLI_NUM_DISTANCE_SHORT_CODES;
  ------------------
  |  |   60|  7.93k|#define BROTLI_NUM_DISTANCE_SHORT_CODES 16
  ------------------
 1595|       |
 1596|       |  /* Fill direct codes. */
 1597|   121k|  for (j = 0; j < ndirect; ++j) {
  ------------------
  |  Branch (1597:15): [True: 113k, False: 7.93k]
  ------------------
 1598|   113k|    b->dist_extra_bits[i] = 0;
 1599|   113k|    b->dist_offset[i] = j + 1;
 1600|   113k|    ++i;
 1601|   113k|  }
 1602|       |
 1603|       |  /* Fill regular distance codes. */
 1604|   389k|  while (i < alphabet_size_limit) {
  ------------------
  |  Branch (1604:10): [True: 381k, False: 7.93k]
  ------------------
 1605|   381k|    uint32_t base = ndirect + ((((2 + half) << bits) - 4) << npostfix) + 1;
 1606|       |    /* Always fill the complete group. */
 1607|  1.14M|    for (j = 0; j < postfix; ++j) {
  ------------------
  |  Branch (1607:17): [True: 765k, False: 381k]
  ------------------
 1608|   765k|      b->dist_extra_bits[i] = (uint8_t)bits;
 1609|   765k|      b->dist_offset[i] = base + j;
 1610|   765k|      ++i;
 1611|   765k|    }
 1612|   381k|    bits = bits + half;
 1613|   381k|    half = half ^ 1;
 1614|   381k|  }
 1615|  7.93k|}
decode.c:ProcessCommands:
 2026|   134k|    BrotliDecoderState* s) {
 2027|   134k|  return ProcessCommandsInternal(0, s);
 2028|   134k|}
decode.c:ProcessCommandsInternal:
 1735|   234k|    int safe, BrotliDecoderState* s) {
 1736|   234k|  int pos = s->pos;
 1737|   234k|  int i = s->loop_counter;
 1738|   234k|  BrotliDecoderErrorCode result = BROTLI_DECODER_SUCCESS;
 1739|   234k|  BrotliBitReader* br = &s->br;
 1740|       |
 1741|   234k|  if (!CheckInputAmount(safe, br, 28)) {
  ------------------
  |  Branch (1741:7): [True: 66.6k, False: 168k]
  ------------------
 1742|  66.6k|    result = BROTLI_DECODER_NEEDS_MORE_INPUT;
 1743|  66.6k|    goto saveStateAndReturn;
 1744|  66.6k|  }
 1745|   168k|  if (!safe) {
  ------------------
  |  Branch (1745:7): [True: 68.2k, False: 100k]
  ------------------
 1746|  68.2k|    BROTLI_UNUSED(BrotliWarmupBitReader(br));
  ------------------
  |  |  511|  68.2k|#define BROTLI_UNUSED(X) (void)(X)
  ------------------
 1747|  68.2k|  }
 1748|       |
 1749|       |  /* Jump into state machine. */
 1750|   168k|  if (s->state == BROTLI_STATE_COMMAND_BEGIN) {
  ------------------
  |  Branch (1750:7): [True: 34.8k, False: 133k]
  ------------------
 1751|  34.8k|    goto CommandBegin;
 1752|   133k|  } else if (s->state == BROTLI_STATE_COMMAND_INNER) {
  ------------------
  |  Branch (1752:14): [True: 58.7k, False: 74.6k]
  ------------------
 1753|  58.7k|    goto CommandInner;
 1754|  74.6k|  } else if (s->state == BROTLI_STATE_COMMAND_POST_DECODE_LITERALS) {
  ------------------
  |  Branch (1754:14): [True: 18.7k, False: 55.9k]
  ------------------
 1755|  18.7k|    goto CommandPostDecodeLiterals;
 1756|  55.9k|  } else if (s->state == BROTLI_STATE_COMMAND_POST_WRAP_COPY) {
  ------------------
  |  Branch (1756:14): [True: 55.9k, False: 0]
  ------------------
 1757|  55.9k|    goto CommandPostWrapCopy;
 1758|  55.9k|  } else {
 1759|      0|    return BROTLI_FAILURE(BROTLI_DECODER_ERROR_UNREACHABLE);
  ------------------
  |  |   31|      0|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|      0|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 1760|      0|  }
 1761|       |
 1762|   305M|CommandBegin:
 1763|   305M|  if (safe) {
  ------------------
  |  Branch (1763:7): [True: 219M, False: 85.9M]
  ------------------
 1764|   219M|    s->state = BROTLI_STATE_COMMAND_BEGIN;
 1765|   219M|  }
 1766|   305M|  if (!CheckInputAmount(safe, br, 28)) {  /* 156 bits + 7 bytes */
  ------------------
  |  Branch (1766:7): [True: 11.8k, False: 305M]
  ------------------
 1767|  11.8k|    s->state = BROTLI_STATE_COMMAND_BEGIN;
 1768|  11.8k|    result = BROTLI_DECODER_NEEDS_MORE_INPUT;
 1769|  11.8k|    goto saveStateAndReturn;
 1770|  11.8k|  }
 1771|   305M|  if (BROTLI_PREDICT_FALSE(s->block_length[1] == 0)) {
  ------------------
  |  |   83|   305M|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 16.9k, False: 305M]
  |  |  ------------------
  ------------------
 1772|  16.9k|    BROTLI_SAFE(DecodeCommandBlockSwitch(s));
  ------------------
  |  | 1723|  16.9k|  {                                               \
  |  | 1724|  16.9k|    if (safe) {                                   \
  |  |  ------------------
  |  |  |  Branch (1724:9): [True: 4.98k, False: 11.9k]
  |  |  ------------------
  |  | 1725|  4.98k|      if (!Safe##METHOD) {                        \
  |  |  ------------------
  |  |  |  Branch (1725:11): [True: 97, False: 4.88k]
  |  |  ------------------
  |  | 1726|     97|        result = BROTLI_DECODER_NEEDS_MORE_INPUT; \
  |  | 1727|     97|        goto saveStateAndReturn;                  \
  |  | 1728|     97|      }                                           \
  |  | 1729|  11.9k|    } else {                                      \
  |  | 1730|  11.9k|      METHOD;                                     \
  |  | 1731|  11.9k|    }                                             \
  |  | 1732|  16.9k|  }
  ------------------
 1773|  16.8k|    goto CommandBegin;
 1774|  16.9k|  }
 1775|       |  /* Read the insert/copy length in the command. */
 1776|   305M|  BROTLI_SAFE(ReadCommand(s, br, &i));
  ------------------
  |  | 1723|   305M|  {                                               \
  |  | 1724|   305M|    if (safe) {                                   \
  |  |  ------------------
  |  |  |  Branch (1724:9): [True: 219M, False: 85.9M]
  |  |  ------------------
  |  | 1725|   219M|      if (!Safe##METHOD) {                        \
  |  |  ------------------
  |  |  |  Branch (1725:11): [True: 262, False: 219M]
  |  |  ------------------
  |  | 1726|    262|        result = BROTLI_DECODER_NEEDS_MORE_INPUT; \
  |  | 1727|    262|        goto saveStateAndReturn;                  \
  |  | 1728|    262|      }                                           \
  |  | 1729|   219M|    } else {                                      \
  |  | 1730|  85.9M|      METHOD;                                     \
  |  | 1731|  85.9M|    }                                             \
  |  | 1732|   305M|  }
  ------------------
 1777|   305M|  BROTLI_LOG(("[ProcessCommandsInternal] pos = %d insert = %d copy = %d\n",
 1778|   305M|              pos, i, s->copy_length));
 1779|   305M|  if (i == 0) {
  ------------------
  |  Branch (1779:7): [True: 6.49M, False: 298M]
  ------------------
 1780|  6.49M|    goto CommandPostDecodeLiterals;
 1781|  6.49M|  }
 1782|   298M|  s->meta_block_remaining_len -= i;
 1783|       |
 1784|   298M|CommandInner:
 1785|   298M|  if (safe) {
  ------------------
  |  Branch (1785:7): [True: 216M, False: 82.4M]
  ------------------
 1786|   216M|    s->state = BROTLI_STATE_COMMAND_INNER;
 1787|   216M|  }
 1788|       |  /* Read the literals in the command. */
 1789|   298M|  if (s->trivial_literal_context) {
  ------------------
  |  Branch (1789:7): [True: 295M, False: 3.02M]
  ------------------
 1790|   295M|    uint32_t bits;
 1791|   295M|    uint32_t value;
 1792|   295M|    PreloadSymbol(safe, s->literal_htree, br, &bits, &value);
 1793|  1.56G|    do {
 1794|  1.56G|      if (!CheckInputAmount(safe, br, 28)) {  /* 162 bits + 7 bytes */
  ------------------
  |  Branch (1794:11): [True: 6.99k, False: 1.56G]
  ------------------
 1795|  6.99k|        s->state = BROTLI_STATE_COMMAND_INNER;
 1796|  6.99k|        result = BROTLI_DECODER_NEEDS_MORE_INPUT;
 1797|  6.99k|        goto saveStateAndReturn;
 1798|  6.99k|      }
 1799|  1.56G|      if (BROTLI_PREDICT_FALSE(s->block_length[0] == 0)) {
  ------------------
  |  |   83|  1.56G|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 13.6k, False: 1.56G]
  |  |  ------------------
  ------------------
 1800|  13.6k|        BROTLI_SAFE(DecodeLiteralBlockSwitch(s));
  ------------------
  |  | 1723|  13.6k|  {                                               \
  |  | 1724|  13.6k|    if (safe) {                                   \
  |  |  ------------------
  |  |  |  Branch (1724:9): [True: 6.01k, False: 7.62k]
  |  |  ------------------
  |  | 1725|  6.01k|      if (!Safe##METHOD) {                        \
  |  |  ------------------
  |  |  |  Branch (1725:11): [True: 112, False: 5.90k]
  |  |  ------------------
  |  | 1726|    112|        result = BROTLI_DECODER_NEEDS_MORE_INPUT; \
  |  | 1727|    112|        goto saveStateAndReturn;                  \
  |  | 1728|    112|      }                                           \
  |  | 1729|  7.62k|    } else {                                      \
  |  | 1730|  7.62k|      METHOD;                                     \
  |  | 1731|  7.62k|    }                                             \
  |  | 1732|  13.6k|  }
  ------------------
 1801|  13.5k|        PreloadSymbol(safe, s->literal_htree, br, &bits, &value);
 1802|  13.5k|        if (!s->trivial_literal_context) goto CommandInner;
  ------------------
  |  Branch (1802:13): [True: 725, False: 12.8k]
  ------------------
 1803|  13.5k|      }
 1804|  1.56G|      if (!safe) {
  ------------------
  |  Branch (1804:11): [True: 461M, False: 1.10G]
  ------------------
 1805|   461M|        s->ringbuffer[pos] =
 1806|   461M|            (uint8_t)ReadPreloadedSymbol(s->literal_htree, br, &bits, &value);
 1807|  1.10G|      } else {
 1808|  1.10G|        uint32_t literal;
 1809|  1.10G|        if (!SafeReadSymbol(s->literal_htree, br, &literal)) {
  ------------------
  |  Branch (1809:13): [True: 48, False: 1.10G]
  ------------------
 1810|     48|          result = BROTLI_DECODER_NEEDS_MORE_INPUT;
 1811|     48|          goto saveStateAndReturn;
 1812|     48|        }
 1813|  1.10G|        s->ringbuffer[pos] = (uint8_t)literal;
 1814|  1.10G|      }
 1815|  1.56G|      --s->block_length[0];
 1816|  1.56G|      BROTLI_LOG_ARRAY_INDEX(s->ringbuffer, pos);
 1817|  1.56G|      ++pos;
 1818|  1.56G|      if (BROTLI_PREDICT_FALSE(pos == s->ringbuffer_size)) {
  ------------------
  |  |   83|  1.56G|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 24.8k, False: 1.56G]
  |  |  ------------------
  ------------------
 1819|  24.8k|        s->state = BROTLI_STATE_COMMAND_INNER_WRITE;
 1820|  24.8k|        --i;
 1821|  24.8k|        goto saveStateAndReturn;
 1822|  24.8k|      }
 1823|  1.56G|    } while (--i != 0);
  ------------------
  |  Branch (1823:14): [True: 1.26G, False: 295M]
  ------------------
 1824|   295M|  } else {
 1825|  3.02M|    uint8_t p1 = s->ringbuffer[(pos - 1) & s->ringbuffer_mask];
 1826|  3.02M|    uint8_t p2 = s->ringbuffer[(pos - 2) & s->ringbuffer_mask];
 1827|   104M|    do {
 1828|   104M|      const HuffmanCode* hc;
 1829|   104M|      uint8_t context;
 1830|   104M|      if (!CheckInputAmount(safe, br, 28)) {  /* 162 bits + 7 bytes */
  ------------------
  |  Branch (1830:11): [True: 14.5k, False: 104M]
  ------------------
 1831|  14.5k|        s->state = BROTLI_STATE_COMMAND_INNER;
 1832|  14.5k|        result = BROTLI_DECODER_NEEDS_MORE_INPUT;
 1833|  14.5k|        goto saveStateAndReturn;
 1834|  14.5k|      }
 1835|   104M|      if (BROTLI_PREDICT_FALSE(s->block_length[0] == 0)) {
  ------------------
  |  |   83|   104M|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 81.4k, False: 103M]
  |  |  ------------------
  ------------------
 1836|  81.4k|        BROTLI_SAFE(DecodeLiteralBlockSwitch(s));
  ------------------
  |  | 1723|  81.4k|  {                                               \
  |  | 1724|  81.4k|    if (safe) {                                   \
  |  |  ------------------
  |  |  |  Branch (1724:9): [True: 1.49k, False: 79.9k]
  |  |  ------------------
  |  | 1725|  1.49k|      if (!Safe##METHOD) {                        \
  |  |  ------------------
  |  |  |  Branch (1725:11): [True: 23, False: 1.46k]
  |  |  ------------------
  |  | 1726|     23|        result = BROTLI_DECODER_NEEDS_MORE_INPUT; \
  |  | 1727|     23|        goto saveStateAndReturn;                  \
  |  | 1728|     23|      }                                           \
  |  | 1729|  79.9k|    } else {                                      \
  |  | 1730|  79.9k|      METHOD;                                     \
  |  | 1731|  79.9k|    }                                             \
  |  | 1732|  81.4k|  }
  ------------------
 1837|  81.4k|        if (s->trivial_literal_context) goto CommandInner;
  ------------------
  |  Branch (1837:13): [True: 722, False: 80.7k]
  ------------------
 1838|  81.4k|      }
 1839|   104M|      context = BROTLI_CONTEXT(p1, p2, s->context_lookup);
  ------------------
  |  |  111|   104M|#define BROTLI_CONTEXT(P1, P2, LUT) ((LUT)[P1] | ((LUT) + 256)[P2])
  ------------------
 1840|   104M|      BROTLI_LOG_UINT(context);
 1841|   104M|      hc = s->literal_hgroup.htrees[s->context_map_slice[context]];
 1842|   104M|      p2 = p1;
 1843|   104M|      if (!safe) {
  ------------------
  |  Branch (1843:11): [True: 39.2M, False: 64.7M]
  ------------------
 1844|  39.2M|        p1 = (uint8_t)ReadSymbol(hc, br);
 1845|  64.7M|      } else {
 1846|  64.7M|        uint32_t literal;
 1847|  64.7M|        if (!SafeReadSymbol(hc, br, &literal)) {
  ------------------
  |  Branch (1847:13): [True: 12, False: 64.7M]
  ------------------
 1848|     12|          result = BROTLI_DECODER_NEEDS_MORE_INPUT;
 1849|     12|          goto saveStateAndReturn;
 1850|     12|        }
 1851|  64.7M|        p1 = (uint8_t)literal;
 1852|  64.7M|      }
 1853|   104M|      s->ringbuffer[pos] = p1;
 1854|   104M|      --s->block_length[0];
 1855|   104M|      BROTLI_LOG_UINT(s->context_map_slice[context]);
 1856|   104M|      BROTLI_LOG_ARRAY_INDEX(s->ringbuffer, pos & s->ringbuffer_mask);
 1857|   104M|      ++pos;
 1858|   104M|      if (BROTLI_PREDICT_FALSE(pos == s->ringbuffer_size)) {
  ------------------
  |  |   83|   104M|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 31.3k, False: 104M]
  |  |  ------------------
  ------------------
 1859|  31.3k|        s->state = BROTLI_STATE_COMMAND_INNER_WRITE;
 1860|  31.3k|        --i;
 1861|  31.3k|        goto saveStateAndReturn;
 1862|  31.3k|      }
 1863|   104M|    } while (--i != 0);
  ------------------
  |  Branch (1863:14): [True: 101M, False: 2.97M]
  ------------------
 1864|  3.02M|  }
 1865|   298M|  BROTLI_LOG_UINT(s->meta_block_remaining_len);
 1866|   298M|  if (BROTLI_PREDICT_FALSE(s->meta_block_remaining_len <= 0)) {
  ------------------
  |  |   83|   298M|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 3.83k, False: 298M]
  |  |  ------------------
  ------------------
 1867|  3.83k|    s->state = BROTLI_STATE_METABLOCK_DONE;
 1868|  3.83k|    goto saveStateAndReturn;
 1869|  3.83k|  }
 1870|       |
 1871|   305M|CommandPostDecodeLiterals:
 1872|   305M|  if (safe) {
  ------------------
  |  Branch (1872:7): [True: 219M, False: 85.9M]
  ------------------
 1873|   219M|    s->state = BROTLI_STATE_COMMAND_POST_DECODE_LITERALS;
 1874|   219M|  }
 1875|   305M|  if (s->distance_code >= 0) {
  ------------------
  |  Branch (1875:7): [True: 260M, False: 44.6M]
  ------------------
 1876|       |    /* Implicit distance case. */
 1877|   260M|    s->distance_context = s->distance_code ? 0 : 1;
  ------------------
  |  Branch (1877:27): [True: 0, False: 260M]
  ------------------
 1878|   260M|    --s->dist_rb_idx;
 1879|   260M|    s->distance_code = s->dist_rb[s->dist_rb_idx & 3];
 1880|   260M|  } else {
 1881|       |    /* Read distance code in the command, unless it was implicitly zero. */
 1882|  44.6M|    if (BROTLI_PREDICT_FALSE(s->block_length[2] == 0)) {
  ------------------
  |  |   83|  44.6M|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 13.7k, False: 44.6M]
  |  |  ------------------
  ------------------
 1883|  13.7k|      BROTLI_SAFE(DecodeDistanceBlockSwitch(s));
  ------------------
  |  | 1723|  13.7k|  {                                               \
  |  | 1724|  13.7k|    if (safe) {                                   \
  |  |  ------------------
  |  |  |  Branch (1724:9): [True: 5.51k, False: 8.25k]
  |  |  ------------------
  |  | 1725|  5.51k|      if (!Safe##METHOD) {                        \
  |  |  ------------------
  |  |  |  Branch (1725:11): [True: 104, False: 5.40k]
  |  |  ------------------
  |  | 1726|    104|        result = BROTLI_DECODER_NEEDS_MORE_INPUT; \
  |  | 1727|    104|        goto saveStateAndReturn;                  \
  |  | 1728|    104|      }                                           \
  |  | 1729|  8.25k|    } else {                                      \
  |  | 1730|  8.25k|      METHOD;                                     \
  |  | 1731|  8.25k|    }                                             \
  |  | 1732|  13.7k|  }
  ------------------
 1884|  13.6k|    }
 1885|  44.6M|    BROTLI_SAFE(ReadDistance(s, br));
  ------------------
  |  | 1723|  44.6M|  {                                               \
  |  | 1724|  44.6M|    if (safe) {                                   \
  |  |  ------------------
  |  |  |  Branch (1724:9): [True: 38.6M, False: 6.03M]
  |  |  ------------------
  |  | 1725|  38.6M|      if (!Safe##METHOD) {                        \
  |  |  ------------------
  |  |  |  Branch (1725:11): [True: 238, False: 38.6M]
  |  |  ------------------
  |  | 1726|    238|        result = BROTLI_DECODER_NEEDS_MORE_INPUT; \
  |  | 1727|    238|        goto saveStateAndReturn;                  \
  |  | 1728|    238|      }                                           \
  |  | 1729|  38.6M|    } else {                                      \
  |  | 1730|  6.03M|      METHOD;                                     \
  |  | 1731|  6.03M|    }                                             \
  |  | 1732|  44.6M|  }
  ------------------
 1886|  44.6M|  }
 1887|   305M|  BROTLI_LOG(("[ProcessCommandsInternal] pos = %d distance = %d\n",
 1888|   305M|              pos, s->distance_code));
 1889|   305M|  if (s->max_distance != s->max_backward_distance) {
  ------------------
  |  Branch (1889:7): [True: 127M, False: 178M]
  ------------------
 1890|   127M|    s->max_distance =
 1891|   127M|        (pos < s->max_backward_distance) ? pos : s->max_backward_distance;
  ------------------
  |  Branch (1891:9): [True: 127M, False: 484]
  ------------------
 1892|   127M|  }
 1893|   305M|  i = s->copy_length;
 1894|       |  /* Apply copy of LZ77 back-reference, or static dictionary reference if
 1895|       |     the distance is larger than the max LZ77 distance */
 1896|   305M|  if (s->distance_code > s->max_distance) {
  ------------------
  |  Branch (1896:7): [True: 12.5M, False: 292M]
  ------------------
 1897|       |    /* The maximum allowed distance is BROTLI_MAX_ALLOWED_DISTANCE = 0x7FFFFFFC.
 1898|       |       With this choice, no signed overflow can occur after decoding
 1899|       |       a special distance code (e.g., after adding 3 to the last distance). */
 1900|  12.5M|    if (s->distance_code > BROTLI_MAX_ALLOWED_DISTANCE) {
  ------------------
  |  |   86|  12.5M|#define BROTLI_MAX_ALLOWED_DISTANCE 0x7FFFFFFC
  ------------------
  |  Branch (1900:9): [True: 30, False: 12.5M]
  ------------------
 1901|     30|      BROTLI_LOG(("Invalid backward reference. pos: %d distance: %d "
 1902|     30|          "len: %d bytes left: %d\n",
 1903|     30|          pos, s->distance_code, i, s->meta_block_remaining_len));
 1904|     30|      return BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_DISTANCE);
  ------------------
  |  |   31|     30|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|     30|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 1905|     30|    }
 1906|  12.5M|    if (i >= BROTLI_MIN_DICTIONARY_WORD_LENGTH &&
  ------------------
  |  |   57|  25.1M|#define BROTLI_MIN_DICTIONARY_WORD_LENGTH 4
  ------------------
  |  Branch (1906:9): [True: 12.5M, False: 12]
  ------------------
 1907|  12.5M|        i <= BROTLI_MAX_DICTIONARY_WORD_LENGTH) {
  ------------------
  |  |   58|  12.5M|#define BROTLI_MAX_DICTIONARY_WORD_LENGTH 24
  ------------------
  |  Branch (1907:9): [True: 12.5M, False: 46]
  ------------------
 1908|  12.5M|      int address = s->distance_code - s->max_distance - 1;
 1909|  12.5M|      const BrotliDictionary* words = s->dictionary;
 1910|  12.5M|      const BrotliTransforms* transforms = s->transforms;
 1911|  12.5M|      int offset = (int)s->dictionary->offsets_by_length[i];
 1912|  12.5M|      uint32_t shift = s->dictionary->size_bits_by_length[i];
 1913|       |
 1914|  12.5M|      int mask = (int)BitMask(shift);
 1915|  12.5M|      int word_idx = address & mask;
 1916|  12.5M|      int transform_idx = address >> shift;
 1917|       |      /* Compensate double distance-ring-buffer roll. */
 1918|  12.5M|      s->dist_rb_idx += s->distance_context;
 1919|  12.5M|      offset += word_idx * i;
 1920|  12.5M|      if (BROTLI_PREDICT_FALSE(!words->data)) {
  ------------------
  |  |   83|  12.5M|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 0, False: 12.5M]
  |  |  ------------------
  ------------------
 1921|      0|        return BROTLI_FAILURE(BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET);
  ------------------
  |  |   31|      0|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|      0|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 1922|      0|      }
 1923|  12.5M|      if (transform_idx < (int)transforms->num_transforms) {
  ------------------
  |  Branch (1923:11): [True: 12.5M, False: 107]
  ------------------
 1924|  12.5M|        const uint8_t* word = &words->data[offset];
 1925|  12.5M|        int len = i;
 1926|  12.5M|        if (transform_idx == transforms->cutOffTransforms[0]) {
  ------------------
  |  Branch (1926:13): [True: 12.5M, False: 26.6k]
  ------------------
 1927|  12.5M|          memcpy(&s->ringbuffer[pos], word, (size_t)len);
 1928|  12.5M|          BROTLI_LOG(("[ProcessCommandsInternal] dictionary word: [%.*s]\n",
 1929|  12.5M|                      len, word));
 1930|  12.5M|        } else {
 1931|  26.6k|          len = BrotliTransformDictionaryWord(&s->ringbuffer[pos], word, len,
 1932|  26.6k|              transforms, transform_idx);
 1933|  26.6k|          BROTLI_LOG(("[ProcessCommandsInternal] dictionary word: [%.*s],"
 1934|  26.6k|                      " transform_idx = %d, transformed: [%.*s]\n",
 1935|  26.6k|                      i, word, transform_idx, len, &s->ringbuffer[pos]));
 1936|  26.6k|        }
 1937|  12.5M|        pos += len;
 1938|  12.5M|        s->meta_block_remaining_len -= len;
 1939|  12.5M|        if (pos >= s->ringbuffer_size) {
  ------------------
  |  Branch (1939:13): [True: 15.1k, False: 12.5M]
  ------------------
 1940|  15.1k|          s->state = BROTLI_STATE_COMMAND_POST_WRITE_1;
 1941|  15.1k|          goto saveStateAndReturn;
 1942|  15.1k|        }
 1943|  12.5M|      } else {
 1944|    107|        BROTLI_LOG(("Invalid backward reference. pos: %d distance: %d "
 1945|    107|            "len: %d bytes left: %d\n",
 1946|    107|            pos, s->distance_code, i, s->meta_block_remaining_len));
 1947|    107|        return BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_TRANSFORM);
  ------------------
  |  |   31|    107|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|    107|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 1948|    107|      }
 1949|  12.5M|    } else {
 1950|     58|      BROTLI_LOG(("Invalid backward reference. pos: %d distance: %d "
 1951|     58|          "len: %d bytes left: %d\n",
 1952|     58|          pos, s->distance_code, i, s->meta_block_remaining_len));
 1953|     58|      return BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_DICTIONARY);
  ------------------
  |  |   31|     58|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|     58|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 1954|     58|    }
 1955|   292M|  } else {
 1956|   292M|    int src_start = (pos - s->distance_code) & s->ringbuffer_mask;
 1957|   292M|    uint8_t* copy_dst = &s->ringbuffer[pos];
 1958|   292M|    uint8_t* copy_src = &s->ringbuffer[src_start];
 1959|   292M|    int dst_end = pos + i;
 1960|   292M|    int src_end = src_start + i;
 1961|       |    /* Update the recent distances cache. */
 1962|   292M|    s->dist_rb[s->dist_rb_idx & 3] = s->distance_code;
 1963|   292M|    ++s->dist_rb_idx;
 1964|   292M|    s->meta_block_remaining_len -= i;
 1965|       |    /* There are 32+ bytes of slack in the ring-buffer allocation.
 1966|       |       Also, we have 16 short codes, that make these 16 bytes irrelevant
 1967|       |       in the ring-buffer. Let's copy over them as a first guess. */
 1968|   292M|    memmove16(copy_dst, copy_src);
 1969|   292M|    if (src_end > pos && dst_end > src_start) {
  ------------------
  |  Branch (1969:9): [True: 210M, False: 81.9M]
  |  Branch (1969:26): [True: 209M, False: 1.76M]
  ------------------
 1970|       |      /* Regions intersect. */
 1971|   209M|      goto CommandPostWrapCopy;
 1972|   209M|    }
 1973|  83.7M|    if (dst_end >= s->ringbuffer_size || src_end >= s->ringbuffer_size) {
  ------------------
  |  Branch (1973:9): [True: 26.6k, False: 83.6M]
  |  Branch (1973:42): [True: 40.1k, False: 83.6M]
  ------------------
 1974|       |      /* At least one region wraps. */
 1975|  66.8k|      goto CommandPostWrapCopy;
 1976|  66.8k|    }
 1977|  83.6M|    pos += i;
 1978|  83.6M|    if (i > 16) {
  ------------------
  |  Branch (1978:9): [True: 9.15k, False: 83.6M]
  ------------------
 1979|  9.15k|      if (i > 32) {
  ------------------
  |  Branch (1979:11): [True: 4.24k, False: 4.90k]
  ------------------
 1980|  4.24k|        memcpy(copy_dst + 16, copy_src + 16, (size_t)(i - 16));
 1981|  4.90k|      } else {
 1982|       |        /* This branch covers about 45% cases.
 1983|       |           Fixed size short copy allows more compiler optimizations. */
 1984|  4.90k|        memmove16(copy_dst + 16, copy_src + 16);
 1985|  4.90k|      }
 1986|  9.15k|    }
 1987|  83.6M|  }
 1988|  96.1M|  BROTLI_LOG_UINT(s->meta_block_remaining_len);
 1989|  96.1M|  if (s->meta_block_remaining_len <= 0) {
  ------------------
  |  Branch (1989:7): [True: 627, False: 96.1M]
  ------------------
 1990|       |    /* Next metablock, if any. */
 1991|    627|    s->state = BROTLI_STATE_METABLOCK_DONE;
 1992|    627|    goto saveStateAndReturn;
 1993|  96.1M|  } else {
 1994|  96.1M|    goto CommandBegin;
 1995|  96.1M|  }
 1996|   209M|CommandPostWrapCopy:
 1997|   209M|  {
 1998|   209M|    int wrap_guard = s->ringbuffer_size - pos;
 1999|  2.07G|    while (--i >= 0) {
  ------------------
  |  Branch (1999:12): [True: 1.86G, False: 209M]
  ------------------
 2000|  1.86G|      s->ringbuffer[pos] =
 2001|  1.86G|          s->ringbuffer[(pos - s->distance_code) & s->ringbuffer_mask];
 2002|  1.86G|      ++pos;
 2003|  1.86G|      if (BROTLI_PREDICT_FALSE(--wrap_guard == 0)) {
  ------------------
  |  |   83|  1.86G|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 56.1k, False: 1.86G]
  |  |  ------------------
  ------------------
 2004|  56.1k|        s->state = BROTLI_STATE_COMMAND_POST_WRITE_2;
 2005|  56.1k|        goto saveStateAndReturn;
 2006|  56.1k|      }
 2007|  1.86G|    }
 2008|   209M|  }
 2009|   209M|  if (s->meta_block_remaining_len <= 0) {
  ------------------
  |  Branch (2009:7): [True: 1.91k, False: 209M]
  ------------------
 2010|       |    /* Next metablock, if any. */
 2011|  1.91k|    s->state = BROTLI_STATE_METABLOCK_DONE;
 2012|  1.91k|    goto saveStateAndReturn;
 2013|   209M|  } else {
 2014|   209M|    goto CommandBegin;
 2015|   209M|  }
 2016|       |
 2017|   234k|saveStateAndReturn:
 2018|   234k|  s->pos = pos;
 2019|   234k|  s->loop_counter = i;
 2020|   234k|  return result;
 2021|   209M|}
decode.c:CheckInputAmount:
 1715|  1.97G|    int safe, BrotliBitReader* const br, size_t num) {
 1716|  1.97G|  if (safe) {
  ------------------
  |  Branch (1716:7): [True: 1.38G, False: 586M]
  ------------------
 1717|  1.38G|    return BROTLI_TRUE;
  ------------------
  |  |   51|  1.38G|#define BROTLI_TRUE 1
  ------------------
 1718|  1.38G|  }
 1719|   586M|  return BrotliCheckInputAmount(br, num);
 1720|  1.97G|}
decode.c:SafeDecodeCommandBlockSwitch:
 1231|  4.98k|    BrotliDecoderState* s) {
 1232|  4.98k|  return DecodeCommandBlockSwitchInternal(1, s);
 1233|  4.98k|}
decode.c:DecodeCommandBlockSwitchInternal:
 1218|  16.9k|    int safe, BrotliDecoderState* s) {
 1219|  16.9k|  if (!DecodeBlockTypeAndLength(safe, s, 1)) {
  ------------------
  |  Branch (1219:7): [True: 97, False: 16.8k]
  ------------------
 1220|     97|    return BROTLI_FALSE;
  ------------------
  |  |   53|     97|#define BROTLI_FALSE 0
  ------------------
 1221|     97|  }
 1222|  16.8k|  s->htree_command = s->insert_copy_hgroup.htrees[s->block_type_rb[3]];
 1223|  16.8k|  return BROTLI_TRUE;
  ------------------
  |  |   51|  16.8k|#define BROTLI_TRUE 1
  ------------------
 1224|  16.9k|}
decode.c:DecodeBlockTypeAndLength:
 1121|   125k|    int safe, BrotliDecoderState* s, int tree_type) {
 1122|   125k|  uint32_t max_block_type = s->num_block_types[tree_type];
 1123|   125k|  const HuffmanCode* type_tree = &s->block_type_trees[
 1124|   125k|      tree_type * BROTLI_HUFFMAN_MAX_SIZE_258];
  ------------------
  |  |   24|   125k|#define BROTLI_HUFFMAN_MAX_SIZE_258 632
  ------------------
 1125|   125k|  const HuffmanCode* len_tree = &s->block_len_trees[
 1126|   125k|      tree_type * BROTLI_HUFFMAN_MAX_SIZE_26];
  ------------------
  |  |   22|   125k|#define BROTLI_HUFFMAN_MAX_SIZE_26 396
  ------------------
 1127|   125k|  BrotliBitReader* br = &s->br;
 1128|   125k|  uint32_t* ringbuffer = &s->block_type_rb[tree_type * 2];
 1129|   125k|  uint32_t block_type;
 1130|   125k|  if (max_block_type <= 1) {
  ------------------
  |  Branch (1130:7): [True: 2, False: 125k]
  ------------------
 1131|      2|    return BROTLI_FALSE;
  ------------------
  |  |   53|      2|#define BROTLI_FALSE 0
  ------------------
 1132|      2|  }
 1133|       |
 1134|       |  /* Read 0..15 + 3..39 bits. */
 1135|   125k|  if (!safe) {
  ------------------
  |  Branch (1135:7): [True: 107k, False: 17.9k]
  ------------------
 1136|   107k|    block_type = ReadSymbol(type_tree, br);
 1137|   107k|    s->block_length[tree_type] = ReadBlockLength(len_tree, br);
 1138|   107k|  } else {
 1139|  17.9k|    BrotliBitReaderState memento;
 1140|  17.9k|    BrotliBitReaderSaveState(br, &memento);
 1141|  17.9k|    if (!SafeReadSymbol(type_tree, br, &block_type)) return BROTLI_FALSE;
  ------------------
  |  |   53|     40|#define BROTLI_FALSE 0
  ------------------
  |  Branch (1141:9): [True: 40, False: 17.9k]
  ------------------
 1142|  17.9k|    if (!SafeReadBlockLength(s, &s->block_length[tree_type], len_tree, br)) {
  ------------------
  |  Branch (1142:9): [True: 295, False: 17.6k]
  ------------------
 1143|    295|      s->substate_read_block_length = BROTLI_STATE_READ_BLOCK_LENGTH_NONE;
 1144|    295|      BrotliBitReaderRestoreState(br, &memento);
 1145|    295|      return BROTLI_FALSE;
  ------------------
  |  |   53|    295|#define BROTLI_FALSE 0
  ------------------
 1146|    295|    }
 1147|  17.9k|  }
 1148|       |
 1149|   125k|  if (block_type == 1) {
  ------------------
  |  Branch (1149:7): [True: 15.0k, False: 110k]
  ------------------
 1150|  15.0k|    block_type = ringbuffer[1] + 1;
 1151|   110k|  } else if (block_type == 0) {
  ------------------
  |  Branch (1151:14): [True: 20.5k, False: 89.9k]
  ------------------
 1152|  20.5k|    block_type = ringbuffer[0];
 1153|  89.9k|  } else {
 1154|  89.9k|    block_type -= 2;
 1155|  89.9k|  }
 1156|   125k|  if (block_type >= max_block_type) {
  ------------------
  |  Branch (1156:7): [True: 6.41k, False: 119k]
  ------------------
 1157|  6.41k|    block_type -= max_block_type;
 1158|  6.41k|  }
 1159|   125k|  ringbuffer[0] = ringbuffer[1];
 1160|   125k|  ringbuffer[1] = block_type;
 1161|   125k|  return BROTLI_TRUE;
  ------------------
  |  |   51|   125k|#define BROTLI_TRUE 1
  ------------------
 1162|   125k|}
decode.c:ReadBlockLength:
  874|   107k|                                              BrotliBitReader* br) {
  875|   107k|  uint32_t code;
  876|   107k|  uint32_t nbits;
  877|   107k|  code = ReadSymbol(table, br);
  878|   107k|  nbits = _kBrotliPrefixCodeRanges[code].nbits;  /* nbits == 2..24 */
  879|   107k|  return _kBrotliPrefixCodeRanges[code].offset + BrotliReadBits24(br, nbits);
  880|   107k|}
decode.c:DecodeCommandBlockSwitch:
 1226|  11.9k|static void BROTLI_NOINLINE DecodeCommandBlockSwitch(BrotliDecoderState* s) {
 1227|  11.9k|  DecodeCommandBlockSwitchInternal(0, s);
 1228|  11.9k|}
decode.c:SafeReadCommand:
 1710|   219M|    BrotliDecoderState* s, BrotliBitReader* br, int* insert_length) {
 1711|   219M|  return ReadCommandInternal(1, s, br, insert_length);
 1712|   219M|}
decode.c:ReadCommandInternal:
 1667|   305M|    int safe, BrotliDecoderState* s, BrotliBitReader* br, int* insert_length) {
 1668|   305M|  uint32_t cmd_code;
 1669|   305M|  uint32_t insert_len_extra = 0;
 1670|   305M|  uint32_t copy_length;
 1671|   305M|  CmdLutElement v;
 1672|   305M|  BrotliBitReaderState memento;
 1673|   305M|  if (!safe) {
  ------------------
  |  Branch (1673:7): [True: 85.9M, False: 219M]
  ------------------
 1674|  85.9M|    cmd_code = ReadSymbol(s->htree_command, br);
 1675|   219M|  } else {
 1676|   219M|    BrotliBitReaderSaveState(br, &memento);
 1677|   219M|    if (!SafeReadSymbol(s->htree_command, br, &cmd_code)) {
  ------------------
  |  Branch (1677:9): [True: 31, False: 219M]
  ------------------
 1678|     31|      return BROTLI_FALSE;
  ------------------
  |  |   53|     31|#define BROTLI_FALSE 0
  ------------------
 1679|     31|    }
 1680|   219M|  }
 1681|   305M|  v = kCmdLut[cmd_code];
 1682|   305M|  s->distance_code = v.distance_code;
 1683|   305M|  s->distance_context = v.context;
 1684|   305M|  s->dist_htree_index = s->dist_context_map_slice[s->distance_context];
 1685|   305M|  *insert_length = v.insert_len_offset;
 1686|   305M|  if (!safe) {
  ------------------
  |  Branch (1686:7): [True: 85.9M, False: 219M]
  ------------------
 1687|  85.9M|    if (BROTLI_PREDICT_FALSE(v.insert_len_extra_bits != 0)) {
  ------------------
  |  |   83|  85.9M|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 28.8k, False: 85.9M]
  |  |  ------------------
  ------------------
 1688|  28.8k|      insert_len_extra = BrotliReadBits24(br, v.insert_len_extra_bits);
 1689|  28.8k|    }
 1690|  85.9M|    copy_length = BrotliReadBits24(br, v.copy_len_extra_bits);
 1691|   219M|  } else {
 1692|   219M|    if (!SafeReadBits(br, v.insert_len_extra_bits, &insert_len_extra) ||
  ------------------
  |  Branch (1692:9): [True: 79, False: 219M]
  ------------------
 1693|   219M|        !SafeReadBits(br, v.copy_len_extra_bits, &copy_length)) {
  ------------------
  |  Branch (1693:9): [True: 152, False: 219M]
  ------------------
 1694|    231|      BrotliBitReaderRestoreState(br, &memento);
 1695|    231|      return BROTLI_FALSE;
  ------------------
  |  |   53|    231|#define BROTLI_FALSE 0
  ------------------
 1696|    231|    }
 1697|   219M|  }
 1698|   305M|  s->copy_length = (int)copy_length + v.copy_len_offset;
 1699|   305M|  --s->block_length[1];
 1700|   305M|  *insert_length += (int)insert_len_extra;
 1701|   305M|  return BROTLI_TRUE;
  ------------------
  |  |   51|   305M|#define BROTLI_TRUE 1
  ------------------
 1702|   305M|}
decode.c:SafeReadBits:
 1497|   438M|    BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
 1498|   438M|  if (n_bits != 0) {
  ------------------
  |  Branch (1498:7): [True: 9.55k, False: 438M]
  ------------------
 1499|  9.55k|    return BrotliSafeReadBits(br, n_bits, val);
 1500|   438M|  } else {
 1501|   438M|    *val = 0;
 1502|   438M|    return BROTLI_TRUE;
  ------------------
  |  |   51|   438M|#define BROTLI_TRUE 1
  ------------------
 1503|   438M|  }
 1504|   438M|}
decode.c:ReadCommand:
 1705|  85.9M|    BrotliDecoderState* s, BrotliBitReader* br, int* insert_length) {
 1706|  85.9M|  ReadCommandInternal(0, s, br, insert_length);
 1707|  85.9M|}
decode.c:PreloadSymbol:
  430|   757M|                                        uint32_t* value) {
  431|   757M|  if (safe) {
  ------------------
  |  Branch (431:7): [True: 213M, False: 543M]
  ------------------
  432|   213M|    return;
  433|   213M|  }
  434|   543M|  BROTLI_HC_MARK_TABLE_FOR_FAST_LOAD(table);
  435|   543M|  BROTLI_HC_ADJUST_TABLE_INDEX(table, BrotliGetBits(br, HUFFMAN_TABLE_BITS));
  ------------------
  |  |   67|   543M|#define BROTLI_HC_ADJUST_TABLE_INDEX(H, V) H += (V)
  ------------------
  436|   543M|  *bits = BROTLI_HC_FAST_LOAD_BITS(table);
  ------------------
  |  |   70|   543M|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  437|   543M|  *value = BROTLI_HC_FAST_LOAD_VALUE(table);
  ------------------
  |  |   71|   543M|#define BROTLI_HC_FAST_LOAD_VALUE(H) (H->value)
  ------------------
  438|   543M|}
decode.c:SafeDecodeLiteralBlockSwitch:
 1211|  7.50k|    BrotliDecoderState* s) {
 1212|  7.50k|  return DecodeLiteralBlockSwitchInternal(1, s);
 1213|  7.50k|}
decode.c:DecodeLiteralBlockSwitchInternal:
 1198|  95.1k|    int safe, BrotliDecoderState* s) {
 1199|  95.1k|  if (!DecodeBlockTypeAndLength(safe, s, 0)) {
  ------------------
  |  Branch (1199:7): [True: 136, False: 94.9k]
  ------------------
 1200|    136|    return BROTLI_FALSE;
  ------------------
  |  |   53|    136|#define BROTLI_FALSE 0
  ------------------
 1201|    136|  }
 1202|  94.9k|  PrepareLiteralDecoding(s);
 1203|  94.9k|  return BROTLI_TRUE;
  ------------------
  |  |   51|  94.9k|#define BROTLI_TRUE 1
  ------------------
 1204|  95.1k|}
decode.c:DecodeLiteralBlockSwitch:
 1206|  87.6k|static void BROTLI_NOINLINE DecodeLiteralBlockSwitch(BrotliDecoderState* s) {
 1207|  87.6k|  DecodeLiteralBlockSwitchInternal(0, s);
 1208|  87.6k|}
decode.c:ReadPreloadedSymbol:
  445|   461M|                                                  uint32_t* value) {
  446|   461M|  uint32_t result = *value;
  447|   461M|  if (BROTLI_PREDICT_FALSE(*bits > HUFFMAN_TABLE_BITS)) {
  ------------------
  |  |   83|   461M|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 1.32k, False: 461M]
  |  |  ------------------
  ------------------
  448|  1.32k|    uint32_t val = BrotliGet16BitsUnmasked(br);
  449|  1.32k|    const HuffmanCode* ext = table + (val & HUFFMAN_TABLE_MASK) + *value;
  ------------------
  |  |   40|  1.32k|#define HUFFMAN_TABLE_MASK 0xFF
  ------------------
  450|  1.32k|    uint32_t mask = BitMask((*bits - HUFFMAN_TABLE_BITS));
  ------------------
  |  |   39|  1.32k|#define HUFFMAN_TABLE_BITS 8U
  ------------------
  451|  1.32k|    BROTLI_HC_MARK_TABLE_FOR_FAST_LOAD(ext);
  452|  1.32k|    BrotliDropBits(br, HUFFMAN_TABLE_BITS);
  ------------------
  |  |   39|  1.32k|#define HUFFMAN_TABLE_BITS 8U
  ------------------
  453|  1.32k|    BROTLI_HC_ADJUST_TABLE_INDEX(ext, (val >> HUFFMAN_TABLE_BITS) & mask);
  ------------------
  |  |   67|  1.32k|#define BROTLI_HC_ADJUST_TABLE_INDEX(H, V) H += (V)
  ------------------
  454|  1.32k|    BrotliDropBits(br, BROTLI_HC_FAST_LOAD_BITS(ext));
  ------------------
  |  |   70|  1.32k|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  455|  1.32k|    result = BROTLI_HC_FAST_LOAD_VALUE(ext);
  ------------------
  |  |   71|  1.32k|#define BROTLI_HC_FAST_LOAD_VALUE(H) (H->value)
  ------------------
  456|   461M|  } else {
  457|   461M|    BrotliDropBits(br, *bits);
  458|   461M|  }
  459|   461M|  PreloadSymbol(0, table, br, bits, value);
  460|   461M|  return result;
  461|   461M|}
decode.c:ReadSymbol:
  369|   131M|                                         BrotliBitReader* br) {
  370|   131M|  return DecodeSymbol(BrotliGet16BitsUnmasked(br), table, br);
  371|   131M|}
decode.c:SafeDecodeDistanceBlockSwitch:
 1253|  5.51k|    BrotliDecoderState* s) {
 1254|  5.51k|  return DecodeDistanceBlockSwitchInternal(1, s);
 1255|  5.51k|}
decode.c:DecodeDistanceBlockSwitchInternal:
 1238|  13.7k|    int safe, BrotliDecoderState* s) {
 1239|  13.7k|  if (!DecodeBlockTypeAndLength(safe, s, 2)) {
  ------------------
  |  Branch (1239:7): [True: 104, False: 13.6k]
  ------------------
 1240|    104|    return BROTLI_FALSE;
  ------------------
  |  |   53|    104|#define BROTLI_FALSE 0
  ------------------
 1241|    104|  }
 1242|  13.6k|  s->dist_context_map_slice = s->dist_context_map +
 1243|  13.6k|      (s->block_type_rb[5] << BROTLI_DISTANCE_CONTEXT_BITS);
  ------------------
  |  |   97|  13.6k|#define BROTLI_DISTANCE_CONTEXT_BITS 2
  ------------------
 1244|  13.6k|  s->dist_htree_index = s->dist_context_map_slice[s->distance_context];
 1245|  13.6k|  return BROTLI_TRUE;
  ------------------
  |  |   51|  13.6k|#define BROTLI_TRUE 1
  ------------------
 1246|  13.7k|}
decode.c:DecodeDistanceBlockSwitch:
 1248|  8.25k|static void BROTLI_NOINLINE DecodeDistanceBlockSwitch(BrotliDecoderState* s) {
 1249|  8.25k|  DecodeDistanceBlockSwitchInternal(0, s);
 1250|  8.25k|}
decode.c:SafeReadDistance:
 1662|  38.6M|    BrotliDecoderState* s, BrotliBitReader* br) {
 1663|  38.6M|  return ReadDistanceInternal(1, s, br);
 1664|  38.6M|}
decode.c:ReadDistanceInternal:
 1619|  44.6M|    int safe, BrotliDecoderState* s, BrotliBitReader* br) {
 1620|  44.6M|  BrotliMetablockBodyArena* b = &s->arena.body;
 1621|  44.6M|  uint32_t code;
 1622|  44.6M|  uint32_t bits;
 1623|  44.6M|  BrotliBitReaderState memento;
 1624|  44.6M|  HuffmanCode* distance_tree = s->distance_hgroup.htrees[s->dist_htree_index];
 1625|  44.6M|  if (!safe) {
  ------------------
  |  Branch (1625:7): [True: 6.03M, False: 38.6M]
  ------------------
 1626|  6.03M|    code = ReadSymbol(distance_tree, br);
 1627|  38.6M|  } else {
 1628|  38.6M|    BrotliBitReaderSaveState(br, &memento);
 1629|  38.6M|    if (!SafeReadSymbol(distance_tree, br, &code)) {
  ------------------
  |  Branch (1629:9): [True: 13, False: 38.6M]
  ------------------
 1630|     13|      return BROTLI_FALSE;
  ------------------
  |  |   53|     13|#define BROTLI_FALSE 0
  ------------------
 1631|     13|    }
 1632|  38.6M|  }
 1633|  44.6M|  --s->block_length[2];
 1634|       |  /* Convert the distance code to the actual distance by possibly
 1635|       |     looking up past distances from the s->dist_rb. */
 1636|  44.6M|  s->distance_context = 0;
 1637|  44.6M|  if ((code & ~0xFu) == 0) {
  ------------------
  |  Branch (1637:7): [True: 35.7M, False: 8.95M]
  ------------------
 1638|  35.7M|    s->distance_code = (int)code;
 1639|  35.7M|    TakeDistanceFromRingBuffer(s);
 1640|  35.7M|    return BROTLI_TRUE;
  ------------------
  |  |   51|  35.7M|#define BROTLI_TRUE 1
  ------------------
 1641|  35.7M|  }
 1642|  8.95M|  if (!safe) {
  ------------------
  |  Branch (1642:7): [True: 1.37M, False: 7.58M]
  ------------------
 1643|  1.37M|    bits = BrotliReadBits32(br, b->dist_extra_bits[code]);
 1644|  7.58M|  } else {
 1645|  7.58M|    if (!SafeReadBits32(br, b->dist_extra_bits[code], &bits)) {
  ------------------
  |  Branch (1645:9): [True: 225, False: 7.58M]
  ------------------
 1646|    225|      ++s->block_length[2];
 1647|    225|      BrotliBitReaderRestoreState(br, &memento);
 1648|    225|      return BROTLI_FALSE;
  ------------------
  |  |   53|    225|#define BROTLI_FALSE 0
  ------------------
 1649|    225|    }
 1650|  7.58M|  }
 1651|  8.95M|  s->distance_code =
 1652|  8.95M|      (int)(b->dist_offset[code] + (bits << s->distance_postfix_bits));
 1653|  8.95M|  return BROTLI_TRUE;
  ------------------
  |  |   51|  8.95M|#define BROTLI_TRUE 1
  ------------------
 1654|  8.95M|}
decode.c:TakeDistanceFromRingBuffer:
 1469|  35.7M|static BROTLI_INLINE void TakeDistanceFromRingBuffer(BrotliDecoderState* s) {
 1470|  35.7M|  int offset = s->distance_code - 3;
 1471|  35.7M|  if (s->distance_code <= 3) {
  ------------------
  |  Branch (1471:7): [True: 12.2M, False: 23.4M]
  ------------------
 1472|       |    /* Compensate double distance-ring-buffer roll for dictionary items. */
 1473|  12.2M|    s->distance_context = 1 >> s->distance_code;
 1474|  12.2M|    s->distance_code = s->dist_rb[(s->dist_rb_idx - offset) & 3];
 1475|  12.2M|    s->dist_rb_idx -= s->distance_context;
 1476|  23.4M|  } else {
 1477|  23.4M|    int index_delta = 3;
 1478|  23.4M|    int delta;
 1479|  23.4M|    int base = s->distance_code - 10;
 1480|  23.4M|    if (s->distance_code < 10) {
  ------------------
  |  Branch (1480:9): [True: 19.3M, False: 4.17M]
  ------------------
 1481|  19.3M|      base = s->distance_code - 4;
 1482|  19.3M|    } else {
 1483|  4.17M|      index_delta = 2;
 1484|  4.17M|    }
 1485|       |    /* Unpack one of six 4-bit values. */
 1486|  23.4M|    delta = ((0x605142 >> (4 * base)) & 0xF) - 3;
 1487|  23.4M|    s->distance_code = s->dist_rb[(s->dist_rb_idx + index_delta) & 0x3] + delta;
 1488|  23.4M|    if (s->distance_code <= 0) {
  ------------------
  |  Branch (1488:9): [True: 30, False: 23.4M]
  ------------------
 1489|       |      /* A huge distance will cause a BROTLI_FAILURE() soon.
 1490|       |         This is a little faster than failing here. */
 1491|     30|      s->distance_code = 0x7FFFFFFF;
 1492|     30|    }
 1493|  23.4M|  }
 1494|  35.7M|}
decode.c:SafeReadBits32:
 1507|  7.58M|    BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
 1508|  7.58M|  if (n_bits != 0) {
  ------------------
  |  Branch (1508:7): [True: 4.24k, False: 7.57M]
  ------------------
 1509|  4.24k|    return BrotliSafeReadBits32(br, n_bits, val);
 1510|  7.57M|  } else {
 1511|  7.57M|    *val = 0;
 1512|  7.57M|    return BROTLI_TRUE;
  ------------------
  |  |   51|  7.57M|#define BROTLI_TRUE 1
  ------------------
 1513|  7.57M|  }
 1514|  7.58M|}
decode.c:ReadDistance:
 1657|  6.03M|    BrotliDecoderState* s, BrotliBitReader* br) {
 1658|  6.03M|  ReadDistanceInternal(0, s, br);
 1659|  6.03M|}
decode.c:memmove16:
  170|   292M|static BROTLI_INLINE void memmove16(uint8_t* dst, uint8_t* src) {
  171|       |#if defined(BROTLI_TARGET_NEON)
  172|       |  vst1q_u8(dst, vld1q_u8(src));
  173|       |#else
  174|   292M|  uint32_t buffer[4];
  175|   292M|  memcpy(buffer, src, 16);
  176|   292M|  memcpy(dst, buffer, 16);
  177|   292M|#endif
  178|   292M|}
decode.c:SafeProcessCommands:
 2031|   100k|    BrotliDecoderState* s) {
 2032|   100k|  return ProcessCommandsInternal(1, s);
 2033|   100k|}
decode.c:WrapRingBuffer:
 1312|   270k|static void BROTLI_NOINLINE WrapRingBuffer(BrotliDecoderState* s) {
 1313|   270k|  if (s->should_wrap_ringbuffer) {
  ------------------
  |  Branch (1313:7): [True: 11.2k, False: 258k]
  ------------------
 1314|  11.2k|    memcpy(s->ringbuffer, s->ringbuffer_end, (size_t)s->pos);
 1315|  11.2k|    s->should_wrap_ringbuffer = 0;
 1316|  11.2k|  }
 1317|   270k|}
decode.c:UnwrittenBytes:
 1257|   415k|static size_t UnwrittenBytes(const BrotliDecoderState* s, BROTLI_BOOL wrap) {
 1258|   415k|  size_t pos = wrap && s->pos > s->ringbuffer_size ?
  ------------------
  |  Branch (1258:16): [True: 415k, False: 0]
  |  Branch (1258:24): [True: 22.5k, False: 393k]
  ------------------
 1259|   393k|      (size_t)s->ringbuffer_size : (size_t)(s->pos);
 1260|   415k|  size_t partial_pos_rb = (s->rb_roundtrips * (size_t)s->ringbuffer_size) + pos;
 1261|   415k|  return partial_pos_rb - s->partial_pos_out;
 1262|   415k|}

BrotliBuildCodeLengthsHuffmanTable:
  106|  5.92k|                                        uint16_t* count) {
  107|  5.92k|  HuffmanCode code;       /* current table entry */
  108|  5.92k|  int symbol;             /* symbol index in original or sorted table */
  109|  5.92k|  brotli_reg_t key;       /* prefix code */
  ------------------
  |  |  241|  5.92k|#define brotli_reg_t uint64_t
  ------------------
  110|  5.92k|  brotli_reg_t key_step;  /* prefix code addend */
  ------------------
  |  |  241|  5.92k|#define brotli_reg_t uint64_t
  ------------------
  111|  5.92k|  int step;               /* step size to replicate values in current table */
  112|  5.92k|  int table_size;         /* size of current table */
  113|  5.92k|  int sorted[BROTLI_CODE_LENGTH_CODES];  /* symbols sorted by code length */
  114|       |  /* offsets in sorted table for each length */
  115|  5.92k|  int offset[BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH + 1];
  116|  5.92k|  int bits;
  117|  5.92k|  int bits_count;
  118|  5.92k|  BROTLI_DCHECK(BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH <=
  119|  5.92k|                BROTLI_REVERSE_BITS_MAX);
  120|       |
  121|       |  /* Generate offsets into sorted symbol table by code length. */
  122|  5.92k|  symbol = -1;
  123|  5.92k|  bits = 1;
  124|  5.92k|  BROTLI_REPEAT(BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH, {
  ------------------
  |  |  505|  5.92k|#define BROTLI_REPEAT(N, X) {     \
  |  |  506|  5.92k|  if ((N & 1) != 0) {X;}          \
  |  |  ------------------
  |  |  |  Branch (506:7): [True: 5.92k, Folded]
  |  |  ------------------
  |  |  507|  5.92k|  if ((N & 2) != 0) {X; X;}       \
  |  |  ------------------
  |  |  |  Branch (507:7): [Folded, False: 5.92k]
  |  |  ------------------
  |  |  508|  5.92k|  if ((N & 4) != 0) {X; X; X; X;} \
  |  |  ------------------
  |  |  |  Branch (508:7): [True: 5.92k, Folded]
  |  |  ------------------
  |  |  509|  5.92k|}
  ------------------
  125|  5.92k|    symbol += count[bits];
  126|  5.92k|    offset[bits] = symbol;
  127|  5.92k|    bits++;
  128|  5.92k|  });
  129|       |  /* Symbols with code length 0 are placed after all other symbols. */
  130|  5.92k|  offset[0] = BROTLI_CODE_LENGTH_CODES - 1;
  ------------------
  |  |   36|  5.92k|#define BROTLI_CODE_LENGTH_CODES (BROTLI_REPEAT_ZERO_CODE_LENGTH + 1)
  |  |  ------------------
  |  |  |  |   35|  5.92k|#define BROTLI_REPEAT_ZERO_CODE_LENGTH 17
  |  |  ------------------
  ------------------
  131|       |
  132|       |  /* Sort symbols by length, by symbol order within each length. */
  133|  5.92k|  symbol = BROTLI_CODE_LENGTH_CODES;
  ------------------
  |  |   36|  5.92k|#define BROTLI_CODE_LENGTH_CODES (BROTLI_REPEAT_ZERO_CODE_LENGTH + 1)
  |  |  ------------------
  |  |  |  |   35|  5.92k|#define BROTLI_REPEAT_ZERO_CODE_LENGTH 17
  |  |  ------------------
  ------------------
  134|  17.7k|  do {
  135|  17.7k|    BROTLI_REPEAT(6, {
  ------------------
  |  |  505|  17.7k|#define BROTLI_REPEAT(N, X) {     \
  |  |  506|  17.7k|  if ((N & 1) != 0) {X;}          \
  |  |  ------------------
  |  |  |  Branch (506:7): [Folded, False: 17.7k]
  |  |  ------------------
  |  |  507|  17.7k|  if ((N & 2) != 0) {X; X;}       \
  |  |  ------------------
  |  |  |  Branch (507:7): [True: 17.7k, Folded]
  |  |  ------------------
  |  |  508|  17.7k|  if ((N & 4) != 0) {X; X; X; X;} \
  |  |  ------------------
  |  |  |  Branch (508:7): [True: 17.7k, Folded]
  |  |  ------------------
  |  |  509|  17.7k|}
  ------------------
  136|  17.7k|      symbol--;
  137|  17.7k|      sorted[offset[code_lengths[symbol]]--] = symbol;
  138|  17.7k|    });
  139|  17.7k|  } while (symbol != 0);
  ------------------
  |  Branch (139:12): [True: 11.8k, False: 5.92k]
  ------------------
  140|       |
  141|  5.92k|  table_size = 1 << BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH;
  ------------------
  |  |   28|  5.92k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH 5
  ------------------
  142|       |
  143|       |  /* Special case: all symbols but one have 0 code length. */
  144|  5.92k|  if (offset[0] == 0) {
  ------------------
  |  Branch (144:7): [True: 305, False: 5.62k]
  ------------------
  145|    305|    code = ConstructHuffmanCode(0, (uint16_t)sorted[0]);
  146|  10.0k|    for (key = 0; key < (brotli_reg_t)table_size; ++key) {
  ------------------
  |  Branch (146:19): [True: 9.76k, False: 305]
  ------------------
  147|  9.76k|      table[key] = code;
  148|  9.76k|    }
  149|    305|    return;
  150|    305|  }
  151|       |
  152|       |  /* Fill in table. */
  153|  5.62k|  key = 0;
  154|  5.62k|  key_step = BROTLI_REVERSE_BITS_LOWEST;
  ------------------
  |  |   65|  5.62k|  ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   21|  5.62k|#define BROTLI_REVERSE_BITS_MAX 8
  |  |  ------------------
  |  |                 ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   27|  5.62k|#define BROTLI_REVERSE_BITS_BASE 0
  |  |  ------------------
  ------------------
  155|  5.62k|  symbol = 0;
  156|  5.62k|  bits = 1;
  157|  5.62k|  step = 2;
  158|  28.1k|  do {
  159|  58.3k|    for (bits_count = count[bits]; bits_count != 0; --bits_count) {
  ------------------
  |  Branch (159:36): [True: 30.2k, False: 28.1k]
  ------------------
  160|  30.2k|      code = ConstructHuffmanCode((uint8_t)bits, (uint16_t)sorted[symbol++]);
  161|  30.2k|      ReplicateValue(&table[BrotliReverseBits(key)], step, table_size, code);
  162|  30.2k|      key += key_step;
  163|  30.2k|    }
  164|  28.1k|    step <<= 1;
  165|  28.1k|    key_step >>= 1;
  166|  28.1k|  } while (++bits <= BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH);
  ------------------
  |  |   28|  28.1k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH 5
  ------------------
  |  Branch (166:12): [True: 22.4k, False: 5.62k]
  ------------------
  167|  5.62k|}
BrotliBuildHuffmanTable:
  172|  5.61k|                                 uint16_t* count) {
  173|  5.61k|  HuffmanCode code;       /* current table entry */
  174|  5.61k|  HuffmanCode* table;     /* next available space in table */
  175|  5.61k|  int len;                /* current code length */
  176|  5.61k|  int symbol;             /* symbol index in original or sorted table */
  177|  5.61k|  brotli_reg_t key;       /* prefix code */
  ------------------
  |  |  241|  5.61k|#define brotli_reg_t uint64_t
  ------------------
  178|  5.61k|  brotli_reg_t key_step;  /* prefix code addend */
  ------------------
  |  |  241|  5.61k|#define brotli_reg_t uint64_t
  ------------------
  179|  5.61k|  brotli_reg_t sub_key;   /* 2nd level table prefix code */
  ------------------
  |  |  241|  5.61k|#define brotli_reg_t uint64_t
  ------------------
  180|  5.61k|  brotli_reg_t sub_key_step;  /* 2nd level table prefix code addend */
  ------------------
  |  |  241|  5.61k|#define brotli_reg_t uint64_t
  ------------------
  181|  5.61k|  int step;               /* step size to replicate values in current table */
  182|  5.61k|  int table_bits;         /* key length of current table */
  183|  5.61k|  int table_size;         /* size of current table */
  184|  5.61k|  int total_size;         /* sum of root table size and 2nd level table sizes */
  185|  5.61k|  int max_length = -1;
  186|  5.61k|  int bits;
  187|  5.61k|  int bits_count;
  188|       |
  189|  5.61k|  BROTLI_DCHECK(root_bits <= BROTLI_REVERSE_BITS_MAX);
  190|  5.61k|  BROTLI_DCHECK(BROTLI_HUFFMAN_MAX_CODE_LENGTH - root_bits <=
  191|  5.61k|                BROTLI_REVERSE_BITS_MAX);
  192|       |
  193|  75.1k|  while (symbol_lists[max_length] == 0xFFFF) max_length--;
  ------------------
  |  Branch (193:10): [True: 69.5k, False: 5.61k]
  ------------------
  194|  5.61k|  max_length += BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1;
  ------------------
  |  |   19|  5.61k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH 15
  ------------------
  195|       |
  196|  5.61k|  table = root_table;
  197|  5.61k|  table_bits = root_bits;
  198|  5.61k|  table_size = 1 << table_bits;
  199|  5.61k|  total_size = table_size;
  200|       |
  201|       |  /* Fill in the root table. Reduce the table size to if possible,
  202|       |     and create the repetitions by memcpy. */
  203|  5.61k|  if (table_bits > max_length) {
  ------------------
  |  Branch (203:7): [True: 4.92k, False: 694]
  ------------------
  204|  4.92k|    table_bits = max_length;
  205|  4.92k|    table_size = 1 << table_bits;
  206|  4.92k|  }
  207|  5.61k|  key = 0;
  208|  5.61k|  key_step = BROTLI_REVERSE_BITS_LOWEST;
  ------------------
  |  |   65|  5.61k|  ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   21|  5.61k|#define BROTLI_REVERSE_BITS_MAX 8
  |  |  ------------------
  |  |                 ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   27|  5.61k|#define BROTLI_REVERSE_BITS_BASE 0
  |  |  ------------------
  ------------------
  209|  5.61k|  bits = 1;
  210|  5.61k|  step = 2;
  211|  13.4k|  do {
  212|  13.4k|    symbol = bits - (BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1);
  ------------------
  |  |   19|  13.4k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH 15
  ------------------
  213|   111k|    for (bits_count = count[bits]; bits_count != 0; --bits_count) {
  ------------------
  |  Branch (213:36): [True: 97.9k, False: 13.4k]
  ------------------
  214|  97.9k|      symbol = symbol_lists[symbol];
  215|  97.9k|      code = ConstructHuffmanCode((uint8_t)bits, (uint16_t)symbol);
  216|  97.9k|      ReplicateValue(&table[BrotliReverseBits(key)], step, table_size, code);
  217|  97.9k|      key += key_step;
  218|  97.9k|    }
  219|  13.4k|    step <<= 1;
  220|  13.4k|    key_step >>= 1;
  221|  13.4k|  } while (++bits <= table_bits);
  ------------------
  |  Branch (221:12): [True: 7.81k, False: 5.61k]
  ------------------
  222|       |
  223|       |  /* If root_bits != table_bits then replicate to fill the remaining slots. */
  224|  37.1k|  while (total_size != table_size) {
  ------------------
  |  Branch (224:10): [True: 31.5k, False: 5.61k]
  ------------------
  225|  31.5k|    memcpy(&table[table_size], &table[0],
  226|  31.5k|           (size_t)table_size * sizeof(table[0]));
  227|  31.5k|    table_size <<= 1;
  228|  31.5k|  }
  229|       |
  230|       |  /* Fill in 2nd level tables and add pointers to root table. */
  231|  5.61k|  key_step = BROTLI_REVERSE_BITS_LOWEST >> (root_bits - 1);
  ------------------
  |  |   65|  5.61k|  ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   21|  5.61k|#define BROTLI_REVERSE_BITS_MAX 8
  |  |  ------------------
  |  |                 ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   27|  5.61k|#define BROTLI_REVERSE_BITS_BASE 0
  |  |  ------------------
  ------------------
  232|  5.61k|  sub_key = (BROTLI_REVERSE_BITS_LOWEST << 1);
  ------------------
  |  |   65|  5.61k|  ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   21|  5.61k|#define BROTLI_REVERSE_BITS_MAX 8
  |  |  ------------------
  |  |                 ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   27|  5.61k|#define BROTLI_REVERSE_BITS_BASE 0
  |  |  ------------------
  ------------------
  233|  5.61k|  sub_key_step = BROTLI_REVERSE_BITS_LOWEST;
  ------------------
  |  |   65|  5.61k|  ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   21|  5.61k|#define BROTLI_REVERSE_BITS_MAX 8
  |  |  ------------------
  |  |                 ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   27|  5.61k|#define BROTLI_REVERSE_BITS_BASE 0
  |  |  ------------------
  ------------------
  234|  6.87k|  for (len = root_bits + 1, step = 2; len <= max_length; ++len) {
  ------------------
  |  Branch (234:39): [True: 1.26k, False: 5.61k]
  ------------------
  235|  1.26k|    symbol = len - (BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1);
  ------------------
  |  |   19|  1.26k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH 15
  ------------------
  236|  40.1k|    for (; count[len] != 0; --count[len]) {
  ------------------
  |  Branch (236:12): [True: 38.8k, False: 1.26k]
  ------------------
  237|  38.8k|      if (sub_key == (BROTLI_REVERSE_BITS_LOWEST << 1U)) {
  ------------------
  |  |   65|  38.8k|  ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   21|  38.8k|#define BROTLI_REVERSE_BITS_MAX 8
  |  |  ------------------
  |  |                 ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   27|  38.8k|#define BROTLI_REVERSE_BITS_BASE 0
  |  |  ------------------
  ------------------
  |  Branch (237:11): [True: 16.4k, False: 22.4k]
  ------------------
  238|  16.4k|        table += table_size;
  239|  16.4k|        table_bits = NextTableBitSize(count, len, root_bits);
  240|  16.4k|        table_size = 1 << table_bits;
  241|  16.4k|        total_size += table_size;
  242|  16.4k|        sub_key = BrotliReverseBits(key);
  243|  16.4k|        key += key_step;
  244|  16.4k|        root_table[sub_key] = ConstructHuffmanCode(
  245|  16.4k|            (uint8_t)(table_bits + root_bits),
  246|  16.4k|            (uint16_t)(((size_t)(table - root_table)) - sub_key));
  247|  16.4k|        sub_key = 0;
  248|  16.4k|      }
  249|  38.8k|      symbol = symbol_lists[symbol];
  250|  38.8k|      code = ConstructHuffmanCode((uint8_t)(len - root_bits), (uint16_t)symbol);
  251|  38.8k|      ReplicateValue(
  252|  38.8k|          &table[BrotliReverseBits(sub_key)], step, table_size, code);
  253|  38.8k|      sub_key += sub_key_step;
  254|  38.8k|    }
  255|  1.26k|    step <<= 1;
  256|  1.26k|    sub_key_step >>= 1;
  257|  1.26k|  }
  258|  5.61k|  return (uint32_t)total_size;
  259|  5.61k|}
BrotliBuildSimpleHuffmanTable:
  264|  36.7k|                                       uint32_t num_symbols) {
  265|  36.7k|  uint32_t table_size = 1;
  266|  36.7k|  const uint32_t goal_size = 1U << root_bits;
  267|  36.7k|  switch (num_symbols) {
  ------------------
  |  Branch (267:11): [True: 36.7k, False: 0]
  ------------------
  268|  23.6k|    case 0:
  ------------------
  |  Branch (268:5): [True: 23.6k, False: 13.1k]
  ------------------
  269|  23.6k|      table[0] = ConstructHuffmanCode(0, val[0]);
  270|  23.6k|      break;
  271|  7.02k|    case 1:
  ------------------
  |  Branch (271:5): [True: 7.02k, False: 29.7k]
  ------------------
  272|  7.02k|      if (val[1] > val[0]) {
  ------------------
  |  Branch (272:11): [True: 4.71k, False: 2.30k]
  ------------------
  273|  4.71k|        table[0] = ConstructHuffmanCode(1, val[0]);
  274|  4.71k|        table[1] = ConstructHuffmanCode(1, val[1]);
  275|  4.71k|      } else {
  276|  2.30k|        table[0] = ConstructHuffmanCode(1, val[1]);
  277|  2.30k|        table[1] = ConstructHuffmanCode(1, val[0]);
  278|  2.30k|      }
  279|  7.02k|      table_size = 2;
  280|  7.02k|      break;
  281|  3.15k|    case 2:
  ------------------
  |  Branch (281:5): [True: 3.15k, False: 33.5k]
  ------------------
  282|  3.15k|      table[0] = ConstructHuffmanCode(1, val[0]);
  283|  3.15k|      table[2] = ConstructHuffmanCode(1, val[0]);
  284|  3.15k|      if (val[2] > val[1]) {
  ------------------
  |  Branch (284:11): [True: 1.99k, False: 1.15k]
  ------------------
  285|  1.99k|        table[1] = ConstructHuffmanCode(2, val[1]);
  286|  1.99k|        table[3] = ConstructHuffmanCode(2, val[2]);
  287|  1.99k|      } else {
  288|  1.15k|        table[1] = ConstructHuffmanCode(2, val[2]);
  289|  1.15k|        table[3] = ConstructHuffmanCode(2, val[1]);
  290|  1.15k|      }
  291|  3.15k|      table_size = 4;
  292|  3.15k|      break;
  293|  2.13k|    case 3: {
  ------------------
  |  Branch (293:5): [True: 2.13k, False: 34.6k]
  ------------------
  294|  2.13k|      int i, k;
  295|  8.52k|      for (i = 0; i < 3; ++i) {
  ------------------
  |  Branch (295:19): [True: 6.39k, False: 2.13k]
  ------------------
  296|  19.1k|        for (k = i + 1; k < 4; ++k) {
  ------------------
  |  Branch (296:25): [True: 12.7k, False: 6.39k]
  ------------------
  297|  12.7k|          if (val[k] < val[i]) {
  ------------------
  |  Branch (297:15): [True: 5.70k, False: 7.08k]
  ------------------
  298|  5.70k|            uint16_t t = val[k];
  299|  5.70k|            val[k] = val[i];
  300|  5.70k|            val[i] = t;
  301|  5.70k|          }
  302|  12.7k|        }
  303|  6.39k|      }
  304|  2.13k|      table[0] = ConstructHuffmanCode(2, val[0]);
  305|  2.13k|      table[2] = ConstructHuffmanCode(2, val[1]);
  306|  2.13k|      table[1] = ConstructHuffmanCode(2, val[2]);
  307|  2.13k|      table[3] = ConstructHuffmanCode(2, val[3]);
  308|  2.13k|      table_size = 4;
  309|  2.13k|      break;
  310|      0|    }
  311|    835|    case 4: {
  ------------------
  |  Branch (311:5): [True: 835, False: 35.9k]
  ------------------
  312|    835|      if (val[3] < val[2]) {
  ------------------
  |  Branch (312:11): [True: 544, False: 291]
  ------------------
  313|    544|        uint16_t t = val[3];
  314|    544|        val[3] = val[2];
  315|    544|        val[2] = t;
  316|    544|      }
  317|    835|      table[0] = ConstructHuffmanCode(1, val[0]);
  318|    835|      table[1] = ConstructHuffmanCode(2, val[1]);
  319|    835|      table[2] = ConstructHuffmanCode(1, val[0]);
  320|    835|      table[3] = ConstructHuffmanCode(3, val[2]);
  321|    835|      table[4] = ConstructHuffmanCode(1, val[0]);
  322|    835|      table[5] = ConstructHuffmanCode(2, val[1]);
  323|    835|      table[6] = ConstructHuffmanCode(1, val[0]);
  324|    835|      table[7] = ConstructHuffmanCode(3, val[3]);
  325|    835|      table_size = 8;
  326|    835|      break;
  327|      0|    }
  328|  36.7k|  }
  329|   310k|  while (table_size != goal_size) {
  ------------------
  |  Branch (329:10): [True: 273k, False: 36.7k]
  ------------------
  330|   273k|    memcpy(&table[table_size], &table[0],
  331|   273k|           (size_t)table_size * sizeof(table[0]));
  332|   273k|    table_size <<= 1;
  333|   273k|  }
  334|  36.7k|  return goal_size;
  335|  36.7k|}
huffman.c:ReplicateValue:
   82|   167k|                                         HuffmanCode code) {
   83|   414k|  do {
   84|   414k|    end -= step;
   85|   414k|    table[end] = code;
   86|   414k|  } while (end > 0);
  ------------------
  |  Branch (86:12): [True: 247k, False: 167k]
  ------------------
   87|   167k|}
huffman.c:BrotliReverseBits:
   70|   183k|static BROTLI_INLINE brotli_reg_t BrotliReverseBits(brotli_reg_t num) {
   71|       |#if defined(BROTLI_RBIT)
   72|       |  return BROTLI_RBIT(num);
   73|       |#else
   74|   183k|  return kReverseBits[num];
   75|   183k|#endif
   76|   183k|}
huffman.c:NextTableBitSize:
   93|  16.4k|                                          int len, int root_bits) {
   94|  16.4k|  int left = 1 << (len - root_bits);
   95|  17.1k|  while (len < BROTLI_HUFFMAN_MAX_CODE_LENGTH) {
  ------------------
  |  |   19|  17.1k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH 15
  ------------------
  |  Branch (95:10): [True: 16.9k, False: 136]
  ------------------
   96|  16.9k|    left -= count[len];
   97|  16.9k|    if (left <= 0) break;
  ------------------
  |  Branch (97:9): [True: 16.2k, False: 677]
  ------------------
   98|    677|    ++len;
   99|    677|    left <<= 1;
  100|    677|  }
  101|  16.4k|  return len - root_bits;
  102|  16.4k|}

huffman.c:ConstructHuffmanCode:
   44|   249k|    const uint16_t value) {
   45|   249k|  HuffmanCode h;
   46|   249k|  h.bits = bits;
   47|   249k|  h.value = value;
   48|   249k|  return h;
   49|   249k|}

BrotliDecoderStateInit:
   19|  3.91k|    brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque) {
   20|  3.91k|  if (!alloc_func) {
  ------------------
  |  Branch (20:7): [True: 3.91k, False: 0]
  ------------------
   21|  3.91k|    s->alloc_func = BrotliDefaultAllocFunc;
   22|  3.91k|    s->free_func = BrotliDefaultFreeFunc;
   23|  3.91k|    s->memory_manager_opaque = 0;
   24|  3.91k|  } else {
   25|      0|    s->alloc_func = alloc_func;
   26|      0|    s->free_func = free_func;
   27|      0|    s->memory_manager_opaque = opaque;
   28|      0|  }
   29|       |
   30|  3.91k|  s->error_code = 0; /* BROTLI_DECODER_NO_ERROR */
   31|       |
   32|  3.91k|  BrotliInitBitReader(&s->br);
   33|  3.91k|  s->state = BROTLI_STATE_UNINITED;
   34|  3.91k|  s->large_window = 0;
   35|  3.91k|  s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_NONE;
   36|  3.91k|  s->substate_uncompressed = BROTLI_STATE_UNCOMPRESSED_NONE;
   37|  3.91k|  s->substate_decode_uint8 = BROTLI_STATE_DECODE_UINT8_NONE;
   38|  3.91k|  s->substate_read_block_length = BROTLI_STATE_READ_BLOCK_LENGTH_NONE;
   39|       |
   40|  3.91k|  s->buffer_length = 0;
   41|  3.91k|  s->loop_counter = 0;
   42|  3.91k|  s->pos = 0;
   43|  3.91k|  s->rb_roundtrips = 0;
   44|  3.91k|  s->partial_pos_out = 0;
   45|       |
   46|  3.91k|  s->block_type_trees = NULL;
   47|  3.91k|  s->block_len_trees = NULL;
   48|  3.91k|  s->ringbuffer = NULL;
   49|  3.91k|  s->ringbuffer_size = 0;
   50|  3.91k|  s->new_ringbuffer_size = 0;
   51|  3.91k|  s->ringbuffer_mask = 0;
   52|       |
   53|  3.91k|  s->context_map = NULL;
   54|  3.91k|  s->context_modes = NULL;
   55|  3.91k|  s->dist_context_map = NULL;
   56|  3.91k|  s->context_map_slice = NULL;
   57|  3.91k|  s->dist_context_map_slice = NULL;
   58|       |
   59|  3.91k|  s->literal_hgroup.codes = NULL;
   60|  3.91k|  s->literal_hgroup.htrees = NULL;
   61|  3.91k|  s->insert_copy_hgroup.codes = NULL;
   62|  3.91k|  s->insert_copy_hgroup.htrees = NULL;
   63|  3.91k|  s->distance_hgroup.codes = NULL;
   64|  3.91k|  s->distance_hgroup.htrees = NULL;
   65|       |
   66|  3.91k|  s->is_last_metablock = 0;
   67|  3.91k|  s->is_uncompressed = 0;
   68|  3.91k|  s->is_metadata = 0;
   69|  3.91k|  s->should_wrap_ringbuffer = 0;
   70|  3.91k|  s->canny_ringbuffer_allocation = 1;
   71|       |
   72|  3.91k|  s->window_bits = 0;
   73|  3.91k|  s->max_distance = 0;
   74|  3.91k|  s->dist_rb[0] = 16;
   75|  3.91k|  s->dist_rb[1] = 15;
   76|  3.91k|  s->dist_rb[2] = 11;
   77|  3.91k|  s->dist_rb[3] = 4;
   78|  3.91k|  s->dist_rb_idx = 0;
   79|  3.91k|  s->block_type_trees = NULL;
   80|  3.91k|  s->block_len_trees = NULL;
   81|       |
   82|  3.91k|  s->mtf_upper_bound = 63;
   83|       |
   84|  3.91k|  s->dictionary = BrotliGetDictionary();
   85|  3.91k|  s->transforms = BrotliGetTransforms();
   86|       |
   87|  3.91k|  return BROTLI_TRUE;
  ------------------
  |  |   51|  3.91k|#define BROTLI_TRUE 1
  ------------------
   88|  3.91k|}
BrotliDecoderStateMetablockBegin:
   90|  13.8k|void BrotliDecoderStateMetablockBegin(BrotliDecoderState* s) {
   91|  13.8k|  s->meta_block_remaining_len = 0;
   92|  13.8k|  s->block_length[0] = 1U << 24;
   93|  13.8k|  s->block_length[1] = 1U << 24;
   94|  13.8k|  s->block_length[2] = 1U << 24;
   95|  13.8k|  s->num_block_types[0] = 1;
   96|  13.8k|  s->num_block_types[1] = 1;
   97|  13.8k|  s->num_block_types[2] = 1;
   98|  13.8k|  s->block_type_rb[0] = 1;
   99|  13.8k|  s->block_type_rb[1] = 0;
  100|  13.8k|  s->block_type_rb[2] = 1;
  101|  13.8k|  s->block_type_rb[3] = 0;
  102|  13.8k|  s->block_type_rb[4] = 1;
  103|  13.8k|  s->block_type_rb[5] = 0;
  104|  13.8k|  s->context_map = NULL;
  105|  13.8k|  s->context_modes = NULL;
  106|  13.8k|  s->dist_context_map = NULL;
  107|  13.8k|  s->context_map_slice = NULL;
  108|  13.8k|  s->literal_htree = NULL;
  109|  13.8k|  s->dist_context_map_slice = NULL;
  110|  13.8k|  s->dist_htree_index = 0;
  111|  13.8k|  s->context_lookup = NULL;
  112|  13.8k|  s->literal_hgroup.codes = NULL;
  113|  13.8k|  s->literal_hgroup.htrees = NULL;
  114|  13.8k|  s->insert_copy_hgroup.codes = NULL;
  115|  13.8k|  s->insert_copy_hgroup.htrees = NULL;
  116|  13.8k|  s->distance_hgroup.codes = NULL;
  117|       |  s->distance_hgroup.htrees = NULL;
  118|  13.8k|}
BrotliDecoderStateCleanupAfterMetablock:
  120|  14.1k|void BrotliDecoderStateCleanupAfterMetablock(BrotliDecoderState* s) {
  121|  14.1k|  BROTLI_DECODER_FREE(s, s->context_modes);
  ------------------
  |  |  356|  14.1k|#define BROTLI_DECODER_FREE(S, X) {          \
  |  |  357|  14.1k|  S->free_func(S->memory_manager_opaque, X); \
  |  |  358|  14.1k|  X = NULL;                                  \
  |  |  359|  14.1k|}
  ------------------
  122|  14.1k|  BROTLI_DECODER_FREE(s, s->context_map);
  ------------------
  |  |  356|  14.1k|#define BROTLI_DECODER_FREE(S, X) {          \
  |  |  357|  14.1k|  S->free_func(S->memory_manager_opaque, X); \
  |  |  358|  14.1k|  X = NULL;                                  \
  |  |  359|  14.1k|}
  ------------------
  123|  14.1k|  BROTLI_DECODER_FREE(s, s->dist_context_map);
  ------------------
  |  |  356|  14.1k|#define BROTLI_DECODER_FREE(S, X) {          \
  |  |  357|  14.1k|  S->free_func(S->memory_manager_opaque, X); \
  |  |  358|  14.1k|  X = NULL;                                  \
  |  |  359|  14.1k|}
  ------------------
  124|  14.1k|  BROTLI_DECODER_FREE(s, s->literal_hgroup.htrees);
  ------------------
  |  |  356|  14.1k|#define BROTLI_DECODER_FREE(S, X) {          \
  |  |  357|  14.1k|  S->free_func(S->memory_manager_opaque, X); \
  |  |  358|  14.1k|  X = NULL;                                  \
  |  |  359|  14.1k|}
  ------------------
  125|  14.1k|  BROTLI_DECODER_FREE(s, s->insert_copy_hgroup.htrees);
  ------------------
  |  |  356|  14.1k|#define BROTLI_DECODER_FREE(S, X) {          \
  |  |  357|  14.1k|  S->free_func(S->memory_manager_opaque, X); \
  |  |  358|  14.1k|  X = NULL;                                  \
  |  |  359|  14.1k|}
  ------------------
  126|       |  BROTLI_DECODER_FREE(s, s->distance_hgroup.htrees);
  ------------------
  |  |  356|  14.1k|#define BROTLI_DECODER_FREE(S, X) {          \
  |  |  357|  14.1k|  S->free_func(S->memory_manager_opaque, X); \
  |  |  358|  14.1k|  X = NULL;                                  \
  |  |  359|  14.1k|}
  ------------------
  127|  14.1k|}
BrotliDecoderStateCleanup:
  129|  3.91k|void BrotliDecoderStateCleanup(BrotliDecoderState* s) {
  130|  3.91k|  BrotliDecoderStateCleanupAfterMetablock(s);
  131|       |
  132|  3.91k|  BROTLI_DECODER_FREE(s, s->ringbuffer);
  ------------------
  |  |  356|  3.91k|#define BROTLI_DECODER_FREE(S, X) {          \
  |  |  357|  3.91k|  S->free_func(S->memory_manager_opaque, X); \
  |  |  358|  3.91k|  X = NULL;                                  \
  |  |  359|  3.91k|}
  ------------------
  133|       |  BROTLI_DECODER_FREE(s, s->block_type_trees);
  ------------------
  |  |  356|  3.91k|#define BROTLI_DECODER_FREE(S, X) {          \
  |  |  357|  3.91k|  S->free_func(S->memory_manager_opaque, X); \
  |  |  358|  3.91k|  X = NULL;                                  \
  |  |  359|  3.91k|}
  ------------------
  134|  3.91k|}
BrotliDecoderHuffmanTreeGroupInit:
  138|  25.4k|    uint32_t alphabet_size_limit, uint32_t ntrees) {
  139|       |  /* 376 = 256 (1-st level table) + 4 + 7 + 15 + 31 + 63 (2-nd level mix-tables)
  140|       |     This number is discovered "unlimited" "enough" calculator; it is actually
  141|       |     a wee bigger than required in several cases (especially for alphabets with
  142|       |     less than 16 symbols). */
  143|  25.4k|  const size_t max_table_size = alphabet_size_limit + 376;
  144|  25.4k|  const size_t code_size = sizeof(HuffmanCode) * ntrees * max_table_size;
  145|  25.4k|  const size_t htree_size = sizeof(HuffmanCode*) * ntrees;
  146|       |  /* Pointer alignment is, hopefully, wider than sizeof(HuffmanCode). */
  147|  25.4k|  HuffmanCode** p = (HuffmanCode**)BROTLI_DECODER_ALLOC(s,
  ------------------
  |  |  354|  25.4k|#define BROTLI_DECODER_ALLOC(S, L) S->alloc_func(S->memory_manager_opaque, L)
  ------------------
  148|  25.4k|      code_size + htree_size);
  149|  25.4k|  group->alphabet_size_max = (uint16_t)alphabet_size_max;
  150|  25.4k|  group->alphabet_size_limit = (uint16_t)alphabet_size_limit;
  151|  25.4k|  group->num_htrees = (uint16_t)ntrees;
  152|  25.4k|  group->htrees = p;
  153|  25.4k|  group->codes = (HuffmanCode*)(&p[ntrees]);
  154|  25.4k|  return !!p;
  155|  25.4k|}

_ZN7brunsli27ComputeACPredictMultipliersEPKiPiS2_:
   20|  5.79k|                                 int* mult_col) {
   21|  52.1k|  for (size_t y = 0; y < 8; ++y) {
  ------------------
  |  Branch (21:22): [True: 46.3k, False: 5.79k]
  ------------------
   22|   417k|    for (size_t x = 0; x < 8; ++x) {
  ------------------
  |  Branch (22:24): [True: 371k, False: 46.3k]
  ------------------
   23|   371k|      mult_row[x + 8 * y] =
   24|   371k|          (quant[x + 8 * y] * kSqrt2FixedPoint) / quant[y * 8];
   25|       |      // mult_col is transposed i.e. destination rows and columns are swapped.
   26|   371k|      mult_col[x * 8 + y] = (quant[x + 8 * y] * kSqrt2FixedPoint) / quant[x];
   27|   371k|    }
   28|  46.3k|  }
   29|  5.79k|}
_ZN7brunsli16ComponentStateDC7InitAllEv:
   33|  6.39k|void ComponentStateDC::InitAll() {
   34|  6.39k|  is_zero_prob.Init(135);
   35|  63.9k|  for (size_t i = 0; i < sign_prob.size(); ++i) {
  ------------------
  |  Branch (35:22): [True: 57.5k, False: 6.39k]
  ------------------
   36|  57.5k|    sign_prob[i].Init(128);
   37|  57.5k|  }
   38|  25.5k|  for (size_t i = 0; i < is_empty_block_prob.size(); ++i) {
  ------------------
  |  Branch (38:22): [True: 19.1k, False: 6.39k]
  ------------------
   39|  19.1k|    is_empty_block_prob[i].Init(74);
   40|  19.1k|  }
   41|  70.3k|  for (size_t i = 0; i < first_extra_bit_prob.size(); ++i) {
  ------------------
  |  Branch (41:22): [True: 63.9k, False: 6.39k]
  ------------------
   42|  63.9k|    first_extra_bit_prob[i].Init(150);
   43|  63.9k|  }
   44|  6.39k|}
_ZN7brunsli14ComponentState7InitAllEv:
  223|  5.79k|void ComponentState::InitAll() {
  224|  69.5k|  for (int i = 0; i < kNumNonzeroBuckets; ++i) {
  ------------------
  |  Branch (224:19): [True: 63.7k, False: 5.79k]
  ------------------
  225|  4.14M|    for (int k = 0; k < kDCTBlockSize; ++k) {
  ------------------
  |  Branch (225:21): [True: 4.08M, False: 63.7k]
  ------------------
  226|  4.08M|      const int v = kInitProb[k] + 9 * (i - 7);
  227|  4.08M|      BRUNSLI_DCHECK(v <= 255);
  228|  4.08M|      is_zero_prob[i * kDCTBlockSize + k].Init(v);
  229|  4.08M|    }
  230|  63.7k|  }
  231|  6.31M|  for (size_t i = 0; i < sign_prob.size(); ++i) {
  ------------------
  |  Branch (231:22): [True: 6.30M, False: 5.79k]
  ------------------
  232|  6.30M|    if (i < kMaxAverageContext * kDCTBlockSize) {
  ------------------
  |  Branch (232:9): [True: 2.96M, False: 3.33M]
  ------------------
  233|  2.96M|      sign_prob[i].Init(108);
  234|  3.33M|    } else if (i < (kMaxAverageContext + 1) * kDCTBlockSize) {
  ------------------
  |  Branch (234:16): [True: 371k, False: 2.96M]
  ------------------
  235|   371k|      sign_prob[i].Init(128);
  236|  2.96M|    } else {
  237|  2.96M|      sign_prob[i].Init(148);
  238|  2.96M|    }
  239|  6.30M|  }
  240|  3.71M|  for (size_t i = 0; i < first_extra_bit_prob.size(); ++i) {
  ------------------
  |  Branch (240:22): [True: 3.71M, False: 5.79k]
  ------------------
  241|  3.71M|    first_extra_bit_prob[i].Init(158);
  242|  3.71M|  }
  243|       |
  244|   191k|  for (size_t i = 0; i < kNumNonZeroContextCount; ++i) {
  ------------------
  |  Branch (244:22): [True: 185k, False: 5.79k]
  ------------------
  245|   185k|    Prob* non_zero_probs = num_nonzero_prob + i * kNumNonZeroTreeSize;
  246|  11.8M|    for (size_t j = 0; j < kNumNonZeroTreeSize; ++j) {
  ------------------
  |  Branch (246:24): [True: 11.6M, False: 185k]
  ------------------
  247|  11.6M|      non_zero_probs[j].Init(kInitProbNonzero[i][j]);
  248|  11.6M|    }
  249|   185k|  }
  250|  5.79k|}

_ZN7brunsli16ComponentStateDC8SetWidthEi:
  328|  6.39k|  void SetWidth(int w) {
  329|  6.39k|    width = w;
  330|  6.39k|    prev_is_nonempty.resize(w + 1, 1);
  331|  6.39k|    prev_abs_coeff.resize(w + 3);
  332|  6.39k|    prev_sign.resize(w + 1);
  333|  6.39k|  }
_ZN7brunsli19IsEmptyBlockContextEPKii:
  313|  41.8M|inline int IsEmptyBlockContext(const int* prev, int x) {
  314|  41.8M|  return prev[x - 1] + prev[x];
  315|  41.8M|}
_ZN7brunsli24WeightedAverageContextDCEPKii:
  168|  3.15M|inline int WeightedAverageContextDC(const int* vals, int x) {
  169|       |  // Since vals is a ringbuffer, vals[x] and vals[x + 1] refer to the
  170|       |  // previous row.
  171|  3.15M|  int sum = 1 + vals[x - 2] + vals[x - 1] + vals[x] + vals[x + 1];
  172|  3.15M|  if ((sum >> kMaxAverageContext) != 0) {
  ------------------
  |  Branch (172:7): [True: 185k, False: 2.96M]
  ------------------
  173|   185k|    return kMaxAverageContext;
  174|   185k|  }
  175|  2.96M|  return Log2FloorNonZero(sum);
  176|  3.15M|}
_ZN7brunsli14ComponentState8SetWidthEi:
  357|  5.79k|  void SetWidth(int w) {
  358|  5.79k|    width = w;
  359|  5.79k|    prev_is_nonempty.resize(w + 1, 1);
  360|  5.79k|    prev_num_nonzeros.resize(w);
  361|  5.79k|    prev_abs_coeff.resize(kDCTBlockSize * 2 * (w + 3));
  362|  5.79k|    prev_sign.resize(kDCTBlockSize * (w + 1));
  363|  5.79k|  }
_ZN7brunsli18NumNonzerosContextEPKhii:
  288|  1.68M|inline uint8_t NumNonzerosContext(const uint8_t* prev, int x, int y) {
  289|  1.68M|  size_t prediction;
  290|  1.68M|  if (y == 0) {
  ------------------
  |  Branch (290:7): [True: 117k, False: 1.56M]
  ------------------
  291|   117k|    if (x == 0) {
  ------------------
  |  Branch (291:9): [True: 2.93k, False: 114k]
  ------------------
  292|       |      // Special case: top-left block.
  293|  2.93k|      prediction = 0;
  294|   114k|    } else {
  295|       |      // No row above; use block at left.
  296|   114k|      prediction = prev[x - 1];
  297|   114k|    }
  298|  1.56M|  } else if (x == 0) {
  ------------------
  |  Branch (298:14): [True: 34.4k, False: 1.52M]
  ------------------
  299|       |    // No column to the left; use block above.
  300|  34.4k|    prediction = prev[x];
  301|  1.52M|  } else {
  302|       |    // Average of left and above blocks.
  303|  1.52M|    prediction = (prev[x - 1] + prev[x] + 1) / 2;
  304|  1.52M|  }
  305|  1.68M|  BRUNSLI_DCHECK(prediction <= kNumNonZeroTreeSize);
  306|  1.68M|  return static_cast<uint8_t>(prediction / kNumNonZeroQuant);
  307|  1.68M|}
_ZN7brunsli19ACPredictContextRowEPKsS1_PKiPmS4_:
  262|   840k|                               const int* mult, size_t* avg_ctx, size_t* sgn) {
  263|   840k|  coeff_t terms[8];
  264|   840k|  terms[0] = 0;
  265|   840k|  terms[1] = cur[8] + prev[8];
  266|   840k|  terms[2] = cur[16] - prev[16];
  267|   840k|  terms[3] = cur[24] + prev[24];
  268|   840k|  terms[4] = cur[32] - prev[32];
  269|   840k|  terms[5] = cur[40] + prev[40];
  270|   840k|  terms[6] = cur[48] - prev[48];
  271|   840k|  terms[7] = cur[56] + prev[56];
  272|   840k|  int64_t delta = terms[0] * static_cast<int64_t>(mult[0]) +
  273|   840k|                  terms[1] * static_cast<int64_t>(mult[1]) +
  274|   840k|                  terms[2] * static_cast<int64_t>(mult[2]) +
  275|   840k|                  terms[3] * static_cast<int64_t>(mult[3]) +
  276|   840k|                  terms[4] * static_cast<int64_t>(mult[4]) +
  277|   840k|                  terms[5] * static_cast<int64_t>(mult[5]) +
  278|   840k|                  terms[6] * static_cast<int64_t>(mult[6]) +
  279|   840k|                  terms[7] * static_cast<int64_t>(mult[7]);
  280|   840k|  ACPredictContext(prev[0] - delta / kACPredictPrecision, avg_ctx, sgn);
  281|   840k|}
_ZN7brunsli16ACPredictContextElPmS0_:
  220|  1.82M|inline void ACPredictContext(int64_t p, size_t* avg_ctx, size_t* sgn) {
  221|  1.82M|  int multiplier;
  222|  1.82M|  if (p >= 0) {
  ------------------
  |  Branch (222:7): [True: 1.09M, False: 727k]
  ------------------
  223|  1.09M|    multiplier = 1;
  224|  1.09M|  } else {
  225|   727k|    multiplier = -1;
  226|   727k|    p = -p;
  227|   727k|  }
  228|  1.82M|  size_t ctx;
  229|  1.82M|  if (p >= (1u << kMaxAverageContext)) {
  ------------------
  |  Branch (229:7): [True: 1.05M, False: 766k]
  ------------------
  230|  1.05M|    ctx = kMaxAverageContext;
  231|  1.05M|  } else {
  232|       |    // 0 -> 0, 1 -> 1, 2..3 -> 2, 4..7 -> 3, etc.
  233|   766k|    ctx = Log2FloorNonZero(2 * static_cast<uint32_t>(p)+ 1);
  234|   766k|  }
  235|  1.82M|  *avg_ctx = ctx;
  236|  1.82M|  *sgn = kMaxAverageContext + multiplier * ctx;
  237|  1.82M|}
_ZN7brunsli19ACPredictContextColEPKsS1_PKiPmS4_:
  240|   982k|                                const int* mult, size_t* avg_ctx, size_t* sgn) {
  241|   982k|  coeff_t terms[8];
  242|   982k|  terms[0] = 0;
  243|   982k|  terms[1] = cur[1] + prev[1];
  244|   982k|  terms[2] = cur[2] - prev[2];
  245|   982k|  terms[3] = cur[3] + prev[3];
  246|   982k|  terms[4] = cur[4] - prev[4];
  247|   982k|  terms[5] = cur[5] + prev[5];
  248|   982k|  terms[6] = cur[6] - prev[6];
  249|   982k|  terms[7] = cur[7] + prev[7];
  250|   982k|  int64_t delta = terms[0] * static_cast<int64_t>(mult[0]) +
  251|   982k|                  terms[1] * static_cast<int64_t>(mult[1]) +
  252|   982k|                  terms[2] * static_cast<int64_t>(mult[2]) +
  253|   982k|                  terms[3] * static_cast<int64_t>(mult[3]) +
  254|   982k|                  terms[4] * static_cast<int64_t>(mult[4]) +
  255|   982k|                  terms[5] * static_cast<int64_t>(mult[5]) +
  256|   982k|                  terms[6] * static_cast<int64_t>(mult[6]) +
  257|   982k|                  terms[7] * static_cast<int64_t>(mult[7]);
  258|   982k|  ACPredictContext(prev[0] - delta / kACPredictPrecision, avg_ctx, sgn);
  259|   982k|}
_ZN7brunsli22WeightedAverageContextEPKii:
  203|  2.54M|inline int WeightedAverageContext(const int* vals, int prev_row_delta) {
  204|  2.54M|  int sum = 4 + vals[0] + (vals[-kDCTBlockSize] + vals[prev_row_delta]) * 2 +
  205|  2.54M|            vals[-2 * kDCTBlockSize] + vals[prev_row_delta - kDCTBlockSize] +
  206|  2.54M|            vals[prev_row_delta + kDCTBlockSize];
  207|  2.54M|  if ((sum >> (kMaxAverageContext + 2)) != 0) {
  ------------------
  |  Branch (207:7): [True: 705k, False: 1.83M]
  ------------------
  208|   705k|    return kMaxAverageContext;
  209|   705k|  }
  210|  1.83M|  return Log2FloorNonZero(sum) - 2;
  211|  2.54M|}
_ZN7brunsli18ZeroDensityContextEmmm:
  161|  4.44M|                                   size_t bits) {
  162|  4.44M|  return kNumNonzeroContext[bits][nonzeros_left] + kFreqContext[bits][k];
  163|  4.44M|}
_ZN7brunsli16ComponentStateDCC2Ev:
  321|  6.39k|      : width(0),
  322|  6.39k|        is_empty_block_prob(kNumIsEmptyBlockContexts),
  323|  6.39k|        sign_prob(9),
  324|  6.39k|        first_extra_bit_prob(10) {
  325|  6.39k|    InitAll();
  326|  6.39k|  }
_ZN7brunsli14ComponentStateC2Ev:
  350|  5.79k|      : width(0),
  351|  5.79k|        is_zero_prob(kNumNonzeroBuckets * kDCTBlockSize),
  352|  5.79k|        sign_prob((2 * kMaxAverageContext + 1) * kDCTBlockSize),
  353|  5.79k|        first_extra_bit_prob(10 * kDCTBlockSize) {
  354|  5.79k|    InitAll();
  355|  5.79k|  }

_ZNK7brunsli4Prob9get_probaEv:
   92|   104M|  uint8_t get_proba() const { return prob8; }
_ZN7brunsli4Prob3AddEi:
   78|   104M|  void Add(int val) {
   79|   104M|    ++total;
   80|   104M|    if (val == 0) {
  ------------------
  |  Branch (80:9): [True: 49.3M, False: 54.9M]
  ------------------
   81|  49.3M|      count += 256;
   82|  54.9M|    } else {
   83|  54.9M|      ++count;
   84|  54.9M|    }
   85|   104M|    prob8 = impl::FastDivide(count, total);
   86|   104M|    if (total == impl::kNormalizeThreshold) {
  ------------------
  |  Branch (86:9): [True: 765k, False: 103M]
  ------------------
   87|   765k|      count >>= 1;
   88|   765k|      total = impl::kNormalizeThreshold >> 1;
   89|   765k|    }
   90|   104M|  }
brunsli_decode.cc:_ZN7brunsli4implL10FastDivideEjh:
   53|   104M|                                         uint8_t denominator) {
   54|   104M|  uint32_t result = (numerator * kDivLut17[denominator]) >> 17;
   55|   104M|  BRUNSLI_DCHECK(result < 256);
   56|   104M|  return static_cast<uint8_t>(result);
   57|   104M|}
_ZN7brunsli4ProbC2Ev:
   67|  25.9M|  Prob(): prob8(impl::kInitProb),
   68|  25.9M|        total(impl::kInitProbCount),
   69|  25.9M|        count(impl::kInitProb * impl::kInitProbCount) {}
_ZN7brunsli4ProbD2Ev:
   70|  25.9M|  ~Prob() {}
_ZN7brunsli4Prob4InitEh:
   72|  25.9M|  void Init(uint8_t probability) {
   73|  25.9M|    prob8 = probability;
   74|  25.9M|    total = impl::kInitProbCount;
   75|  25.9M|    count = impl::kInitProbCount * probability;
   76|  25.9M|  }

_ZN7brunsli27GetPopulationCountPrecisionEj:
   16|  19.4k|inline uint32_t GetPopulationCountPrecision(uint32_t logcount) {
   17|  19.4k|  return (logcount + 1) >> 1;
   18|  19.4k|}

_ZN7brunsli16DecodeLehmerCodeEPKjmPj:
   27|  5.39k|bool DecodeLehmerCode(const uint32_t* code, size_t len, uint32_t* sigma) {
   28|  5.39k|  std::vector<uint32_t> items(len);
   29|   350k|  for (size_t i = 0; i < len; ++i) items[i] = static_cast<uint32_t>(i);
  ------------------
  |  Branch (29:22): [True: 345k, False: 5.39k]
  ------------------
   30|   350k|  for (size_t i = 0; i < len; ++i) {
  ------------------
  |  Branch (30:22): [True: 344k, False: 5.38k]
  ------------------
   31|   344k|    uint32_t index = code[i];
   32|   344k|    if (index >= items.size()) return false;
  ------------------
  |  Branch (32:9): [True: 11, False: 344k]
  ------------------
   33|   344k|    const uint32_t value = items[index];
   34|   344k|    items.erase(items.begin() + index);
   35|   344k|    sigma[i] = value;
   36|   344k|  }
   37|  5.38k|  return true;
   38|  5.39k|}

_ZN7brunsli16PermutationCoder4InitENSt3__16vectorIhNS1_9allocatorIhEEEE:
   40|  10.3k|  void Init(std::vector<uint8_t> values) {
   41|  10.3k|    values_ = std::move(values);
   42|  10.3k|  }
_ZNK7brunsli16PermutationCoder8num_bitsEv:
   49|  71.4k|  int num_bits() const {
   50|  71.4k|    uint32_t num_values = static_cast<uint32_t>(values_.size());
   51|  71.4k|    BRUNSLI_DCHECK(num_values > 0);
   52|  71.4k|    if (num_values <= 1) return 0;
  ------------------
  |  Branch (52:9): [True: 71, False: 71.4k]
  ------------------
   53|  71.4k|    return static_cast<int>(Log2FloorNonZero(num_values - 1) + 1);
   54|  71.4k|  }
_ZN7brunsli16PermutationCoder6RemoveEmPh:
   58|  71.4k|  bool Remove(size_t code, uint8_t* value) {
   59|  71.4k|    if (code >= values_.size()) {
  ------------------
  |  Branch (59:9): [True: 15, False: 71.4k]
  ------------------
   60|     15|      return false;
   61|     15|    }
   62|  71.4k|    *value = values_[code];
   63|  71.4k|    values_.erase(values_.begin() + code);
   64|  71.4k|    return true;
   65|  71.4k|  }
_ZN7brunsli16PermutationCoder5ClearEv:
   44|  10.6k|  void Clear() {
   45|  10.6k|    std::vector<uint8_t>().swap(values_);
   46|  10.6k|  }
_ZN7brunsli16PermutationCoderC2Ev:
   38|  21.1k|  PermutationCoder() {}

_Z16Log2FloorNonZeroj:
  466|  18.1M|inline int Log2FloorNonZero(uint32_t n) {
  467|  18.1M|#ifdef __GNUC__
  468|  18.1M|  return 31 ^ __builtin_clz(n);
  469|       |#else
  470|       |  unsigned int result = 0;
  471|       |  while (n >>= 1) result++;
  472|       |  return result;
  473|       |#endif
  474|  18.1M|}
brunsli_decode.cc:_ZN7brunsliL6AppendEPNSt3__16vectorIhNS0_9allocatorIhEEEEPKhS7_:
  437|   186k|                                  const uint8_t* begin, const uint8_t* end) {
  438|   186k|  dst->insert(dst->end(), begin, end);
  439|   186k|}
brunsli_decode.cc:_ZN7brunsliL6AppendEPNSt3__16vectorIhNS0_9allocatorIhEEEEPKhm:
  441|   159k|                                  const uint8_t* begin, size_t length) {
  442|   159k|  Append(dst, begin, begin + length);
  443|   159k|}
brunsli_decode.cc:_ZL22BrunsliUnalignedRead16PKv:
  284|  3.86M|static BRUNSLI_INLINE uint16_t BrunsliUnalignedRead16(const void* p) {
  285|  3.86M|  uint16_t t;
  286|  3.86M|  memcpy(&t, p, sizeof t);
  287|  3.86M|  return t;
  288|  3.86M|}

_ZN7brunsli25PredictWithAdaptiveMedianEPKsiii:
   29|  41.8M|int PredictWithAdaptiveMedian(const coeff_t* coeffs, int x, int y, int stride) {
   30|  41.8M|  const int offset1 = -kDCTBlockSize;
   31|  41.8M|  const int offset2 = -stride;
   32|  41.8M|  const int offset3 = offset2 + offset1;
   33|  41.8M|  if (y != 0) {
  ------------------
  |  Branch (33:7): [True: 40.8M, False: 999k]
  ------------------
   34|  40.8M|    if (x != 0) {
  ------------------
  |  Branch (34:9): [True: 40.4M, False: 375k]
  ------------------
   35|  40.4M|      return AdaptiveMedian(coeffs[offset1], coeffs[offset2], coeffs[offset3]);
   36|  40.4M|    } else {
   37|   375k|      return coeffs[offset2];
   38|   375k|    }
   39|  40.8M|  } else {
   40|   999k|    return x ? coeffs[offset1] : 0;
  ------------------
  |  Branch (40:12): [True: 992k, False: 6.27k]
  ------------------
   41|   999k|  }
   42|  41.8M|}
predict.cc:_ZN7brunsli12_GLOBAL__N_114AdaptiveMedianEiii:
   15|  40.4M|int AdaptiveMedian(int w, int n, int nw) {
   16|  40.4M|  const int mx = (w > n) ? w : n;
  ------------------
  |  Branch (16:18): [True: 7.84M, False: 32.6M]
  ------------------
   17|  40.4M|  const int mn = w + n - mx;
   18|  40.4M|  if (nw > mx) {
  ------------------
  |  Branch (18:7): [True: 1.42M, False: 39.0M]
  ------------------
   19|  1.42M|    return mn;
   20|  39.0M|  } else if (nw < mn) {
  ------------------
  |  Branch (20:14): [True: 1.11M, False: 37.9M]
  ------------------
   21|  1.11M|    return mx;
   22|  37.9M|  } else {
   23|  37.9M|    return n + w - nw;
   24|  37.9M|  }
   25|  40.4M|}

_ZN7brunsli15FillQuantMatrixEbjPh:
   17|    851|                     uint8_t dst[kDCTBlockSize]) {
   18|    851|  BRUNSLI_DCHECK(q >= 0 && q < kQFactorLimit);
   19|    851|  const uint8_t* const in = kDefaultQuantMatrix[is_chroma];
   20|  55.3k|  for (int i = 0; i < kDCTBlockSize; ++i) {
  ------------------
  |  Branch (20:19): [True: 54.4k, False: 851]
  ------------------
   21|  54.4k|    const uint32_t v = (in[i] * q + 32) >> 6;
   22|       |    // clamp to prevent illegal quantizer values
   23|  54.4k|    dst[i] = (v < 1) ? 1 : (v > 255) ? 255u : v;
  ------------------
  |  Branch (23:14): [True: 14.2k, False: 40.1k]
  |  Branch (23:28): [True: 0, False: 40.1k]
  ------------------
   24|  54.4k|  }
   25|    851|}

_ZN7brunsli15ANSDecodingData4InitERKNSt3__16vectorIjNS1_9allocatorIjEEEE:
   15|  11.5k|bool ANSDecodingData::Init(const std::vector<uint32_t>& counts) {
   16|  11.5k|  size_t pos = 0;
   17|   218k|  for (size_t i = 0; i < counts.size(); ++i) {
  ------------------
  |  Branch (17:22): [True: 207k, False: 11.5k]
  ------------------
   18|  11.9M|    for (size_t j = 0; j < counts[i]; ++j, ++pos) {
  ------------------
  |  Branch (18:24): [True: 11.7M, False: 207k]
  ------------------
   19|  11.7M|      map_[pos].symbol_ = static_cast<uint8_t>(i);
   20|  11.7M|      map_[pos].freq_ = static_cast<uint16_t>(counts[i]);
   21|  11.7M|      map_[pos].offset_ = static_cast<uint16_t>(j);
   22|  11.7M|    }
   23|   207k|  }
   24|  11.5k|  return (pos == BRUNSLI_ANS_TAB_SIZE);
   25|  11.5k|}

_ZN7brunsli10ANSDecoder4InitEPNS_10WordSourceE:
   39|  10.8k|  void Init(WordSource* in) {
   40|  10.8k|    state_ = in->GetNextWord();
   41|  10.8k|    state_ = (state_ << 16u) | in->GetNextWord();
   42|  10.8k|  }
_ZNK7brunsli10ANSDecoder8CheckCRCEv:
   53|  10.4k|  bool CheckCRC() const { return state_ == (BRUNSLI_ANS_SIGNATURE << 16u); }
  ------------------
  |  |   18|  10.4k|#define BRUNSLI_ANS_SIGNATURE 0x13u  // Initial state, used as CRC.
  ------------------
_ZN7brunsli10ANSDecoder10ReadSymbolERKNS_15ANSDecodingDataEPNS_10WordSourceE:
   44|  7.59M|  int ReadSymbol(const ANSDecodingData& code, WordSource* in) {
   45|  7.59M|    const uint32_t res = state_ & (BRUNSLI_ANS_TAB_SIZE - 1);
   46|  7.59M|    const ANSSymbolInfo& s = code.map_[res];
   47|  7.59M|    state_ = s.freq_ * (state_ >> BRUNSLI_ANS_LOG_TAB_SIZE) + s.offset_;
   48|  7.59M|    if (state_ < (1u << 16u)) {
  ------------------
  |  Branch (48:9): [True: 512k, False: 7.08M]
  ------------------
   49|   512k|      state_ = (state_ << 16u) | in->GetNextWord();
   50|   512k|    }
   51|  7.59M|    return s.symbol_;
   52|  7.59M|  }
_ZN7brunsli15ANSDecodingDataC2Ev:
   28|  87.8k|  ANSDecodingData() {}
_ZN7brunsli10ANSDecoderC2Ev:
   37|  21.1k|  ANSDecoder() {}

_ZN7brunsli23BinaryArithmeticDecoder4InitEPNS_10WordSourceE:
   22|  10.8k|  void Init(WordSource* in) {
   23|  10.8k|    low_ = 0;
   24|  10.8k|    high_ = ~0u;
   25|  10.8k|    value_ = in->GetNextWord();
   26|  10.8k|    value_ = (value_ << 16u) | in->GetNextWord();
   27|  10.8k|  }
_ZN7brunsli23BinaryArithmeticDecoder7ReadBitEiPNS_10WordSourceE:
   32|   104M|  int ReadBit(int prob, WordSource* in) {
   33|   104M|    const uint32_t diff = high_ - low_;
   34|   104M|    const uint32_t split = low_ + (((uint64_t)diff * prob) >> 8u);
   35|   104M|    int bit;
   36|   104M|    if (value_ > split) {
  ------------------
  |  Branch (36:9): [True: 54.9M, False: 49.3M]
  ------------------
   37|  54.9M|      low_ = split + 1;
   38|  54.9M|      bit = 1;
   39|  54.9M|    } else {
   40|  49.3M|      high_ = split;
   41|  49.3M|      bit = 0;
   42|  49.3M|    }
   43|   104M|    if (((low_ ^ high_) >> 16u) == 0) {
  ------------------
  |  Branch (43:9): [True: 1.89M, False: 102M]
  ------------------
   44|  1.89M|      value_ = (value_ << 16u) | in->GetNextWord();
   45|  1.89M|      low_ <<= 16u;
   46|  1.89M|      high_ <<= 16u;
   47|  1.89M|      high_ |= 0xFFFFu;
   48|  1.89M|    }
   49|   104M|    return bit;
   50|   104M|  }
_ZN7brunsli23BinaryArithmeticDecoderC2Ev:
   20|  21.1k|  BinaryArithmeticDecoder() {}

_ZN7brunsli20BrunsliBitReaderInitEPNS_16BrunsliBitReaderE:
   13|  26.1k|void BrunsliBitReaderInit(BrunsliBitReader* br) {
   14|  26.1k|  br->num_bits_ = 0;
   15|  26.1k|  br->bits_ = 0;
   16|  26.1k|  br->num_debt_bytes_ = 0;
   17|  26.1k|  br->is_healthy_ = true;
   18|  26.1k|  br->is_optimistic_ = false;
   19|  26.1k|}
_ZN7brunsli22BrunsliBitReaderResumeEPNS_16BrunsliBitReaderEPKhm:
   22|  26.1k|                              size_t length) {
   23|  26.1k|  br->next_ = buffer;
   24|  26.1k|  br->end_ = buffer + length;
   25|  26.1k|  br->is_optimistic_ = false;
   26|  26.1k|}
_ZN7brunsli23BrunsliBitReaderSuspendEPNS_16BrunsliBitReaderE:
   49|  26.1k|size_t BrunsliBitReaderSuspend(BrunsliBitReader* br) {
   50|  26.1k|  BrunsliBitReaderUnload(br);
   51|  26.1k|  size_t unused_bytes = br->end_ - br->next_;
   52|  26.1k|  br->next_ = nullptr;
   53|  26.1k|  br->end_ = nullptr;
   54|  26.1k|  return unused_bytes;
   55|  26.1k|}
_ZN7brunsli22BrunsliBitReaderFinishEPNS_16BrunsliBitReaderE:
   57|  21.2k|void BrunsliBitReaderFinish(BrunsliBitReader* br) {
   58|  21.2k|  uint32_t n_bits = br->num_bits_;
   59|       |  // Likely, did not invoke Suspend before.
   60|  21.2k|  if (n_bits >= 8) {
  ------------------
  |  Branch (60:7): [True: 0, False: 21.2k]
  ------------------
   61|      0|    br->is_healthy_ = false;
   62|      0|    return;
   63|      0|  }
   64|  21.2k|  if (n_bits > 0) {
  ------------------
  |  Branch (64:7): [True: 15.0k, False: 6.19k]
  ------------------
   65|  15.0k|    uint32_t padding_bits = BrunsliBitReaderRead(br, n_bits);
   66|  15.0k|    if (padding_bits != 0) br->is_healthy_ = false;
  ------------------
  |  Branch (66:9): [True: 21, False: 15.0k]
  ------------------
   67|  15.0k|  }
   68|  21.2k|}
_ZN7brunsli25BrunsliBitReaderIsHealthyEPNS_16BrunsliBitReaderE:
   70|  48.5k|bool BrunsliBitReaderIsHealthy(BrunsliBitReader* br) {
   71|  48.5k|  BrunsliBitReaderUnload(br);
   72|  48.5k|  return (br->num_debt_bytes_ == 0) && (br->is_healthy_);
  ------------------
  |  Branch (72:10): [True: 48.2k, False: 336]
  |  Branch (72:40): [True: 48.2k, False: 21]
  ------------------
   73|  48.5k|}
_ZN7brunsli29BrunsliBitReaderSetOptimisticEPNS_16BrunsliBitReaderE:
   75|  6.40k|void BrunsliBitReaderSetOptimistic(BrunsliBitReader* br) {
   76|  6.40k|  br->is_optimistic_ = true;
   77|  6.40k|}
_ZN7brunsli23BrunsliBitReaderCanReadEPNS_16BrunsliBitReaderEm:
   79|  6.98M|bool BrunsliBitReaderCanRead(BrunsliBitReader* br, size_t n_bits) {
   80|  6.98M|  if (br->is_optimistic_) return true;
  ------------------
  |  Branch (80:7): [True: 841k, False: 6.14M]
  ------------------
   81|  6.14M|  if (br->num_debt_bytes_ != 0) return false;
  ------------------
  |  Branch (81:7): [True: 0, False: 6.14M]
  ------------------
   82|  6.14M|  if (br->num_bits_ >= n_bits) return true;
  ------------------
  |  Branch (82:7): [True: 2.11M, False: 4.02M]
  ------------------
   83|  4.02M|  size_t num_extra_bytes = (n_bits - br->num_bits_ + 7) >> 3;
   84|  4.02M|  return (br->next_ + num_extra_bytes <= br->end_);
   85|  6.14M|}
bit_reader.cc:_ZN7brunsliL22BrunsliBitReaderUnloadEPNS_16BrunsliBitReaderE:
   35|  74.7k|static BRUNSLI_INLINE void BrunsliBitReaderUnload(BrunsliBitReader* br) {
   36|       |  // Cancel the overdraft.
   37|  74.8k|  while ((br->num_debt_bytes_ > 0) && (br->num_bits_ >= 8)) {
  ------------------
  |  Branch (37:10): [True: 1.00k, False: 73.8k]
  |  Branch (37:39): [True: 159, False: 842]
  ------------------
   38|    159|    br->num_debt_bytes_--;
   39|    159|    br->num_bits_ -= 8;
   40|    159|  }
   41|       |  // Return unused bytes.
   42|  75.1k|  while (br->num_bits_ >= 8) {
  ------------------
  |  Branch (42:10): [True: 471, False: 74.7k]
  ------------------
   43|    471|    br->next_--;
   44|    471|    br->num_bits_ -= 8;
   45|    471|  }
   46|  74.7k|  br->bits_ &= BrunsliBitReaderBitMask(br->num_bits_);
   47|  74.7k|}

_ZN7brunsli20BrunsliBitReaderReadEPNS_16BrunsliBitReaderEj:
  127|  6.41M|                                                    uint32_t n_bits) {
  128|  6.41M|  uint32_t result = BrunsliBitReaderGet(br, n_bits);
  129|  6.41M|  BrunsliBitReaderDrop(br, n_bits);
  130|  6.41M|  return result;
  131|  6.41M|}
brunsli_decode.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|  6.25M|                                                   uint32_t n_bits) {
  110|  6.25M|  BRUNSLI_DCHECK(n_bits <= 24);
  111|  6.25M|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|  6.25M|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 2.49k, False: 6.25M]
  ------------------
  113|  2.49k|    BrunsliBitReaderMaybeFetchByte(br, n_bits);
  114|  2.49k|    if (n_bits > 16) BrunsliBitReaderMaybeFetchByte(br, n_bits);
  ------------------
  |  Branch (114:9): [True: 0, False: 2.49k]
  ------------------
  115|  2.49k|  }
  116|  6.25M|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|  6.25M|}
brunsli_decode.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|  6.26M|                                                          uint32_t n_bits) {
   81|  6.26M|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 3.95M, False: 2.30M]
  ------------------
   82|  3.95M|    if (BRUNSLI_PREDICT_FALSE(br->next_ >= br->end_)) {
  ------------------
  |  |   85|  3.95M|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 41, False: 3.95M]
  |  |  ------------------
  ------------------
   83|     41|      BrunsliBitReaderOweByte(br);
   84|  3.95M|    } else {
   85|  3.95M|      br->bits_ |= static_cast<uint32_t>(*br->next_) << br->num_bits_;
   86|  3.95M|      br->num_bits_ += 8;
   87|  3.95M|      br->next_++;
   88|  3.95M|    }
   89|  3.95M|  }
   90|  6.26M|}
brunsli_decode.cc:_ZN7brunsliL23BrunsliBitReaderOweByteEPNS_16BrunsliBitReaderE:
   73|     41|static BRUNSLI_INLINE void BrunsliBitReaderOweByte(BrunsliBitReader* br) {
   74|     41|  br->num_bits_ += 8;
   75|     41|  br->num_debt_bytes_++;
   76|     41|}
brunsli_decode.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|  6.25M|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|  6.25M|  return ~((0xFFFFFFFFu) << n);
   70|  6.25M|}
brunsli_decode.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|  6.25M|                                                uint32_t n_bits) {
  121|  6.25M|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|  6.25M|  br->bits_ >>= n_bits;
  123|  6.25M|  br->num_bits_ -= n_bits;
  124|  6.25M|}
context_map_decode.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|  5.73k|                                                   uint32_t n_bits) {
  110|  5.73k|  BRUNSLI_DCHECK(n_bits <= 24);
  111|  5.73k|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|  5.73k|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 125, False: 5.61k]
  ------------------
  113|    125|    BrunsliBitReaderMaybeFetchByte(br, n_bits);
  114|    125|    if (n_bits > 16) BrunsliBitReaderMaybeFetchByte(br, n_bits);
  ------------------
  |  Branch (114:9): [True: 0, False: 125]
  ------------------
  115|    125|  }
  116|  5.73k|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|  5.73k|}
context_map_decode.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|  5.86k|                                                          uint32_t n_bits) {
   81|  5.86k|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 793, False: 5.06k]
  ------------------
   82|    793|    if (BRUNSLI_PREDICT_FALSE(br->next_ >= br->end_)) {
  ------------------
  |  |   85|    793|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 484, False: 309]
  |  |  ------------------
  ------------------
   83|    484|      BrunsliBitReaderOweByte(br);
   84|    484|    } else {
   85|    309|      br->bits_ |= static_cast<uint32_t>(*br->next_) << br->num_bits_;
   86|    309|      br->num_bits_ += 8;
   87|    309|      br->next_++;
   88|    309|    }
   89|    793|  }
   90|  5.86k|}
context_map_decode.cc:_ZN7brunsliL23BrunsliBitReaderOweByteEPNS_16BrunsliBitReaderE:
   73|    484|static BRUNSLI_INLINE void BrunsliBitReaderOweByte(BrunsliBitReader* br) {
   74|    484|  br->num_bits_ += 8;
   75|    484|  br->num_debt_bytes_++;
   76|    484|}
context_map_decode.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|  5.73k|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|  5.73k|  return ~((0xFFFFFFFFu) << n);
   70|  5.73k|}
context_map_decode.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|  5.73k|                                                uint32_t n_bits) {
  121|  5.73k|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|  5.73k|  br->bits_ >>= n_bits;
  123|  5.73k|  br->num_bits_ -= n_bits;
  124|  5.73k|}
histogram_decode.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|   133k|                                                   uint32_t n_bits) {
  110|   133k|  BRUNSLI_DCHECK(n_bits <= 24);
  111|   133k|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|   133k|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 2.39k, False: 131k]
  ------------------
  113|  2.39k|    BrunsliBitReaderMaybeFetchByte(br, n_bits);
  114|  2.39k|    if (n_bits > 16) BrunsliBitReaderMaybeFetchByte(br, n_bits);
  ------------------
  |  Branch (114:9): [True: 0, False: 2.39k]
  ------------------
  115|  2.39k|  }
  116|   133k|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|   133k|}
histogram_decode.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|   135k|                                                          uint32_t n_bits) {
   81|   135k|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 29.8k, False: 105k]
  ------------------
   82|  29.8k|    if (BRUNSLI_PREDICT_FALSE(br->next_ >= br->end_)) {
  ------------------
  |  |   85|  29.8k|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 835, False: 29.0k]
  |  |  ------------------
  ------------------
   83|    835|      BrunsliBitReaderOweByte(br);
   84|  29.0k|    } else {
   85|  29.0k|      br->bits_ |= static_cast<uint32_t>(*br->next_) << br->num_bits_;
   86|  29.0k|      br->num_bits_ += 8;
   87|  29.0k|      br->next_++;
   88|  29.0k|    }
   89|  29.8k|  }
   90|   135k|}
histogram_decode.cc:_ZN7brunsliL23BrunsliBitReaderOweByteEPNS_16BrunsliBitReaderE:
   73|    835|static BRUNSLI_INLINE void BrunsliBitReaderOweByte(BrunsliBitReader* br) {
   74|    835|  br->num_bits_ += 8;
   75|    835|  br->num_debt_bytes_++;
   76|    835|}
histogram_decode.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|   133k|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|   133k|  return ~((0xFFFFFFFFu) << n);
   70|   133k|}
histogram_decode.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|   133k|                                                uint32_t n_bits) {
  121|   133k|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|   133k|  br->bits_ >>= n_bits;
  123|   133k|  br->num_bits_ -= n_bits;
  124|   133k|}
huffman_decode.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|   930k|                                                   uint32_t n_bits) {
  110|   930k|  BRUNSLI_DCHECK(n_bits <= 24);
  111|   930k|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|   930k|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 128, False: 929k]
  ------------------
  113|    128|    BrunsliBitReaderMaybeFetchByte(br, n_bits);
  114|    128|    if (n_bits > 16) BrunsliBitReaderMaybeFetchByte(br, n_bits);
  ------------------
  |  Branch (114:9): [True: 0, False: 128]
  ------------------
  115|    128|  }
  116|   930k|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|   930k|}
huffman_decode.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|   930k|                                                          uint32_t n_bits) {
   81|   930k|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 98.4k, False: 831k]
  ------------------
   82|  98.4k|    if (BRUNSLI_PREDICT_FALSE(br->next_ >= br->end_)) {
  ------------------
  |  |   85|  98.4k|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 86.3k, False: 12.0k]
  |  |  ------------------
  ------------------
   83|  86.3k|      BrunsliBitReaderOweByte(br);
   84|  86.3k|    } else {
   85|  12.0k|      br->bits_ |= static_cast<uint32_t>(*br->next_) << br->num_bits_;
   86|  12.0k|      br->num_bits_ += 8;
   87|  12.0k|      br->next_++;
   88|  12.0k|    }
   89|  98.4k|  }
   90|   930k|}
huffman_decode.cc:_ZN7brunsliL23BrunsliBitReaderOweByteEPNS_16BrunsliBitReaderE:
   73|  86.3k|static BRUNSLI_INLINE void BrunsliBitReaderOweByte(BrunsliBitReader* br) {
   74|  86.3k|  br->num_bits_ += 8;
   75|  86.3k|  br->num_debt_bytes_++;
   76|  86.3k|}
huffman_decode.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|   930k|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|   930k|  return ~((0xFFFFFFFFu) << n);
   70|   930k|}
huffman_decode.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|   930k|                                                uint32_t n_bits) {
  121|   930k|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|   930k|  br->bits_ >>= n_bits;
  123|   930k|  br->num_bits_ -= n_bits;
  124|   930k|}
bit_reader.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|  89.8k|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|  89.8k|  return ~((0xFFFFFFFFu) << n);
   70|  89.8k|}
bit_reader.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|  15.0k|                                                   uint32_t n_bits) {
  110|  15.0k|  BRUNSLI_DCHECK(n_bits <= 24);
  111|  15.0k|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|  15.0k|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 0, False: 15.0k]
  ------------------
  113|      0|    BrunsliBitReaderMaybeFetchByte(br, n_bits);
  114|      0|    if (n_bits > 16) BrunsliBitReaderMaybeFetchByte(br, n_bits);
  ------------------
  |  Branch (114:9): [True: 0, False: 0]
  ------------------
  115|      0|  }
  116|  15.0k|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|  15.0k|}
bit_reader.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|  15.0k|                                                          uint32_t n_bits) {
   81|  15.0k|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 0, False: 15.0k]
  ------------------
   82|      0|    if (BRUNSLI_PREDICT_FALSE(br->next_ >= br->end_)) {
  ------------------
  |  |   85|      0|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 0, False: 0]
  |  |  ------------------
  ------------------
   83|      0|      BrunsliBitReaderOweByte(br);
   84|      0|    } else {
   85|      0|      br->bits_ |= static_cast<uint32_t>(*br->next_) << br->num_bits_;
   86|      0|      br->num_bits_ += 8;
   87|      0|      br->next_++;
   88|      0|    }
   89|      0|  }
   90|  15.0k|}
bit_reader.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|  15.0k|                                                uint32_t n_bits) {
  121|  15.0k|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|  15.0k|  br->bits_ >>= n_bits;
  123|  15.0k|  br->num_bits_ -= n_bits;
  124|  15.0k|}

_ZN7brunsli12DecodeVarintEPNS_8internal3dec11VarintStateEPNS_16BrunsliBitReaderEm:
   99|   145k|bool DecodeVarint(VarintState* s, BrunsliBitReader* br, size_t max_bits) {
  100|   145k|  if (s->stage == VarintState::INIT) {
  ------------------
  |  Branch (100:7): [True: 145k, False: 0]
  ------------------
  101|   145k|    s->value = 0;
  102|   145k|    s->i = 0;
  103|   145k|    s->stage = VarintState::READ_CONTINUATION;
  104|   145k|  }
  105|       |
  106|   530k|  while (true) {
  ------------------
  |  Branch (106:10): [True: 530k, Folded]
  ------------------
  107|   530k|    switch (s->stage) {
  108|   337k|      case VarintState::READ_CONTINUATION: {
  ------------------
  |  Branch (108:7): [True: 337k, False: 192k]
  ------------------
  109|   337k|        if (s->i >= max_bits) {
  ------------------
  |  Branch (109:13): [True: 424, False: 337k]
  ------------------
  110|    424|          s->stage = VarintState::INIT;
  111|    424|          return true;
  112|    424|        }
  113|   337k|        if (s->i + 1 != max_bits) {
  ------------------
  |  Branch (113:13): [True: 336k, False: 425]
  ------------------
  114|   336k|          if (!BrunsliBitReaderCanRead(br, 1)) return false;
  ------------------
  |  Branch (114:15): [True: 124, False: 336k]
  ------------------
  115|   336k|          if (!BrunsliBitReaderRead(br, 1)) {
  ------------------
  |  Branch (115:15): [True: 144k, False: 191k]
  ------------------
  116|   144k|            s->stage = VarintState::INIT;
  117|   144k|            return true;
  118|   144k|          }
  119|   336k|        }
  120|   192k|        s->stage = VarintState::READ_DATA;
  121|   192k|        continue;
  122|   337k|      }
  123|   192k|      case VarintState::READ_DATA: {
  ------------------
  |  Branch (123:7): [True: 192k, False: 337k]
  ------------------
  124|   192k|        if (!BrunsliBitReaderCanRead(br, 1)) return false;
  ------------------
  |  Branch (124:13): [True: 68, False: 192k]
  ------------------
  125|   192k|        size_t next_bit = BrunsliBitReaderRead(br, 1);
  126|   192k|        s->value |= next_bit << s->i;
  127|   192k|        ++s->i;
  128|   192k|        s->stage = VarintState::READ_CONTINUATION;
  129|   192k|        continue;
  130|   192k|      }
  131|      0|      default: {
  ------------------
  |  Branch (131:7): [True: 0, False: 530k]
  ------------------
  132|      0|        BRUNSLI_CHECK(false);
  ------------------
  |  |  452|      0|  if (!(V)) {                                                         \
  |  |  ------------------
  |  |  |  Branch (452:7): [True: 0, Folded]
  |  |  ------------------
  |  |  453|      0|    ::brunsli::BrunsliDumpAndAbort(__FILE__, __LINE__, __FUNCTION__); \
  |  |  454|      0|    /* Tell the compiler, that there is no escape route. */           \
  |  |  455|      0|    while (true) ;                                                    \
  |  |  ------------------
  |  |  |  Branch (455:12): [True: 0, Folded]
  |  |  ------------------
  |  |  456|      0|  }
  ------------------
  133|      0|        return false;
  134|   192k|      }
  135|   530k|    }
  136|   530k|  }
  137|   145k|}
_ZN7brunsli18GenerateApp0MarkerEh:
  176|  19.6k|std::vector<uint8_t> GenerateApp0Marker(uint8_t app0_status) {
  177|  19.6k|  std::vector<uint8_t> app0_marker(AppData_0xe0, AppData_0xe0 + 17);
  178|  19.6k|  app0_marker[9] = app0_status & 1u ? 2 : 1;
  ------------------
  |  Branch (178:20): [True: 15.9k, False: 3.71k]
  ------------------
  179|  19.6k|  app0_status >>= 1u;
  180|  19.6k|  app0_marker[10] = app0_status & 0x3u;
  181|  19.6k|  app0_status >>= 2u;
  182|  19.6k|  uint16_t x_dens = kApp0Densities[app0_status];
  183|  19.6k|  app0_marker[11] = app0_marker[13] = x_dens >> 8u;
  184|  19.6k|  app0_marker[12] = app0_marker[14] = x_dens & 0xFFu;
  185|  19.6k|  return app0_marker;
  186|  19.6k|}
_ZN7brunsli17GenerateAppMarkerEhh:
  188|  12.3k|std::vector<uint8_t> GenerateAppMarker(uint8_t marker, uint8_t code) {
  189|  12.3k|  std::vector<uint8_t> s;
  190|  12.3k|  if (marker == 0x80) {
  ------------------
  |  Branch (190:7): [True: 10.4k, False: 1.88k]
  ------------------
  191|  10.4k|    s = std::vector<uint8_t>(AppData_0xe2, AppData_0xe2 + 3161);
  192|  10.4k|    s[84] = code;
  193|  10.4k|  } else if (marker == 0x81) {
  ------------------
  |  Branch (193:14): [True: 1.04k, False: 840]
  ------------------
  194|  1.04k|    s = std::vector<uint8_t>(AppData_0xec, AppData_0xec + 18);
  195|  1.04k|    s[15] = code;
  196|  1.04k|  } else {
  197|    840|    BRUNSLI_DCHECK(marker == 0x82);
  198|    840|    s = std::vector<uint8_t>(AppData_0xee, AppData_0xee + 15);
  199|    840|    s[10] = code;
  200|    840|  }
  201|  12.3k|  return s;
  202|  12.3k|}
_ZN7brunsli15ProcessMetaDataEPKhmPNS_8internal3dec13MetadataStateEPNS_8JPEGDataE:
  205|   143k|                     JPEGData* jpg) {
  206|   143k|  size_t pos = 0;
  207|   436k|  while (pos < len) {
  ------------------
  |  Branch (207:10): [True: 293k, False: 142k]
  ------------------
  208|   293k|    switch (state->stage) {
  209|  59.7k|      case MetadataState::READ_MARKER: {
  ------------------
  |  Branch (209:7): [True: 59.7k, False: 233k]
  ------------------
  210|  59.7k|        state->marker = static_cast<uint8_t>(data[pos++]);
  211|  59.7k|        if (state->marker == 0xD9) {
  ------------------
  |  Branch (211:13): [True: 133, False: 59.6k]
  ------------------
  212|    133|          jpg->tail_data = std::vector<uint8_t>();
  213|    133|          state->stage = MetadataState::READ_TAIL;
  214|    133|          continue;
  215|  59.6k|        } else if (state->marker < 0x40) {
  ------------------
  |  Branch (215:20): [True: 19.6k, False: 40.0k]
  ------------------
  216|  19.6k|          state->short_marker_count++;
  217|  19.6k|          if (state->short_marker_count > kBrunsliShortMarkerLimit) {
  ------------------
  |  Branch (217:15): [True: 11, False: 19.6k]
  ------------------
  218|     11|            return false;
  219|     11|          }
  220|  19.6k|          jpg->app_data.push_back(GenerateApp0Marker(state->marker));
  221|  19.6k|          continue;
  222|  40.0k|        } else if (state->marker >= 0x80 && state->marker <= 0x82) {
  ------------------
  |  Branch (222:20): [True: 39.8k, False: 113]
  |  Branch (222:45): [True: 12.4k, False: 27.4k]
  ------------------
  223|  12.4k|          state->short_marker_count++;
  224|  12.4k|          if (state->short_marker_count > kBrunsliShortMarkerLimit) {
  ------------------
  |  Branch (224:15): [True: 10, False: 12.3k]
  ------------------
  225|     10|            return false;
  226|     10|          }
  227|  12.3k|          state->stage = MetadataState::READ_CODE;
  228|  12.3k|          continue;
  229|  12.4k|        }
  230|       |        // Otherwise - mutlibyte sequence.
  231|  27.6k|        if ((state->marker != 0xFE) && ((state->marker >> 4u) != 0x0E)) {
  ------------------
  |  Branch (231:13): [True: 22.5k, False: 5.01k]
  |  Branch (231:40): [True: 165, False: 22.4k]
  ------------------
  232|    165|          return false;
  233|    165|        }
  234|  27.4k|        state->stage = MetadataState::READ_LENGTH_HI;
  235|  27.4k|        continue;
  236|  27.6k|      }
  237|       |
  238|  26.4k|      case MetadataState::READ_TAIL: {
  ------------------
  |  Branch (238:7): [True: 26.4k, False: 267k]
  ------------------
  239|  26.4k|        Append(&jpg->tail_data, data + pos, data + len);
  240|  26.4k|        pos = len;
  241|  26.4k|        continue;
  242|  27.6k|      }
  243|       |
  244|  12.3k|      case MetadataState::READ_CODE: {
  ------------------
  |  Branch (244:7): [True: 12.3k, False: 281k]
  ------------------
  245|  12.3k|        const uint8_t code = data[pos++];
  246|  12.3k|        jpg->app_data.push_back(GenerateAppMarker(state->marker, code));
  247|  12.3k|        state->stage = MetadataState::READ_MARKER;
  248|  12.3k|        continue;
  249|  27.6k|      }
  250|       |
  251|  27.4k|      case MetadataState::READ_LENGTH_HI: {
  ------------------
  |  Branch (251:7): [True: 27.4k, False: 266k]
  ------------------
  252|  27.4k|        state->length_hi = data[pos++];
  253|  27.4k|        state->stage = MetadataState::READ_LENGTH_LO;
  254|  27.4k|        continue;
  255|  27.6k|      }
  256|       |
  257|  27.4k|      case MetadataState::READ_LENGTH_LO: {
  ------------------
  |  Branch (257:7): [True: 27.4k, False: 266k]
  ------------------
  258|  27.4k|        const uint8_t lo = data[pos++];
  259|  27.4k|        size_t marker_len = (state->length_hi << 8u) + lo;
  260|  27.4k|        if (marker_len < 2) return false;
  ------------------
  |  Branch (260:13): [True: 2, False: 27.4k]
  ------------------
  261|  27.4k|        state->remaining_multibyte_length = marker_len - 2;
  262|  27.4k|        uint8_t head[3] = {state->marker, state->length_hi, lo};
  263|  27.4k|        auto* dest = (state->marker == 0xFE) ? &jpg->com_data : &jpg->app_data;
  ------------------
  |  Branch (263:22): [True: 5.00k, False: 22.4k]
  ------------------
  264|  27.4k|        size_t delta = (state->marker == 0xFE) ? 0 : state->short_marker_count;
  ------------------
  |  Branch (264:24): [True: 5.00k, False: 22.4k]
  ------------------
  265|  27.4k|        if (dest->size() - delta >= kBrunsliMultibyteMarkerLimit) {
  ------------------
  |  Branch (265:13): [True: 2, False: 27.4k]
  ------------------
  266|      2|          return false;
  267|      2|        }
  268|  27.4k|        dest->emplace_back(head, head + 3);
  269|  27.4k|        state->multibyte_sink = &dest->back();
  270|       |        // Turn state machine to default state in case there is no payload in
  271|       |        // multibyte sequence. This is important when such a sequence concludes
  272|       |        // the input.
  273|  27.4k|        state->stage = (state->remaining_multibyte_length > 0)
  ------------------
  |  Branch (273:24): [True: 26.3k, False: 1.02k]
  ------------------
  274|  27.4k|                           ? MetadataState::READ_MULTIBYTE
  275|  27.4k|                           : MetadataState::READ_MARKER;
  276|  27.4k|        continue;
  277|  27.4k|      }
  278|       |
  279|   140k|      case MetadataState::READ_MULTIBYTE: {
  ------------------
  |  Branch (279:7): [True: 140k, False: 153k]
  ------------------
  280|   140k|        size_t chunk_size =
  281|   140k|            std::min(state->remaining_multibyte_length, len - pos);
  282|   140k|        Append(state->multibyte_sink, data + pos, chunk_size);
  283|   140k|        state->remaining_multibyte_length -= chunk_size;
  284|   140k|        pos += chunk_size;
  285|   140k|        if (state->remaining_multibyte_length == 0) {
  ------------------
  |  Branch (285:13): [True: 25.9k, False: 114k]
  ------------------
  286|  25.9k|          state->stage = MetadataState::READ_MARKER;
  287|  25.9k|        }
  288|   140k|        continue;
  289|  27.4k|      }
  290|       |
  291|      0|      default: return false;
  ------------------
  |  Branch (291:7): [True: 0, False: 293k]
  ------------------
  292|   293k|    }
  293|   293k|  }
  294|   142k|  return true;
  295|   143k|}
_ZN7brunsli14DecodeScanInfoEPNS_8internal3dec5StateEPNS_8JPEGDataE:
  436|  5.13k|BrunsliStatus DecodeScanInfo(State* state, JPEGData* jpg) {
  437|  5.13k|  InternalState& s = *state->internal;
  438|  5.13k|  JpegInternalsState& js = s.internals;
  439|  5.13k|  BrunsliBitReader* br = &js.br;
  440|       |
  441|  5.13k|  const auto maybe_add_zero_run = [&js, jpg] () {
  442|  5.13k|    if (js.last_num > 0) {
  443|  5.13k|      JPEGScanInfo::ExtraZeroRunInfo info;
  444|  5.13k|      info.block_idx = js.last_block_idx;
  445|  5.13k|      info.num_extra_zero_runs = js.last_num;
  446|  5.13k|      jpg->scan_info[js.i].extra_zero_runs.push_back(info);
  447|  5.13k|      js.last_num = 0;
  448|  5.13k|    }
  449|  5.13k|  };
  450|       |
  451|   353k|  while (true) {
  ------------------
  |  Branch (451:10): [True: 353k, Folded]
  ------------------
  452|   353k|    switch (js.stage) {
  453|  11.1k|      case JpegInternalsState::READ_SCAN_COMMON: {
  ------------------
  |  Branch (453:7): [True: 11.1k, False: 342k]
  ------------------
  454|  11.1k|        JPEGScanInfo* si = &jpg->scan_info[js.i];
  455|  11.1k|        if (!BrunsliBitReaderCanRead(br, 22)) return BRUNSLI_NOT_ENOUGH_DATA;
  ------------------
  |  Branch (455:13): [True: 153, False: 11.0k]
  ------------------
  456|  11.0k|        si->Ss = BrunsliBitReaderRead(br, 6);
  457|  11.0k|        si->Se = BrunsliBitReaderRead(br, 6);
  458|  11.0k|        si->Ah = BrunsliBitReaderRead(br, 4);
  459|  11.0k|        si->Al = BrunsliBitReaderRead(br, 4);
  460|  11.0k|        si->num_components = BrunsliBitReaderRead(br, 2) + 1;
  461|  11.0k|        js.j = 0;
  462|  11.0k|        js.stage = JpegInternalsState::READ_SCAN_COMPONENT;
  463|  11.0k|        continue;
  464|  11.1k|      }
  465|  35.1k|      case JpegInternalsState::READ_SCAN_COMPONENT: {
  ------------------
  |  Branch (465:7): [True: 35.1k, False: 318k]
  ------------------
  466|  35.1k|        JPEGScanInfo* si = &jpg->scan_info[js.i];
  467|  35.1k|        if (js.j < si->num_components) {
  ------------------
  |  Branch (467:13): [True: 24.1k, False: 10.9k]
  ------------------
  468|  24.1k|          if (!BrunsliBitReaderCanRead(br, 6)) return BRUNSLI_NOT_ENOUGH_DATA;
  ------------------
  |  Branch (468:15): [True: 43, False: 24.1k]
  ------------------
  469|  24.1k|          si->components[js.j].comp_idx = BrunsliBitReaderRead(br, 2);
  470|  24.1k|          si->components[js.j].dc_tbl_idx = BrunsliBitReaderRead(br, 2);
  471|  24.1k|          si->components[js.j].ac_tbl_idx = BrunsliBitReaderRead(br, 2);
  472|  24.1k|          js.j++;
  473|  24.1k|        } else {
  474|  10.9k|          js.last_block_idx = -1;
  475|  10.9k|          js.stage = JpegInternalsState::READ_SCAN_RESET_POINT_CONTINUATION;
  476|  10.9k|        }
  477|  35.1k|        continue;
  478|  35.1k|      }
  479|  54.9k|      case JpegInternalsState::READ_SCAN_RESET_POINT_CONTINUATION: {
  ------------------
  |  Branch (479:7): [True: 54.9k, False: 298k]
  ------------------
  480|  54.9k|        if (!BrunsliBitReaderCanRead(br, 1)) return BRUNSLI_NOT_ENOUGH_DATA;
  ------------------
  |  Branch (480:13): [True: 43, False: 54.9k]
  ------------------
  481|  54.9k|        if (BrunsliBitReaderRead(br, 1)) {
  ------------------
  |  Branch (481:13): [True: 44.0k, False: 10.9k]
  ------------------
  482|  44.0k|          js.stage = JpegInternalsState::READ_SCAN_RESET_POINT_DATA;
  483|  44.0k|        } else {
  484|  10.9k|          js.last_block_idx = 0;
  485|  10.9k|          js.last_num = 0;
  486|  10.9k|          js.stage = JpegInternalsState::READ_SCAN_ZERO_RUN_CONTINUATION;
  487|  10.9k|        }
  488|  54.9k|        continue;
  489|  54.9k|      }
  490|  44.0k|      case JpegInternalsState::READ_SCAN_RESET_POINT_DATA: {
  ------------------
  |  Branch (490:7): [True: 44.0k, False: 309k]
  ------------------
  491|  44.0k|        JPEGScanInfo* si = &jpg->scan_info[js.i];
  492|  44.0k|        if (!DecodeVarint(&js.varint, br, 28)) return BRUNSLI_NOT_ENOUGH_DATA;
  ------------------
  |  Branch (492:13): [True: 30, False: 43.9k]
  ------------------
  493|  43.9k|        int block_idx =
  494|  43.9k|            js.last_block_idx + static_cast<int>(js.varint.value) + 1;
  495|  43.9k|        si->reset_points.emplace_back(block_idx);
  496|  43.9k|        js.last_block_idx = block_idx;
  497|       |        // TODO(eustas): limit to exact number of blocks.
  498|  43.9k|        if (js.last_block_idx > (1 << 30)) {
  ------------------
  |  Branch (498:13): [True: 7, False: 43.9k]
  ------------------
  499|       |          // At most 8K x 8K x num_channels blocks are expected. That is,
  500|       |          // typically, 1.5 * 2^27. 2^30 should be sufficient for any sane
  501|       |          // image.
  502|      7|          return BRUNSLI_INVALID_BRN;
  503|      7|        }
  504|  43.9k|        js.stage = JpegInternalsState::READ_SCAN_RESET_POINT_CONTINUATION;
  505|  43.9k|        continue;
  506|  43.9k|      }
  507|   109k|      case JpegInternalsState::READ_SCAN_ZERO_RUN_CONTINUATION: {
  ------------------
  |  Branch (507:7): [True: 109k, False: 244k]
  ------------------
  508|   109k|        if (!BrunsliBitReaderCanRead(br, 1)) return BRUNSLI_NOT_ENOUGH_DATA;
  ------------------
  |  Branch (508:13): [True: 7, False: 109k]
  ------------------
  509|   109k|        if (BrunsliBitReaderRead(br, 1)) {
  ------------------
  |  Branch (509:13): [True: 98.7k, False: 10.8k]
  ------------------
  510|  98.7k|          js.stage = JpegInternalsState::READ_SCAN_ZERO_RUN_DATA;
  511|  98.7k|        } else {
  512|  10.8k|          maybe_add_zero_run();
  513|  10.8k|          ++js.i;
  514|  10.8k|          if (js.i < js.num_scans) {
  ------------------
  |  Branch (514:15): [True: 6.06k, False: 4.81k]
  ------------------
  515|  6.06k|            js.stage = JpegInternalsState::READ_SCAN_COMMON;
  516|  6.06k|            continue;
  517|  6.06k|          }
  518|  4.81k|          return BRUNSLI_OK;
  519|  10.8k|        }
  520|  98.7k|        continue;
  521|   109k|      }
  522|  98.7k|      case JpegInternalsState::READ_SCAN_ZERO_RUN_DATA: {
  ------------------
  |  Branch (522:7): [True: 98.7k, False: 254k]
  ------------------
  523|  98.7k|        if (!DecodeVarint(&js.varint, br, 28)) return BRUNSLI_NOT_ENOUGH_DATA;
  ------------------
  |  Branch (523:13): [True: 28, False: 98.6k]
  ------------------
  524|  98.6k|        int block_idx = js.last_block_idx + static_cast<int>(js.varint.value);
  525|  98.6k|        if (block_idx > js.last_block_idx) maybe_add_zero_run();
  ------------------
  |  Branch (525:13): [True: 48.5k, False: 50.0k]
  ------------------
  526|  98.6k|        ++js.last_num;
  527|  98.6k|        js.last_block_idx = block_idx;
  528|       |        // TODO(eustas): limit to exact number of blocks.
  529|  98.6k|        if (js.last_block_idx > (1 << 30)) {
  ------------------
  |  Branch (529:13): [True: 3, False: 98.6k]
  ------------------
  530|       |          // At most 8K x 8K x num_channels blocks are expected. That is,
  531|       |          // typically, 1.5 * 2^27. 2^30 should be sufficient for any sane
  532|       |          // image.
  533|      3|          return BRUNSLI_INVALID_BRN;
  534|      3|        }
  535|  98.6k|        js.stage = JpegInternalsState::READ_SCAN_ZERO_RUN_CONTINUATION;
  536|  98.6k|        continue;
  537|  98.6k|      }
  538|      0|      default: return BRUNSLI_DECOMPRESSION_ERROR;
  ------------------
  |  Branch (538:7): [True: 0, False: 353k]
  ------------------
  539|   353k|    }
  540|   353k|  }
  541|  5.13k|}
_ZN7brunsli28EnsureSubdecodersInitializedEPNS_8internal3dec5StateEPNS_10WordSourceE:
  597|  10.8k|void EnsureSubdecodersInitialized(State* state, WordSource* in) {
  598|  10.8k|  InternalState& s = *state->internal;
  599|  10.8k|  if (!s.subdecoders_initialized) {
  ------------------
  |  Branch (599:7): [True: 10.8k, False: 0]
  ------------------
  600|  10.8k|    s.ans_decoder.Init(in);
  601|  10.8k|    s.bit_reader.Init(in);
  602|  10.8k|    s.arith_decoder.Init(in);
  603|  10.8k|    s.subdecoders_initialized = true;
  604|  10.8k|  }
  605|  10.8k|}
_ZN7brunsli19FinalizeSubdecodersEPNS_8internal3dec5StateE:
  607|  10.4k|bool FinalizeSubdecoders(State* state) {
  608|  10.4k|  InternalState& s = *state->internal;
  609|  10.4k|  if (!s.ans_decoder.CheckCRC()) return false;
  ------------------
  |  Branch (609:7): [True: 636, False: 9.81k]
  ------------------
  610|  9.81k|  if (!s.bit_reader.Finish()) return false;
  ------------------
  |  Branch (610:7): [True: 16, False: 9.80k]
  ------------------
  611|  9.80k|  s.subdecoders_initialized = false;
  612|  9.80k|  return true;
  613|  9.81k|}
_ZN7brunsli8DecodeDCEPNS_8internal3dec5StateEPNS_10WordSourceE:
  615|  5.78k|BrunsliStatus DecodeDC(State* state, WordSource* in) {
  616|  5.78k|  const std::vector<ComponentMeta>& meta = state->meta;
  617|  5.78k|  const size_t num_components = meta.size();
  618|  5.78k|  const int mcu_rows = meta[0].height_in_blocks / meta[0].v_samp;
  619|  5.78k|  InternalState& s = *state->internal;
  620|  5.78k|  AcDcState& ac_dc_state = s.ac_dc;
  621|       |
  622|  5.78k|  std::vector<ComponentStateDC>& comps = ac_dc_state.dc;
  623|  5.78k|  if (comps.empty()) {
  ------------------
  |  Branch (623:7): [True: 5.78k, False: 0]
  ------------------
  624|  5.78k|    comps.resize(num_components);
  625|  12.1k|    for (size_t c = 0; c < num_components; ++c) {
  ------------------
  |  Branch (625:24): [True: 6.39k, False: 5.78k]
  ------------------
  626|  6.39k|      comps[c].SetWidth(meta[c].width_in_blocks);
  627|  6.39k|    }
  628|  5.78k|  }
  629|       |
  630|  5.78k|  if (!in->CanRead(5)) return BRUNSLI_NOT_ENOUGH_DATA;
  ------------------
  |  Branch (630:7): [True: 111, False: 5.67k]
  ------------------
  631|  5.67k|  EnsureSubdecodersInitialized(state, in);
  632|  5.67k|  ANSDecoder ans = s.ans_decoder;
  633|  5.67k|  BitSource br = s.bit_reader;
  634|  5.67k|  BinaryArithmeticDecoder ac = s.arith_decoder;
  635|       |
  636|       |  // We decode DC components in the following interleaved manner:
  637|       |  //   v_samp[0] rows from component 0
  638|       |  //   v_samp[1] rows from component 1
  639|       |  //   v_samp[2] rows from component 2
  640|       |  //   v_samp[3] rows from component 3 (if present)
  641|       |  //
  642|       |  // E.g. in a YUV420 image, we decode 2 rows of DC components from Y and then
  643|       |  // 1 row of DC components from U and 1 row of DC components from V.
  644|   137k|  for (int mcu_y = ac_dc_state.next_mcu_y; mcu_y < mcu_rows; ++mcu_y) {
  ------------------
  |  Branch (644:44): [True: 131k, False: 5.57k]
  ------------------
  645|   271k|    for (size_t i = ac_dc_state.next_component; i < num_components; ++i) {
  ------------------
  |  Branch (645:49): [True: 140k, False: 131k]
  ------------------
  646|   140k|      ComponentStateDC* c = &comps[i];
  647|   140k|      const ComponentMeta& m = meta[i];
  648|   140k|      const uint8_t* context_map = state->context_map + i * kNumAvrgContexts;
  649|   140k|      const int ac_stride = static_cast<int>(m.ac_stride);
  650|   140k|      const size_t b_stride = m.b_stride;
  651|   140k|      const int width = m.width_in_blocks;
  652|   140k|      int y = mcu_y * m.v_samp + ac_dc_state.next_iy;
  653|   140k|      int* const prev_sgn = &c->prev_sign[1];
  654|   140k|      int* const prev_abs = &c->prev_abs_coeff[2];
  655|   522k|      for (int iy = ac_dc_state.next_iy; iy < m.v_samp; ++iy, ++y) {
  ------------------
  |  Branch (655:42): [True: 382k, False: 140k]
  ------------------
  656|   382k|        coeff_t* coeffs =
  657|   382k|            m.ac_coeffs + y * ac_stride + ac_dc_state.next_x * kDCTBlockSize;
  658|   382k|        uint8_t* block_state =
  659|   382k|            m.block_state + y * b_stride + ac_dc_state.next_x;
  660|  42.2M|        for (int x = ac_dc_state.next_x; x < width; ++x) {
  ------------------
  |  Branch (660:42): [True: 41.8M, False: 381k]
  ------------------
  661|  41.8M|          if (BRUNSLI_PREDICT_FALSE(!in->CanRead(6))) {
  ------------------
  |  |   85|  41.8M|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 99, False: 41.8M]
  |  |  ------------------
  ------------------
  662|     99|            ac_dc_state.next_mcu_y = mcu_y;
  663|     99|            ac_dc_state.next_component = i;
  664|     99|            ac_dc_state.next_iy = iy;
  665|     99|            ac_dc_state.next_x = x;
  666|     99|            s.ans_decoder = ans;
  667|     99|            s.bit_reader = br;
  668|     99|            s.arith_decoder = ac;
  669|     99|            return BRUNSLI_NOT_ENOUGH_DATA;
  670|     99|          }
  671|  41.8M|          const int is_empty_ctx =
  672|  41.8M|              IsEmptyBlockContext(&c->prev_is_nonempty[1], x);
  673|  41.8M|          Prob* BRUNSLI_RESTRICT is_empty_p =
  674|  41.8M|              &c->is_empty_block_prob[is_empty_ctx];
  675|  41.8M|          const bool is_empty_block = !ac.ReadBit(is_empty_p->get_proba(), in);
  676|  41.8M|          is_empty_p->Add(!is_empty_block);
  677|  41.8M|          c->prev_is_nonempty[x + 1] = !is_empty_block;
  678|  41.8M|          *block_state = is_empty_block;
  679|  41.8M|          int abs_val = 0;
  680|  41.8M|          int sign = 0;
  681|  41.8M|          if (!is_empty_block) {
  ------------------
  |  Branch (681:15): [True: 12.6M, False: 29.1M]
  ------------------
  682|  12.6M|            Prob* BRUNSLI_RESTRICT p_is_zero = &c->is_zero_prob;
  683|  12.6M|            int is_zero = ac.ReadBit(p_is_zero->get_proba(), in);
  684|  12.6M|            p_is_zero->Add(is_zero);
  685|  12.6M|            if (!is_zero) {
  ------------------
  |  Branch (685:17): [True: 3.15M, False: 9.49M]
  ------------------
  686|  3.15M|              const int avg_ctx = WeightedAverageContextDC(prev_abs, x);
  687|  3.15M|              const int sign_ctx = prev_sgn[x] * 3 + prev_sgn[x - 1];
  688|  3.15M|              Prob* BRUNSLI_RESTRICT sign_p = &c->sign_prob[sign_ctx];
  689|  3.15M|              sign = ac.ReadBit(sign_p->get_proba(), in);
  690|  3.15M|              sign_p->Add(sign);
  691|  3.15M|              const int entropy_ix = context_map[avg_ctx];
  692|  3.15M|              int code = ans.ReadSymbol(state->entropy_codes[entropy_ix], in);
  693|  3.15M|              if (code < kNumDirectCodes) {
  ------------------
  |  Branch (693:19): [True: 453k, False: 2.69M]
  ------------------
  694|   453k|                abs_val = code + 1;
  695|  2.69M|              } else {
  696|  2.69M|                int nbits = code - kNumDirectCodes;
  697|  2.69M|                Prob* BRUNSLI_RESTRICT p_first_extra_bit =
  698|  2.69M|                    &c->first_extra_bit_prob[nbits];
  699|  2.69M|                int first_extra_bit =
  700|  2.69M|                    ac.ReadBit(p_first_extra_bit->get_proba(), in);
  701|  2.69M|                p_first_extra_bit->Add(first_extra_bit);
  702|  2.69M|                int extra_bits_val = first_extra_bit << nbits;
  703|  2.69M|                if (nbits > 0) {
  ------------------
  |  Branch (703:21): [True: 2.54M, False: 156k]
  ------------------
  704|  2.54M|                  extra_bits_val |= static_cast<int>(br.ReadBits(nbits, in));
  705|  2.54M|                }
  706|  2.69M|                abs_val = kNumDirectCodes - 1 + (2 << nbits) + extra_bits_val;
  707|  2.69M|              }
  708|  3.15M|            }
  709|  12.6M|          }
  710|  41.8M|          prev_abs[x] = abs_val;
  711|  41.8M|          prev_sgn[x] = abs_val ? sign + 1 : 0;
  ------------------
  |  Branch (711:25): [True: 3.15M, False: 38.6M]
  ------------------
  712|  41.8M|          coeffs[0] = ((1 - 2 * sign) * abs_val +
  713|  41.8M|                       PredictWithAdaptiveMedian(coeffs, x, y, ac_stride));
  714|  41.8M|          block_state++;
  715|  41.8M|          coeffs += kDCTBlockSize;
  716|  41.8M|        }
  717|   381k|        ac_dc_state.next_x = 0;
  718|   381k|      }
  719|   140k|      ac_dc_state.next_iy = 0;
  720|   140k|    }
  721|   131k|    ac_dc_state.next_component = 0;
  722|   131k|  }
  723|       |
  724|       |  // Prepare for AC decoding.
  725|  5.57k|  ac_dc_state.next_mcu_y = 0;
  726|  5.57k|  ac_dc_state.next_component = 0;
  727|  5.57k|  ac_dc_state.next_iy = 0;
  728|  5.57k|  ac_dc_state.next_x = 0;
  729|       |
  730|  5.57k|  comps.clear();
  731|  5.57k|  comps.shrink_to_fit();
  732|       |
  733|  5.57k|  s.ans_decoder = ans;
  734|  5.57k|  s.bit_reader = br;
  735|  5.57k|  s.arith_decoder = ac;
  736|  5.57k|  if (!FinalizeSubdecoders(state)) return BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (736:7): [True: 251, False: 5.32k]
  ------------------
  737|       |
  738|  5.32k|  return BRUNSLI_OK;
  739|  5.57k|}
_ZN7brunsli8DecodeACEPNS_8internal3dec5StateEPNS_10WordSourceE:
  865|  5.26k|BrunsliStatus DecodeAC(State* state, WordSource* in) {
  866|  5.26k|  const std::vector<ComponentMeta>& meta = state->meta;
  867|  5.26k|  const size_t num_components = meta.size();
  868|  5.26k|  const int mcu_rows = meta[0].height_in_blocks / meta[0].v_samp;
  869|  5.26k|  InternalState& s = *state->internal;
  870|  5.26k|  AcDcState& ac_dc_state = s.ac_dc;
  871|       |
  872|  5.26k|  std::vector<ComponentState>& comps = ac_dc_state.ac;
  873|  5.26k|  if (comps.empty()) {
  ------------------
  |  Branch (873:7): [True: 5.26k, False: 0]
  ------------------
  874|  5.26k|    comps.resize(num_components);
  875|  11.0k|    for (size_t c = 0; c < num_components; ++c) {
  ------------------
  |  Branch (875:24): [True: 5.79k, False: 5.26k]
  ------------------
  876|  5.79k|      comps[c].SetWidth(meta[c].width_in_blocks);
  877|  5.79k|      ComputeACPredictMultipliers(&meta[c].quant[0], comps[c].mult_row,
  878|  5.79k|                                  comps[c].mult_col);
  879|  5.79k|    }
  880|  5.26k|  }
  881|       |
  882|  5.26k|  if (!in->CanRead(5)) return BRUNSLI_NOT_ENOUGH_DATA;
  ------------------
  |  Branch (882:7): [True: 89, False: 5.17k]
  ------------------
  883|  5.17k|  EnsureSubdecodersInitialized(state, in);
  884|       |
  885|  5.17k|  if (!ac_dc_state.ac_coeffs_order_decoded) {
  ------------------
  |  Branch (885:7): [True: 5.17k, False: 0]
  ------------------
  886|  10.5k|    while (ac_dc_state.next_component < num_components) {
  ------------------
  |  Branch (886:12): [True: 5.62k, False: 4.93k]
  ------------------
  887|  5.62k|      if (!in->CanRead(121)) return BRUNSLI_NOT_ENOUGH_DATA;
  ------------------
  |  Branch (887:11): [True: 9, False: 5.61k]
  ------------------
  888|  5.61k|      if (!DecodeCoeffOrder(comps[ac_dc_state.next_component].order,
  ------------------
  |  Branch (888:11): [True: 230, False: 5.38k]
  ------------------
  889|  5.61k|                            &s.bit_reader, in)) {
  890|    230|        return BRUNSLI_INVALID_BRN;
  891|    230|      }
  892|  5.38k|      ac_dc_state.next_component++;
  893|  5.38k|    }
  894|  4.93k|    ac_dc_state.next_component = 0;
  895|  4.93k|    ac_dc_state.ac_coeffs_order_decoded = true;
  896|  4.93k|  }
  897|       |
  898|  4.93k|  AcBlockCookie c;
  899|  4.93k|  c.ac = &s.arith_decoder;
  900|  4.93k|  c.in = in;
  901|  4.93k|  c.ans = &s.ans_decoder;
  902|  4.93k|  c.br = &s.bit_reader;
  903|  4.93k|  c.entropy_codes = state->entropy_codes;
  904|  4.93k|  c.context_modes =
  905|  4.93k|      kContextAlgorithm + (state->use_legacy_context_model ? 64 : 0);
  ------------------
  |  Branch (905:28): [True: 3.85k, False: 1.07k]
  ------------------
  906|       |
  907|   114k|  for (int mcu_y = ac_dc_state.next_mcu_y; mcu_y < mcu_rows; ++mcu_y) {
  ------------------
  |  Branch (907:44): [True: 109k, False: 4.87k]
  ------------------
  908|   220k|    for (size_t i = ac_dc_state.next_component; i < num_components; ++i) {
  ------------------
  |  Branch (908:49): [True: 110k, False: 109k]
  ------------------
  909|   110k|      ComponentState& cst = comps[i];
  910|   110k|      c.prev_num_nonzeros = cst.prev_num_nonzeros.data();
  911|   110k|      c.num_nonzero_prob = cst.num_nonzero_prob;
  912|   110k|      c.is_zero_prob = cst.is_zero_prob.data();
  913|   110k|      c.order = cst.order;
  914|   110k|      c.mult_col = cst.mult_col;
  915|   110k|      c.mult_row = cst.mult_row;
  916|   110k|      c.sign_prob = cst.sign_prob.data();
  917|   110k|      c.first_extra_bit_prob = cst.first_extra_bit_prob.data();
  918|   110k|      const ComponentMeta& m = meta[i];
  919|   110k|      c.context_map = state->context_map + m.context_offset * kNumAvrgContexts;
  920|   110k|      c.context_bits = m.context_bits;
  921|   110k|      const int width = m.width_in_blocks;
  922|   110k|      const size_t ac_stride = m.ac_stride;
  923|   110k|      const size_t b_stride = m.b_stride;
  924|   110k|      const int next_iy = ac_dc_state.next_iy;
  925|   110k|      c.y = mcu_y * m.v_samp + next_iy;
  926|   110k|      c.prev_row_delta = (1 - 2 * (c.y & 1u)) * (width + 3) * kDCTBlockSize;
  927|   437k|      for (int iy = next_iy; iy < m.v_samp; ++iy, ++c.y) {
  ------------------
  |  Branch (927:30): [True: 327k, False: 110k]
  ------------------
  928|   327k|        const int next_x = ac_dc_state.next_x;
  929|   327k|        const size_t block_offset = next_x * kDCTBlockSize;
  930|   327k|        c.coeffs = m.ac_coeffs + c.y * ac_stride + block_offset;
  931|   327k|        c.prev_row_coeffs = c.coeffs - ac_stride;
  932|   327k|        c.prev_col_coeffs = c.coeffs - kDCTBlockSize;
  933|   327k|        const uint8_t* block_state = m.block_state + c.y * b_stride + next_x;
  934|   327k|        c.prev_sgn = &cst.prev_sign[kDCTBlockSize] + block_offset;
  935|   327k|        c.prev_abs = &cst.prev_abs_coeff[((c.y & 1u) * (width + 3) + 2) *
  936|   327k|                                         kDCTBlockSize] +
  937|   327k|                     block_offset;
  938|  12.3M|        for (c.x = next_x; c.x < width; ++c.x) {
  ------------------
  |  Branch (938:28): [True: 11.9M, False: 327k]
  ------------------
  939|  11.9M|          bool is_empty = *(block_state++);
  940|  11.9M|          if (!is_empty) {
  ------------------
  |  Branch (940:15): [True: 1.68M, False: 10.2M]
  ------------------
  941|  1.68M|            if (BRUNSLI_PREDICT_FALSE(!in->CanRead(297))) {
  ------------------
  |  |   85|  1.68M|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 61, False: 1.68M]
  |  |  ------------------
  ------------------
  942|     61|              ac_dc_state.next_mcu_y = mcu_y;
  943|     61|              ac_dc_state.next_component = i;
  944|     61|              ac_dc_state.next_iy = iy;
  945|     61|              ac_dc_state.next_x = c.x;
  946|     61|              return BRUNSLI_NOT_ENOUGH_DATA;
  947|     61|            }
  948|  1.68M|            size_t num_nonzeros = DecodeAcBlock(c);
  949|  1.68M|            BRUNSLI_DCHECK(num_nonzeros <= kNumNonZeroTreeSize);
  950|  1.68M|            c.prev_num_nonzeros[c.x] = static_cast<uint8_t>(num_nonzeros);
  951|  10.2M|          } else {
  952|  10.2M|            DecodeEmptyAcBlock(c.prev_sgn, c.prev_abs);
  953|  10.2M|            c.prev_num_nonzeros[c.x] = 0;
  954|  10.2M|          }
  955|  11.9M|          c.coeffs += kDCTBlockSize;
  956|  11.9M|          c.prev_sgn += kDCTBlockSize;
  957|  11.9M|          c.prev_abs += kDCTBlockSize;
  958|  11.9M|          c.prev_row_coeffs += kDCTBlockSize;
  959|  11.9M|          c.prev_col_coeffs += kDCTBlockSize;
  960|  11.9M|        }
  961|   327k|        c.prev_row_delta *= -1;
  962|   327k|        ac_dc_state.next_x = 0;
  963|   327k|      }
  964|   110k|      ac_dc_state.next_iy = 0;
  965|   110k|    }
  966|   109k|    ac_dc_state.next_component = 0;
  967|   109k|  }
  968|  4.87k|  ac_dc_state.next_mcu_y = 0;
  969|       |
  970|  4.87k|  comps.clear();
  971|  4.87k|  comps.shrink_to_fit();
  972|       |
  973|  4.87k|  if (!FinalizeSubdecoders(state)) return BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (973:7): [True: 401, False: 4.47k]
  ------------------
  974|       |
  975|  4.47k|  return BRUNSLI_OK;
  976|  4.87k|}
_ZN7brunsli15VerifySignatureEPNS_8internal3dec5StateE:
 1097|  16.6k|Stage VerifySignature(State* state) {
 1098|  16.6k|  InternalState& s = *state->internal;
 1099|       |
 1100|  16.6k|  if (!CheckCanRead(state, kBrunsliSignatureSize)) {
  ------------------
  |  Branch (1100:7): [True: 5, False: 16.6k]
  ------------------
 1101|      5|    return Fail(state, BRUNSLI_NOT_ENOUGH_DATA);
 1102|      5|  }
 1103|  16.6k|  const bool is_signature_ok =
 1104|  16.6k|      (memcmp(state->data + state->pos, kBrunsliSignature,
 1105|  16.6k|              kBrunsliSignatureSize) != 0);
 1106|  16.6k|  state->pos += kBrunsliSignatureSize;
 1107|  16.6k|  s.section.tags_met |= 1u << kBrunsliSignatureTag;
 1108|  16.6k|  if (is_signature_ok) return Fail(state, BRUNSLI_INVALID_BRN);
  ------------------
  |  Branch (1108:7): [True: 54, False: 16.6k]
  ------------------
 1109|  16.6k|  return Stage::HEADER;
 1110|  16.6k|}
_ZN7brunsli12DecodeHeaderEPNS_8internal3dec5StateEPNS_8JPEGDataE:
 1116|  16.6k|Stage DecodeHeader(State* state, JPEGData* jpg) {
 1117|  16.6k|  InternalState& s = *state->internal;
 1118|  16.6k|  HeaderState& hs = s.header;
 1119|       |
 1120|   214k|  while (hs.stage != HeaderState::DONE) {
  ------------------
  |  Branch (1120:10): [True: 198k, False: 15.9k]
  ------------------
 1121|   198k|    switch (hs.stage) {
 1122|  16.6k|      case HeaderState::READ_TAG: {
  ------------------
  |  Branch (1122:7): [True: 16.6k, False: 181k]
  ------------------
 1123|  16.6k|        BrunsliStatus status = ReadTag(state, &s.section);
 1124|  16.6k|        if (status != BRUNSLI_OK) return Fail(state, status);
  ------------------
  |  Branch (1124:13): [True: 17, False: 16.5k]
  ------------------
 1125|  16.5k|        if (s.section.tag != kBrunsliHeaderTag || !s.section.is_section) {
  ------------------
  |  Branch (1125:13): [True: 5, False: 16.5k]
  |  Branch (1125:51): [True: 1, False: 16.5k]
  ------------------
 1126|      6|          return Fail(state, BRUNSLI_INVALID_BRN);
 1127|      6|        }
 1128|  16.5k|        hs.stage = HeaderState::ENTER_SECTION;
 1129|  16.5k|        break;
 1130|  16.5k|      }
 1131|       |
 1132|  16.5k|      case HeaderState::ENTER_SECTION: {
  ------------------
  |  Branch (1132:7): [True: 16.5k, False: 181k]
  ------------------
 1133|  16.5k|        BrunsliStatus status = EnterSection(state, &s.section);
 1134|  16.5k|        if (status != BRUNSLI_OK) return Fail(state, status);
  ------------------
  |  Branch (1134:13): [True: 43, False: 16.5k]
  ------------------
 1135|  16.5k|        hs.stage = HeaderState::ITEM_READ_TAG;
 1136|  16.5k|        break;
 1137|  16.5k|      }
 1138|       |
 1139|  80.1k|      case HeaderState::ITEM_READ_TAG: {
  ------------------
  |  Branch (1139:7): [True: 80.1k, False: 118k]
  ------------------
 1140|  80.1k|        if (IsAtSectionBoundary(state)) {
  ------------------
  |  Branch (1140:13): [True: 16.2k, False: 63.9k]
  ------------------
 1141|  16.2k|          hs.stage = HeaderState::FINALE;
 1142|  16.2k|          break;
 1143|  16.2k|        }
 1144|  63.9k|        BrunsliStatus status = ReadTag(state, &hs.section);
 1145|  63.9k|        if (status != BRUNSLI_OK) return Fail(state, status);
  ------------------
  |  Branch (1145:13): [True: 145, False: 63.7k]
  ------------------
 1146|  63.7k|        const uint32_t tag_bit = 1u << hs.section.tag;
 1147|  63.7k|        if (hs.section.is_section) {
  ------------------
  |  Branch (1147:13): [True: 5.00k, False: 58.7k]
  ------------------
 1148|  5.00k|          if (kKnownHeaderVarintTags & tag_bit) {
  ------------------
  |  Branch (1148:15): [True: 4.90k, False: 99]
  ------------------
 1149|  4.90k|            Fail(state, BRUNSLI_INVALID_BRN);
 1150|  4.90k|          }
 1151|  5.00k|          hs.stage = HeaderState::ITEM_ENTER_SECTION;
 1152|  5.00k|          break;
 1153|  5.00k|        }
 1154|  58.7k|        hs.stage = HeaderState::ITEM_READ_VALUE;
 1155|  58.7k|        break;
 1156|  63.7k|      }
 1157|       |
 1158|  5.00k|      case HeaderState::ITEM_ENTER_SECTION: {
  ------------------
  |  Branch (1158:7): [True: 5.00k, False: 193k]
  ------------------
 1159|  5.00k|        BrunsliStatus status = DecodeBase128(state, &hs.remaining_skip_length);
 1160|  5.00k|        if (status != BRUNSLI_OK) return Fail(state, status);
  ------------------
  |  Branch (1160:13): [True: 8, False: 4.99k]
  ------------------
 1161|  4.99k|        hs.stage = HeaderState::ITEM_SKIP_CONTENTS;
 1162|  4.99k|        break;
 1163|  5.00k|      }
 1164|       |
 1165|  4.99k|      case HeaderState::ITEM_SKIP_CONTENTS: {
  ------------------
  |  Branch (1165:7): [True: 4.99k, False: 193k]
  ------------------
 1166|  4.99k|        size_t bytes_skipped =
 1167|  4.99k|            SkipAvailableBytes(state, hs.remaining_skip_length);
 1168|  4.99k|        hs.remaining_skip_length -= bytes_skipped;
 1169|  4.99k|        if (hs.remaining_skip_length > 0) {
  ------------------
  |  Branch (1169:13): [True: 118, False: 4.87k]
  ------------------
 1170|    118|          return Fail(state, BRUNSLI_NOT_ENOUGH_DATA);
 1171|    118|        }
 1172|  4.87k|        hs.stage = HeaderState::ITEM_READ_TAG;
 1173|  4.87k|        break;
 1174|  4.99k|      }
 1175|       |
 1176|  58.7k|      case HeaderState::ITEM_READ_VALUE: {
  ------------------
  |  Branch (1176:7): [True: 58.7k, False: 139k]
  ------------------
 1177|  58.7k|        size_t value;
 1178|  58.7k|        BrunsliStatus status = DecodeBase128(state, &value);
 1179|  58.7k|        if (status != BRUNSLI_OK) return Fail(state, status);
  ------------------
  |  Branch (1179:13): [True: 12, False: 58.7k]
  ------------------
 1180|  58.7k|        hs.varint_values[hs.section.tag] = value;
 1181|  58.7k|        hs.stage = HeaderState::ITEM_READ_TAG;
 1182|  58.7k|        break;
 1183|  58.7k|      }
 1184|       |
 1185|  16.2k|      case HeaderState::FINALE: {
  ------------------
  |  Branch (1185:7): [True: 16.2k, False: 182k]
  ------------------
 1186|  16.2k|        const bool has_version =
 1187|  16.2k|            hs.section.tags_met & (1u << kBrunsliHeaderVersionCompTag);
 1188|  16.2k|        if (!has_version) return Fail(state, BRUNSLI_INVALID_BRN);
  ------------------
  |  Branch (1188:13): [True: 3, False: 16.2k]
  ------------------
 1189|  16.2k|        const size_t version_and_comp_count =
 1190|  16.2k|            hs.varint_values[kBrunsliHeaderVersionCompTag];
 1191|       |
 1192|  16.2k|        const size_t version = version_and_comp_count >> 2u;
 1193|  16.2k|        jpg->version = static_cast<int>(version);
 1194|       |
 1195|  16.2k|        if (version == 1) {  // fallback mode
  ------------------
  |  Branch (1195:13): [True: 415, False: 15.8k]
  ------------------
 1196|       |          // TODO(eustas): do we need this?
 1197|    415|          jpg->width = 0;
 1198|    415|          jpg->height = 0;
 1199|    415|          hs.stage = HeaderState::DONE;
 1200|    415|          break;
 1201|    415|        }
 1202|       |
 1203|       |        // Wrong mode = fallback + something.
 1204|  15.8k|        if ((version & 1u) != 0) {
  ------------------
  |  Branch (1204:13): [True: 16, False: 15.8k]
  ------------------
 1205|     16|          return Fail(state, BRUNSLI_INVALID_BRN);
 1206|     16|        }
 1207|       |        // Unknown mode - only 3 bits are defined.
 1208|  15.8k|        if ((version & ~0x7u) != 0) {
  ------------------
  |  Branch (1208:13): [True: 49, False: 15.7k]
  ------------------
 1209|     49|          return Fail(state, BRUNSLI_INVALID_BRN);
 1210|     49|        }
 1211|       |
 1212|       |        // Otherwise regular brunsli.
 1213|  15.7k|        state->use_legacy_context_model = !(version & 2);
 1214|       |
 1215|       |        // Do not allow "original_jpg" for regular Brunsli files.
 1216|  15.7k|        s.section.tags_met |= 1u << kBrunsliOriginalJpgTag;
 1217|       |
 1218|  15.7k|        const bool has_width =
 1219|  15.7k|            hs.section.tags_met & (1u << kBrunsliHeaderWidthTag);
 1220|  15.7k|        if (!has_width) return Fail(state, BRUNSLI_INVALID_BRN);
  ------------------
  |  Branch (1220:13): [True: 2, False: 15.7k]
  ------------------
 1221|  15.7k|        const size_t width = hs.varint_values[kBrunsliHeaderWidthTag];
 1222|  15.7k|        const bool has_height =
 1223|  15.7k|            hs.section.tags_met & (1u << kBrunsliHeaderHeightTag);
 1224|  15.7k|        if (!has_height) return Fail(state, BRUNSLI_INVALID_BRN);
  ------------------
  |  Branch (1224:13): [True: 1, False: 15.7k]
  ------------------
 1225|  15.7k|        const size_t height = hs.varint_values[kBrunsliHeaderHeightTag];
 1226|       |
 1227|  15.7k|        if (width == 0 || height == 0) return Fail(state, BRUNSLI_INVALID_BRN);
  ------------------
  |  Branch (1227:13): [True: 1, False: 15.7k]
  |  Branch (1227:27): [True: 6, False: 15.7k]
  ------------------
 1228|  15.7k|        if (width > kMaxDimPixels || height > kMaxDimPixels) {
  ------------------
  |  Branch (1228:13): [True: 84, False: 15.6k]
  |  Branch (1228:38): [True: 79, False: 15.5k]
  ------------------
 1229|    163|          return Fail(state, BRUNSLI_INVALID_BRN);
 1230|    163|        }
 1231|  15.5k|        jpg->width = static_cast<int>(width);
 1232|  15.5k|        jpg->height = static_cast<int>(height);
 1233|       |
 1234|  15.5k|        const size_t num_components = (version_and_comp_count & 3u) + 1u;
 1235|  15.5k|        jpg->components.resize(num_components);
 1236|       |
 1237|  15.5k|        const bool has_subsampling =
 1238|  15.5k|            hs.section.tags_met & (1u << kBrunsliHeaderSubsamplingTag);
 1239|  15.5k|        if (!has_subsampling) return Fail(state, BRUNSLI_INVALID_BRN);
  ------------------
  |  Branch (1239:13): [True: 33, False: 15.5k]
  ------------------
 1240|  15.5k|        size_t subsampling_code =
 1241|  15.5k|            hs.varint_values[kBrunsliHeaderSubsamplingTag];
 1242|       |
 1243|  41.2k|        for (size_t i = 0; i < jpg->components.size(); ++i) {
  ------------------
  |  Branch (1243:28): [True: 25.7k, False: 15.5k]
  ------------------
 1244|  25.7k|          JPEGComponent* c = &jpg->components[i];
 1245|  25.7k|          c->v_samp_factor = (subsampling_code & 0xFu) + 1;
 1246|  25.7k|          subsampling_code >>= 4u;
 1247|  25.7k|          c->h_samp_factor = (subsampling_code & 0xFu) + 1;
 1248|  25.7k|          subsampling_code >>= 4u;
 1249|  25.7k|          if (c->v_samp_factor > kBrunsliMaxSampling) {
  ------------------
  |  Branch (1249:15): [True: 1, False: 25.7k]
  ------------------
 1250|      1|            return Fail(state, BRUNSLI_INVALID_BRN);
 1251|      1|          }
 1252|  25.7k|          if (c->h_samp_factor > kBrunsliMaxSampling) {
  ------------------
  |  Branch (1252:15): [True: 1, False: 25.7k]
  ------------------
 1253|      1|            return Fail(state, BRUNSLI_INVALID_BRN);
 1254|      1|          }
 1255|  25.7k|        }
 1256|  15.5k|        if (!UpdateSubsamplingDerivatives(jpg)) {
  ------------------
  |  Branch (1256:13): [True: 1, False: 15.5k]
  ------------------
 1257|      1|          return Fail(state, BRUNSLI_INVALID_BRN);
 1258|      1|        }
 1259|       |
 1260|  15.5k|        PrepareMeta(jpg, state);
 1261|       |
 1262|  15.5k|        hs.stage = HeaderState::DONE;
 1263|  15.5k|        break;
 1264|  15.5k|      }
 1265|       |
 1266|      0|      default: return Fail(state, BRUNSLI_DECOMPRESSION_ERROR);
  ------------------
  |  Branch (1266:7): [True: 0, False: 198k]
  ------------------
 1267|   198k|    }
 1268|   198k|  }
 1269|       |
 1270|  15.9k|  LeaveSection(&s.section);
 1271|  15.9k|  return (jpg->version == kFallbackVersion) ? Stage::FALLBACK : Stage::SECTION;
  ------------------
  |  Branch (1271:10): [True: 415, False: 15.5k]
  ------------------
 1272|  16.6k|}
_ZN7brunsli8internal3dec28UpdateSubsamplingDerivativesEPNS_8JPEGDataE:
 2201|  15.5k|bool UpdateSubsamplingDerivatives(JPEGData* jpg) {
 2202|  41.2k|  for (size_t i = 0; i < jpg->components.size(); ++i) {
  ------------------
  |  Branch (2202:22): [True: 25.7k, False: 15.5k]
  ------------------
 2203|  25.7k|    JPEGComponent* c = &jpg->components[i];
 2204|  25.7k|    jpg->max_h_samp_factor = std::max(jpg->max_h_samp_factor, c->h_samp_factor);
 2205|  25.7k|    jpg->max_v_samp_factor = std::max(jpg->max_v_samp_factor, c->v_samp_factor);
 2206|  25.7k|  }
 2207|  15.5k|  jpg->MCU_rows = DivCeil(jpg->height, jpg->max_v_samp_factor * 8);
 2208|  15.5k|  jpg->MCU_cols = DivCeil(jpg->width, jpg->max_h_samp_factor * 8);
 2209|  41.2k|  for (size_t i = 0; i < jpg->components.size(); ++i) {
  ------------------
  |  Branch (2209:22): [True: 25.7k, False: 15.5k]
  ------------------
 2210|  25.7k|    JPEGComponent* c = &jpg->components[i];
 2211|  25.7k|    c->width_in_blocks = jpg->MCU_cols * c->h_samp_factor;
 2212|  25.7k|    c->height_in_blocks = jpg->MCU_rows * c->v_samp_factor;
 2213|       |    // 8205 == max[ceil((65535 / (i * 8)) * i) for i in range(1, 16 + 1)]
 2214|  25.7k|    BRUNSLI_DCHECK(c->width_in_blocks <= 8205);
 2215|  25.7k|    BRUNSLI_DCHECK(c->height_in_blocks <= 8205);
 2216|  25.7k|    uint32_t num_blocks = c->width_in_blocks * c->height_in_blocks;
 2217|  25.7k|    if (num_blocks > kBrunsliMaxNumBlocks) {
  ------------------
  |  Branch (2217:9): [True: 1, False: 25.7k]
  ------------------
 2218|      1|      return false;
 2219|      1|    }
 2220|  25.7k|    c->num_blocks = num_blocks;
 2221|  25.7k|  }
 2222|  15.5k|  return true;
 2223|  15.5k|}
_ZN7brunsli8internal3dec11PrepareMetaEPKNS_8JPEGDataEPNS1_5StateE:
 2225|  15.5k|void PrepareMeta(const JPEGData* jpg, State* state) {
 2226|  15.5k|  InternalState& s = *state->internal;
 2227|       |
 2228|  15.5k|  size_t num_components = jpg->components.size();
 2229|  15.5k|  s.block_state_.resize(num_components);
 2230|  15.5k|  std::vector<ComponentMeta>& meta = state->meta;
 2231|  15.5k|  meta.resize(num_components);
 2232|  41.2k|  for (size_t i = 0; i < num_components; ++i) {
  ------------------
  |  Branch (2232:22): [True: 25.7k, False: 15.5k]
  ------------------
 2233|  25.7k|    const JPEGComponent& c = jpg->components[i];
 2234|  25.7k|    ComponentMeta& m = meta[i];
 2235|  25.7k|    m.h_samp = c.h_samp_factor;
 2236|  25.7k|    m.v_samp = c.v_samp_factor;
 2237|  25.7k|    m.width_in_blocks = jpg->MCU_cols * m.h_samp;
 2238|  25.7k|    m.height_in_blocks = jpg->MCU_rows * m.v_samp;
 2239|  25.7k|  }
 2240|  15.5k|}
_ZN7brunsli8internal3dec10WarmupMetaEPNS_8JPEGDataEPNS1_5StateE:
 2242|  11.0k|void WarmupMeta(JPEGData* jpg, State* state) {
 2243|  11.0k|  InternalState& s = *state->internal;
 2244|  11.0k|  std::vector<ComponentMeta>& meta = state->meta;
 2245|  11.0k|  const size_t num_components = meta.size();
 2246|       |
 2247|  11.0k|  if (!state->is_storage_allocated) {
  ------------------
  |  Branch (2247:7): [True: 5.78k, False: 5.26k]
  ------------------
 2248|  5.78k|    state->is_storage_allocated = true;
 2249|  12.1k|    for (size_t i = 0; i < num_components; ++i) {
  ------------------
  |  Branch (2249:24): [True: 6.39k, False: 5.78k]
  ------------------
 2250|  6.39k|      size_t num_blocks = meta[i].width_in_blocks * meta[i].height_in_blocks;
 2251|  6.39k|      jpg->components[i].coeffs.resize(num_blocks * kDCTBlockSize);
 2252|  6.39k|      s.block_state_[i].resize(num_blocks);
 2253|  6.39k|      meta[i].block_state = s.block_state_[i].data();
 2254|  6.39k|    }
 2255|  5.78k|  }
 2256|       |
 2257|  11.0k|  if (!s.is_meta_warm) {
  ------------------
  |  Branch (2257:7): [True: 5.78k, False: 5.26k]
  ------------------
 2258|  5.78k|    s.is_meta_warm = true;
 2259|  12.1k|    for (size_t c = 0; c < num_components; ++c) {
  ------------------
  |  Branch (2259:24): [True: 6.39k, False: 5.78k]
  ------------------
 2260|  6.39k|      ComponentMeta& m = meta[c];
 2261|  6.39k|      const JPEGQuantTable& q = jpg->quant[jpg->components[c].quant_idx];
 2262|  6.39k|      m.ac_coeffs = jpg->components[c].coeffs.data();
 2263|  6.39k|      m.ac_stride = m.width_in_blocks * kDCTBlockSize;
 2264|  6.39k|      m.b_stride = m.width_in_blocks;
 2265|  6.39k|      memcpy(m.quant.data(), q.values.data(),
 2266|  6.39k|             kDCTBlockSize * sizeof(m.quant[0]));
 2267|  6.39k|    }
 2268|  5.78k|  }
 2269|  11.0k|}
_ZN7brunsli8internal3dec13DoProcessJpegEPNS1_5StateEPNS_8JPEGDataE:
 2271|  16.6k|BrunsliStatus DoProcessJpeg(State* state, JPEGData* jpg) {
 2272|   133k|  while (true) {
  ------------------
  |  Branch (2272:10): [True: 133k, Folded]
  ------------------
 2273|   133k|    switch (state->stage) {
 2274|  16.6k|      case Stage::SIGNATURE:
  ------------------
  |  Branch (2274:7): [True: 16.6k, False: 116k]
  ------------------
 2275|  16.6k|        state->stage = VerifySignature(state);
 2276|  16.6k|        break;
 2277|       |
 2278|  16.6k|      case Stage::HEADER:
  ------------------
  |  Branch (2278:7): [True: 16.6k, False: 116k]
  ------------------
 2279|  16.6k|        state->stage = DecodeHeader(state, jpg);
 2280|  16.6k|        break;
 2281|       |
 2282|    415|      case Stage::FALLBACK:
  ------------------
  |  Branch (2282:7): [True: 415, False: 132k]
  ------------------
 2283|    415|        state->stage = DecodeOriginalJpg(state, jpg);
 2284|    415|        break;
 2285|       |
 2286|  41.5k|      case Stage::SECTION:
  ------------------
  |  Branch (2286:7): [True: 41.5k, False: 91.7k]
  ------------------
 2287|  41.5k|        state->stage = ParseSection(state);
 2288|  41.5k|        break;
 2289|       |
 2290|  41.3k|      case Stage::SECTION_BODY:
  ------------------
  |  Branch (2290:7): [True: 41.3k, False: 91.8k]
  ------------------
 2291|  41.3k|        state->stage = ProcessSection(state, jpg);
 2292|  41.3k|        break;
 2293|       |
 2294|  4.49k|      case Stage::DONE:
  ------------------
  |  Branch (2294:7): [True: 4.49k, False: 128k]
  ------------------
 2295|       |        // It is expected that there is no garbage after the valid brunsli
 2296|       |        // stream.
 2297|  4.49k|        if (state->pos != state->len) {
  ------------------
  |  Branch (2297:13): [True: 38, False: 4.45k]
  ------------------
 2298|     38|          state->stage = Fail(state, BRUNSLI_INVALID_BRN);
 2299|     38|          break;
 2300|     38|        }
 2301|  4.45k|        return BRUNSLI_OK;
 2302|       |
 2303|  12.2k|      case Stage::ERROR:
  ------------------
  |  Branch (2303:7): [True: 12.2k, False: 121k]
  ------------------
 2304|  12.2k|        return state->internal->result;
 2305|       |
 2306|      0|      default:
  ------------------
  |  Branch (2306:7): [True: 0, False: 133k]
  ------------------
 2307|       |        /* Unreachable */
 2308|      0|        state->stage = Fail(state, BRUNSLI_DECOMPRESSION_ERROR);
 2309|      0|        break;
 2310|   133k|    }
 2311|   133k|  }
 2312|  16.6k|}
_ZN7brunsli8internal3dec12ChargeBufferEPNS1_5StateE:
 2315|  16.6k|void ChargeBuffer(State* state) {
 2316|  16.6k|  InternalState& s = *state->internal;
 2317|  16.6k|  Buffer& b = s.buffer;
 2318|       |
 2319|  16.6k|  b.borrowed_len = 0;
 2320|  16.6k|  b.external_data = state->data;
 2321|  16.6k|  b.external_pos = state->pos;
 2322|  16.6k|  b.external_len = state->len;
 2323|  16.6k|}
_ZN7brunsli8internal3dec9LoadInputEPNS1_5StateE:
 2328|  16.6k|void LoadInput(State* state) {
 2329|  16.6k|  InternalState& s = *state->internal;
 2330|  16.6k|  Buffer& b = s.buffer;
 2331|       |
 2332|       |  // No data buffered. Just pass external data as is.
 2333|  16.6k|  if (b.data_len == 0) {
  ------------------
  |  Branch (2333:7): [True: 16.6k, False: 0]
  ------------------
 2334|  16.6k|    state->data = b.external_data;
 2335|  16.6k|    state->pos = b.external_pos;
 2336|  16.6k|    state->len = b.external_len;
 2337|  16.6k|    return;
 2338|  16.6k|  }
 2339|       |
 2340|      0|  BRUNSLI_DCHECK(b.data_len <= kBufferMaxReadAhead);
 2341|       |
 2342|       |  // Otherwise use buffered data.
 2343|      0|  size_t available = b.external_len - b.external_pos;
 2344|       |  // Always try to borrow as much as parser could require. This way, when
 2345|       |  // buffer is unable to provide enough input, we could switch to unbuffered
 2346|       |  // input.
 2347|      0|  b.borrowed_len = std::min(kBufferMaxReadAhead, available);
 2348|      0|  memcpy(b.data.data() + b.data_len, b.external_data + b.external_pos,
 2349|      0|         b.borrowed_len);
 2350|      0|  state->data = b.data.data();
 2351|      0|  state->pos = 0;
 2352|      0|  state->len = b.data_len + b.borrowed_len;
 2353|      0|}
_ZN7brunsli8internal3dec11UnloadInputEPNS1_5StateENS_13BrunsliStatusE:
 2360|  16.6k|bool UnloadInput(State* state, BrunsliStatus result) {
 2361|  16.6k|  InternalState& s = *state->internal;
 2362|  16.6k|  Buffer& b = s.buffer;
 2363|       |
 2364|       |  // Non-buffered input; put tail to buffer.
 2365|  16.6k|  if (state->data == b.external_data) {
  ------------------
  |  Branch (2365:7): [True: 16.6k, False: 0]
  ------------------
 2366|  16.6k|    b.external_pos = state->pos;
 2367|  16.6k|    BRUNSLI_DCHECK(b.external_pos <= b.external_len);
 2368|  16.6k|    if (result != BRUNSLI_NOT_ENOUGH_DATA) return true;
  ------------------
  |  Branch (2368:9): [True: 10.5k, False: 6.07k]
  ------------------
 2369|  6.07k|    BRUNSLI_DCHECK(b.data_len == 0);
 2370|  6.07k|    size_t available = b.external_len - b.external_pos;
 2371|  6.07k|    BRUNSLI_DCHECK(available < kBufferMaxReadAhead);
 2372|  6.07k|    if (b.data.empty()) b.data.resize(2 * kBufferMaxReadAhead);
  ------------------
  |  Branch (2372:9): [True: 6.07k, False: 0]
  ------------------
 2373|  6.07k|    b.data_len = available;
 2374|  6.07k|    memcpy(b.data.data(), b.external_data + b.external_pos, b.data_len);
 2375|  6.07k|    b.external_pos += available;
 2376|  6.07k|    return false;
 2377|  16.6k|  }
 2378|       |
 2379|       |  // Buffer depleted; switch to non-buffered input.
 2380|      0|  if (state->pos >= b.data_len) {
  ------------------
  |  Branch (2380:7): [True: 0, False: 0]
  ------------------
 2381|      0|    size_t used_borrowed_bytes = state->pos - b.data_len;
 2382|      0|    b.data_len = 0;
 2383|      0|    b.external_pos += used_borrowed_bytes;
 2384|      0|    return true;
 2385|      0|  }
 2386|       |
 2387|       |  // Buffer not depleted; either problem discovered was already buffered data,
 2388|       |  // or extra input was too-short.
 2389|      0|  b.data_len -= state->pos;
 2390|      0|  if (result == BRUNSLI_NOT_ENOUGH_DATA) {
  ------------------
  |  Branch (2390:7): [True: 0, False: 0]
  ------------------
 2391|       |    // We couldn't have taken more bytes.
 2392|      0|    BRUNSLI_DCHECK(b.external_pos + b.borrowed_len == b.external_len);
 2393|       |    // Remaining piece is not too large.
 2394|      0|    BRUNSLI_DCHECK(b.data_len + b.borrowed_len < kBufferMaxReadAhead);
 2395|      0|    b.data_len += b.borrowed_len;
 2396|      0|    b.external_pos += b.borrowed_len;
 2397|      0|  }
 2398|      0|  BRUNSLI_DCHECK(!b.data.empty());
 2399|      0|  if (state->pos > 0 && b.data_len > 0) {
  ------------------
  |  Branch (2399:7): [True: 0, False: 0]
  |  Branch (2399:25): [True: 0, False: 0]
  ------------------
 2400|      0|    memmove(b.data.data(), b.data.data() + state->pos, b.data_len);
 2401|      0|  }
 2402|      0|  BRUNSLI_DCHECK(b.data_len <= kBufferMaxReadAhead);
 2403|       |
 2404|      0|  return (result != BRUNSLI_NOT_ENOUGH_DATA);
 2405|      0|}
_ZN7brunsli8internal3dec14UnchargeBufferEPNS1_5StateE:
 2408|  16.6k|void UnchargeBuffer(State* state) {
 2409|  16.6k|  InternalState& s = *state->internal;
 2410|  16.6k|  Buffer& b = s.buffer;
 2411|       |
 2412|  16.6k|  state->data = b.external_data;
 2413|  16.6k|  state->pos = b.external_pos;
 2414|  16.6k|  state->len = b.external_len;
 2415|  16.6k|}
_ZN7brunsli8internal3dec11ProcessJpegEPNS1_5StateEPNS_8JPEGDataE:
 2417|  16.6k|BrunsliStatus ProcessJpeg(State* state, JPEGData* jpg) {
 2418|  16.6k|  InternalState& s = *state->internal;
 2419|       |
 2420|  16.6k|  if (state->pos > state->len) return BRUNSLI_INVALID_PARAM;
  ------------------
  |  Branch (2420:7): [True: 0, False: 16.6k]
  ------------------
 2421|  16.6k|  ChargeBuffer(state);
 2422|       |
 2423|  16.6k|  BrunsliStatus result = BRUNSLI_NOT_ENOUGH_DATA;
 2424|  27.2k|  while (result == BRUNSLI_NOT_ENOUGH_DATA) {
  ------------------
  |  Branch (2424:10): [True: 16.6k, False: 10.5k]
  ------------------
 2425|  16.6k|    if (state->stage == Stage::ERROR) {
  ------------------
  |  Branch (2425:9): [True: 0, False: 16.6k]
  ------------------
 2426|       |      // General error -> no recovery.
 2427|      0|      if (s.result != BRUNSLI_NOT_ENOUGH_DATA) return s.result;
  ------------------
  |  Branch (2427:11): [True: 0, False: 0]
  ------------------
 2428|       |      // Continue parsing.
 2429|      0|      s.result = BRUNSLI_OK;
 2430|      0|      state->stage = s.last_stage;
 2431|      0|      s.last_stage = Stage::ERROR;
 2432|      0|    }
 2433|       |
 2434|  16.6k|    LoadInput(state);
 2435|  16.6k|    if (s.section.is_active) {
  ------------------
  |  Branch (2435:9): [True: 0, False: 16.6k]
  ------------------
 2436|      0|      s.section.milestone = state->pos;
 2437|      0|      s.section.projected_end = s.section.milestone + s.section.remaining;
 2438|      0|    }
 2439|       |
 2440|  16.6k|    s.section.tags_met |= state->tags_met;
 2441|  16.6k|    result = DoProcessJpeg(state, jpg);
 2442|       |
 2443|  16.6k|    if (s.section.is_active) {
  ------------------
  |  Branch (2443:9): [True: 16.3k, False: 320]
  ------------------
 2444|       |      // TODO(eustas): dcheck state->pos > s.section.milestone
 2445|  16.3k|      size_t processed_len = state->pos - s.section.milestone;
 2446|       |      // TODO(eustas): dcheck processed_len < s.section.remaining
 2447|  16.3k|      s.section.remaining -= processed_len;
 2448|  16.3k|    }
 2449|       |
 2450|  16.6k|    if (!UnloadInput(state, result)) break;
  ------------------
  |  Branch (2450:9): [True: 6.07k, False: 10.5k]
  ------------------
 2451|  16.6k|  }
 2452|  16.6k|  UnchargeBuffer(state);
 2453|  16.6k|  return result;
 2454|  16.6k|}
_ZN7brunsli17BrunsliDecodeJpegEPKhmPNS_8JPEGDataE:
 2460|  16.6k|                                JPEGData* jpg) {
 2461|  16.6k|  if (!data) return BRUNSLI_INVALID_PARAM;
  ------------------
  |  Branch (2461:7): [True: 0, False: 16.6k]
  ------------------
 2462|       |
 2463|  16.6k|  State state;
 2464|  16.6k|  state.data = data;
 2465|  16.6k|  state.len = len;
 2466|       |
 2467|  16.6k|  return internal::dec::ProcessJpeg(&state, jpg);
 2468|  16.6k|}
brunsli_decode.cc:_ZZN7brunsli14DecodeScanInfoEPNS_8internal3dec5StateEPNS_8JPEGDataEENK3$_0clEv:
  441|  59.4k|  const auto maybe_add_zero_run = [&js, jpg] () {
  442|  59.4k|    if (js.last_num > 0) {
  ------------------
  |  Branch (442:9): [True: 50.7k, False: 8.74k]
  ------------------
  443|  50.7k|      JPEGScanInfo::ExtraZeroRunInfo info;
  444|  50.7k|      info.block_idx = js.last_block_idx;
  445|  50.7k|      info.num_extra_zero_runs = js.last_num;
  446|  50.7k|      jpg->scan_info[js.i].extra_zero_runs.push_back(info);
  447|  50.7k|      js.last_num = 0;
  448|  50.7k|    }
  449|  59.4k|  };
brunsli_decode.cc:_ZN7brunsliL16DecodeCoeffOrderEPjPNS_9BitSourceEPNS_10WordSourceE:
  544|  5.61k|                                              WordSource* in) {
  545|  5.61k|  uint32_t lehmer[kDCTBlockSize] = {0};
  546|  5.61k|  static const int kSpan = 16;
  547|  28.0k|  for (int i = 0; i < kDCTBlockSize; i += kSpan) {
  ------------------
  |  Branch (547:19): [True: 22.4k, False: 5.60k]
  ------------------
  548|  22.4k|    if (!br->ReadBits(1, in)) continue;  // span is all-zero
  ------------------
  |  Branch (548:9): [True: 19.9k, False: 2.50k]
  ------------------
  549|  2.50k|    const int start = (i > 0) ? i : 1;
  ------------------
  |  Branch (549:23): [True: 784, False: 1.72k]
  ------------------
  550|  2.50k|    const int end = i + kSpan;
  551|  40.7k|    for (int j = start; j < end; ++j) {
  ------------------
  |  Branch (551:25): [True: 38.2k, False: 2.49k]
  ------------------
  552|  38.2k|      uint32_t v = 0;
  553|  49.8k|      while (v <= kDCTBlockSize) {
  ------------------
  |  Branch (553:14): [True: 49.8k, False: 9]
  ------------------
  554|  49.8k|        const uint32_t bits = br->ReadBits(3, in);
  555|  49.8k|        v += bits;
  556|  49.8k|        if (bits < 7) break;
  ------------------
  |  Branch (556:13): [True: 38.2k, False: 11.6k]
  ------------------
  557|  49.8k|      }
  558|  38.2k|      if (v > kDCTBlockSize) return false;
  ------------------
  |  Branch (558:11): [True: 10, False: 38.2k]
  ------------------
  559|  38.2k|      lehmer[j] = v;
  560|  38.2k|    }
  561|  2.50k|  }
  562|  5.60k|  int end = kDCTBlockSize - 1;
  563|   328k|  while (end >= 1 && lehmer[end] == 0) {
  ------------------
  |  Branch (563:10): [True: 324k, False: 3.77k]
  |  Branch (563:22): [True: 322k, False: 1.83k]
  ------------------
  564|   322k|    --end;
  565|   322k|  }
  566|  5.60k|  if (lehmer[end] == 1) return false;
  ------------------
  |  Branch (566:7): [True: 46, False: 5.56k]
  ------------------
  567|  29.7k|  for (int i = 1; i <= end; ++i) {
  ------------------
  |  Branch (567:19): [True: 24.3k, False: 5.39k]
  ------------------
  568|  24.3k|    if (lehmer[i] == 0) return false;
  ------------------
  |  Branch (568:9): [True: 163, False: 24.1k]
  ------------------
  569|  24.1k|    --lehmer[i];
  570|  24.1k|  }
  571|  5.39k|  if (!DecodeLehmerCode(lehmer, kDCTBlockSize, order)) return false;
  ------------------
  |  Branch (571:7): [True: 11, False: 5.38k]
  ------------------
  572|   350k|  for (int k = 0; k < kDCTBlockSize; ++k) {
  ------------------
  |  Branch (572:19): [True: 344k, False: 5.38k]
  ------------------
  573|   344k|    order[k] = kJPEGNaturalOrder[order[k]];
  574|   344k|  }
  575|  5.38k|  return true;
  576|  5.39k|}
brunsli_decode.cc:_ZN7brunsliL13DecodeAcBlockERKNS_13AcBlockCookieE:
  779|  1.68M|static size_t BRUNSLI_NOINLINE DecodeAcBlock(const AcBlockCookie& cookie) {
  780|  1.68M|  AcBlockCookie c = cookie;
  781|       |
  782|  1.68M|  BinaryArithmeticDecoder ac = *c.ac;
  783|  1.68M|  WordSource* in = c.in;
  784|  1.68M|  ANSDecoder ans = *c.ans;
  785|  1.68M|  BitSource br = *c.br;
  786|       |
  787|  1.68M|  size_t num_nonzeros = 0;
  788|       |
  789|  1.68M|  const uint8_t nonzero_ctx = NumNonzerosContext(c.prev_num_nonzeros, c.x, c.y);
  790|  1.68M|  size_t last_nz = DecodeNumNonzeros(
  791|  1.68M|      c.num_nonzero_prob + kNumNonZeroTreeSize * nonzero_ctx, &ac, in);
  792|  79.6M|  for (size_t k = last_nz + 1; k < kDCTBlockSize; ++k) {
  ------------------
  |  Branch (792:32): [True: 77.9M, False: 1.68M]
  ------------------
  793|  77.9M|    c.prev_sgn[k] = 0;
  794|  77.9M|    c.prev_abs[k] = 0;
  795|  77.9M|  }
  796|  29.6M|  for (size_t k = last_nz; k > 0; --k) {
  ------------------
  |  Branch (796:28): [True: 27.9M, False: 1.68M]
  ------------------
  797|  27.9M|    int is_zero = 0;
  798|  27.9M|    if (k < last_nz) {
  ------------------
  |  Branch (798:9): [True: 27.2M, False: 706k]
  ------------------
  799|  27.2M|      size_t bucket = kNonzeroBuckets[num_nonzeros - 1];
  800|  27.2M|      size_t is_zero_ctx = bucket * kDCTBlockSize + k;
  801|  27.2M|      Prob& p = c.is_zero_prob[is_zero_ctx];
  802|  27.2M|      is_zero = ac.ReadBit(p.get_proba(), in);
  803|  27.2M|      p.Add(is_zero);
  804|  27.2M|    }
  805|  27.9M|    int abs_val = 0;
  806|  27.9M|    int sign = 1;
  807|  27.9M|    const int k_nat = c.order[k];
  808|  27.9M|    if (!is_zero) {
  ------------------
  |  Branch (808:9): [True: 4.44M, False: 23.5M]
  ------------------
  809|  4.44M|      size_t context_type = c.context_modes[k_nat];
  810|  4.44M|      size_t avg_ctx = 0;
  811|  4.44M|      size_t sign_ctx = kMaxAverageContext;
  812|  4.44M|      if ((context_type & 1) && (c.y > 0)) {
  ------------------
  |  Branch (812:11): [True: 909k, False: 3.53M]
  |  Branch (812:33): [True: 840k, False: 69.8k]
  ------------------
  813|   840k|        size_t offset = k_nat & 7;
  814|   840k|        ACPredictContextRow(c.prev_row_coeffs + offset, c.coeffs + offset,
  815|   840k|                            c.mult_col + offset * 8, &avg_ctx, &sign_ctx);
  816|  3.60M|      } else if ((context_type & 2) && (c.x > 0)) {
  ------------------
  |  Branch (816:18): [True: 993k, False: 2.61M]
  |  Branch (816:40): [True: 982k, False: 11.2k]
  ------------------
  817|   982k|        size_t offset = k_nat & ~7;
  818|   982k|        ACPredictContextCol(c.prev_col_coeffs + offset, c.coeffs + offset,
  819|   982k|                            c.mult_row + offset, &avg_ctx, &sign_ctx);
  820|  2.62M|      } else if (!context_type) {
  ------------------
  |  Branch (820:18): [True: 2.54M, False: 80.8k]
  ------------------
  821|  2.54M|        avg_ctx = WeightedAverageContext(c.prev_abs + k, c.prev_row_delta);
  822|  2.54M|        sign_ctx =
  823|  2.54M|            c.prev_sgn[k] * 3 + c.prev_sgn[static_cast<int>(k) - kDCTBlockSize];
  824|  2.54M|      }
  825|  4.44M|      sign_ctx = sign_ctx * kDCTBlockSize + k;
  826|  4.44M|      Prob& sign_p = c.sign_prob[sign_ctx];
  827|  4.44M|      sign = ac.ReadBit(sign_p.get_proba(), in);
  828|  4.44M|      sign_p.Add(sign);
  829|  4.44M|      c.prev_sgn[k] = sign + 1;
  830|  4.44M|      sign = 1 - 2 * sign;
  831|  4.44M|      const size_t z_dens_ctx =
  832|  4.44M|          ZeroDensityContext(num_nonzeros, k, c.context_bits);
  833|  4.44M|      size_t histo_ix = z_dens_ctx * kNumAvrgContexts + avg_ctx;
  834|  4.44M|      size_t entropy_ix = c.context_map[histo_ix];
  835|  4.44M|      int code = ans.ReadSymbol(c.entropy_codes[entropy_ix], in);
  836|  4.44M|      if (code < kNumDirectCodes) {
  ------------------
  |  Branch (836:11): [True: 2.20M, False: 2.23M]
  ------------------
  837|  2.20M|        abs_val = code + 1;
  838|  2.23M|      } else {
  839|  2.23M|        int nbits = code - kNumDirectCodes;
  840|  2.23M|        Prob& p = c.first_extra_bit_prob[k * 10 + nbits];
  841|  2.23M|        int first_extra_bit = ac.ReadBit(p.get_proba(), in);
  842|  2.23M|        p.Add(first_extra_bit);
  843|  2.23M|        int extra_bits_val = first_extra_bit << nbits;
  844|  2.23M|        if (nbits > 0) {
  ------------------
  |  Branch (844:13): [True: 1.61M, False: 624k]
  ------------------
  845|  1.61M|          extra_bits_val |= br.ReadBits(nbits, in);
  846|  1.61M|        }
  847|  2.23M|        abs_val = kNumDirectCodes - 1 + (2u << nbits) + extra_bits_val;
  848|  2.23M|      }
  849|  4.44M|      ++num_nonzeros;
  850|  23.5M|    } else {
  851|  23.5M|      c.prev_sgn[k] = 0;
  852|  23.5M|    }
  853|  27.9M|    int coeff = sign * abs_val;
  854|  27.9M|    c.coeffs[k_nat] = coeff;
  855|  27.9M|    c.prev_abs[k] = abs_val;
  856|  27.9M|  }
  857|       |
  858|  1.68M|  *c.ans = ans;
  859|  1.68M|  *c.br = br;
  860|  1.68M|  *c.ac = ac;
  861|       |
  862|  1.68M|  return num_nonzeros;
  863|  1.68M|}
brunsli_decode.cc:_ZN7brunsliL17DecodeNumNonzerosEPNS_4ProbEPNS_23BinaryArithmeticDecoderEPNS_10WordSourceE:
  580|  1.68M|                                WordSource* in) {
  581|       |  // To simplity BST navigation, we use 1-based indexing.
  582|  1.68M|  Prob* bst = p - 1;
  583|  1.68M|  size_t ctx = 1;
  584|       |
  585|  11.7M|  for (size_t b = 0; b < kNumNonZeroBits; ++b) {
  ------------------
  |  Branch (585:22): [True: 10.0M, False: 1.68M]
  ------------------
  586|  10.0M|    const int bit = ac->ReadBit(bst[ctx].get_proba(), in);
  587|  10.0M|    bst[ctx].Add(bit);
  588|  10.0M|    ctx = 2 * ctx + bit;
  589|  10.0M|  }
  590|       |
  591|       |  // Leaf index in the level corresponds to the resuling value.
  592|  1.68M|  size_t val = ctx - (1u << kNumNonZeroBits);
  593|  1.68M|  BRUNSLI_DCHECK(val <= kNumNonZeroTreeSize);
  594|  1.68M|  return val;
  595|  1.68M|}
brunsli_decode.cc:_ZN7brunsliL18DecodeEmptyAcBlockEPiS0_:
  742|  10.2M|    int* BRUNSLI_RESTRICT prev_sgn, int* BRUNSLI_RESTRICT prev_abs) {
  743|   658M|  for (int k = 1; k < kDCTBlockSize; ++k) {
  ------------------
  |  Branch (743:19): [True: 648M, False: 10.2M]
  ------------------
  744|   648M|    prev_sgn[k] = 0;
  745|   648M|    prev_abs[k] = 0;
  746|   648M|  }
  747|  10.2M|}
brunsli_decode.cc:_ZN7brunsliL12CheckCanReadEPNS_8internal3dec5StateEm:
  978|   199k|static bool CheckCanRead(State* state, size_t required) {
  979|       |  // TODO(eustas): dcheck len > pos
  980|   199k|  size_t available = state->len - state->pos;
  981|   199k|  return required <= available;
  982|   199k|}
brunsli_decode.cc:_ZN7brunsliL4FailEPNS_8internal3dec5StateENS_13BrunsliStatusE:
 1034|  17.1k|static Stage Fail(State* state, BrunsliStatus result) {
 1035|  17.1k|  InternalState& s = *state->internal;
 1036|  17.1k|  s.result = result;
 1037|       |  // Preserve current stage for continuation / error reporting.
 1038|  17.1k|  s.last_stage = state->stage;
 1039|  17.1k|  return Stage::ERROR;
 1040|  17.1k|}
brunsli_decode.cc:_ZN7brunsliL7ReadTagEPNS_8internal3dec5StateEPNS1_12SectionStateE:
 1042|   122k|static BrunsliStatus ReadTag(State* state, SectionState* section) {
 1043|   122k|  if (!CheckCanReadByte(state)) return BRUNSLI_NOT_ENOUGH_DATA;
  ------------------
  |  Branch (1043:7): [True: 187, False: 122k]
  ------------------
 1044|   122k|  const uint8_t marker = ReadByte(state);
 1045|       |
 1046|   122k|  const size_t tag = marker >> 3u;
 1047|   122k|  if (tag == 0 || tag > 15) return BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (1047:7): [True: 30, False: 122k]
  |  Branch (1047:19): [True: 25, False: 122k]
  ------------------
 1048|   122k|  section->tag = tag;
 1049|       |
 1050|   122k|  const size_t wiring_type = marker & 0x7u;
 1051|   122k|  if (wiring_type != kBrunsliWiringTypeVarint &&
  ------------------
  |  Branch (1051:7): [True: 63.4k, False: 58.8k]
  ------------------
 1052|  63.4k|      wiring_type != kBrunsliWiringTypeLengthDelimited) {
  ------------------
  |  Branch (1052:7): [True: 23, False: 63.3k]
  ------------------
 1053|     23|    return BRUNSLI_INVALID_BRN;
 1054|     23|  }
 1055|   122k|  section->is_section = (wiring_type == kBrunsliWiringTypeLengthDelimited);
 1056|       |
 1057|   122k|  const uint32_t tag_bit = 1u << tag;
 1058|   122k|  if (section->tags_met & tag_bit) {
  ------------------
  |  Branch (1058:7): [True: 16, False: 122k]
  ------------------
 1059|     16|    BRUNSLI_LOG_ERROR() << "Duplicate marker " << std::hex
  ------------------
  |  |  431|     16|#define BRUNSLI_LOG_ERROR() BRUNSLI_LOG_(ERROR)
  |  |  ------------------
  |  |  |  |  413|     80|#define BRUNSLI_LOG_(LEVEL) std::cerr
  |  |  ------------------
  ------------------
 1060|     16|                        << static_cast<int>(marker) << BRUNSLI_ENDL();
  ------------------
  |  |  414|     16|#define BRUNSLI_ENDL() std::endl
  ------------------
 1061|     16|    return BRUNSLI_INVALID_BRN;
 1062|     16|  }
 1063|   122k|  section->tags_met |= tag_bit;
 1064|       |
 1065|   122k|  return BRUNSLI_OK;
 1066|   122k|}
brunsli_decode.cc:_ZN7brunsliL16CheckCanReadByteEPNS_8internal3dec5StateE:
  984|   122k|static bool CheckCanReadByte(State* state) {
  985|       |  // TODO(eustas): dcheck len > pos
  986|   122k|  return state->pos != state->len;
  987|   122k|}
brunsli_decode.cc:_ZN7brunsliL8ReadByteEPNS_8internal3dec5StateE:
  989|   122k|static uint8_t ReadByte(State* state) {
  990|       |  // TODO(eustas): dcheck len > pos
  991|   122k|  return state->data[state->pos++];
  992|   122k|}
brunsli_decode.cc:_ZN7brunsliL12EnterSectionEPNS_8internal3dec5StateEPNS1_12SectionStateE:
 1068|  58.3k|static BrunsliStatus EnterSection(State* state, SectionState* section) {
 1069|  58.3k|  size_t section_size;
 1070|  58.3k|  BrunsliStatus status = DecodeBase128(state, &section_size);
 1071|  58.3k|  if (status != BRUNSLI_OK) return status;
  ------------------
  |  Branch (1071:7): [True: 100, False: 58.2k]
  ------------------
 1072|  58.2k|  section->is_active = true;
 1073|  58.2k|  section->remaining = section_size;
 1074|  58.2k|  section->milestone = state->pos;
 1075|  58.2k|  section->projected_end = state->pos + section->remaining;
 1076|  58.2k|  return BRUNSLI_OK;
 1077|  58.3k|}
brunsli_decode.cc:_ZN7brunsliL19IsAtSectionBoundaryEPNS_8internal3dec5StateE:
 1093|   145k|static bool IsAtSectionBoundary(State* state) {
 1094|   145k|  return state->pos == state->internal->section.projected_end;
 1095|   145k|}
brunsli_decode.cc:_ZN7brunsliL13DecodeBase128EPNS_8internal3dec5StateEPm:
 1016|   146k|static BrunsliStatus DecodeBase128(State* state, size_t* val) {
 1017|   146k|  *val = 0;
 1018|   146k|  uint64_t b = 0x80;
 1019|   146k|  uint64_t v = 0;
 1020|   146k|  size_t i = 0;
 1021|   329k|  while ((i < 9) && (b & 0x80u)) {
  ------------------
  |  Branch (1021:10): [True: 328k, False: 1.03k]
  |  Branch (1021:21): [True: 183k, False: 144k]
  ------------------
 1022|   183k|    if (!CheckCanRead(state, i + 1)) return BRUNSLI_NOT_ENOUGH_DATA;
  ------------------
  |  Branch (1022:9): [True: 293, False: 182k]
  ------------------
 1023|   182k|    b = PeekByte(state, i);
 1024|   182k|    v |= (b & 0x7Fu) << (i * 7);
 1025|   182k|    ++i;
 1026|   182k|  }
 1027|   145k|  SkipBytes(state, i);
 1028|   145k|  *val = v;
 1029|   145k|  bool terminated = ((b & 0x80u) == 0);
 1030|   145k|  bool fit = (v == *val);
 1031|   145k|  return (terminated && fit) ? BRUNSLI_OK : BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (1031:11): [True: 145k, False: 41]
  |  Branch (1031:25): [True: 145k, False: 0]
  ------------------
 1032|   146k|}
brunsli_decode.cc:_ZN7brunsliL8PeekByteEPNS_8internal3dec5StateEm:
  994|   182k|static uint8_t PeekByte(State* state, size_t offset) {
  995|       |  // TODO(eustas): dcheck overflow.
  996|   182k|  return state->data[state->pos + offset];
  997|   182k|}
brunsli_decode.cc:_ZN7brunsliL9SkipBytesEPNS_8internal3dec5StateEm:
  999|   345k|static void SkipBytes(State* state, size_t len) {
 1000|       |  // TODO(eustas): dcheck overflow.
 1001|   345k|  state->pos += len;
 1002|   345k|}
brunsli_decode.cc:_ZN7brunsliL18SkipAvailableBytesEPNS_8internal3dec5StateEm:
 1009|  4.99k|static size_t SkipAvailableBytes(State* state, size_t len) {
 1010|  4.99k|  size_t available = GetBytesAvailable(state);
 1011|  4.99k|  size_t skip_bytes = std::min(available, len);
 1012|  4.99k|  state->pos += skip_bytes;
 1013|  4.99k|  return skip_bytes;
 1014|  4.99k|}
brunsli_decode.cc:_ZN7brunsliL17GetBytesAvailableEPNS_8internal3dec5StateE:
 1004|   244k|static size_t GetBytesAvailable(State* state) {
 1005|       |  // TODO(eustas): dcheck len > pos
 1006|   244k|  return state->len - state->pos;
 1007|   244k|}
brunsli_decode.cc:_ZN7brunsliL12LeaveSectionEPNS_8internal3dec12SectionStateE:
 1079|  16.0k|static void LeaveSection(SectionState* section) {
 1080|  16.0k|  section->is_active = false;
 1081|  16.0k|}
_ZN7brunsli7DivCeilEii:
   84|  31.1k|inline int DivCeil(int a, int b) { return (a + b - 1) / b; }
brunsli_decode.cc:_ZN7brunsliL17DecodeOriginalJpgEPNS_8internal3dec5StateEPNS_8JPEGDataE:
 1978|    415|static Stage DecodeOriginalJpg(State* state, JPEGData* jpg) {
 1979|    415|  InternalState& s = *state->internal;
 1980|    415|  FallbackState& fs = s.fallback;
 1981|       |
 1982|  1.18k|  while (fs.stage != FallbackState::DONE) {
  ------------------
  |  Branch (1982:10): [True: 1.14k, False: 47]
  ------------------
 1983|  1.14k|    switch (fs.stage) {
 1984|    415|      case FallbackState::READ_TAG: {
  ------------------
  |  Branch (1984:7): [True: 415, False: 727]
  ------------------
 1985|    415|        BrunsliStatus status = ReadTag(state, &s.section);
 1986|    415|        if (status != BRUNSLI_OK) return Fail(state, status);
  ------------------
  |  Branch (1986:13): [True: 17, False: 398]
  ------------------
 1987|    398|        if (s.section.tag != kBrunsliOriginalJpgTag || !s.section.is_section) {
  ------------------
  |  Branch (1987:13): [True: 4, False: 394]
  |  Branch (1987:56): [True: 1, False: 393]
  ------------------
 1988|      5|          return Fail(state, BRUNSLI_INVALID_BRN);
 1989|      5|        }
 1990|    393|        fs.stage = FallbackState::ENTER_SECTION;
 1991|    393|        break;
 1992|    398|      }
 1993|       |
 1994|    393|      case FallbackState::ENTER_SECTION: {
  ------------------
  |  Branch (1994:7): [True: 393, False: 749]
  ------------------
 1995|    393|        BrunsliStatus status = EnterSection(state, &s.section);
 1996|    393|        if (status != BRUNSLI_OK) return Fail(state, status);
  ------------------
  |  Branch (1996:13): [True: 55, False: 338]
  ------------------
 1997|    338|        jpg->original_jpg_size = s.section.remaining;
 1998|       |        // Edge case - empty payload.
 1999|    338|        if (jpg->original_jpg_size == 0) {
  ------------------
  |  Branch (1999:13): [True: 4, False: 334]
  ------------------
 2000|      4|          jpg->original_jpg = nullptr;
 2001|      4|          fs.stage = FallbackState::DONE;
 2002|      4|          break;
 2003|      4|        }
 2004|    334|        fs.stage = FallbackState::READ_CONTENTS;
 2005|    334|        break;
 2006|    338|      }
 2007|       |
 2008|    334|      case FallbackState::READ_CONTENTS: {
  ------------------
  |  Branch (2008:7): [True: 334, False: 808]
  ------------------
 2009|    334|        size_t chunk_size = GetBytesAvailable(state);
 2010|    334|        if (chunk_size == 0) {
  ------------------
  |  Branch (2010:13): [True: 80, False: 254]
  ------------------
 2011|       |          // TODO(eustas): dcheck s.section.remaining != 0
 2012|     80|          return Fail(state, BRUNSLI_NOT_ENOUGH_DATA);
 2013|     80|        }
 2014|       |        // Check if it is possible to avoid copy.
 2015|    254|        const uint8_t* src = state->data + state->pos;
 2016|    254|        if (fs.storage.empty()) {
  ------------------
  |  Branch (2016:13): [True: 254, False: 0]
  ------------------
 2017|    254|          if (chunk_size >= jpg->original_jpg_size) {
  ------------------
  |  Branch (2017:15): [True: 43, False: 211]
  ------------------
 2018|     43|            jpg->original_jpg = src;
 2019|     43|            SkipBytes(state, jpg->original_jpg_size);
 2020|     43|            fs.stage = FallbackState::DONE;
 2021|     43|            break;
 2022|     43|          }
 2023|    254|        }
 2024|       |        // Otherwise, copy input.
 2025|    211|        size_t remaining = jpg->original_jpg_size - fs.storage.size();
 2026|    211|        size_t to_copy = std::min(chunk_size, remaining);
 2027|    211|        fs.storage.insert(fs.storage.cend(), src, src + to_copy);
 2028|    211|        SkipBytes(state, to_copy);
 2029|    211|        if (fs.storage.size() == jpg->original_jpg_size) {
  ------------------
  |  Branch (2029:13): [True: 0, False: 211]
  ------------------
 2030|      0|          jpg->original_jpg = fs.storage.data();
 2031|      0|          fs.stage = FallbackState::DONE;
 2032|      0|          break;
 2033|      0|        }
 2034|       |        // TODO(eustas): dcheck GetBytesAvailable(state) == 0
 2035|    211|        return Fail(state, BRUNSLI_NOT_ENOUGH_DATA);
 2036|    211|      }
 2037|       |
 2038|      0|      default: return Fail(state, BRUNSLI_DECOMPRESSION_ERROR);
  ------------------
  |  Branch (2038:7): [True: 0, False: 1.14k]
  ------------------
 2039|  1.14k|    }
 2040|  1.14k|  }
 2041|       |
 2042|     47|  LeaveSection(&s.section);
 2043|     47|  return Stage::DONE;
 2044|    415|}
brunsli_decode.cc:_ZN7brunsliL12ParseSectionEPNS_8internal3dec5StateE:
 2046|  41.5k|static Stage ParseSection(State* state) {
 2047|  41.5k|  InternalState& s = *state->internal;
 2048|  41.5k|  SectionHeaderState& sh = s.section_header;
 2049|       |
 2050|  41.5k|  Stage result = Stage::ERROR;
 2051|       |
 2052|   124k|  while (sh.stage != SectionHeaderState::DONE) {
  ------------------
  |  Branch (2052:10): [True: 82.9k, False: 41.4k]
  ------------------
 2053|  82.9k|    switch (sh.stage) {
 2054|  41.5k|      case SectionHeaderState::READ_TAG: {
  ------------------
  |  Branch (2054:7): [True: 41.5k, False: 41.4k]
  ------------------
 2055|  41.5k|        BrunsliStatus status = ReadTag(state, &s.section);
 2056|  41.5k|        if (status == BRUNSLI_NOT_ENOUGH_DATA) {
  ------------------
  |  Branch (2056:13): [True: 74, False: 41.4k]
  ------------------
 2057|     74|          if (HasSection(state, kBrunsliACDataTag)) return Stage::DONE;
  ------------------
  |  Branch (2057:15): [True: 0, False: 74]
  ------------------
 2058|     74|        }
 2059|  41.5k|        if (status != BRUNSLI_OK) return Fail(state, status);
  ------------------
  |  Branch (2059:13): [True: 102, False: 41.4k]
  ------------------
 2060|  41.4k|        if (s.section.is_section) {
  ------------------
  |  Branch (2060:13): [True: 41.3k, False: 23]
  ------------------
 2061|  41.3k|          sh.stage = SectionHeaderState::ENTER_SECTION;
 2062|  41.3k|          continue;
 2063|  41.3k|        }
 2064|     23|        const uint32_t tag_bit = 1u << s.section.tag;
 2065|     23|        const bool is_known_section_tag = kKnownSectionTags & tag_bit;
 2066|     23|        if (is_known_section_tag) return Fail(state, BRUNSLI_INVALID_BRN);
  ------------------
  |  Branch (2066:13): [True: 2, False: 21]
  ------------------
 2067|     21|        sh.stage = SectionHeaderState::READ_VALUE;
 2068|     21|        continue;
 2069|     23|      }
 2070|       |
 2071|     21|      case SectionHeaderState::READ_VALUE: {
  ------------------
  |  Branch (2071:7): [True: 21, False: 82.9k]
  ------------------
 2072|       |        // No known varint tags on top level.
 2073|     21|        size_t sink;
 2074|     21|        BrunsliStatus status = DecodeBase128(state, &sink);
 2075|     21|        if (status != BRUNSLI_OK) return Fail(state, status);
  ------------------
  |  Branch (2075:13): [True: 3, False: 18]
  ------------------
 2076|     18|        result = Stage::SECTION;
 2077|     18|        sh.stage = SectionHeaderState::DONE;
 2078|     18|        continue;
 2079|     21|      }
 2080|       |
 2081|  41.3k|      case SectionHeaderState::ENTER_SECTION: {
  ------------------
  |  Branch (2081:7): [True: 41.3k, False: 41.5k]
  ------------------
 2082|  41.3k|        BrunsliStatus status = EnterSection(state, &s.section);
 2083|  41.3k|        if (status != BRUNSLI_OK) return Fail(state, status);
  ------------------
  |  Branch (2083:13): [True: 2, False: 41.3k]
  ------------------
 2084|  41.3k|        result = Stage::SECTION_BODY;
 2085|  41.3k|        sh.stage = SectionHeaderState::DONE;
 2086|  41.3k|        continue;
 2087|  41.3k|      }
 2088|       |
 2089|      0|      default: return Fail(state, BRUNSLI_DECOMPRESSION_ERROR);
  ------------------
  |  Branch (2089:7): [True: 0, False: 82.9k]
  ------------------
 2090|  82.9k|    }
 2091|  82.9k|  }
 2092|       |
 2093|  41.4k|  sh.stage = SectionHeaderState::READ_TAG;
 2094|  41.4k|  BRUNSLI_DCHECK(result != Stage::ERROR);
 2095|  41.4k|  return result;
 2096|  41.5k|}
brunsli_decode.cc:_ZN7brunsliL14ProcessSectionEPNS_8internal3dec5StateEPNS_8JPEGDataE:
 2098|  41.3k|static Stage ProcessSection(State* state, JPEGData* jpg) {
 2099|  41.3k|  InternalState& s = *state->internal;
 2100|       |
 2101|  41.3k|  const int32_t tag_bit = 1u << s.section.tag;
 2102|  41.3k|  const bool is_known_section_tag = kKnownSectionTags & tag_bit;
 2103|       |
 2104|  41.3k|  const bool skip_section =
 2105|  41.3k|      !is_known_section_tag || (state->skip_tags & tag_bit);
  ------------------
  |  Branch (2105:7): [True: 172, False: 41.2k]
  |  Branch (2105:32): [True: 0, False: 41.2k]
  ------------------
 2106|       |
 2107|  41.3k|  if (skip_section) {
  ------------------
  |  Branch (2107:7): [True: 172, False: 41.2k]
  ------------------
 2108|       |    // Skip section content.
 2109|    172|    size_t to_skip =
 2110|    172|        std::min(GetBytesAvailable(state), RemainingSectionLength(state));
 2111|    172|    state->pos += to_skip;
 2112|    172|    if (RemainingSectionLength(state) != 0) {
  ------------------
  |  Branch (2112:9): [True: 132, False: 40]
  ------------------
 2113|    132|      BRUNSLI_DCHECK(GetBytesAvailable(state) == 0);
 2114|    132|      return Fail(state, BRUNSLI_NOT_ENOUGH_DATA);
 2115|    132|    }
 2116|     40|    return Stage::SECTION;
 2117|    172|  }
 2118|       |
 2119|  41.2k|  switch (s.section.tag) {
 2120|  4.02k|    case kBrunsliMetaDataTag: {
  ------------------
  |  Branch (2120:5): [True: 4.02k, False: 37.1k]
  ------------------
 2121|  4.02k|      BrunsliStatus status = DecodeMetaDataSection(state, jpg);
 2122|  4.02k|      if (status != BRUNSLI_OK) return Fail(state, status);
  ------------------
  |  Branch (2122:11): [True: 4.00k, False: 26]
  ------------------
 2123|     26|      break;
 2124|  4.02k|    }
 2125|       |
 2126|  11.3k|    case kBrunsliJPEGInternalsTag: {
  ------------------
  |  Branch (2126:5): [True: 11.3k, False: 29.8k]
  ------------------
 2127|  11.3k|      BrunsliStatus status = DecodeJPEGInternalsSection(state, jpg);
 2128|  11.3k|      if (status != BRUNSLI_OK) return Fail(state, status);
  ------------------
  |  Branch (2128:11): [True: 2.37k, False: 8.96k]
  ------------------
 2129|  8.96k|      break;
 2130|  11.3k|    }
 2131|       |
 2132|  8.96k|    case kBrunsliQuantDataTag: {
  ------------------
  |  Branch (2132:5): [True: 7.52k, False: 33.6k]
  ------------------
 2133|  7.52k|      if (!HasSection(state, kBrunsliJPEGInternalsTag)) {
  ------------------
  |  Branch (2133:11): [True: 1, False: 7.52k]
  ------------------
 2134|      1|        return Fail(state, BRUNSLI_INVALID_BRN);
 2135|      1|      }
 2136|  7.52k|      BrunsliStatus status = DecodeQuantDataSection(state, jpg);
 2137|  7.52k|      if (status != BRUNSLI_OK) return Fail(state, status);
  ------------------
  |  Branch (2137:11): [True: 1.68k, False: 5.83k]
  ------------------
 2138|  5.83k|      break;
 2139|  7.52k|    }
 2140|       |
 2141|  7.26k|    case kBrunsliHistogramDataTag: {
  ------------------
  |  Branch (2141:5): [True: 7.26k, False: 33.9k]
  ------------------
 2142|  7.26k|      if (!HasSection(state, kBrunsliJPEGInternalsTag)) {
  ------------------
  |  Branch (2142:11): [True: 2, False: 7.26k]
  ------------------
 2143|      2|        return Fail(state, BRUNSLI_INVALID_BRN);
 2144|      2|      }
 2145|  7.26k|      BrunsliStatus status = DecodeHistogramDataSection(state, jpg);
 2146|  7.26k|      if (status != BRUNSLI_OK) return Fail(state, status);
  ------------------
  |  Branch (2146:11): [True: 1.46k, False: 5.80k]
  ------------------
 2147|  5.80k|      break;
 2148|  7.26k|    }
 2149|       |
 2150|  5.80k|    case kBrunsliDCDataTag: {
  ------------------
  |  Branch (2150:5): [True: 5.79k, False: 35.4k]
  ------------------
 2151|  5.79k|      if (!HasSection(state, kBrunsliHistogramDataTag)) {
  ------------------
  |  Branch (2151:11): [True: 1, False: 5.79k]
  ------------------
 2152|      1|        return Fail(state, BRUNSLI_INVALID_BRN);
 2153|      1|      }
 2154|  5.79k|      if (!HasSection(state, kBrunsliQuantDataTag)) {
  ------------------
  |  Branch (2154:11): [True: 1, False: 5.79k]
  ------------------
 2155|      1|        return Fail(state, BRUNSLI_INVALID_BRN);
 2156|      1|      }
 2157|       |      // This section reads input word by word.
 2158|  5.79k|      if ((RemainingSectionLength(state) & 1) != 0) {
  ------------------
  |  Branch (2158:11): [True: 6, False: 5.78k]
  ------------------
 2159|      6|        return Fail(state, BRUNSLI_INVALID_BRN);
 2160|      6|      }
 2161|  5.78k|      internal::dec::WarmupMeta(jpg, state);
 2162|  5.78k|      BrunsliStatus status = DecodeDCDataSection(state);
 2163|  5.78k|      if (status != BRUNSLI_OK) return Fail(state, status);
  ------------------
  |  Branch (2163:11): [True: 471, False: 5.31k]
  ------------------
 2164|  5.31k|      break;
 2165|  5.78k|    }
 2166|       |
 2167|  5.31k|    case kBrunsliACDataTag: {
  ------------------
  |  Branch (2167:5): [True: 5.26k, False: 35.9k]
  ------------------
 2168|  5.26k|      if (!HasSection(state, kBrunsliDCDataTag)) {
  ------------------
  |  Branch (2168:11): [True: 1, False: 5.26k]
  ------------------
 2169|      1|        return Fail(state, BRUNSLI_INVALID_BRN);
 2170|      1|      }
 2171|       |      // This section reads input word by word.
 2172|  5.26k|      if ((RemainingSectionLength(state) & 1) != 0) {
  ------------------
  |  Branch (2172:11): [True: 1, False: 5.26k]
  ------------------
 2173|      1|        return Fail(state, BRUNSLI_INVALID_BRN);
 2174|      1|      }
 2175|  5.26k|      internal::dec::WarmupMeta(jpg, state);
 2176|  5.26k|      BrunsliStatus status = DecodeACDataSection(state);
 2177|  5.26k|      if (status != BRUNSLI_OK) return Fail(state, status);
  ------------------
  |  Branch (2177:11): [True: 813, False: 4.44k]
  ------------------
 2178|  4.44k|      break;
 2179|  5.26k|    }
 2180|       |
 2181|  4.44k|    default:
  ------------------
  |  Branch (2181:5): [True: 0, False: 41.2k]
  ------------------
 2182|       |      /* Unreachable */
 2183|      0|      return Fail(state, BRUNSLI_INVALID_BRN);
 2184|  41.2k|  }
 2185|       |
 2186|  30.4k|  if (!IsAtSectionBoundary(state)) {
  ------------------
  |  Branch (2186:7): [True: 55, False: 30.3k]
  ------------------
 2187|     55|    return Fail(state, BRUNSLI_INVALID_BRN);
 2188|     55|  }
 2189|       |
 2190|       |  // Nothing is expected after the AC data.
 2191|  30.3k|  if (s.section.tag == kBrunsliACDataTag) {
  ------------------
  |  Branch (2191:7): [True: 4.44k, False: 25.8k]
  ------------------
 2192|  4.44k|    return Stage::DONE;
 2193|  4.44k|  }
 2194|       |
 2195|  25.8k|  return Stage::SECTION;
 2196|  30.3k|}
brunsli_decode.cc:_ZN7brunsliL22RemainingSectionLengthEPNS_8internal3dec5StateE:
 1087|   260k|static size_t RemainingSectionLength(State* state) {
 1088|       |  // TODO(eustas): remove this check?
 1089|   260k|  if (IsOutOfSectionBounds(state)) return 0;
  ------------------
  |  Branch (1089:7): [True: 3.55k, False: 256k]
  ------------------
 1090|   256k|  return state->internal->section.projected_end - state->pos;
 1091|   260k|}
brunsli_decode.cc:_ZN7brunsliL20IsOutOfSectionBoundsEPNS_8internal3dec5StateE:
 1083|   263k|static bool IsOutOfSectionBounds(State* state) {
 1084|   263k|  return state->pos > state->internal->section.projected_end;
 1085|   263k|}
brunsli_decode.cc:_ZN7brunsliL21DecodeMetaDataSectionEPNS_8internal3dec5StateEPNS_8JPEGDataE:
 1274|  4.02k|static BrunsliStatus DecodeMetaDataSection(State* state, JPEGData* jpg) {
 1275|  4.02k|  InternalState& s = *state->internal;
 1276|  4.02k|  MetadataState& ms = s.metadata;
 1277|       |
 1278|  4.02k|  if (ms.decompression_stage == MetadataDecompressionStage::DONE) {
  ------------------
  |  Branch (1278:7): [True: 0, False: 4.02k]
  ------------------
 1279|      0|    return BRUNSLI_INVALID_BRN;
 1280|      0|  }
 1281|       |
 1282|  4.02k|  if (ms.decompression_stage == MetadataDecompressionStage::INITIAL) {
  ------------------
  |  Branch (1282:7): [True: 4.02k, False: 0]
  ------------------
 1283|  4.02k|    if (IsAtSectionBoundary(state)) {
  ------------------
  |  Branch (1283:9): [True: 3, False: 4.02k]
  ------------------
 1284|      3|      ms.decompression_stage = MetadataDecompressionStage::DONE;
 1285|      3|      return BRUNSLI_OK;
 1286|      3|    }
 1287|  4.02k|    if (RemainingSectionLength(state) == 1) {
  ------------------
  |  Branch (1287:9): [True: 37, False: 3.98k]
  ------------------
 1288|     37|      if (!CheckCanReadByte(state)) {
  ------------------
  |  Branch (1288:11): [True: 1, False: 36]
  ------------------
 1289|      1|        return BRUNSLI_NOT_ENOUGH_DATA;
 1290|      1|      }
 1291|     36|      uint8_t data[1];
 1292|     36|      data[0] = ReadByte(state);
 1293|     36|      bool ok = ProcessMetaData(data, 1, &ms, jpg) && ms.CanFinish();
  ------------------
  |  Branch (1293:17): [True: 25, False: 11]
  |  Branch (1293:55): [True: 21, False: 4]
  ------------------
 1294|     36|      ms.decompression_stage = MetadataDecompressionStage::DONE;
 1295|     36|      return ok ? BRUNSLI_OK : BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (1295:14): [True: 21, False: 15]
  ------------------
 1296|     37|    }
 1297|  3.98k|    ms.decompression_stage =
 1298|  3.98k|        MetadataDecompressionStage::READ_LENGTH;
 1299|  3.98k|  }
 1300|       |
 1301|  3.98k|  if (ms.decompression_stage == MetadataDecompressionStage::READ_LENGTH) {
  ------------------
  |  Branch (1301:7): [True: 3.98k, False: 0]
  ------------------
 1302|  3.98k|    BrunsliStatus status = DecodeBase128(state, &ms.metadata_size);
 1303|  3.98k|    if (status != BRUNSLI_OK) return status;
  ------------------
  |  Branch (1303:9): [True: 76, False: 3.91k]
  ------------------
 1304|       |    // TODO(eustas): ms.metadata_size should be limited to avoid "zip-bombs".
 1305|  3.91k|    if (IsOutOfSectionBounds(state)) return BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (1305:9): [True: 2, False: 3.91k]
  ------------------
 1306|  3.91k|    if (RemainingSectionLength(state) == 0) return BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (1306:9): [True: 1, False: 3.91k]
  ------------------
 1307|  3.91k|    ms.brotli = BrotliDecoderCreateInstance(nullptr, nullptr, nullptr);
 1308|  3.91k|    if (ms.brotli == nullptr) return BRUNSLI_DECOMPRESSION_ERROR;
  ------------------
  |  Branch (1308:9): [True: 0, False: 3.91k]
  ------------------
 1309|  3.91k|    ms.decompression_stage = MetadataDecompressionStage::DECOMPRESSING;
 1310|  3.91k|  }
 1311|       |
 1312|  3.91k|  if (ms.decompression_stage == MetadataDecompressionStage::DECOMPRESSING) {
  ------------------
  |  Branch (1312:7): [True: 3.91k, False: 0]
  ------------------
 1313|       |    // Free Brotli decoder and return result
 1314|  3.91k|    const auto finish_decompression = [&ms] (BrunsliStatus result) {
 1315|  3.91k|      BRUNSLI_DCHECK(ms.brotli != nullptr);
 1316|  3.91k|      BrotliDecoderDestroyInstance(ms.brotli);
 1317|  3.91k|      ms.brotli = nullptr;
 1318|  3.91k|      ms.decompression_stage = MetadataDecompressionStage::DONE;
 1319|  3.91k|      return result;
 1320|  3.91k|    };
 1321|       |
 1322|   145k|    while (true) {
  ------------------
  |  Branch (1322:12): [True: 145k, Folded]
  ------------------
 1323|   145k|      size_t available_bytes =
 1324|   145k|          std::min(GetBytesAvailable(state), RemainingSectionLength(state));
 1325|   145k|      size_t available_in = available_bytes;
 1326|   145k|      const uint8_t* next_in = state->data + state->pos;
 1327|   145k|      size_t available_out = 0;
 1328|   145k|      BrotliDecoderResult result = BrotliDecoderDecompressStream(
 1329|   145k|          ms.brotli, &available_in, &next_in, &available_out, nullptr, nullptr);
 1330|   145k|      if (result == BROTLI_DECODER_RESULT_ERROR) {
  ------------------
  |  Branch (1330:11): [True: 1.09k, False: 144k]
  ------------------
 1331|  1.09k|        return finish_decompression(BRUNSLI_INVALID_BRN);
 1332|  1.09k|      }
 1333|   144k|      size_t chunk_size = 0;
 1334|   144k|      const uint8_t* chunk_data =
 1335|   144k|          BrotliDecoderTakeOutput(ms.brotli, &chunk_size);
 1336|   144k|      ms.decompressed_size += chunk_size;
 1337|   144k|      if (ms.decompressed_size > ms.metadata_size) {
  ------------------
  |  Branch (1337:11): [True: 1.00k, False: 143k]
  ------------------
 1338|  1.00k|        return finish_decompression(BRUNSLI_INVALID_BRN);
 1339|  1.00k|      }
 1340|   143k|      size_t consumed_bytes = available_bytes - available_in;
 1341|   143k|      SkipBytes(state, consumed_bytes);
 1342|   143k|      bool chunk_ok = ProcessMetaData(chunk_data, chunk_size, &ms, jpg);
 1343|   143k|      if (!chunk_ok) return finish_decompression(BRUNSLI_INVALID_BRN);
  ------------------
  |  Branch (1343:11): [True: 179, False: 142k]
  ------------------
 1344|   142k|      if (result == BROTLI_DECODER_RESULT_SUCCESS) {
  ------------------
  |  Branch (1344:11): [True: 169, False: 142k]
  ------------------
 1345|    169|        if (RemainingSectionLength(state) != 0) {
  ------------------
  |  Branch (1345:13): [True: 114, False: 55]
  ------------------
 1346|    114|          return finish_decompression(BRUNSLI_INVALID_BRN);
 1347|    114|        }
 1348|     55|        if (ms.decompressed_size != ms.metadata_size) {
  ------------------
  |  Branch (1348:13): [True: 53, False: 2]
  ------------------
 1349|     53|          return finish_decompression(BRUNSLI_INVALID_BRN);
 1350|     53|        }
 1351|      2|        if (!ms.CanFinish()) return finish_decompression(BRUNSLI_INVALID_BRN);
  ------------------
  |  Branch (1351:13): [True: 0, False: 2]
  ------------------
 1352|      2|        return finish_decompression(BRUNSLI_OK);
 1353|      2|      }
 1354|   142k|      if (result == BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT) continue;
  ------------------
  |  Branch (1354:11): [True: 141k, False: 1.46k]
  ------------------
 1355|  1.46k|      BRUNSLI_DCHECK(result == BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT);
 1356|  1.46k|      if (RemainingSectionLength(state) == 0) {
  ------------------
  |  Branch (1356:11): [True: 14, False: 1.44k]
  ------------------
 1357|     14|        return finish_decompression(BRUNSLI_INVALID_BRN);
 1358|     14|      }
 1359|  1.44k|      return BRUNSLI_NOT_ENOUGH_DATA;
 1360|  1.46k|    }
 1361|  3.91k|  }
 1362|       |
 1363|       |  // Unreachable.
 1364|      0|  BRUNSLI_DCHECK(false);
 1365|      0|  return BRUNSLI_DECOMPRESSION_ERROR;
 1366|  3.91k|}
brunsli_decode.cc:_ZZN7brunsliL21DecodeMetaDataSectionEPNS_8internal3dec5StateEPNS_8JPEGDataEENK3$_0clENS_13BrunsliStatusE:
 1314|  2.46k|    const auto finish_decompression = [&ms] (BrunsliStatus result) {
 1315|  2.46k|      BRUNSLI_DCHECK(ms.brotli != nullptr);
 1316|  2.46k|      BrotliDecoderDestroyInstance(ms.brotli);
 1317|  2.46k|      ms.brotli = nullptr;
 1318|  2.46k|      ms.decompression_stage = MetadataDecompressionStage::DONE;
 1319|  2.46k|      return result;
 1320|  2.46k|    };
brunsli_decode.cc:_ZN7brunsliL26DecodeJPEGInternalsSectionEPNS_8internal3dec5StateEPNS_8JPEGDataE:
 1408|  11.3k|static BrunsliStatus DecodeJPEGInternalsSection(State* state, JPEGData* jpg) {
 1409|  11.3k|  InternalState& s = *state->internal;
 1410|  11.3k|  JpegInternalsState& js = s.internals;
 1411|  11.3k|  BrunsliBitReader* br = &js.br;
 1412|       |
 1413|  11.3k|  if (js.stage == JpegInternalsState::INIT) {
  ------------------
  |  Branch (1413:7): [True: 11.3k, False: 0]
  ------------------
 1414|  11.3k|    BrunsliBitReaderInit(br);
 1415|  11.3k|    js.stage = JpegInternalsState::READ_MARKERS;
 1416|  11.3k|  }
 1417|  11.3k|  PrepareBitReader(br, state);
 1418|       |
 1419|  11.3k|  const auto suspend_bit_reader = [&](BrunsliStatus result) -> BrunsliStatus {
 1420|  11.3k|    return SuspendBitReader(br, state, result);
 1421|  11.3k|  };
 1422|       |
 1423|  11.3k|  if (js.stage == JpegInternalsState::READ_MARKERS) {
  ------------------
  |  Branch (1423:7): [True: 11.3k, False: 0]
  ------------------
 1424|  4.96M|    while (true) {
  ------------------
  |  Branch (1424:12): [True: 4.96M, Folded]
  ------------------
 1425|  4.96M|      if (!BrunsliBitReaderCanRead(br, 6)) {
  ------------------
  |  Branch (1425:11): [True: 206, False: 4.96M]
  ------------------
 1426|    206|        return suspend_bit_reader(BRUNSLI_NOT_ENOUGH_DATA);
 1427|    206|      }
 1428|  4.96M|      uint8_t marker = 0xc0 + BrunsliBitReaderRead(br, 6);
 1429|  4.96M|      jpg->marker_order.push_back(marker);
 1430|  4.96M|      if (marker == 0xc4) ++js.dht_count;
  ------------------
  |  Branch (1430:11): [True: 28.8k, False: 4.93M]
  ------------------
 1431|  4.96M|      if (marker == 0xdd) js.have_dri = true;
  ------------------
  |  Branch (1431:11): [True: 3.68k, False: 4.95M]
  ------------------
 1432|  4.96M|      if (marker == 0xda) ++js.num_scans;
  ------------------
  |  Branch (1432:11): [True: 716k, False: 4.24M]
  ------------------
 1433|  4.96M|      if (marker == 0xd9) break;
  ------------------
  |  Branch (1433:11): [True: 11.1k, False: 4.94M]
  ------------------
 1434|  4.96M|    }
 1435|  11.1k|    js.stage = JpegInternalsState::READ_DRI;
 1436|  11.1k|  }
 1437|       |
 1438|  11.1k|  if (js.stage == JpegInternalsState::READ_DRI) {
  ------------------
  |  Branch (1438:7): [True: 11.1k, False: 0]
  ------------------
 1439|  11.1k|    if (js.have_dri) {
  ------------------
  |  Branch (1439:9): [True: 1.58k, False: 9.54k]
  ------------------
 1440|  1.58k|      if (!BrunsliBitReaderCanRead(br, 16)) {
  ------------------
  |  Branch (1440:11): [True: 123, False: 1.46k]
  ------------------
 1441|    123|        return suspend_bit_reader(BRUNSLI_NOT_ENOUGH_DATA);
 1442|    123|      }
 1443|  1.46k|      jpg->restart_interval = BrunsliBitReaderRead(br, 16);
 1444|  1.46k|    }
 1445|  11.0k|    js.stage = JpegInternalsState::READ_HUFFMAN_LAST;
 1446|  11.0k|  }
 1447|       |
 1448|  11.0k|  if (js.stage & JpegInternalsState::DECODE_HUFFMAN_MASK) {
  ------------------
  |  Branch (1448:7): [True: 11.0k, False: 0]
  ------------------
 1449|  11.0k|    BrunsliStatus status = DecodeHuffmanCode(state, jpg);
 1450|  11.0k|    if (status != BRUNSLI_OK) return suspend_bit_reader(status);
  ------------------
  |  Branch (1450:9): [True: 361, False: 10.6k]
  ------------------
 1451|  10.6k|    js.stage = JpegInternalsState::PREPARE_READ_SCANS;
 1452|  10.6k|  }
 1453|       |
 1454|  10.6k|  if (js.stage == JpegInternalsState::PREPARE_READ_SCANS) {
  ------------------
  |  Branch (1454:7): [True: 10.6k, False: 0]
  ------------------
 1455|  10.6k|    if (js.dht_count != js.terminal_huffman_code_count) {
  ------------------
  |  Branch (1455:9): [True: 156, False: 10.4k]
  ------------------
 1456|    156|      BRUNSLI_LOG_ERROR() << "Invalid number of DHT markers" << BRUNSLI_ENDL();
  ------------------
  |  |  431|    156|#define BRUNSLI_LOG_ERROR() BRUNSLI_LOG_(ERROR)
  |  |  ------------------
  |  |  |  |  413|    468|#define BRUNSLI_LOG_(LEVEL) std::cerr
  |  |  ------------------
  ------------------
                    BRUNSLI_LOG_ERROR() << "Invalid number of DHT markers" << BRUNSLI_ENDL();
  ------------------
  |  |  414|    156|#define BRUNSLI_ENDL() std::endl
  ------------------
 1457|    156|      return suspend_bit_reader(BRUNSLI_INVALID_BRN);
 1458|    156|    }
 1459|  10.4k|    if (js.num_scans > 0) {
  ------------------
  |  Branch (1459:9): [True: 5.13k, False: 5.36k]
  ------------------
 1460|  5.13k|      jpg->scan_info.resize(js.num_scans);
 1461|  5.13k|      js.i = 0;
 1462|  5.13k|      js.stage = JpegInternalsState::READ_SCAN_COMMON;
 1463|  5.36k|    } else {
 1464|  5.36k|      js.stage = JpegInternalsState::READ_NUM_QUANT;
 1465|  5.36k|    }
 1466|  10.4k|  }
 1467|       |
 1468|  10.4k|  if (js.stage & JpegInternalsState::DECODE_SCAN_MASK) {
  ------------------
  |  Branch (1468:7): [True: 5.13k, False: 5.36k]
  ------------------
 1469|  5.13k|    BrunsliStatus status = DecodeScanInfo(state, jpg);
 1470|  5.13k|    if (status != BRUNSLI_OK) return suspend_bit_reader(status);
  ------------------
  |  Branch (1470:9): [True: 314, False: 4.81k]
  ------------------
 1471|  4.81k|    js.stage = JpegInternalsState::READ_NUM_QUANT;
 1472|  4.81k|  }
 1473|       |
 1474|  10.1k|  if (js.stage == JpegInternalsState::READ_NUM_QUANT) {
  ------------------
  |  Branch (1474:7): [True: 10.1k, False: 0]
  ------------------
 1475|  10.1k|    if (!BrunsliBitReaderCanRead(br, 2)) {
  ------------------
  |  Branch (1475:9): [True: 138, False: 10.0k]
  ------------------
 1476|    138|      return suspend_bit_reader(BRUNSLI_NOT_ENOUGH_DATA);
 1477|    138|    }
 1478|  10.0k|    int num_quant_tables = BrunsliBitReaderRead(br, 2) + 1;
 1479|  10.0k|    jpg->quant.resize(num_quant_tables);
 1480|  10.0k|    js.i = 0;
 1481|  10.0k|    js.stage = JpegInternalsState::READ_QUANT;
 1482|  10.0k|  }
 1483|       |
 1484|  19.9k|  while (js.stage == JpegInternalsState::READ_QUANT) {
  ------------------
  |  Branch (1484:10): [True: 19.9k, False: 0]
  ------------------
 1485|  19.9k|    if (js.i >= jpg->quant.size()) {
  ------------------
  |  Branch (1485:9): [True: 9.74k, False: 10.2k]
  ------------------
 1486|  9.74k|      js.stage = JpegInternalsState::READ_COMP_ID_SCHEME;
 1487|  9.74k|      break;
 1488|  9.74k|    }
 1489|       |    // 6 or 7 bits are used, but we know that at least one more bit is
 1490|       |    // guaranteed to be used by varint out of the loop.
 1491|  10.2k|    if (!BrunsliBitReaderCanRead(br, 7)) {
  ------------------
  |  Branch (1491:9): [True: 161, False: 10.0k]
  ------------------
 1492|    161|      return suspend_bit_reader(BRUNSLI_NOT_ENOUGH_DATA);
 1493|    161|    }
 1494|  10.0k|    JPEGQuantTable* q = &jpg->quant[js.i];
 1495|  10.0k|    q->index = BrunsliBitReaderRead(br, 2);
 1496|  10.0k|    q->is_last = (js.i == jpg->quant.size() - 1) || BrunsliBitReaderRead(br, 1);
  ------------------
  |  Branch (1496:18): [True: 9.80k, False: 277]
  |  Branch (1496:53): [True: 67, False: 210]
  ------------------
 1497|  10.0k|    q->precision = BrunsliBitReaderRead(br, 4);
 1498|  10.0k|    if (q->precision > 1) {
  ------------------
  |  Branch (1498:9): [True: 133, False: 9.95k]
  ------------------
 1499|    133|      BRUNSLI_LOG_ERROR() << "Invalid quantization table precision: "
  ------------------
  |  |  431|    133|#define BRUNSLI_LOG_ERROR() BRUNSLI_LOG_(ERROR)
  |  |  ------------------
  |  |  |  |  413|    532|#define BRUNSLI_LOG_(LEVEL) std::cerr
  |  |  ------------------
  ------------------
 1500|    133|                          << q->precision << BRUNSLI_ENDL();
  ------------------
  |  |  414|    133|#define BRUNSLI_ENDL() std::endl
  ------------------
 1501|    133|      return suspend_bit_reader(BRUNSLI_INVALID_BRN);
 1502|    133|    }
 1503|       |    // note that q->values[] are initialized to invalid 0 values.
 1504|  9.95k|    ++js.i;
 1505|  9.95k|  }
 1506|       |
 1507|  9.74k|  if (js.stage == JpegInternalsState::READ_COMP_ID_SCHEME) {
  ------------------
  |  Branch (1507:7): [True: 9.74k, False: 0]
  ------------------
 1508|  9.74k|    if (!BrunsliBitReaderCanRead(br, 2)) {
  ------------------
  |  Branch (1508:9): [True: 125, False: 9.62k]
  ------------------
 1509|    125|      return suspend_bit_reader(BRUNSLI_NOT_ENOUGH_DATA);
 1510|    125|    }
 1511|  9.62k|    int comp_ids = BrunsliBitReaderRead(br, 2);
 1512|  9.62k|    static const size_t kMinRequiredComponents[4] = {
 1513|  9.62k|        3 /* Ids123*/, 1 /* IdsGray */, 3 /* IdsRGB */, 0 /* IdsCustom */
 1514|  9.62k|    };
 1515|  9.62k|    if (jpg->components.size() < kMinRequiredComponents[comp_ids]) {
  ------------------
  |  Branch (1515:9): [True: 3, False: 9.62k]
  ------------------
 1516|      3|      BRUNSLI_LOG_ERROR() << "Insufficient number of components for ColorId #"
  ------------------
  |  |  431|      3|#define BRUNSLI_LOG_ERROR() BRUNSLI_LOG_(ERROR)
  |  |  ------------------
  |  |  |  |  413|     12|#define BRUNSLI_LOG_(LEVEL) std::cerr
  |  |  ------------------
  ------------------
 1517|      3|                          << comp_ids << BRUNSLI_ENDL();
  ------------------
  |  |  414|      3|#define BRUNSLI_ENDL() std::endl
  ------------------
 1518|      3|      return suspend_bit_reader(BRUNSLI_INVALID_BRN);
 1519|      3|    }
 1520|  9.62k|    js.stage = JpegInternalsState::READ_NUM_PADDING_BITS;
 1521|  9.62k|    if (comp_ids == kComponentIds123) {
  ------------------
  |  Branch (1521:9): [True: 449, False: 9.17k]
  ------------------
 1522|    449|      jpg->components[0].id = 1;
 1523|    449|      jpg->components[1].id = 2;
 1524|    449|      jpg->components[2].id = 3;
 1525|  9.17k|    } else if (comp_ids == kComponentIdsGray) {
  ------------------
  |  Branch (1525:16): [True: 8.71k, False: 459]
  ------------------
 1526|  8.71k|      jpg->components[0].id = 1;
 1527|  8.71k|    } else if (comp_ids == kComponentIdsRGB) {
  ------------------
  |  Branch (1527:16): [True: 33, False: 426]
  ------------------
 1528|     33|      jpg->components[0].id = 'R';
 1529|     33|      jpg->components[1].id = 'G';
 1530|     33|      jpg->components[2].id = 'B';
 1531|    426|    } else {
 1532|    426|      BRUNSLI_DCHECK(comp_ids == kComponentIdsCustom);
 1533|    426|      js.i = 0;
 1534|    426|      js.stage = JpegInternalsState::READ_COMP_ID;
 1535|    426|    }
 1536|  9.62k|  }
 1537|       |
 1538|  9.62k|  if (js.stage == JpegInternalsState::READ_COMP_ID) {
  ------------------
  |  Branch (1538:7): [True: 426, False: 9.19k]
  ------------------
 1539|    832|    while (js.i < jpg->components.size()) {
  ------------------
  |  Branch (1539:12): [True: 441, False: 391]
  ------------------
 1540|    441|      if (!BrunsliBitReaderCanRead(br, 8)) {
  ------------------
  |  Branch (1540:11): [True: 35, False: 406]
  ------------------
 1541|     35|        return suspend_bit_reader(BRUNSLI_NOT_ENOUGH_DATA);
 1542|     35|      }
 1543|    406|      jpg->components[js.i].id = BrunsliBitReaderRead(br, 8);
 1544|    406|      ++js.i;
 1545|    406|    }
 1546|    391|    js.stage = JpegInternalsState::READ_NUM_PADDING_BITS;
 1547|    391|  }
 1548|       |
 1549|  9.58k|  if (js.stage == JpegInternalsState::READ_NUM_PADDING_BITS) {
  ------------------
  |  Branch (1549:7): [True: 9.58k, False: 0]
  ------------------
 1550|       |    // TODO(eustas): sanitize: should not be bigger than
 1551|       |    //               7 x (num_scans + num_blocks / dri)
 1552|       |    // security: limit is 32b for n_size
 1553|  9.58k|    if (!DecodeLimitedVarint<8>(&js.varint, br, 4)) {
  ------------------
  |  Branch (1553:9): [True: 73, False: 9.51k]
  ------------------
 1554|     73|      return suspend_bit_reader(BRUNSLI_NOT_ENOUGH_DATA);
 1555|     73|    }
 1556|  9.51k|    js.num_padding_bits = js.varint.value;
 1557|  9.51k|    jpg->has_zero_padding_bit = (js.num_padding_bits > 0);
 1558|  9.51k|    if (js.num_padding_bits > PaddingBitsLimit(*jpg)) {
  ------------------
  |  Branch (1558:9): [True: 42, False: 9.47k]
  ------------------
 1559|     42|      BRUNSLI_LOG_ERROR() << "Suspicious number of padding bits "
  ------------------
  |  |  431|     42|#define BRUNSLI_LOG_ERROR() BRUNSLI_LOG_(ERROR)
  |  |  ------------------
  |  |  |  |  413|    168|#define BRUNSLI_LOG_(LEVEL) std::cerr
  |  |  ------------------
  ------------------
 1560|     42|                          << js.num_padding_bits << BRUNSLI_ENDL();
  ------------------
  |  |  414|     42|#define BRUNSLI_ENDL() std::endl
  ------------------
 1561|     42|      return suspend_bit_reader(BRUNSLI_INVALID_BRN);
 1562|     42|    }
 1563|  9.47k|    js.i = 0;
 1564|  9.47k|    js.stage = JpegInternalsState::READ_PADDING_BITS;
 1565|  9.47k|  }
 1566|       |
 1567|  9.47k|  if (js.stage == JpegInternalsState::READ_PADDING_BITS) {
  ------------------
  |  Branch (1567:7): [True: 9.47k, False: 0]
  ------------------
 1568|  70.2k|    while (js.i < js.num_padding_bits) {
  ------------------
  |  Branch (1568:12): [True: 60.7k, False: 9.44k]
  ------------------
 1569|  60.7k|      if (!BrunsliBitReaderCanRead(br, 1)) {
  ------------------
  |  Branch (1569:11): [True: 23, False: 60.7k]
  ------------------
 1570|     23|        return suspend_bit_reader(BRUNSLI_NOT_ENOUGH_DATA);
 1571|     23|      }
 1572|  60.7k|      jpg->padding_bits.emplace_back(BrunsliBitReaderRead(br, 1));
 1573|  60.7k|      ++js.i;
 1574|  60.7k|    }
 1575|  9.44k|    suspend_bit_reader(BRUNSLI_OK);
 1576|  9.44k|    BrunsliBitReaderFinish(br);
 1577|  9.44k|    if (!BrunsliBitReaderIsHealthy(br)) return BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (1577:9): [True: 9, False: 9.43k]
  ------------------
 1578|  9.43k|    js.i = 0;
 1579|  9.43k|    js.stage = JpegInternalsState::ITERATE_MARKERS;
 1580|  9.43k|  } else {
 1581|       |    // no-op
 1582|      0|    suspend_bit_reader(BRUNSLI_OK);
 1583|      0|  }
 1584|       |
 1585|  2.08M|  while (true) {
  ------------------
  |  Branch (1585:10): [True: 2.08M, Folded]
  ------------------
 1586|  2.08M|    switch (js.stage) {
 1587|  2.03M|      case JpegInternalsState::ITERATE_MARKERS: {
  ------------------
  |  Branch (1587:7): [True: 2.03M, False: 49.0k]
  ------------------
 1588|  2.03M|        if (js.i >= jpg->marker_order.size()) {
  ------------------
  |  Branch (1588:13): [True: 9.10k, False: 2.02M]
  ------------------
 1589|  9.10k|          js.stage = JpegInternalsState::DONE;
 1590|  2.02M|        } else if (jpg->marker_order[js.i] == 0xFF) {
  ------------------
  |  Branch (1590:20): [True: 20.1k, False: 2.00M]
  ------------------
 1591|  20.1k|          js.stage = JpegInternalsState::READ_INTERMARKER_LENGTH;
 1592|  2.00M|        } else {
 1593|  2.00M|          ++js.i;
 1594|  2.00M|        }
 1595|  2.03M|        continue;
 1596|      0|      }
 1597|       |
 1598|  20.1k|      case JpegInternalsState::READ_INTERMARKER_LENGTH: {
  ------------------
  |  Branch (1598:7): [True: 20.1k, False: 2.06M]
  ------------------
 1599|  20.1k|        BrunsliStatus status = DecodeBase128(state, &js.intermarker_length);
 1600|  20.1k|        if (status != BRUNSLI_OK) return CheckBoundary(state, status);
  ------------------
  |  Branch (1600:13): [True: 135, False: 19.9k]
  ------------------
 1601|  19.9k|        if (js.intermarker_length > RemainingSectionLength(state)) {
  ------------------
  |  Branch (1601:13): [True: 76, False: 19.8k]
  ------------------
 1602|     76|          return BRUNSLI_INVALID_BRN;
 1603|     76|        }
 1604|  19.8k|        jpg->inter_marker_data.emplace_back();
 1605|  19.8k|        js.stage = JpegInternalsState::READ_INTERMARKER_DATA;
 1606|  19.8k|        continue;
 1607|  19.9k|      }
 1608|       |
 1609|  19.8k|      case JpegInternalsState::READ_INTERMARKER_DATA: {
  ------------------
  |  Branch (1609:7): [True: 19.8k, False: 2.06M]
  ------------------
 1610|  19.8k|        auto& dest = jpg->inter_marker_data.back();
 1611|  19.8k|        size_t piece_limit = js.intermarker_length - dest.size();
 1612|  19.8k|        size_t piece_size = std::min(piece_limit, GetBytesAvailable(state));
 1613|  19.8k|        Append(&dest, state->data + state->pos, piece_size);
 1614|  19.8k|        SkipBytes(state, piece_size);
 1615|  19.8k|        if (dest.size() < js.intermarker_length) {
  ------------------
  |  Branch (1615:13): [True: 123, False: 19.7k]
  ------------------
 1616|    123|          BRUNSLI_DCHECK(GetBytesAvailable(state) == 0);
 1617|    123|          BRUNSLI_DCHECK(RemainingSectionLength(state) > 0);
 1618|    123|          return BRUNSLI_NOT_ENOUGH_DATA;
 1619|    123|        }
 1620|  19.7k|        ++js.i;
 1621|  19.7k|        js.stage = JpegInternalsState::ITERATE_MARKERS;
 1622|  19.7k|        continue;
 1623|  19.8k|      }
 1624|       |
 1625|  9.10k|      default: { /* no-op */ }
  ------------------
  |  Branch (1625:7): [True: 9.10k, False: 2.07M]
  ------------------
 1626|  2.08M|    }
 1627|  9.10k|    break;  // no matching stage has been found; exit the loop.
 1628|  2.08M|  }
 1629|       |
 1630|  9.10k|  if (!IsAtSectionBoundary(state)) return BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (1630:7): [True: 140, False: 8.96k]
  ------------------
 1631|       |
 1632|  8.96k|  return BRUNSLI_OK;
 1633|  9.10k|}
brunsli_decode.cc:_ZN7brunsliL16PrepareBitReaderEPNS_16BrunsliBitReaderEPNS_8internal3dec5StateE:
 1383|  26.1k|static void PrepareBitReader(BrunsliBitReader* br, State* state) {
 1384|  26.1k|  size_t chunk_len =
 1385|  26.1k|      std::min(GetBytesAvailable(state), RemainingSectionLength(state));
 1386|  26.1k|  BrunsliBitReaderResume(br, state->data + state->pos, chunk_len);
 1387|  26.1k|  BRUNSLI_DCHECK(BrunsliBitReaderIsHealthy(br));
 1388|  26.1k|}
brunsli_decode.cc:_ZZN7brunsliL26DecodeJPEGInternalsSectionEPNS_8internal3dec5StateEPNS_8JPEGDataEENK3$_0clENS_13BrunsliStatusE:
 1419|  11.3k|  const auto suspend_bit_reader = [&](BrunsliStatus result) -> BrunsliStatus {
 1420|  11.3k|    return SuspendBitReader(br, state, result);
 1421|  11.3k|  };
brunsli_decode.cc:_ZN7brunsliL16SuspendBitReaderEPNS_16BrunsliBitReaderEPNS_8internal3dec5StateENS_13BrunsliStatusE:
 1394|  26.1k|                                      BrunsliStatus result) {
 1395|  26.1k|  size_t chunk_len =
 1396|  26.1k|      std::min(GetBytesAvailable(state), RemainingSectionLength(state));
 1397|  26.1k|  size_t unused_bytes = BrunsliBitReaderSuspend(br);
 1398|  26.1k|  size_t consumed_bytes = chunk_len - unused_bytes;
 1399|  26.1k|  SkipBytes(state, consumed_bytes);
 1400|  26.1k|  result = CheckBoundary(state, result);
 1401|       |  // Once BitReader becomes unhealthy, further decoding should be impossible.
 1402|  26.1k|  BRUNSLI_DCHECK(
 1403|  26.1k|      BrunsliBitReaderIsHealthy(br) ||
 1404|  26.1k|      ((result != BRUNSLI_OK) && (result != BRUNSLI_NOT_ENOUGH_DATA)));
 1405|  26.1k|  return result;
 1406|  26.1k|}
brunsli_decode.cc:_ZN7brunsliL17DecodeHuffmanCodeEPNS_8internal3dec5StateEPNS_8JPEGDataE:
  297|  11.0k|static BrunsliStatus DecodeHuffmanCode(State* state, JPEGData* jpg) {
  298|  11.0k|  InternalState& s = *state->internal;
  299|  11.0k|  JpegInternalsState& js = s.internals;
  300|  11.0k|  BrunsliBitReader* br = &js.br;
  301|       |
  302|   219k|  while (true) {
  ------------------
  |  Branch (302:10): [True: 219k, Folded]
  ------------------
  303|   219k|    switch (js.stage) {
  304|  26.6k|      case JpegInternalsState::READ_HUFFMAN_LAST: {
  ------------------
  |  Branch (304:7): [True: 26.6k, False: 192k]
  ------------------
  305|  26.6k|        if (!BrunsliBitReaderCanRead(br, 1)) return BRUNSLI_NOT_ENOUGH_DATA;
  ------------------
  |  Branch (305:13): [True: 14, False: 26.6k]
  ------------------
  306|  26.6k|        js.is_known_last_huffman_code = BrunsliBitReaderRead(br, 1);
  307|  26.6k|        jpg->huffman_code.emplace_back();
  308|  26.6k|        js.stage = JpegInternalsState::READ_HUFFMAN_SIMPLE;
  309|  26.6k|        continue;
  310|  26.6k|      }
  311|  26.6k|      case JpegInternalsState::READ_HUFFMAN_SIMPLE: {
  ------------------
  |  Branch (311:7): [True: 26.6k, False: 192k]
  ------------------
  312|  26.6k|        if (!BrunsliBitReaderCanRead(br, 5 + !js.is_known_last_huffman_code)) {
  ------------------
  |  Branch (312:13): [True: 163, False: 26.4k]
  ------------------
  313|    163|          return BRUNSLI_NOT_ENOUGH_DATA;
  314|    163|        }
  315|  26.4k|        JPEGHuffmanCode* huff = &jpg->huffman_code.back();
  316|       |
  317|  26.4k|        huff->slot_id = BrunsliBitReaderRead(br, 2);
  318|  26.4k|        js.is_dc_table = (BrunsliBitReaderRead(br, 1) == 0);
  319|  26.4k|        huff->slot_id += js.is_dc_table ? 0 : 0x10;
  ------------------
  |  Branch (319:26): [True: 15.7k, False: 10.7k]
  ------------------
  320|  26.4k|        huff->is_last =
  321|  26.4k|            js.is_known_last_huffman_code || BrunsliBitReaderRead(br, 1);
  ------------------
  |  Branch (321:13): [True: 10.7k, False: 15.7k]
  |  Branch (321:46): [True: 2.67k, False: 13.0k]
  ------------------
  322|  26.4k|        huff->counts[0] = 0;
  323|  26.4k|        int found_match = BrunsliBitReaderRead(br, 1);
  324|  26.4k|        if (found_match) {
  ------------------
  |  Branch (324:13): [True: 16.1k, False: 10.3k]
  ------------------
  325|  16.1k|          if (js.is_dc_table) {
  ------------------
  |  Branch (325:15): [True: 8.72k, False: 7.39k]
  ------------------
  326|  8.72k|            int huff_table_idx = BrunsliBitReaderRead(br, 1);
  327|  8.72k|            memcpy(&huff->counts[1], kStockDCHuffmanCodeCounts[huff_table_idx],
  328|  8.72k|                   sizeof(kStockDCHuffmanCodeCounts[0]));
  329|  8.72k|            memcpy(&huff->values[0], kStockDCHuffmanCodeValues[huff_table_idx],
  330|  8.72k|                   sizeof(kStockDCHuffmanCodeValues[0]));
  331|  8.72k|          } else {
  332|  7.39k|            int huff_table_idx = BrunsliBitReaderRead(br, 1);
  333|  7.39k|            memcpy(&huff->counts[1], kStockACHuffmanCodeCounts[huff_table_idx],
  334|  7.39k|                   sizeof(kStockACHuffmanCodeCounts[0]));
  335|  7.39k|            memcpy(&huff->values[0], kStockACHuffmanCodeValues[huff_table_idx],
  336|  7.39k|                   sizeof(kStockACHuffmanCodeValues[0]));
  337|  7.39k|          }
  338|  16.1k|          js.stage = JpegInternalsState::HUFFMAN_UPDATE;
  339|  16.1k|        } else {
  340|       |          // One less bit is used than requested, but it is guaranteed to be
  341|       |          // consumed in complex Huffman code case.
  342|  10.3k|          js.p.Init(js.is_dc_table
  ------------------
  |  Branch (342:21): [True: 7.01k, False: 3.31k]
  ------------------
  343|  10.3k|                        ? std::vector<uint8_t>(kDefaultDCValues,
  344|  7.01k|                                               std::end(kDefaultDCValues))
  345|  10.3k|                        : std::vector<uint8_t>(kDefaultACValues,
  346|  3.31k|                                               std::end(kDefaultACValues)));
  347|  10.3k|          js.stage = JpegInternalsState::READ_HUFFMAN_MAX_LEN;
  348|  10.3k|        }
  349|  26.4k|        continue;
  350|  26.6k|      }
  351|  10.3k|      case JpegInternalsState::READ_HUFFMAN_MAX_LEN: {
  ------------------
  |  Branch (351:7): [True: 10.3k, False: 209k]
  ------------------
  352|  10.3k|        if (!BrunsliBitReaderCanRead(br, 4)) return BRUNSLI_NOT_ENOUGH_DATA;
  ------------------
  |  Branch (352:13): [True: 36, False: 10.2k]
  ------------------
  353|  10.2k|        js.max_len = BrunsliBitReaderRead(br, 4) + 1;
  354|  10.2k|        js.total_count = 0;
  355|  10.2k|        js.max_count =
  356|  10.2k|            js.is_dc_table ? kJpegDCAlphabetSize : kJpegHuffmanAlphabetSize;
  ------------------
  |  Branch (356:13): [True: 6.99k, False: 3.29k]
  ------------------
  357|  10.2k|        js.space = (1u << kJpegHuffmanMaxBitLength) -
  358|  10.2k|                   (1u << (kJpegHuffmanMaxBitLength - js.max_len));
  359|  10.2k|        js.i = 1;
  360|  10.2k|        js.stage = JpegInternalsState::READ_HUFFMAN_COUNT;
  361|  10.2k|        continue;
  362|  10.3k|      }
  363|  47.9k|      case JpegInternalsState::READ_HUFFMAN_COUNT: {
  ------------------
  |  Branch (363:7): [True: 47.9k, False: 171k]
  ------------------
  364|  47.9k|        JPEGHuffmanCode* huff = &jpg->huffman_code.back();
  365|  47.9k|        if (js.i <= js.max_len) {
  ------------------
  |  Branch (365:13): [True: 37.7k, False: 10.2k]
  ------------------
  366|  37.7k|          size_t shift = kJpegHuffmanMaxBitLength - js.i;
  367|  37.7k|          size_t count_limit =
  368|  37.7k|              std::min(js.max_count - js.total_count, js.space >> shift);
  369|  37.7k|          if (count_limit > 0) {
  ------------------
  |  Branch (369:15): [True: 36.2k, False: 1.47k]
  ------------------
  370|  36.2k|            int nbits =
  371|  36.2k|                Log2FloorNonZero(static_cast<uint32_t>(count_limit)) + 1;
  372|  36.2k|            if (!BrunsliBitReaderCanRead(br, nbits)) {
  ------------------
  |  Branch (372:17): [True: 75, False: 36.2k]
  ------------------
  373|     75|              return BRUNSLI_NOT_ENOUGH_DATA;
  374|     75|            }
  375|  36.2k|            size_t count = BrunsliBitReaderRead(br, nbits);
  376|  36.2k|            if (count > count_limit) {
  ------------------
  |  Branch (376:17): [True: 6, False: 36.2k]
  ------------------
  377|      6|              return BRUNSLI_INVALID_BRN;
  378|      6|            }
  379|  36.2k|            huff->counts[js.i] = static_cast<int>(count);
  380|  36.2k|            js.total_count += count;
  381|  36.2k|            js.space -= count * (static_cast<size_t>(1) << shift);
  382|  36.2k|          }
  383|  37.6k|          ++js.i;
  384|  37.6k|          continue;
  385|  37.7k|        }
  386|  10.2k|        ++huff->counts[js.max_len];
  387|  10.2k|        js.i = 0;
  388|  10.2k|        js.stage = JpegInternalsState::READ_HUFFMAN_PERMUTATION;
  389|  10.2k|        continue;
  390|  47.9k|      }
  391|  81.6k|      case JpegInternalsState::READ_HUFFMAN_PERMUTATION: {
  ------------------
  |  Branch (391:7): [True: 81.6k, False: 137k]
  ------------------
  392|  81.6k|        JPEGHuffmanCode* huff = &jpg->huffman_code.back();
  393|  81.6k|        if (js.i < js.total_count) {
  ------------------
  |  Branch (393:13): [True: 71.4k, False: 10.1k]
  ------------------
  394|  71.4k|          const int nbits = js.p.num_bits();
  395|  71.4k|          if (!DecodeLimitedVarint<2>(&js.varint, br, (nbits + 1) >> 1u)) {
  ------------------
  |  Branch (395:15): [True: 51, False: 71.4k]
  ------------------
  396|     51|            return BRUNSLI_NOT_ENOUGH_DATA;
  397|     51|          }
  398|  71.4k|          uint8_t value;
  399|  71.4k|          if (!js.p.Remove(js.varint.value, &value)) {
  ------------------
  |  Branch (399:15): [True: 15, False: 71.4k]
  ------------------
  400|     15|            return BRUNSLI_INVALID_BRN;
  401|     15|          }
  402|  71.4k|          huff->values[js.i] = value;
  403|  71.4k|          ++js.i;
  404|  71.4k|          continue;
  405|  71.4k|        }
  406|  10.1k|        huff->values[js.total_count] = kJpegHuffmanAlphabetSize;
  407|  10.1k|        js.stage = JpegInternalsState::HUFFMAN_UPDATE;
  408|  10.1k|        continue;
  409|  81.6k|      }
  410|  26.2k|      case JpegInternalsState::HUFFMAN_UPDATE: {
  ------------------
  |  Branch (410:7): [True: 26.2k, False: 193k]
  ------------------
  411|       |        // This stage does not perform reading -> transient.
  412|  26.2k|        if (jpg->huffman_code.back().is_last) {
  ------------------
  |  Branch (412:13): [True: 13.2k, False: 13.0k]
  ------------------
  413|  13.2k|          js.terminal_huffman_code_count++;
  414|  13.2k|        }
  415|  26.2k|        if (js.is_known_last_huffman_code) {
  ------------------
  |  Branch (415:13): [True: 10.6k, False: 15.6k]
  ------------------
  416|  10.6k|          js.p.Clear();
  417|  10.6k|          return BRUNSLI_OK;
  418|  10.6k|        }
  419|  15.6k|        if (jpg->huffman_code.size() >= kMaxDHTMarkers) {
  ------------------
  |  Branch (419:13): [True: 1, False: 15.6k]
  ------------------
  420|       |          // Too many Huffman codes for a valid bit-stream. Normally, a jpeg
  421|       |          // file can have any arbitrary number of DHT, DQT, etc. But i prefer
  422|       |          // we force a reasonable lower bound instead of open door to likely
  423|       |          // forged BRN input.
  424|      1|          return BRUNSLI_INVALID_BRN;
  425|      1|        }
  426|  15.6k|        js.stage = JpegInternalsState::READ_HUFFMAN_LAST;
  427|  15.6k|        continue;
  428|  15.6k|      }
  429|      0|      default:
  ------------------
  |  Branch (429:7): [True: 0, False: 219k]
  ------------------
  430|      0|        return BRUNSLI_DECOMPRESSION_ERROR;
  431|   219k|    }
  432|   219k|  }
  433|      0|  return BRUNSLI_OK;
  434|  11.0k|}
_ZN7brunsli19DecodeLimitedVarintILm2EEEbPNS_8internal3dec11VarintStateEPNS_16BrunsliBitReaderEm:
  141|  71.4k|                         size_t max_symbols) {
  142|  71.4k|  if (s->stage == VarintState::INIT) {
  ------------------
  |  Branch (142:7): [True: 71.4k, False: 0]
  ------------------
  143|  71.4k|    s->value = 0;
  144|  71.4k|    s->i = 0;
  145|  71.4k|    s->stage = VarintState::READ_CONTINUATION;
  146|  71.4k|  }
  147|   114k|  while (true) {
  ------------------
  |  Branch (147:10): [True: 114k, Folded]
  ------------------
  148|   114k|    switch (s->stage) {
  149|  92.9k|      case VarintState::READ_CONTINUATION: {
  ------------------
  |  Branch (149:7): [True: 92.9k, False: 21.5k]
  ------------------
  150|  92.9k|        if (s->i < max_symbols) {
  ------------------
  |  Branch (150:13): [True: 90.8k, False: 2.15k]
  ------------------
  151|  90.8k|          if (!BrunsliBitReaderCanRead(br, 1)) return false;
  ------------------
  |  Branch (151:15): [True: 31, False: 90.7k]
  ------------------
  152|  90.7k|          if (BrunsliBitReaderRead(br, 1)) {
  ------------------
  |  Branch (152:15): [True: 21.5k, False: 69.2k]
  ------------------
  153|  21.5k|            s->stage = VarintState::READ_DATA;
  154|  21.5k|            continue;
  155|  21.5k|          }
  156|  90.7k|        }
  157|  71.4k|        s->stage = VarintState::INIT;
  158|  71.4k|        return true;
  159|  92.9k|      }
  160|  21.5k|      case VarintState::READ_DATA: {
  ------------------
  |  Branch (160:7): [True: 21.5k, False: 92.9k]
  ------------------
  161|  21.5k|        if (!BrunsliBitReaderCanRead(br, kChunkSize)) return false;
  ------------------
  |  Branch (161:13): [True: 20, False: 21.5k]
  ------------------
  162|  21.5k|        size_t next_bits = BrunsliBitReaderRead(br, kChunkSize);
  163|  21.5k|        s->value |= next_bits << (s->i * kChunkSize);
  164|  21.5k|        ++s->i;
  165|  21.5k|        s->stage = VarintState::READ_CONTINUATION;
  166|  21.5k|        continue;
  167|  21.5k|      }
  168|      0|      default: {
  ------------------
  |  Branch (168:7): [True: 0, False: 114k]
  ------------------
  169|      0|        BRUNSLI_CHECK(false);
  ------------------
  |  |  452|      0|  if (!(V)) {                                                         \
  |  |  ------------------
  |  |  |  Branch (452:7): [True: 0, Folded]
  |  |  ------------------
  |  |  453|      0|    ::brunsli::BrunsliDumpAndAbort(__FILE__, __LINE__, __FUNCTION__); \
  |  |  454|      0|    /* Tell the compiler, that there is no escape route. */           \
  |  |  455|      0|    while (true) ;                                                    \
  |  |  ------------------
  |  |  |  Branch (455:12): [True: 0, Folded]
  |  |  ------------------
  |  |  456|      0|  }
  ------------------
  170|      0|        return false;
  171|  21.5k|      }
  172|   114k|    }
  173|   114k|  }
  174|  71.4k|}
_ZN7brunsli19DecodeLimitedVarintILm8EEEbPNS_8internal3dec11VarintStateEPNS_16BrunsliBitReaderEm:
  141|  9.58k|                         size_t max_symbols) {
  142|  9.58k|  if (s->stage == VarintState::INIT) {
  ------------------
  |  Branch (142:7): [True: 9.58k, False: 0]
  ------------------
  143|  9.58k|    s->value = 0;
  144|  9.58k|    s->i = 0;
  145|  9.58k|    s->stage = VarintState::READ_CONTINUATION;
  146|  9.58k|  }
  147|  11.0k|  while (true) {
  ------------------
  |  Branch (147:10): [True: 11.0k, Folded]
  ------------------
  148|  11.0k|    switch (s->stage) {
  149|  10.3k|      case VarintState::READ_CONTINUATION: {
  ------------------
  |  Branch (149:7): [True: 10.3k, False: 742]
  ------------------
  150|  10.3k|        if (s->i < max_symbols) {
  ------------------
  |  Branch (150:13): [True: 10.2k, False: 19]
  ------------------
  151|  10.2k|          if (!BrunsliBitReaderCanRead(br, 1)) return false;
  ------------------
  |  Branch (151:15): [True: 49, False: 10.2k]
  ------------------
  152|  10.2k|          if (BrunsliBitReaderRead(br, 1)) {
  ------------------
  |  Branch (152:15): [True: 742, False: 9.49k]
  ------------------
  153|    742|            s->stage = VarintState::READ_DATA;
  154|    742|            continue;
  155|    742|          }
  156|  10.2k|        }
  157|  9.51k|        s->stage = VarintState::INIT;
  158|  9.51k|        return true;
  159|  10.3k|      }
  160|    742|      case VarintState::READ_DATA: {
  ------------------
  |  Branch (160:7): [True: 742, False: 10.3k]
  ------------------
  161|    742|        if (!BrunsliBitReaderCanRead(br, kChunkSize)) return false;
  ------------------
  |  Branch (161:13): [True: 24, False: 718]
  ------------------
  162|    718|        size_t next_bits = BrunsliBitReaderRead(br, kChunkSize);
  163|    718|        s->value |= next_bits << (s->i * kChunkSize);
  164|    718|        ++s->i;
  165|    718|        s->stage = VarintState::READ_CONTINUATION;
  166|    718|        continue;
  167|    742|      }
  168|      0|      default: {
  ------------------
  |  Branch (168:7): [True: 0, False: 11.0k]
  ------------------
  169|      0|        BRUNSLI_CHECK(false);
  ------------------
  |  |  452|      0|  if (!(V)) {                                                         \
  |  |  ------------------
  |  |  |  Branch (452:7): [True: 0, Folded]
  |  |  ------------------
  |  |  453|      0|    ::brunsli::BrunsliDumpAndAbort(__FILE__, __LINE__, __FUNCTION__); \
  |  |  454|      0|    /* Tell the compiler, that there is no escape route. */           \
  |  |  455|      0|    while (true) ;                                                    \
  |  |  ------------------
  |  |  |  Branch (455:12): [True: 0, Folded]
  |  |  ------------------
  |  |  456|      0|  }
  ------------------
  170|      0|        return false;
  171|    742|      }
  172|  11.0k|    }
  173|  11.0k|  }
  174|  9.58k|}
brunsli_decode.cc:_ZN7brunsliL13CheckBoundaryEPNS_8internal3dec5StateENS_13BrunsliStatusE:
 1374|  26.2k|static BrunsliStatus CheckBoundary(State* state, BrunsliStatus result) {
 1375|  26.2k|  if (result == BRUNSLI_NOT_ENOUGH_DATA) {
  ------------------
  |  Branch (1375:7): [True: 3.29k, False: 22.9k]
  ------------------
 1376|  3.29k|    bool last = (RemainingSectionLength(state) <= GetBytesAvailable(state));
 1377|  3.29k|    return last ? BRUNSLI_INVALID_BRN : BRUNSLI_NOT_ENOUGH_DATA;
  ------------------
  |  Branch (1377:12): [True: 62, False: 3.23k]
  ------------------
 1378|  22.9k|  } else {
 1379|  22.9k|    return result;
 1380|  22.9k|  }
 1381|  26.2k|}
brunsli_decode.cc:_ZN7brunsliL22DecodeQuantDataSectionEPNS_8internal3dec5StateEPNS_8JPEGDataE:
 1635|  7.52k|static BrunsliStatus DecodeQuantDataSection(State* state, JPEGData* jpg) {
 1636|  7.52k|  InternalState& s = *state->internal;
 1637|  7.52k|  QuantDataState& qs = s.quant;
 1638|  7.52k|  BrunsliBitReader* br = &qs.br;
 1639|       |
 1640|  7.52k|  if (qs.stage == QuantDataState::INIT) {
  ------------------
  |  Branch (1640:7): [True: 7.52k, False: 0]
  ------------------
 1641|  7.52k|    BrunsliBitReaderInit(br);
 1642|  7.52k|    qs.stage = QuantDataState::READ_NUM_QUANT;
 1643|  7.52k|  }
 1644|  7.52k|  PrepareBitReader(br, state);
 1645|       |
 1646|  7.52k|  const auto suspend_bit_reader = [&](BrunsliStatus result) -> BrunsliStatus {
 1647|  7.52k|    return SuspendBitReader(br, state, result);
 1648|  7.52k|  };
 1649|       |
 1650|  7.52k|  if (qs.stage == QuantDataState::READ_NUM_QUANT) {
  ------------------
  |  Branch (1650:7): [True: 7.52k, False: 0]
  ------------------
 1651|  7.52k|    if (!BrunsliBitReaderCanRead(br, 2)) {
  ------------------
  |  Branch (1651:9): [True: 146, False: 7.37k]
  ------------------
 1652|    146|      return suspend_bit_reader(BRUNSLI_NOT_ENOUGH_DATA);
 1653|    146|    }
 1654|  7.37k|    size_t num_quant_tables = BrunsliBitReaderRead(br, 2) + 1;
 1655|  7.37k|    if (jpg->quant.size() != num_quant_tables) {
  ------------------
  |  Branch (1655:9): [True: 123, False: 7.25k]
  ------------------
 1656|    123|      return suspend_bit_reader(BRUNSLI_INVALID_BRN);
 1657|    123|    }
 1658|  7.25k|    qs.predictor.resize(kDCTBlockSize);
 1659|  7.25k|    qs.i = 0;
 1660|  7.25k|    qs.stage = QuantDataState::READ_STOCK;
 1661|  7.25k|  }
 1662|       |
 1663|  65.6k|  while (true) {
  ------------------
  |  Branch (1663:10): [True: 65.6k, Folded]
  ------------------
 1664|  65.6k|    switch (qs.stage) {
 1665|  13.6k|      case QuantDataState::READ_STOCK: {
  ------------------
  |  Branch (1665:7): [True: 13.6k, False: 51.9k]
  ------------------
 1666|  13.6k|        if (qs.i >= jpg->quant.size()) {
  ------------------
  |  Branch (1666:13): [True: 6.21k, False: 7.41k]
  ------------------
 1667|  6.21k|          std::vector<uint8_t>().swap(qs.predictor);
 1668|  6.21k|          qs.i = 0;
 1669|  6.21k|          qs.stage = QuantDataState::READ_QUANT_IDX;
 1670|  6.21k|          continue;
 1671|  6.21k|        }
 1672|       |        // Depending on еру 1-st bit, it is guaranteed that we will need to read
 1673|       |        // at least 3 or 6 more bits.
 1674|  7.41k|        if (!BrunsliBitReaderCanRead(br, 4)) {
  ------------------
  |  Branch (1674:13): [True: 131, False: 7.28k]
  ------------------
 1675|    131|          return suspend_bit_reader(BRUNSLI_NOT_ENOUGH_DATA);
 1676|    131|        }
 1677|  7.28k|        qs.data_precision = 0;
 1678|  7.28k|        bool is_short = !BrunsliBitReaderRead(br, 1);
 1679|  7.28k|        if (is_short) {
  ------------------
  |  Branch (1679:13): [True: 6.28k, False: 1.00k]
  ------------------
 1680|  6.28k|          const size_t short_code = BrunsliBitReaderRead(br, 3);
 1681|  6.28k|          int32_t* table = jpg->quant[qs.i].values.data();
 1682|  6.28k|          size_t selector = (qs.i > 0) ? 1 : 0;
  ------------------
  |  Branch (1682:29): [True: 12, False: 6.27k]
  ------------------
 1683|   408k|          for (size_t k = 0; k < kDCTBlockSize; ++k) {
  ------------------
  |  Branch (1683:30): [True: 402k, False: 6.28k]
  ------------------
 1684|   402k|            table[k] = kStockQuantizationTables[selector][short_code][k];
 1685|   402k|          }
 1686|  6.28k|          qs.stage = QuantDataState::UPDATE;
 1687|  6.28k|        } else {
 1688|  1.00k|          qs.stage = QuantDataState::READ_Q_FACTOR;
 1689|  1.00k|        }
 1690|  7.28k|        continue;
 1691|  7.41k|      }
 1692|       |
 1693|  1.00k|      case QuantDataState::READ_Q_FACTOR: {
  ------------------
  |  Branch (1693:7): [True: 1.00k, False: 64.6k]
  ------------------
 1694|  1.00k|        if (!BrunsliBitReaderCanRead(br, 6)) {
  ------------------
  |  Branch (1694:13): [True: 152, False: 851]
  ------------------
 1695|    152|          return suspend_bit_reader(BRUNSLI_NOT_ENOUGH_DATA);
 1696|    152|        }
 1697|    851|        const uint32_t q_factor = BrunsliBitReaderRead(br, 6);
 1698|    851|        FillQuantMatrix(qs.i > 0, q_factor, qs.predictor.data());
 1699|    851|        qs.j = 0;
 1700|    851|        qs.delta = 0;
 1701|    851|        qs.stage = QuantDataState::READ_DIFF_IS_ZERO;
 1702|    851|        continue;
 1703|  1.00k|      }
 1704|       |
 1705|  16.6k|      case QuantDataState::READ_DIFF_IS_ZERO: {
  ------------------
  |  Branch (1705:7): [True: 16.6k, False: 48.9k]
  ------------------
 1706|  16.6k|        if (qs.j >= kDCTBlockSize) {
  ------------------
  |  Branch (1706:13): [True: 206, False: 16.4k]
  ------------------
 1707|    206|          qs.stage = QuantDataState::UPDATE;
 1708|    206|          continue;
 1709|    206|        }
 1710|  16.4k|        if (!BrunsliBitReaderCanRead(br, 1)) {
  ------------------
  |  Branch (1710:13): [True: 173, False: 16.3k]
  ------------------
 1711|    173|          return suspend_bit_reader(BRUNSLI_NOT_ENOUGH_DATA);
 1712|    173|        }
 1713|  16.3k|        if (BrunsliBitReaderRead(br, 1)) {
  ------------------
  |  Branch (1713:13): [True: 2.86k, False: 13.4k]
  ------------------
 1714|  2.86k|          qs.stage = QuantDataState::READ_DIFF_SIGN;
 1715|  13.4k|        } else {
 1716|  13.4k|          qs.stage = QuantDataState::APPLY_DIFF;
 1717|  13.4k|        }
 1718|  16.3k|        continue;
 1719|  16.4k|      }
 1720|       |
 1721|  2.86k|      case QuantDataState::READ_DIFF_SIGN: {
  ------------------
  |  Branch (1721:7): [True: 2.86k, False: 62.7k]
  ------------------
 1722|  2.86k|        if (!BrunsliBitReaderCanRead(br, 1)) {
  ------------------
  |  Branch (1722:13): [True: 150, False: 2.71k]
  ------------------
 1723|    150|          return suspend_bit_reader(BRUNSLI_NOT_ENOUGH_DATA);
 1724|    150|        }
 1725|  2.71k|        qs.sign = BrunsliBitReaderRead(br, 1) ? -1 : 1;
  ------------------
  |  Branch (1725:19): [True: 864, False: 1.85k]
  ------------------
 1726|  2.71k|        qs.stage = QuantDataState::READ_DIFF;
 1727|  2.71k|        continue;
 1728|  2.86k|      }
 1729|       |
 1730|  2.71k|      case QuantDataState::READ_DIFF: {
  ------------------
  |  Branch (1730:7): [True: 2.71k, False: 62.9k]
  ------------------
 1731|  2.71k|        if (!DecodeVarint(&qs.vs, br, 16)) {
  ------------------
  |  Branch (1731:13): [True: 134, False: 2.58k]
  ------------------
 1732|    134|          return suspend_bit_reader(BRUNSLI_NOT_ENOUGH_DATA);
 1733|    134|        }
 1734|  2.58k|        int diff = static_cast<int>(qs.vs.value) + 1;
 1735|  2.58k|        qs.delta += qs.sign * diff;
 1736|  2.58k|        qs.stage = QuantDataState::APPLY_DIFF;
 1737|  2.58k|        continue;
 1738|  2.71k|      }
 1739|       |
 1740|  16.0k|      case QuantDataState::APPLY_DIFF: {
  ------------------
  |  Branch (1740:7): [True: 16.0k, False: 49.6k]
  ------------------
 1741|  16.0k|        const int k = kJPEGNaturalOrder[qs.j];
 1742|  16.0k|        const int quant_value = qs.predictor[k] + qs.delta;
 1743|  16.0k|        jpg->quant[qs.i].values[k] = quant_value;
 1744|  16.0k|        if (quant_value <= 0) {
  ------------------
  |  Branch (1744:13): [True: 97, False: 15.9k]
  ------------------
 1745|     97|          return suspend_bit_reader(BRUNSLI_INVALID_BRN);
 1746|     97|        }
 1747|  15.9k|        if (quant_value >= 256) {
  ------------------
  |  Branch (1747:13): [True: 9.34k, False: 6.57k]
  ------------------
 1748|  9.34k|          qs.data_precision = 1;
 1749|  9.34k|        }
 1750|  15.9k|        if (quant_value >= 65536) {
  ------------------
  |  Branch (1750:13): [True: 91, False: 15.8k]
  ------------------
 1751|     91|          return suspend_bit_reader(BRUNSLI_INVALID_BRN);
 1752|     91|        }
 1753|  15.8k|        ++qs.j;
 1754|  15.8k|        qs.stage = QuantDataState::READ_DIFF_IS_ZERO;
 1755|  15.8k|        continue;
 1756|  15.9k|      }
 1757|       |
 1758|  6.48k|      case QuantDataState::UPDATE: {
  ------------------
  |  Branch (1758:7): [True: 6.48k, False: 59.1k]
  ------------------
 1759|  6.48k|        if (jpg->quant[qs.i].precision < qs.data_precision) {
  ------------------
  |  Branch (1759:13): [True: 104, False: 6.38k]
  ------------------
 1760|    104|          return suspend_bit_reader(BRUNSLI_INVALID_BRN);
 1761|    104|        }
 1762|       |        // jpg->quant[qs.i].precision > qs.data_precision means that original
 1763|       |        // JPEG1 was inefficiently encoded.
 1764|  6.38k|        ++qs.i;
 1765|  6.38k|        qs.stage = QuantDataState::READ_STOCK;
 1766|  6.38k|        continue;
 1767|  6.48k|      }
 1768|       |
 1769|  6.21k|      default: { /* no-op */ }
  ------------------
  |  Branch (1769:7): [True: 6.21k, False: 59.4k]
  ------------------
 1770|  65.6k|    }
 1771|  6.21k|    break;  // no matching stage has been found; exit the loop.
 1772|  65.6k|  }
 1773|       |
 1774|  18.9k|  while (qs.stage == QuantDataState::READ_QUANT_IDX) {
  ------------------
  |  Branch (1774:10): [True: 12.9k, False: 5.96k]
  ------------------
 1775|  12.9k|    if (qs.i >= jpg->components.size()) {
  ------------------
  |  Branch (1775:9): [True: 5.96k, False: 7.02k]
  ------------------
 1776|  5.96k|      qs.stage = QuantDataState::FINISH;
 1777|  5.96k|      continue;
 1778|  5.96k|    }
 1779|  7.02k|    JPEGComponent* c = &jpg->components[qs.i];
 1780|  7.02k|    if (!BrunsliBitReaderCanRead(br, 2)) {
  ------------------
  |  Branch (1780:9): [True: 152, False: 6.87k]
  ------------------
 1781|    152|       return suspend_bit_reader(BRUNSLI_NOT_ENOUGH_DATA);
 1782|    152|    }
 1783|  6.87k|    c->quant_idx = BrunsliBitReaderRead(br, 2);
 1784|  6.87k|    if (c->quant_idx >= jpg->quant.size()) {
  ------------------
  |  Branch (1784:9): [True: 102, False: 6.77k]
  ------------------
 1785|    102|      return suspend_bit_reader(BRUNSLI_INVALID_BRN);
 1786|    102|    }
 1787|  6.77k|    ++qs.i;
 1788|  6.77k|  }
 1789|       |
 1790|  5.96k|  BRUNSLI_DCHECK(qs.stage == QuantDataState::FINISH);
 1791|  5.96k|  suspend_bit_reader(BRUNSLI_OK);
 1792|  5.96k|  BrunsliBitReaderFinish(br);
 1793|  5.96k|  if (!BrunsliBitReaderIsHealthy(br)) return BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (1793:7): [True: 1, False: 5.96k]
  ------------------
 1794|  5.96k|  if (!IsAtSectionBoundary(state)) return BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (1794:7): [True: 125, False: 5.83k]
  ------------------
 1795|  5.83k|  return BRUNSLI_OK;
 1796|  5.96k|}
brunsli_decode.cc:_ZZN7brunsliL22DecodeQuantDataSectionEPNS_8internal3dec5StateEPNS_8JPEGDataEENK3$_0clENS_13BrunsliStatusE:
 1646|  7.52k|  const auto suspend_bit_reader = [&](BrunsliStatus result) -> BrunsliStatus {
 1647|  7.52k|    return SuspendBitReader(br, state, result);
 1648|  7.52k|  };
brunsli_decode.cc:_ZN7brunsliL26DecodeHistogramDataSectionEPNS_8internal3dec5StateEPNS_8JPEGDataE:
 1798|  7.26k|static BrunsliStatus DecodeHistogramDataSection(State* state, JPEGData* jpg) {
 1799|  7.26k|  InternalState& s = *state->internal;
 1800|  7.26k|  HistogramDataState& hs = s.histogram;
 1801|  7.26k|  BrunsliBitReader* br = &hs.br;
 1802|       |
 1803|  7.26k|  if (hs.stage == HistogramDataState::INIT) {
  ------------------
  |  Branch (1803:7): [True: 7.26k, False: 0]
  ------------------
 1804|  7.26k|    BrunsliBitReaderInit(br);
 1805|  7.26k|    BRUNSLI_DCHECK(!jpg->components.empty());
 1806|  7.26k|    s.num_contexts = jpg->components.size();
 1807|  7.26k|    hs.stage = HistogramDataState::READ_SCHEME;
 1808|       |    /* Optimization: hint arena about maximal used alphabet size: 272.
 1809|       |     * 648 = 272 + 376, where 376 is a "universal" overhead for max-15-bit
 1810|       |     * root-8-bit 2-level Huffman tables. */
 1811|  7.26k|    hs.arena.reserve(648);
 1812|  7.26k|  }
 1813|  7.26k|  PrepareBitReader(br, state);
 1814|  7.26k|  if (RemainingSectionLength(state) <= GetBytesAvailable(state)) {
  ------------------
  |  Branch (1814:7): [True: 6.40k, False: 859]
  ------------------
 1815|       |    // If end of section is reachable, then we could parse the remainings in
 1816|       |    // non-streaming mode.
 1817|  6.40k|    BrunsliBitReaderSetOptimistic(br);
 1818|  6.40k|  }
 1819|  7.26k|  const auto suspend_bit_reader = [&](BrunsliStatus result) -> BrunsliStatus {
 1820|  7.26k|    return SuspendBitReader(br, state, result);
 1821|  7.26k|  };
 1822|       |
 1823|  7.26k|  if (hs.stage == HistogramDataState::READ_SCHEME) {
  ------------------
  |  Branch (1823:7): [True: 7.26k, False: 0]
  ------------------
 1824|  7.26k|    const size_t num_components = jpg->components.size();
 1825|  7.26k|    BRUNSLI_DCHECK(num_components <= 4);
 1826|  7.26k|    if (!BrunsliBitReaderCanRead(br, 3 * num_components)) {
  ------------------
  |  Branch (1826:9): [True: 150, False: 7.11k]
  ------------------
 1827|    150|      return suspend_bit_reader(BRUNSLI_NOT_ENOUGH_DATA);
 1828|    150|    }
 1829|  15.0k|    for (size_t i = 0; i < num_components; ++i) {
  ------------------
  |  Branch (1829:24): [True: 8.02k, False: 7.03k]
  ------------------
 1830|  8.02k|      size_t scheme = BrunsliBitReaderRead(br, 3);
 1831|  8.02k|      if (scheme >= kNumSchemes) return suspend_bit_reader(BRUNSLI_INVALID_BRN);
  ------------------
  |  Branch (1831:11): [True: 84, False: 7.93k]
  ------------------
 1832|  7.93k|      ComponentMeta& m = state->meta[i];
 1833|  7.93k|      m.context_bits = scheme;
 1834|  7.93k|      m.context_offset = s.num_contexts;
 1835|  7.93k|      s.num_contexts += kNumNonzeroContextSkip[scheme];
 1836|  7.93k|    }
 1837|  7.03k|    if (!BrunsliBitReaderIsHealthy(br)) {
  ------------------
  |  Branch (1837:9): [True: 11, False: 7.02k]
  ------------------
 1838|     11|      return suspend_bit_reader(BRUNSLI_INVALID_BRN);
 1839|     11|    }
 1840|  7.02k|    hs.stage = HistogramDataState::READ_NUM_HISTOGRAMS;
 1841|  7.02k|  }
 1842|       |
 1843|  7.02k|  if (hs.stage == HistogramDataState::READ_NUM_HISTOGRAMS) {
  ------------------
  |  Branch (1843:7): [True: 7.02k, False: 0]
  ------------------
 1844|  7.02k|    if (!BrunsliBitReaderCanRead(br, 11)) {
  ------------------
  |  Branch (1844:9): [True: 25, False: 6.99k]
  ------------------
 1845|     25|      return suspend_bit_reader(BRUNSLI_NOT_ENOUGH_DATA);
 1846|     25|    }
 1847|  6.99k|    s.num_histograms = DecodeVarLenUint8(br) + 1;
 1848|  6.99k|    if (!BrunsliBitReaderIsHealthy(br)) {
  ------------------
  |  Branch (1848:9): [True: 15, False: 6.98k]
  ------------------
 1849|     15|      return suspend_bit_reader(BRUNSLI_INVALID_BRN);
 1850|     15|    }
 1851|  6.98k|    if (s.shallow_histograms) {
  ------------------
  |  Branch (1851:9): [True: 0, False: 6.98k]
  ------------------
 1852|      0|      hs.stage = HistogramDataState::SKIP_CONTENT;
 1853|  6.98k|    } else {
 1854|  6.98k|      s.context_map_.resize(s.num_contexts * kNumAvrgContexts);
 1855|  6.98k|      state->context_map = s.context_map_.data();
 1856|  6.98k|      s.entropy_codes_.resize(s.num_histograms);
 1857|  6.98k|      state->entropy_codes = s.entropy_codes_.data();
 1858|  6.98k|      if (s.num_histograms > 1) {
  ------------------
  |  Branch (1858:11): [True: 1.18k, False: 5.80k]
  ------------------
 1859|  1.18k|        hs.stage = HistogramDataState::READ_CONTEXT_MAP_CODE;
 1860|  5.80k|      } else {
 1861|  5.80k|        hs.i = 0;
 1862|  5.80k|        hs.counts.resize(kCoeffAlphabetSize);
 1863|  5.80k|        hs.stage = HistogramDataState::READ_HISTOGRAMS;
 1864|  5.80k|      }
 1865|  6.98k|    }
 1866|  6.98k|  }
 1867|       |
 1868|  6.98k|  if (hs.stage == HistogramDataState::SKIP_CONTENT) {
  ------------------
  |  Branch (1868:7): [True: 0, False: 6.98k]
  ------------------
 1869|      0|    suspend_bit_reader(BRUNSLI_OK);
 1870|      0|    if (!BrunsliBitReaderIsHealthy(br)) {
  ------------------
  |  Branch (1870:9): [True: 0, False: 0]
  ------------------
 1871|      0|      return suspend_bit_reader(BRUNSLI_INVALID_BRN);
 1872|      0|    }
 1873|      0|    SkipAvailableBytes(state, RemainingSectionLength(state));
 1874|      0|    if (!IsAtSectionBoundary(state)) return BRUNSLI_NOT_ENOUGH_DATA;
  ------------------
  |  Branch (1874:9): [True: 0, False: 0]
  ------------------
 1875|      0|    hs.stage = HistogramDataState::DONE;
 1876|      0|  }
 1877|       |
 1878|  6.98k|  if (hs.stage == HistogramDataState::READ_CONTEXT_MAP_CODE) {
  ------------------
  |  Branch (1878:7): [True: 1.18k, False: 5.80k]
  ------------------
 1879|  1.18k|    if (!BrunsliBitReaderCanRead(br, 207 + s.num_histograms * 8)) {
  ------------------
  |  Branch (1879:9): [True: 90, False: 1.09k]
  ------------------
 1880|     90|      return suspend_bit_reader(BRUNSLI_NOT_ENOUGH_DATA);
 1881|     90|    }
 1882|  1.09k|    hs.max_run_length_prefix = 0;
 1883|  1.09k|    bool use_rle_for_zeros = !!BrunsliBitReaderRead(br, 1);
 1884|  1.09k|    if (use_rle_for_zeros) {
  ------------------
  |  Branch (1884:9): [True: 384, False: 708]
  ------------------
 1885|    384|      hs.max_run_length_prefix = BrunsliBitReaderRead(br, 4) + 1;
 1886|    384|    }
 1887|  1.09k|    size_t alphabet_size = s.num_histograms + hs.max_run_length_prefix;
 1888|  1.09k|    hs.entropy.reset(new HuffmanDecodingData);
 1889|  1.09k|    if (!hs.entropy->ReadFromBitStream(alphabet_size, br, &hs.arena)) {
  ------------------
  |  Branch (1889:9): [True: 300, False: 792]
  ------------------
 1890|    300|      return suspend_bit_reader(BRUNSLI_INVALID_BRN);
 1891|    300|    }
 1892|    792|    hs.i = 0;
 1893|    792|    hs.stage = HistogramDataState::READ_CONTEXT_MAP;
 1894|    792|  }
 1895|       |
 1896|  6.59k|  if (hs.stage == HistogramDataState::READ_CONTEXT_MAP) {
  ------------------
  |  Branch (1896:7): [True: 792, False: 5.80k]
  ------------------
 1897|    792|    BrunsliStatus status = DecodeContextMap(
 1898|    792|        *hs.entropy, hs.max_run_length_prefix, &hs.i, &s.context_map_, br);
 1899|    792|    if (status != BRUNSLI_OK) return suspend_bit_reader(status);
  ------------------
  |  Branch (1899:9): [True: 315, False: 477]
  ------------------
 1900|    477|    hs.i = 0;
 1901|    477|    hs.counts.resize(kCoeffAlphabetSize);
 1902|    477|    hs.stage = HistogramDataState::READ_HISTOGRAMS;
 1903|    477|  }
 1904|       |
 1905|  6.27k|  if (hs.stage == HistogramDataState::READ_HISTOGRAMS) {
  ------------------
  |  Branch (1905:7): [True: 6.27k, False: 0]
  ------------------
 1906|  17.7k|    while (hs.i < s.num_histograms) {
  ------------------
  |  Branch (1906:12): [True: 11.9k, False: 5.87k]
  ------------------
 1907|  11.9k|      if (!BrunsliBitReaderCanRead(br, 9 + kCoeffAlphabetSize * 11)) {
  ------------------
  |  Branch (1907:11): [True: 185, False: 11.7k]
  ------------------
 1908|    185|        return suspend_bit_reader(BRUNSLI_NOT_ENOUGH_DATA);
 1909|    185|      }
 1910|  11.7k|      if (!ReadHistogram(BRUNSLI_ANS_LOG_TAB_SIZE, &hs.counts, br)) {
  ------------------
  |  Branch (1910:11): [True: 213, False: 11.5k]
  ------------------
 1911|    213|        return suspend_bit_reader(BRUNSLI_INVALID_BRN);
 1912|    213|      }
 1913|  11.5k|      if (!s.entropy_codes_[hs.i].Init(hs.counts)) {
  ------------------
  |  Branch (1913:11): [True: 0, False: 11.5k]
  ------------------
 1914|      0|        return suspend_bit_reader(BRUNSLI_INVALID_BRN);
 1915|      0|      }
 1916|  11.5k|      ++hs.i;
 1917|  11.5k|    }
 1918|  5.87k|    hs.entropy.reset();
 1919|  5.87k|    std::vector<uint32_t>().swap(hs.counts);
 1920|  5.87k|    suspend_bit_reader(BRUNSLI_OK);
 1921|  5.87k|    BrunsliBitReaderFinish(br);
 1922|  5.87k|    if (!BrunsliBitReaderIsHealthy(br)) return BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (1922:9): [True: 11, False: 5.86k]
  ------------------
 1923|  5.86k|    if (!IsAtSectionBoundary(state)) return BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (1923:9): [True: 62, False: 5.80k]
  ------------------
 1924|  5.80k|    hs.stage = HistogramDataState::DONE;
 1925|  5.80k|  }
 1926|       |
 1927|  5.80k|  hs.arena.reset();
 1928|  5.80k|  BRUNSLI_DCHECK(hs.stage == HistogramDataState::DONE);
 1929|  5.80k|  return BRUNSLI_OK;
 1930|  6.27k|}
brunsli_decode.cc:_ZZN7brunsliL26DecodeHistogramDataSectionEPNS_8internal3dec5StateEPNS_8JPEGDataEENK3$_0clENS_13BrunsliStatusE:
 1819|  7.26k|  const auto suspend_bit_reader = [&](BrunsliStatus result) -> BrunsliStatus {
 1820|  7.26k|    return SuspendBitReader(br, state, result);
 1821|  7.26k|  };
_ZN7brunsli17DecodeVarLenUint8EPNS_16BrunsliBitReaderE:
   87|  6.99k|inline uint32_t DecodeVarLenUint8(BrunsliBitReader* br) {
   88|  6.99k|  if (BrunsliBitReaderRead(br, 1)) {
  ------------------
  |  Branch (88:7): [True: 1.19k, False: 5.80k]
  ------------------
   89|  1.19k|    uint32_t nbits = BrunsliBitReaderRead(br, 3);
   90|  1.19k|    if (nbits == 0) {
  ------------------
  |  Branch (90:9): [True: 584, False: 613]
  ------------------
   91|    584|      return 1u;
   92|    613|    } else {
   93|    613|      return BrunsliBitReaderRead(br, nbits) + (1u << nbits);
   94|    613|    }
   95|  1.19k|  }
   96|  5.80k|  return 0;
   97|  6.99k|}
brunsli_decode.cc:_ZN7brunsliL19DecodeDCDataSectionEPNS_8internal3dec5StateE:
 1932|  5.78k|static BrunsliStatus DecodeDCDataSection(State* state) {
 1933|  5.78k|  size_t available = GetBytesAvailable(state) & ~1;
 1934|  5.78k|  size_t limit = RemainingSectionLength(state);
 1935|  5.78k|  BRUNSLI_DCHECK((limit & 1) == 0);
 1936|  5.78k|  size_t chunk_len = std::min(available, limit);
 1937|       |  // If end of section is reachable, then we could parse the remainings in
 1938|       |  // non-streaming mode.
 1939|  5.78k|  bool is_last_chunk = (chunk_len == limit);
 1940|  5.78k|  WordSource in(state->data + state->pos, chunk_len, is_last_chunk);
 1941|       |
 1942|  5.78k|  BrunsliStatus status = DecodeDC(state, &in);
 1943|       |
 1944|  5.78k|  BRUNSLI_DCHECK((in.pos_ & 1) == 0);
 1945|  5.78k|  if (in.error_) return BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (1945:7): [True: 212, False: 5.57k]
  ------------------
 1946|  5.57k|  BRUNSLI_DCHECK(in.pos_ <= chunk_len);
 1947|  5.57k|  SkipBytes(state, in.pos_);
 1948|  5.57k|  if (is_last_chunk) {
  ------------------
  |  Branch (1948:7): [True: 5.29k, False: 285]
  ------------------
 1949|  5.29k|    BRUNSLI_DCHECK(status != BRUNSLI_NOT_ENOUGH_DATA);
 1950|  5.29k|    if (!IsAtSectionBoundary(state)) return BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (1950:9): [True: 11, False: 5.28k]
  ------------------
 1951|  5.29k|  }
 1952|  5.56k|  return status;
 1953|  5.57k|}
brunsli_decode.cc:_ZN7brunsliL19DecodeACDataSectionEPNS_8internal3dec5StateE:
 1955|  5.26k|static BrunsliStatus DecodeACDataSection(State* state) {
 1956|  5.26k|  size_t available = GetBytesAvailable(state) & ~1;
 1957|  5.26k|  size_t limit = RemainingSectionLength(state);
 1958|  5.26k|  BRUNSLI_DCHECK((limit & 1) == 0);
 1959|  5.26k|  size_t chunk_len = std::min(available, limit);
 1960|       |  // If end of section is reachable, then we could parse the remainings in
 1961|       |  // non-streaming mode.
 1962|  5.26k|  bool is_last_chunk = (chunk_len == limit);
 1963|  5.26k|  WordSource in(state->data + state->pos, chunk_len, is_last_chunk);
 1964|       |
 1965|  5.26k|  BrunsliStatus status = DecodeAC(state, &in);
 1966|       |
 1967|  5.26k|  BRUNSLI_DCHECK((in.pos_ & 1) == 0);
 1968|  5.26k|  if (in.error_) return BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (1968:7): [True: 526, False: 4.73k]
  ------------------
 1969|  4.73k|  BRUNSLI_DCHECK(in.pos_ <= chunk_len);
 1970|  4.73k|  SkipBytes(state, in.pos_);
 1971|  4.73k|  if (is_last_chunk) {
  ------------------
  |  Branch (1971:7): [True: 4.53k, False: 197]
  ------------------
 1972|  4.53k|    BRUNSLI_DCHECK(status != BRUNSLI_NOT_ENOUGH_DATA);
 1973|  4.53k|    if (!IsAtSectionBoundary(state)) return BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (1973:9): [True: 71, False: 4.46k]
  ------------------
 1974|  4.53k|  }
 1975|  4.66k|  return status;
 1976|  4.73k|}

_ZN7brunsli10WordSource11GetNextWordEv:
   27|  3.90M|  uint16_t GetNextWord() {
   28|  3.90M|    uint16_t val = 0;
   29|  3.90M|    if (pos_ < len_) {  /* NB: both pos_ and len_ are even. */
  ------------------
  |  Branch (29:9): [True: 3.86M, False: 35.0k]
  ------------------
   30|  3.86M|      val = BRUNSLI_UNALIGNED_LOAD16LE(data_ + pos_);
  ------------------
  |  |  309|  3.86M|#define BRUNSLI_UNALIGNED_LOAD16LE BrunsliUnalignedRead16
  ------------------
   31|  3.86M|    } else {
   32|  35.0k|      error_ = true;
   33|  35.0k|    }
   34|       |    // TODO(eustas): take care of overflows?
   35|  3.90M|    pos_ += 2;
   36|  3.90M|    return val;
   37|  3.90M|  }
_ZN7brunsli9BitSource4InitEPNS_10WordSourceE:
   58|  10.8k|  void Init(WordSource* in) {
   59|  10.8k|    val_ = in->GetNextWord();
   60|  10.8k|    bit_pos_ = 0;
   61|  10.8k|  }
_ZN7brunsli9BitSource6FinishEv:
   77|  9.81k|  bool Finish() {
   78|  9.81k|    size_t n_bits = 16 - bit_pos_;
   79|  9.81k|    if (n_bits > 0) {
  ------------------
  |  Branch (79:9): [True: 8.57k, False: 1.23k]
  ------------------
   80|  8.57k|      int padding_bits = (val_ >> bit_pos_) & kBitMask[n_bits];
   81|  8.57k|      if (padding_bits != 0) return false;
  ------------------
  |  Branch (81:11): [True: 16, False: 8.56k]
  ------------------
   82|  8.57k|    }
   83|  9.80k|    return true;
   84|  9.81k|  }
_ZN7brunsli10WordSource7CanReadEm:
   39|  43.5M|  bool CanRead(size_t n) {
   40|  43.5M|    if (optimistic_) return true;
  ------------------
  |  Branch (40:9): [True: 24.4M, False: 19.0M]
  ------------------
   41|  19.0M|    size_t delta = 2 * n;
   42|  19.0M|    size_t projected_end = pos_ + delta;
   43|       |    // Check for overflow; just in case.
   44|  19.0M|    if (projected_end < pos_) return false;
  ------------------
  |  Branch (44:9): [True: 0, False: 19.0M]
  ------------------
   45|  19.0M|    return projected_end <= len_;
   46|  19.0M|  }
_ZN7brunsli9BitSource8ReadBitsEiPNS_10WordSourceE:
   63|  4.22M|  uint32_t ReadBits(int nbits, WordSource* in) {
   64|  4.22M|    if (bit_pos_ + nbits > 16) {
  ------------------
  |  Branch (64:9): [True: 1.43M, False: 2.79M]
  ------------------
   65|  1.43M|      uint32_t new_bits = in->GetNextWord();
   66|  1.43M|      val_ |= new_bits << 16;
   67|  1.43M|    }
   68|  4.22M|    uint32_t result = (val_ >> bit_pos_) & kBitMask[nbits];
   69|  4.22M|    bit_pos_ += nbits;
   70|  4.22M|    if (bit_pos_ > 16) {
  ------------------
  |  Branch (70:9): [True: 1.43M, False: 2.79M]
  ------------------
   71|  1.43M|      bit_pos_ -= 16;
   72|  1.43M|      val_ >>= 16;
   73|  1.43M|    }
   74|  4.22M|    return result;
   75|  4.22M|  }
_ZN7brunsli10WordSourceC2EPKhmb:
   21|  11.0k|      : data_(data),
   22|  11.0k|        len_(len & ~1),
   23|  11.0k|        pos_(0),
   24|  11.0k|        error_(false),
   25|  11.0k|        optimistic_(optimistic) {}
_ZN7brunsli9BitSourceC2Ev:
   56|  21.1k|  BitSource() {}

_ZN7brunsli16DecodeContextMapERKNS_19HuffmanDecodingDataEmPmPNSt3__16vectorIhNS4_9allocatorIhEEEEPNS_16BrunsliBitReaderE:
   44|    792|                               BrunsliBitReader* br) {
   45|    792|  size_t& i = *index;
   46|    792|  uint8_t* map = context_map->data();
   47|    792|  const size_t length = context_map->size();
   48|   911k|  while (i < length) {
  ------------------
  |  Branch (48:10): [True: 910k, False: 570]
  ------------------
   49|       |    // Check there is enough deta for Huffman code, RLE and IMTF bit.
   50|   910k|    if (!BrunsliBitReaderCanRead(br, 15 + max_run_length_prefix + 1)) {
  ------------------
  |  Branch (50:9): [True: 151, False: 910k]
  ------------------
   51|    151|      return BRUNSLI_NOT_ENOUGH_DATA;
   52|    151|    }
   53|   910k|    uint32_t code = entropy.ReadSymbol(br);
   54|   910k|    if (code == 0) {
  ------------------
  |  Branch (54:9): [True: 174k, False: 735k]
  ------------------
   55|   174k|      map[i] = 0;
   56|   174k|      ++i;
   57|   735k|    } else if (code <= max_run_length_prefix) {
  ------------------
  |  Branch (57:16): [True: 5.16k, False: 730k]
  ------------------
   58|  5.16k|      size_t reps = 1u + (1u << code) + (int)BrunsliBitReaderRead(br, code);
   59|   211k|      while (--reps) {
  ------------------
  |  Branch (59:14): [True: 206k, False: 5.09k]
  ------------------
   60|   206k|        if (i >= length) return BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (60:13): [True: 71, False: 206k]
  ------------------
   61|   206k|        map[i] = 0;
   62|   206k|        ++i;
   63|   206k|      }
   64|   730k|    } else {
   65|   730k|      map[i] = (uint8_t)(code - max_run_length_prefix);
   66|   730k|      ++i;
   67|   730k|    }
   68|   910k|  }
   69|    570|  if (BrunsliBitReaderRead(br, 1)) {
  ------------------
  |  Branch (69:7): [True: 411, False: 159]
  ------------------
   70|    411|    InverseMoveToFrontTransform(map, length);
   71|    411|  }
   72|    570|  return BrunsliBitReaderIsHealthy(br) ? BRUNSLI_OK : BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (72:10): [True: 477, False: 93]
  ------------------
   73|    792|}
context_map_decode.cc:_ZN7brunsli12_GLOBAL__N_127InverseMoveToFrontTransformEPhm:
   27|    411|void InverseMoveToFrontTransform(uint8_t* v, size_t v_len) {
   28|    411|  uint8_t mtf[256];
   29|   105k|  for (size_t i = 0; i < 256; ++i) {
  ------------------
  |  Branch (29:22): [True: 105k, False: 411]
  ------------------
   30|   105k|    mtf[i] = static_cast<uint8_t>(i);
   31|   105k|  }
   32|   644k|  for (size_t i = 0; i < v_len; ++i) {
  ------------------
  |  Branch (32:22): [True: 644k, False: 411]
  ------------------
   33|   644k|    uint8_t index = v[i];
   34|   644k|    v[i] = mtf[index];
   35|   644k|    if (index) MoveToFront(mtf, index);
  ------------------
  |  Branch (35:9): [True: 619k, False: 25.3k]
  ------------------
   36|   644k|  }
   37|    411|}
context_map_decode.cc:_ZN7brunsli12_GLOBAL__N_111MoveToFrontEPhh:
   20|   619k|void MoveToFront(uint8_t* v, uint8_t index) {
   21|   619k|  uint8_t value = v[index];
   22|   619k|  uint8_t i = index;
   23|  16.6M|  for (; i; --i) v[i] = v[i - 1];
  ------------------
  |  Branch (23:10): [True: 16.0M, False: 619k]
  ------------------
   24|   619k|  v[0] = value;
   25|   619k|}

_ZN7brunsli13ReadHistogramEjPNSt3__16vectorIjNS0_9allocatorIjEEEEPNS_16BrunsliBitReaderE:
   40|  11.7k|                   BrunsliBitReader* br) {
   41|  11.7k|  BRUNSLI_DCHECK(!counts->empty());
   42|  11.7k|  uint32_t space = 1u << precision_bits;
   43|  11.7k|  const size_t length = counts->size();
   44|  11.7k|  std::fill(counts->begin(), counts->end(), 0);
   45|  11.7k|  uint32_t* histogram = counts->data();
   46|  11.7k|  int simple_code = BrunsliBitReaderRead(br, 1);
   47|  11.7k|  if (simple_code == 1) {
  ------------------
  |  Branch (47:7): [True: 9.58k, False: 2.13k]
  ------------------
   48|  9.58k|    size_t max_bits_counter = length - 1;
   49|  9.58k|    uint32_t max_bits = 0;
   50|  9.58k|    int symbols[2] = {0};
   51|  9.58k|    const size_t num_symbols = BrunsliBitReaderRead(br, 1) + 1u;
   52|  57.5k|    while (max_bits_counter) {
  ------------------
  |  Branch (52:12): [True: 47.9k, False: 9.58k]
  ------------------
   53|  47.9k|      max_bits_counter >>= 1;
   54|  47.9k|      ++max_bits;
   55|  47.9k|    }
   56|  21.5k|    for (size_t i = 0; i < num_symbols; ++i) {
  ------------------
  |  Branch (56:24): [True: 11.9k, False: 9.58k]
  ------------------
   57|  11.9k|      symbols[i] = BrunsliBitReaderRead(br, max_bits) % length;
   58|  11.9k|    }
   59|  9.58k|    if (num_symbols == 1) {
  ------------------
  |  Branch (59:9): [True: 7.17k, False: 2.40k]
  ------------------
   60|  7.17k|      histogram[symbols[0]] = space;
   61|  7.17k|    } else {
   62|  2.40k|      if (symbols[0] == symbols[1]) {  // corrupt data
  ------------------
  |  Branch (62:11): [True: 18, False: 2.39k]
  ------------------
   63|     18|        return false;
   64|     18|      }
   65|  2.39k|      uint32_t value = BrunsliBitReaderRead(br, precision_bits);
   66|  2.39k|      histogram[symbols[0]] = value;
   67|  2.39k|      histogram[symbols[1]] = space - value;
   68|  2.39k|    }
   69|  9.58k|  } else {
   70|  2.13k|    size_t real_length = ReadShortHuffmanCode(br, kLengthTree);
   71|  2.13k|    uint32_t total_count = 0;
   72|  2.13k|    uint32_t log_counts[BRUNSLI_ANS_MAX_SYMBOLS];
   73|  2.13k|    size_t omit_pos = 0;
   74|  2.13k|    BRUNSLI_DCHECK(real_length > 2);
   75|  26.7k|    for (size_t i = 0; i < real_length; ++i) {
  ------------------
  |  Branch (75:24): [True: 24.6k, False: 2.13k]
  ------------------
   76|  24.6k|      log_counts[i] =
   77|  24.6k|          static_cast<uint32_t>(ReadShortHuffmanCode(br, kLogCountTree));
   78|  24.6k|      if (log_counts[i] > log_counts[omit_pos]) omit_pos = i;
  ------------------
  |  Branch (78:11): [True: 1.93k, False: 22.6k]
  ------------------
   79|  24.6k|    }
   80|  2.13k|    BRUNSLI_DCHECK(omit_pos >= 0);
   81|  26.7k|    for (size_t i = 0; i < real_length; ++i) {
  ------------------
  |  Branch (81:24): [True: 24.6k, False: 2.13k]
  ------------------
   82|  24.6k|      uint32_t code = log_counts[i];
   83|  24.6k|      if (i == omit_pos) {
  ------------------
  |  Branch (83:11): [True: 2.13k, False: 22.4k]
  ------------------
   84|  2.13k|        continue;
   85|  22.4k|      } else if (code == 0) {
  ------------------
  |  Branch (85:18): [True: 1.61k, False: 20.8k]
  ------------------
   86|  1.61k|        continue;
   87|  20.8k|      } else if (code == 1) {
  ------------------
  |  Branch (87:18): [True: 1.39k, False: 19.4k]
  ------------------
   88|  1.39k|        histogram[i] = 1;
   89|  19.4k|      } else {
   90|  19.4k|        uint32_t bit_count = GetPopulationCountPrecision(code - 1);
   91|  19.4k|        histogram[i] = (1u << (code - 1)) + (BrunsliBitReaderRead(br, bit_count)
   92|  19.4k|                                             << (code - 1 - bit_count));
   93|  19.4k|      }
   94|  20.8k|      total_count += histogram[i];
   95|  20.8k|    }
   96|  2.13k|    if (total_count >= space) {
  ------------------
  |  Branch (96:9): [True: 24, False: 2.11k]
  ------------------
   97|       |      // The histogram we've read sums to more than total_count (including at
   98|       |      // least 1 for the omitted value).
   99|     24|      return false;
  100|     24|    }
  101|  2.11k|    histogram[omit_pos] = space - total_count;
  102|  2.11k|  }
  103|  11.6k|  return BrunsliBitReaderIsHealthy(br);
  104|  11.7k|}
histogram_decode.cc:_ZN7brunsli12_GLOBAL__N_120ReadShortHuffmanCodeEPNS_16BrunsliBitReaderEPKa:
   27|  26.7k|size_t ReadShortHuffmanCode(BrunsliBitReader* br, const int8_t* tree) {
   28|  26.7k|  size_t pos = 0;
   29|  26.7k|  int8_t delta = 1;
   30|   105k|  while (delta > 0) {
  ------------------
  |  Branch (30:10): [True: 78.2k, False: 26.7k]
  ------------------
   31|  78.2k|    pos += delta + BrunsliBitReaderRead(br, 1);
   32|  78.2k|    delta = tree[pos];
   33|  78.2k|  }
   34|  26.7k|  return static_cast<size_t>(-delta);
   35|  26.7k|}

_ZN7brunsli22ReadHuffmanCodeLengthsEPKhmPhPNS_16BrunsliBitReaderE:
   29|    309|                           BrunsliBitReader* br) {
   30|    309|  size_t symbol = 0;
   31|    309|  uint8_t prev_code_len = kDefaultCodeLength;
   32|    309|  size_t repeat = 0;
   33|    309|  uint8_t repeat_code_len = 0;
   34|    309|  const int kFullSpace = 1 << 15;
   35|    309|  int space = kFullSpace;
   36|    309|  HuffmanCode table[32];
   37|       |
   38|    309|  uint16_t counts[16] = {0};
   39|  5.87k|  for (int i = 0; i < kCodeLengthCodes; ++i) {
  ------------------
  |  Branch (39:19): [True: 5.56k, False: 309]
  ------------------
   40|  5.56k|    ++counts[code_length_code_lengths[i]];
   41|  5.56k|  }
   42|    309|  if (!BuildHuffmanTable(table, 5, code_length_code_lengths, kCodeLengthCodes,
  ------------------
  |  Branch (42:7): [True: 0, False: 309]
  ------------------
   43|    309|                         &counts[0])) {
   44|      0|    return false;
   45|      0|  }
   46|       |
   47|  10.6k|  while (symbol < num_symbols && space > 0) {
  ------------------
  |  Branch (47:10): [True: 10.5k, False: 101]
  |  Branch (47:34): [True: 10.4k, False: 174]
  ------------------
   48|  10.4k|    const HuffmanCode* p = table;
   49|  10.4k|    uint8_t code_len;
   50|  10.4k|    p += BrunsliBitReaderGet(br, 5);
   51|  10.4k|    BrunsliBitReaderDrop(br, p->bits);
   52|  10.4k|    code_len = (uint8_t)p->value;
   53|  10.4k|    if (code_len < kCodeLengthRepeatCode) {
  ------------------
  |  Branch (53:9): [True: 9.72k, False: 679]
  ------------------
   54|  9.72k|      repeat = 0;
   55|  9.72k|      code_lengths[symbol++] = code_len;
   56|  9.72k|      if (code_len != 0) {
  ------------------
  |  Branch (56:11): [True: 8.59k, False: 1.12k]
  ------------------
   57|  8.59k|        prev_code_len = code_len;
   58|  8.59k|        space -= kFullSpace >> code_len;
   59|  8.59k|      }
   60|  9.72k|    } else {
   61|    679|      uint32_t extra_bits = code_len - 14;  // >= 2
   62|    679|      size_t old_repeat;
   63|    679|      size_t repeat_delta;
   64|    679|      uint8_t new_len = 0;
   65|    679|      if (code_len == kCodeLengthRepeatCode) {
  ------------------
  |  Branch (65:11): [True: 446, False: 233]
  ------------------
   66|    446|        new_len = prev_code_len;
   67|    446|      }
   68|    679|      if (repeat_code_len != new_len) {
  ------------------
  |  Branch (68:11): [True: 195, False: 484]
  ------------------
   69|    195|        repeat = 0;
   70|    195|        repeat_code_len = new_len;
   71|    195|      }
   72|    679|      old_repeat = repeat;
   73|    679|      if (repeat > 0) {  // >= 3
  ------------------
  |  Branch (73:11): [True: 161, False: 518]
  ------------------
   74|    161|        repeat -= 2;
   75|    161|        repeat <<= extra_bits;
   76|    161|      }
   77|    679|      repeat += BrunsliBitReaderRead(br, extra_bits) + 3u;
   78|    679|      repeat_delta = repeat - old_repeat;
   79|    679|      if (symbol + repeat_delta > num_symbols) {
  ------------------
  |  Branch (79:11): [True: 34, False: 645]
  ------------------
   80|     34|        return false;
   81|     34|      }
   82|    645|      memset(&code_lengths[symbol], repeat_code_len, (size_t)repeat_delta);
   83|    645|      symbol += repeat_delta;
   84|    645|      if (repeat_code_len != 0) {
  ------------------
  |  Branch (84:11): [True: 435, False: 210]
  ------------------
   85|    435|        space -= static_cast<int>(repeat_delta * kFullSpace) >> repeat_code_len;
   86|    435|      }
   87|    645|    }
   88|  10.4k|  }
   89|    275|  if (space != 0) {
  ------------------
  |  Branch (89:7): [True: 80, False: 195]
  ------------------
   90|     80|    return false;
   91|     80|  }
   92|    195|  memset(&code_lengths[symbol], 0, (size_t)(num_symbols - symbol));
   93|    195|  return BrunsliBitReaderIsHealthy(br);
   94|    275|}
_ZN7brunsli19HuffmanDecodingData17ReadFromBitStreamEmPNS_16BrunsliBitReaderEPNS_5ArenaINS_11HuffmanCodeEEE:
  191|  1.09k|    Arena<HuffmanCode>* arena) {
  192|  1.09k|  Arena<HuffmanCode> local_arena;
  193|  1.09k|  if (arena == nullptr) arena = &local_arena;
  ------------------
  |  Branch (193:7): [True: 0, False: 1.09k]
  ------------------
  194|       |
  195|  1.09k|  if (alphabet_size > (1 << kMaxHuffmanBits)) return false;
  ------------------
  |  Branch (195:7): [True: 0, False: 1.09k]
  ------------------
  196|       |
  197|  1.09k|  std::vector<uint8_t> code_lengths(alphabet_size, 0);
  198|       |  /* simple_code_or_skip is used as follows:
  199|       |     1 for simple code;
  200|       |     0 for no skipping, 2 skips 2 code lengths, 3 skips 3 code lengths */
  201|  1.09k|  uint32_t simple_code_or_skip = BrunsliBitReaderRead(br, 2);
  202|  1.09k|  if (simple_code_or_skip == 1u) {
  ------------------
  |  Branch (202:7): [True: 697, False: 395]
  ------------------
  203|    697|    table_.resize(1u << kHuffmanTableBits);
  204|    697|    return ReadSimpleCode(static_cast<uint16_t>(alphabet_size), br,
  205|    697|                          table_.data());
  206|    697|  }
  207|       |
  208|    395|  uint8_t code_length_code_lengths[kCodeLengthCodes] = {0};
  209|    395|  int space = 32;
  210|    395|  int num_codes = 0;
  211|       |  /* Static Huffman code for the code length code lengths */
  212|    395|  static const HuffmanCode huff[16] = {
  213|    395|      {2, 0}, {2, 4}, {2, 3}, {3, 2}, {2, 0}, {2, 4}, {2, 3}, {4, 1},
  214|    395|      {2, 0}, {2, 4}, {2, 3}, {3, 2}, {2, 0}, {2, 4}, {2, 3}, {4, 5},
  215|    395|  };
  216|  5.31k|  for (size_t i = simple_code_or_skip; i < kCodeLengthCodes && space > 0; ++i) {
  ------------------
  |  Branch (216:40): [True: 5.16k, False: 153]
  |  Branch (216:64): [True: 4.92k, False: 242]
  ------------------
  217|  4.92k|    const int code_len_idx = kCodeLengthCodeOrder[i];
  218|  4.92k|    const HuffmanCode* p = huff;
  219|  4.92k|    uint8_t v;
  220|  4.92k|    p += BrunsliBitReaderGet(br, 4);
  221|  4.92k|    BrunsliBitReaderDrop(br, p->bits);
  222|  4.92k|    v = (uint8_t)p->value;
  223|  4.92k|    code_length_code_lengths[code_len_idx] = v;
  224|  4.92k|    if (v != 0) {
  ------------------
  |  Branch (224:9): [True: 2.22k, False: 2.69k]
  ------------------
  225|  2.22k|      space -= (32u >> v);
  226|  2.22k|      ++num_codes;
  227|  2.22k|    }
  228|  4.92k|  }
  229|    395|  bool ok = (num_codes == 1 || space == 0) &&
  ------------------
  |  Branch (229:14): [True: 63, False: 332]
  |  Branch (229:32): [True: 246, False: 86]
  ------------------
  230|    309|       ReadHuffmanCodeLengths(code_length_code_lengths, alphabet_size,
  ------------------
  |  Branch (230:8): [True: 186, False: 123]
  ------------------
  231|    309|                              &code_lengths[0], br);
  232|       |
  233|    395|  if (!ok || !BrunsliBitReaderIsHealthy(br)) return false;
  ------------------
  |  Branch (233:7): [True: 209, False: 186]
  |  Branch (233:14): [True: 0, False: 186]
  ------------------
  234|    186|  uint16_t counts[16] = {0};
  235|  21.4k|  for (size_t i = 0; i < alphabet_size; ++i) {
  ------------------
  |  Branch (235:22): [True: 21.2k, False: 186]
  ------------------
  236|  21.2k|    ++counts[code_lengths[i]];
  237|  21.2k|  }
  238|    186|  arena->reserve(alphabet_size + 376);
  239|    186|  uint32_t table_size =
  240|    186|      BuildHuffmanTable(arena->data(), kHuffmanTableBits, &code_lengths[0],
  241|    186|                        alphabet_size, &counts[0]);
  242|    186|  table_ = std::vector<HuffmanCode>(arena->data(), arena->data() + table_size);
  243|    186|  return (table_size > 0);
  244|    395|}
_ZNK7brunsli19HuffmanDecodingData10ReadSymbolEPNS_16BrunsliBitReaderE:
  247|   910k|uint16_t HuffmanDecodingData::ReadSymbol(BrunsliBitReader* br) const {
  248|   910k|  uint32_t n_bits;
  249|   910k|  const HuffmanCode* table = table_.data();
  250|   910k|  table += BrunsliBitReaderGet(br, kHuffmanTableBits);
  251|   910k|  n_bits = table->bits;
  252|   910k|  if (n_bits > kHuffmanTableBits) {
  ------------------
  |  Branch (252:7): [True: 681, False: 909k]
  ------------------
  253|    681|    BrunsliBitReaderDrop(br, kHuffmanTableBits);
  254|    681|    n_bits -= kHuffmanTableBits;
  255|    681|    table += table->value;
  256|    681|    table += BrunsliBitReaderGet(br, n_bits);
  257|    681|  }
  258|   910k|  BrunsliBitReaderDrop(br, table->bits);
  259|   910k|  return table->value;
  260|   910k|}
huffman_decode.cc:_ZN7brunsliL14ReadSimpleCodeEtPNS_16BrunsliBitReaderEPNS_11HuffmanCodeE:
   98|    697|                                          HuffmanCode* table) {
   99|    697|  uint32_t max_bits =
  100|    697|      (alphabet_size > 1u) ? Log2FloorNonZero(alphabet_size - 1u) + 1 : 0;
  ------------------
  |  Branch (100:7): [True: 697, False: 0]
  ------------------
  101|       |
  102|    697|  size_t num_symbols = BrunsliBitReaderRead(br, 2) + 1;
  103|       |
  104|    697|  uint16_t symbols[4] = {0};
  105|  1.82k|  for (size_t i = 0; i < num_symbols; ++i) {
  ------------------
  |  Branch (105:22): [True: 1.15k, False: 668]
  ------------------
  106|  1.15k|    uint16_t symbol = BrunsliBitReaderRead(br, max_bits);
  107|  1.15k|    if (symbol >= alphabet_size) {
  ------------------
  |  Branch (107:9): [True: 29, False: 1.12k]
  ------------------
  108|     29|      return false;
  109|     29|    }
  110|  1.12k|    symbols[i] = symbol;
  111|  1.12k|  }
  112|       |
  113|  1.03k|  for (size_t i = 0; i < num_symbols - 1; ++i) {
  ------------------
  |  Branch (113:22): [True: 394, False: 643]
  ------------------
  114|  1.00k|    for (size_t j = i + 1; j < num_symbols; ++j) {
  ------------------
  |  Branch (114:28): [True: 637, False: 369]
  ------------------
  115|    637|      if (symbols[i] == symbols[j]) return false;
  ------------------
  |  Branch (115:11): [True: 25, False: 612]
  ------------------
  116|    637|    }
  117|    394|  }
  118|       |
  119|       |  // 4 symbols have to option to encode.
  120|    643|  if (num_symbols == 4) num_symbols += BrunsliBitReaderRead(br, 1);
  ------------------
  |  Branch (120:7): [True: 58, False: 585]
  ------------------
  121|       |
  122|    643|  const auto swap_symbols = [&symbols] (size_t i, size_t j) {
  123|    643|    uint16_t t = symbols[j];
  124|    643|    symbols[j] = symbols[i];
  125|    643|    symbols[i] = t;
  126|    643|  };
  127|       |
  128|    643|  size_t table_size = 1;
  129|    643|  switch (num_symbols) {
  130|    445|    case 1:
  ------------------
  |  Branch (130:5): [True: 445, False: 198]
  ------------------
  131|    445|      table[0] = {0, symbols[0]};
  132|    445|      break;
  133|    102|    case 2:
  ------------------
  |  Branch (133:5): [True: 102, False: 541]
  ------------------
  134|    102|      if (symbols[0] > symbols[1]) swap_symbols(0, 1);
  ------------------
  |  Branch (134:11): [True: 64, False: 38]
  ------------------
  135|    102|      table[0] = {1, symbols[0]};
  136|    102|      table[1] = {1, symbols[1]};
  137|    102|      table_size = 2;
  138|    102|      break;
  139|     38|    case 3:
  ------------------
  |  Branch (139:5): [True: 38, False: 605]
  ------------------
  140|     38|      if (symbols[1] > symbols[2]) swap_symbols(1, 2);
  ------------------
  |  Branch (140:11): [True: 17, False: 21]
  ------------------
  141|     38|      table[0] = {1, symbols[0]};
  142|     38|      table[2] = {1, symbols[0]};
  143|     38|      table[1] = {2, symbols[1]};
  144|     38|      table[3] = {2, symbols[2]};
  145|     38|      table_size = 4;
  146|     38|      break;
  147|     34|    case 4: {
  ------------------
  |  Branch (147:5): [True: 34, False: 609]
  ------------------
  148|    136|      for (size_t i = 0; i < 3; ++i) {
  ------------------
  |  Branch (148:26): [True: 102, False: 34]
  ------------------
  149|    306|        for (size_t j = i + 1; j < 4; ++j) {
  ------------------
  |  Branch (149:32): [True: 204, False: 102]
  ------------------
  150|    204|          if (symbols[i] > symbols[j]) swap_symbols(i, j);
  ------------------
  |  Branch (150:15): [True: 158, False: 46]
  ------------------
  151|    204|        }
  152|    102|      }
  153|     34|      table[0] = {2, symbols[0]};
  154|     34|      table[2] = {2, symbols[1]};
  155|     34|      table[1] = {2, symbols[2]};
  156|     34|      table[3] = {2, symbols[3]};
  157|     34|      table_size = 4;
  158|     34|      break;
  159|      0|    }
  160|     24|    case 5: {
  ------------------
  |  Branch (160:5): [True: 24, False: 619]
  ------------------
  161|     24|      if (symbols[2] > symbols[3]) swap_symbols(2, 3);
  ------------------
  |  Branch (161:11): [True: 15, False: 9]
  ------------------
  162|     24|      table[0] = {1, symbols[0]};
  163|     24|      table[1] = {2, symbols[1]};
  164|     24|      table[2] = {1, symbols[0]};
  165|     24|      table[3] = {3, symbols[2]};
  166|     24|      table[4] = {1, symbols[0]};
  167|     24|      table[5] = {2, symbols[1]};
  168|     24|      table[6] = {1, symbols[0]};
  169|     24|      table[7] = {3, symbols[3]};
  170|     24|      table_size = 8;
  171|     24|      break;
  172|      0|    }
  173|      0|    default: {
  ------------------
  |  Branch (173:5): [True: 0, False: 643]
  ------------------
  174|       |      // Unreachable.
  175|      0|      return false;
  176|      0|    }
  177|    643|  }
  178|       |
  179|    643|  const uint32_t goal_size = 1u << kHuffmanTableBits;
  180|  5.46k|  while (table_size != goal_size) {
  ------------------
  |  Branch (180:10): [True: 4.82k, False: 643]
  ------------------
  181|  4.82k|    memcpy(&table[table_size], &table[0],
  182|  4.82k|           (size_t)table_size * sizeof(table[0]));
  183|  4.82k|    table_size <<= 1;
  184|  4.82k|  }
  185|       |
  186|    643|  return BrunsliBitReaderIsHealthy(br);
  187|    643|}
huffman_decode.cc:_ZZN7brunsliL14ReadSimpleCodeEtPNS_16BrunsliBitReaderEPNS_11HuffmanCodeEENKUlmmE_clEmm:
  122|    254|  const auto swap_symbols = [&symbols] (size_t i, size_t j) {
  123|    254|    uint16_t t = symbols[j];
  124|    254|    symbols[j] = symbols[i];
  125|    254|    symbols[i] = t;
  126|    254|  };

_ZN7brunsli5ArenaINS_11HuffmanCodeEE7reserveEm:
   28|  7.45k|  void reserve(size_t limit) {
   29|  7.45k|    if (capacity < limit) {
  ------------------
  |  Branch (29:9): [True: 7.26k, False: 186]
  ------------------
   30|  7.26k|      capacity = limit;
   31|  7.26k|      storage.reset(new T[capacity]);
   32|  7.26k|    }
   33|  7.45k|  }
_ZN7brunsli5ArenaINS_11HuffmanCodeEE5resetEv:
   39|  5.80k|  void reset() {
   40|  5.80k|    capacity = 0;
   41|  5.80k|    storage.reset();
   42|  5.80k|  }
_ZN7brunsli5ArenaINS_11HuffmanCodeEE4dataEv:
   35|    558|  T* data() {
   36|    558|    return storage.get();
   37|    558|  }

_ZN7brunsli17BuildHuffmanTableEPNS_11HuffmanCodeEmPKhmPt:
   55|    495|                           size_t code_lengths_size, uint16_t* count) {
   56|    495|  HuffmanCode code;    /* current table entry */
   57|    495|  HuffmanCode* table;  /* next available space in table */
   58|    495|  size_t len;          /* current code length */
   59|    495|  size_t symbol;       /* symbol index in original or sorted table */
   60|    495|  int key;             /* reversed prefix code */
   61|    495|  int step;            /* step size to replicate values in current table */
   62|    495|  int low;             /* low bits for current root entry */
   63|    495|  int mask;            /* mask for low bits */
   64|    495|  size_t table_bits;   /* key length of current table */
   65|    495|  int table_size;      /* size of current table */
   66|    495|  int total_size;      /* sum of root table size and 2nd level table sizes */
   67|       |  /* offsets in sorted table for each length */
   68|    495|  uint16_t offset[kMaxHuffmanBits + 1];
   69|    495|  size_t max_length = 1;
   70|       |
   71|    495|  if (code_lengths_size > 1u << kMaxHuffmanBits) return 0;
  ------------------
  |  Branch (71:7): [True: 0, False: 495]
  ------------------
   72|       |
   73|       |  /* symbols sorted by code length */
   74|    495|  std::vector<uint16_t> sorted_storage(code_lengths_size);
   75|    495|  uint16_t* sorted = sorted_storage.data();
   76|       |
   77|       |  /* generate offsets into sorted symbol table by code length */
   78|    495|  {
   79|    495|    uint16_t sum = 0;
   80|  7.92k|    for (len = 1; len <= kMaxHuffmanBits; len++) {
  ------------------
  |  Branch (80:19): [True: 7.42k, False: 495]
  ------------------
   81|  7.42k|      offset[len] = sum;
   82|  7.42k|      if (count[len]) {
  ------------------
  |  Branch (82:11): [True: 1.22k, False: 6.20k]
  ------------------
   83|  1.22k|        sum = static_cast<uint16_t>(sum + count[len]);
   84|  1.22k|        max_length = len;
   85|  1.22k|      }
   86|  7.42k|    }
   87|    495|  }
   88|       |
   89|       |  /* sort symbols by length, by symbol order within each length */
   90|  27.3k|  for (symbol = 0; symbol < code_lengths_size; symbol++) {
  ------------------
  |  Branch (90:20): [True: 26.8k, False: 495]
  ------------------
   91|  26.8k|    if (code_lengths[symbol] != 0) {
  ------------------
  |  Branch (91:9): [True: 11.1k, False: 15.7k]
  ------------------
   92|  11.1k|      sorted[offset[code_lengths[symbol]]++] = static_cast<uint16_t>(symbol);
   93|  11.1k|    }
   94|  26.8k|  }
   95|       |
   96|    495|  table = root_table;
   97|    495|  table_bits = root_bits;
   98|    495|  table_size = 1u << table_bits;
   99|    495|  total_size = table_size;
  100|       |
  101|       |  /* special case code with only one value */
  102|    495|  if (offset[kMaxHuffmanBits] == 1) {
  ------------------
  |  Branch (102:7): [True: 63, False: 432]
  ------------------
  103|     63|    code.bits = 0;
  104|     63|    code.value = static_cast<uint16_t>(sorted[0]);
  105|  2.07k|    for (key = 0; key < total_size; ++key) {
  ------------------
  |  Branch (105:19): [True: 2.01k, False: 63]
  ------------------
  106|  2.01k|      table[key] = code;
  107|  2.01k|    }
  108|     63|    return total_size;
  109|     63|  }
  110|       |
  111|       |  /* fill in root table */
  112|       |  /* let's reduce the table size to a smaller size if possible, and */
  113|       |  /* create the repetitions by memcpy if possible in the coming loop */
  114|    432|  if (table_bits > max_length) {
  ------------------
  |  Branch (114:7): [True: 331, False: 101]
  ------------------
  115|    331|    table_bits = max_length;
  116|    331|    table_size = 1u << table_bits;
  117|    331|  }
  118|    432|  key = 0;
  119|    432|  symbol = 0;
  120|    432|  code.bits = 1;
  121|    432|  step = 2;
  122|  1.71k|  do {
  123|  8.46k|    for (; count[code.bits] != 0; --count[code.bits]) {
  ------------------
  |  Branch (123:12): [True: 6.74k, False: 1.71k]
  ------------------
  124|  6.74k|      code.value = static_cast<uint16_t>(sorted[symbol++]);
  125|  6.74k|      ReplicateValue(&table[key], step, table_size, code);
  126|  6.74k|      key = GetNextKey(key, code.bits);
  127|  6.74k|    }
  128|  1.71k|    step <<= 1;
  129|  1.71k|  } while (++code.bits <= table_bits);
  ------------------
  |  Branch (129:12): [True: 1.28k, False: 432]
  ------------------
  130|       |
  131|       |  /* if root_bits != table_bits we only created one fraction of the */
  132|       |  /* table, and we need to replicate it now. */
  133|  1.43k|  while (total_size != table_size) {
  ------------------
  |  Branch (133:10): [True: 999, False: 432]
  ------------------
  134|    999|    memcpy(&table[table_size], &table[0], table_size * sizeof(table[0]));
  135|    999|    table_size <<= 1;
  136|    999|  }
  137|       |
  138|       |  /* fill in 2nd level tables and add pointers to root table */
  139|    432|  mask = total_size - 1;
  140|    432|  low = -1;
  141|    609|  for (len = root_bits + 1, step = 2; len <= max_length; ++len, step <<= 1) {
  ------------------
  |  Branch (141:39): [True: 177, False: 432]
  ------------------
  142|  4.48k|    for (; count[len] != 0; --count[len]) {
  ------------------
  |  Branch (142:12): [True: 4.30k, False: 177]
  ------------------
  143|  4.30k|      if ((key & mask) != low) {
  ------------------
  |  Branch (143:11): [True: 1.35k, False: 2.95k]
  ------------------
  144|  1.35k|        table += table_size;
  145|  1.35k|        table_bits = NextTableBitSize(count, len, root_bits);
  146|  1.35k|        table_size = 1u << table_bits;
  147|  1.35k|        total_size += table_size;
  148|  1.35k|        low = key & mask;
  149|  1.35k|        root_table[low].bits = static_cast<uint8_t>(table_bits + root_bits);
  150|  1.35k|        root_table[low].value =
  151|  1.35k|            static_cast<uint16_t>((table - root_table) - low);
  152|  1.35k|      }
  153|  4.30k|      code.bits = static_cast<uint8_t>(len - root_bits);
  154|  4.30k|      code.value = static_cast<uint16_t>(sorted[symbol++]);
  155|  4.30k|      ReplicateValue(&table[key >> root_bits], step, table_size, code);
  156|  4.30k|      key = GetNextKey(key, len);
  157|  4.30k|    }
  158|    177|  }
  159|       |
  160|    432|  return total_size;
  161|    495|}
huffman_table.cc:_ZN7brunsliL14ReplicateValueEPNS_11HuffmanCodeEiiS0_:
   31|  11.0k|                                  HuffmanCode code) {
   32|  26.0k|  do {
   33|  26.0k|    end -= step;
   34|  26.0k|    table[end] = code;
   35|  26.0k|  } while (end > 0);
  ------------------
  |  Branch (35:12): [True: 15.0k, False: 11.0k]
  ------------------
   36|  11.0k|}
huffman_table.cc:_ZN7brunsliL10GetNextKeyEim:
   20|  11.0k|static inline int GetNextKey(int key, size_t len) {
   21|  11.0k|  int step = 1u << (len - 1);
   22|  21.6k|  while (key & step) {
  ------------------
  |  Branch (22:10): [True: 10.6k, False: 11.0k]
  ------------------
   23|  10.6k|    step >>= 1;
   24|  10.6k|  }
   25|  11.0k|  return (key & (step - 1)) + step;
   26|  11.0k|}
huffman_table.cc:_ZN7brunsliL16NextTableBitSizeEPKtmm:
   42|  1.35k|                                      size_t root_bits) {
   43|  1.35k|  size_t left = size_t(1) << (len - root_bits);
   44|  1.42k|  while (len < kMaxHuffmanBits) {
  ------------------
  |  Branch (44:10): [True: 1.40k, False: 15]
  ------------------
   45|  1.40k|    if (left <= count[len]) break;
  ------------------
  |  Branch (45:9): [True: 1.33k, False: 70]
  ------------------
   46|     70|    left -= count[len];
   47|     70|    ++len;
   48|     70|    left <<= 1;
   49|     70|  }
   50|  1.35k|  return len - root_bits;
   51|  1.35k|}

_ZN7brunsli9WriteJpegERKNS_8JPEGDataENS_10JPEGOutputE:
  967|  4.45k|bool WriteJpeg(const JPEGData& jpg, JPEGOutput out) {
  968|  4.45k|  State state;
  969|  4.45k|  state.stage = Stage::DONE;
  970|  4.45k|  std::vector<uint8_t> buffer(16384);
  971|  4.68k|  while (true) {
  ------------------
  |  Branch (971:10): [True: 4.68k, Folded]
  ------------------
  972|  4.68k|    uint8_t* next_out = buffer.data();
  973|  4.68k|    size_t available_out = buffer.size();
  974|  4.68k|    SerializationStatus status =
  975|  4.68k|        SerializeJpeg(&state, jpg, &available_out, &next_out);
  976|  4.68k|    if (status != SerializationStatus::DONE &&
  ------------------
  |  Branch (976:9): [True: 4.42k, False: 260]
  ------------------
  977|  4.42k|        status != SerializationStatus::NEEDS_MORE_OUTPUT) {
  ------------------
  |  Branch (977:9): [True: 4.19k, False: 229]
  ------------------
  978|  4.19k|      return false;
  979|  4.19k|    }
  980|    489|    size_t to_write = buffer.size() - available_out;
  981|    489|    if (!out.Write(buffer.data(), to_write)) return false;
  ------------------
  |  Branch (981:9): [True: 0, False: 489]
  ------------------
  982|    489|    if (status == SerializationStatus::DONE) return true;
  ------------------
  |  Branch (982:9): [True: 260, False: 229]
  ------------------
  983|    489|  }
  984|  4.45k|}
_ZN7brunsli8internal3dec13SerializeJpegEPNS1_5StateERKNS_8JPEGDataEPmPPh:
  989|  4.68k|                                  size_t* available_out, uint8_t** next_out) {
  990|  4.68k|  SerializationState& ss = state->internal->serialization;
  991|       |
  992|  4.68k|  const auto maybe_push_output = [&]() {
  993|  4.68k|    if (ss.stage != SerializationState::ERROR) {
  994|  4.68k|      PushOutput(&ss.output_queue, available_out, next_out);
  995|  4.68k|    }
  996|  4.68k|  };
  997|       |
  998|       |  // Push remaining output from prevoius session.
  999|  4.68k|  maybe_push_output();
 1000|       |
 1001|  42.7k|  while (true) {
  ------------------
  |  Branch (1001:10): [True: 42.7k, Folded]
  ------------------
 1002|  42.7k|    switch (ss.stage) {
 1003|  4.45k|      case SerializationState::INIT: {
  ------------------
  |  Branch (1003:7): [True: 4.45k, False: 38.2k]
  ------------------
 1004|       |        // If parsing is complete, serialization is possible.
 1005|  4.45k|        bool can_start_serialization = (state->stage == Stage::DONE);
 1006|       |        // Parsing of AC/DC has started; i.e. quant/huffman/metadata is ready
 1007|       |        // to be used.
 1008|  4.45k|        if (HasSection(state, kBrunsliDCDataTag) ||
  ------------------
  |  Branch (1008:13): [True: 0, False: 4.45k]
  ------------------
 1009|  4.45k|            HasSection(state, kBrunsliACDataTag)) {
  ------------------
  |  Branch (1009:13): [True: 0, False: 4.45k]
  ------------------
 1010|      0|          can_start_serialization = true;
 1011|      0|        }
 1012|  4.45k|        if (!can_start_serialization) {
  ------------------
  |  Branch (1012:13): [True: 0, False: 4.45k]
  ------------------
 1013|      0|          return SerializationStatus::NEEDS_MORE_INPUT;
 1014|      0|        }
 1015|       |        // JpegBypass is a very simple / special case.
 1016|  4.45k|        if (jpg.version == kFallbackVersion) {
  ------------------
  |  Branch (1016:13): [True: 9, False: 4.44k]
  ------------------
 1017|      9|          if (jpg.original_jpg == nullptr) {
  ------------------
  |  Branch (1017:15): [True: 1, False: 8]
  ------------------
 1018|      1|            ss.stage = SerializationState::ERROR;
 1019|      1|            break;
 1020|      1|          }
 1021|       |          // TODO(eustas): investigate if bad things can happen when complete
 1022|       |          //               file is passed to parser, but it is impossible to
 1023|       |          //               push complete output.
 1024|      8|          ss.output_queue.emplace_back(jpg.original_jpg, jpg.original_jpg_size);
 1025|      8|          ss.stage = SerializationState::DONE;
 1026|      8|          break;
 1027|      9|        }
 1028|       |
 1029|       |        // Invalid mode - fallback + something else.
 1030|  4.44k|        if ((jpg.version & 1) == kFallbackVersion) {
  ------------------
  |  Branch (1030:13): [True: 0, False: 4.44k]
  ------------------
 1031|      0|          ss.stage = SerializationState::ERROR;
 1032|      0|          break;
 1033|      0|        }
 1034|       |
 1035|       |        // Valid Brunsli requires, at least, 0xD9 marker.
 1036|       |        // This might happen on corrupted stream, or on unconditioned JPEGData.
 1037|       |        // TODO(eustas): check D9 in the only one and is the last one.
 1038|  4.44k|        if (jpg.marker_order.empty()) {
  ------------------
  |  Branch (1038:13): [True: 0, False: 4.44k]
  ------------------
 1039|      0|          ss.stage = SerializationState::ERROR;
 1040|      0|          break;
 1041|      0|        }
 1042|       |
 1043|  4.44k|        ss.dc_huff_table.resize(kMaxHuffmanTables);
 1044|  4.44k|        ss.ac_huff_table.resize(kMaxHuffmanTables);
 1045|  4.44k|        if (jpg.has_zero_padding_bit) {
  ------------------
  |  Branch (1045:13): [True: 247, False: 4.20k]
  ------------------
 1046|    247|          ss.pad_bits = jpg.padding_bits.data();
 1047|    247|          ss.pad_bits_end = ss.pad_bits + jpg.padding_bits.size();
 1048|    247|        }
 1049|       |
 1050|  4.44k|        EncodeSOI(&ss);
 1051|  4.44k|        maybe_push_output();
 1052|  4.44k|        ss.stage = SerializationState::SERIALIZE_SECTION;
 1053|  4.44k|        break;
 1054|  4.44k|      }
 1055|       |
 1056|  33.5k|      case SerializationState::SERIALIZE_SECTION: {
  ------------------
  |  Branch (1056:7): [True: 33.5k, False: 9.14k]
  ------------------
 1057|  33.5k|        if (ss.section_index >= jpg.marker_order.size()) {
  ------------------
  |  Branch (1057:13): [True: 252, False: 33.3k]
  ------------------
 1058|    252|          ss.stage = SerializationState::DONE;
 1059|    252|          break;
 1060|    252|        }
 1061|  33.3k|        uint8_t marker = jpg.marker_order[ss.section_index];
 1062|  33.3k|        SerializationStatus status = SerializeSection(marker, *state, &ss, jpg);
 1063|  33.3k|        if (status == SerializationStatus::ERROR) {
  ------------------
  |  Branch (1063:13): [True: 4.19k, False: 29.1k]
  ------------------
 1064|  4.19k|          BRUNSLI_LOG_DEBUG() << "Failed to encode marker " << std::hex
  ------------------
  |  |  427|  4.19k|#define BRUNSLI_LOG_DEBUG() BRUNSLI_VOID_LOG()
  |  |  ------------------
  |  |  |  |  406|  4.19k|#define BRUNSLI_VOID_LOG() if (true) {} else std::cerr
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (406:32): [True: 4.19k, Folded]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1065|      0|                              << marker << BRUNSLI_ENDL();
  ------------------
  |  |  414|      0|#define BRUNSLI_ENDL() std::endl
  ------------------
 1066|  4.19k|          ss.stage = SerializationState::ERROR;
 1067|  4.19k|          break;
 1068|  4.19k|        }
 1069|  29.1k|        maybe_push_output();
 1070|  29.1k|        if (status == SerializationStatus::NEEDS_MORE_INPUT) {
  ------------------
  |  Branch (1070:13): [True: 0, False: 29.1k]
  ------------------
 1071|      0|          return SerializationStatus::NEEDS_MORE_INPUT;
 1072|  29.1k|        } else if (status != SerializationStatus::DONE) {
  ------------------
  |  Branch (1072:20): [True: 0, False: 29.1k]
  ------------------
 1073|      0|          BRUNSLI_DCHECK(false);
 1074|      0|          ss.stage = SerializationState::ERROR;
 1075|      0|          break;
 1076|      0|        }
 1077|  29.1k|        ++ss.section_index;
 1078|  29.1k|        break;
 1079|  29.1k|      }
 1080|       |
 1081|    489|      case SerializationState::DONE: {
  ------------------
  |  Branch (1081:7): [True: 489, False: 42.2k]
  ------------------
 1082|    489|        if (!ss.output_queue.empty()) {
  ------------------
  |  Branch (1082:13): [True: 229, False: 260]
  ------------------
 1083|    229|          return SerializationStatus::NEEDS_MORE_OUTPUT;
 1084|    260|        } else {
 1085|    260|          return SerializationStatus::DONE;
 1086|    260|        }
 1087|    489|      }
 1088|       |
 1089|  4.19k|      default:
  ------------------
  |  Branch (1089:7): [True: 4.19k, False: 38.5k]
  ------------------
 1090|  4.19k|        return SerializationStatus::ERROR;
 1091|  42.7k|    }
 1092|  42.7k|  }
 1093|  4.68k|}
jpeg_data_writer.cc:_ZZN7brunsli8internal3dec13SerializeJpegEPNS1_5StateERKNS_8JPEGDataEPmPPhENK3$_0clEv:
  992|  38.2k|  const auto maybe_push_output = [&]() {
  993|  38.2k|    if (ss.stage != SerializationState::ERROR) {
  ------------------
  |  Branch (993:9): [True: 38.2k, False: 0]
  ------------------
  994|  38.2k|      PushOutput(&ss.output_queue, available_out, next_out);
  995|  38.2k|    }
  996|  38.2k|  };
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_110PushOutputEPNSt3__15dequeINS_8internal3dec11OutputChunkENS1_9allocatorIS5_EEEEPmPPh:
  946|  38.2k|                uint8_t** next_out) {
  947|  73.2k|  while (*available_out > 0) {
  ------------------
  |  Branch (947:10): [True: 72.5k, False: 673]
  ------------------
  948|       |    // No more data.
  949|  72.5k|    if (in->empty()) return;
  ------------------
  |  Branch (949:9): [True: 37.5k, False: 34.9k]
  ------------------
  950|  34.9k|    OutputChunk& chunk = in->front();
  951|  34.9k|    size_t to_copy = std::min(*available_out, chunk.len);
  952|  34.9k|    if (to_copy > 0) {
  ------------------
  |  Branch (952:9): [True: 34.7k, False: 261]
  ------------------
  953|  34.7k|      memcpy(*next_out, chunk.next, to_copy);
  954|  34.7k|      *next_out += to_copy;
  955|  34.7k|      *available_out -= to_copy;
  956|  34.7k|      chunk.next += to_copy;
  957|  34.7k|      chunk.len -= to_copy;
  958|  34.7k|    }
  959|  34.9k|    if (chunk.len == 0) in->pop_front();
  ------------------
  |  Branch (959:9): [True: 34.6k, False: 291]
  ------------------
  960|  34.9k|  }
  961|  38.2k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeSOIEPNS_8internal3dec18SerializationStateE:
  306|  4.44k|bool EncodeSOI(SerializationState* state) {
  307|  4.44k|  state->output_queue.push_back(OutputChunk({0xFF, 0xD8}));
  308|  4.44k|  return true;
  309|  4.44k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_116SerializeSectionEhRKNS_8internal3dec5StateEPNS2_18SerializationStateERKNS_8JPEGDataE:
  878|  33.3k|                                     const JPEGData& jpg) {
  879|  33.3k|  const auto to_status = [](bool result) {
  880|  33.3k|    return result ? SerializationStatus::DONE : SerializationStatus::ERROR;
  881|  33.3k|  };
  882|       |  // TODO(eustas): add and use marker enum
  883|  33.3k|  switch (marker) {
  884|  3.76k|    case 0xC0:
  ------------------
  |  Branch (884:5): [True: 3.76k, False: 29.5k]
  ------------------
  885|  4.82k|    case 0xC1:
  ------------------
  |  Branch (885:5): [True: 1.06k, False: 32.2k]
  ------------------
  886|  9.49k|    case 0xC2:
  ------------------
  |  Branch (886:5): [True: 4.66k, False: 28.6k]
  ------------------
  887|  10.8k|    case 0xC9:
  ------------------
  |  Branch (887:5): [True: 1.30k, False: 32.0k]
  ------------------
  888|  11.9k|    case 0xCA:
  ------------------
  |  Branch (888:5): [True: 1.14k, False: 32.1k]
  ------------------
  889|  11.9k|      return to_status(EncodeSOF(jpg, marker, state));
  890|       |
  891|  4.64k|    case 0xC4:
  ------------------
  |  Branch (891:5): [True: 4.64k, False: 28.6k]
  ------------------
  892|  4.64k|      return to_status(EncodeDHT(jpg, state));
  893|       |
  894|  1.91k|    case 0xD0:
  ------------------
  |  Branch (894:5): [True: 1.91k, False: 31.3k]
  ------------------
  895|  2.93k|    case 0xD1:
  ------------------
  |  Branch (895:5): [True: 1.02k, False: 32.2k]
  ------------------
  896|  3.65k|    case 0xD2:
  ------------------
  |  Branch (896:5): [True: 720, False: 32.5k]
  ------------------
  897|  4.65k|    case 0xD3:
  ------------------
  |  Branch (897:5): [True: 998, False: 32.3k]
  ------------------
  898|  5.70k|    case 0xD4:
  ------------------
  |  Branch (898:5): [True: 1.04k, False: 32.2k]
  ------------------
  899|  6.75k|    case 0xD5:
  ------------------
  |  Branch (899:5): [True: 1.05k, False: 32.2k]
  ------------------
  900|  8.05k|    case 0xD6:
  ------------------
  |  Branch (900:5): [True: 1.30k, False: 32.0k]
  ------------------
  901|  9.06k|    case 0xD7:
  ------------------
  |  Branch (901:5): [True: 1.00k, False: 32.3k]
  ------------------
  902|  9.06k|      return to_status(EncodeRestart(marker, state));
  903|       |
  904|    252|    case 0xD9:
  ------------------
  |  Branch (904:5): [True: 252, False: 33.0k]
  ------------------
  905|    252|      return to_status(EncodeEOI(jpg, state));
  906|       |
  907|  4.95k|    case 0xDA:
  ------------------
  |  Branch (907:5): [True: 4.95k, False: 28.3k]
  ------------------
  908|  4.95k|      return EncodeScan(jpg, parsing_state, state);
  909|       |
  910|    212|    case 0xDB:
  ------------------
  |  Branch (910:5): [True: 212, False: 33.0k]
  ------------------
  911|    212|      return to_status(EncodeDQT(jpg, state));
  912|       |
  913|  1.85k|    case 0xDD:
  ------------------
  |  Branch (913:5): [True: 1.85k, False: 31.4k]
  ------------------
  914|  1.85k|      return to_status(EncodeDRI(jpg, state));
  915|       |
  916|     24|    case 0xE0:
  ------------------
  |  Branch (916:5): [True: 24, False: 33.2k]
  ------------------
  917|     39|    case 0xE1:
  ------------------
  |  Branch (917:5): [True: 15, False: 33.2k]
  ------------------
  918|     48|    case 0xE2:
  ------------------
  |  Branch (918:5): [True: 9, False: 33.2k]
  ------------------
  919|     60|    case 0xE3:
  ------------------
  |  Branch (919:5): [True: 12, False: 33.2k]
  ------------------
  920|     70|    case 0xE4:
  ------------------
  |  Branch (920:5): [True: 10, False: 33.2k]
  ------------------
  921|     80|    case 0xE5:
  ------------------
  |  Branch (921:5): [True: 10, False: 33.2k]
  ------------------
  922|    101|    case 0xE6:
  ------------------
  |  Branch (922:5): [True: 21, False: 33.2k]
  ------------------
  923|    120|    case 0xE7:
  ------------------
  |  Branch (923:5): [True: 19, False: 33.2k]
  ------------------
  924|    136|    case 0xE8:
  ------------------
  |  Branch (924:5): [True: 16, False: 33.2k]
  ------------------
  925|    141|    case 0xE9:
  ------------------
  |  Branch (925:5): [True: 5, False: 33.3k]
  ------------------
  926|    152|    case 0xEA:
  ------------------
  |  Branch (926:5): [True: 11, False: 33.2k]
  ------------------
  927|    163|    case 0xEB:
  ------------------
  |  Branch (927:5): [True: 11, False: 33.2k]
  ------------------
  928|    183|    case 0xEC:
  ------------------
  |  Branch (928:5): [True: 20, False: 33.2k]
  ------------------
  929|    207|    case 0xED:
  ------------------
  |  Branch (929:5): [True: 24, False: 33.2k]
  ------------------
  930|    225|    case 0xEE:
  ------------------
  |  Branch (930:5): [True: 18, False: 33.2k]
  ------------------
  931|    238|    case 0xEF:
  ------------------
  |  Branch (931:5): [True: 13, False: 33.2k]
  ------------------
  932|    238|      return to_status(EncodeAPP(jpg, marker, state));
  933|       |
  934|      4|    case 0xFE:
  ------------------
  |  Branch (934:5): [True: 4, False: 33.3k]
  ------------------
  935|      4|      return to_status(EncodeCOM(jpg, state));
  936|       |
  937|     17|    case 0xFF:
  ------------------
  |  Branch (937:5): [True: 17, False: 33.2k]
  ------------------
  938|     17|      return to_status(EncodeInterMarkerData(jpg, state));
  939|       |
  940|    117|    default:
  ------------------
  |  Branch (940:5): [True: 117, False: 33.1k]
  ------------------
  941|    117|      return SerializationStatus::ERROR;
  942|  33.3k|  }
  943|  33.3k|}
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_116SerializeSectionEhRKNS_8internal3dec5StateEPNS2_18SerializationStateERKNS_8JPEGDataEENK3$_0clEb:
  879|  28.2k|  const auto to_status = [](bool result) {
  880|  28.2k|    return result ? SerializationStatus::DONE : SerializationStatus::ERROR;
  ------------------
  |  Branch (880:12): [True: 27.9k, False: 238]
  ------------------
  881|  28.2k|  };
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeSOFERKNS_8JPEGDataEhPNS_8internal3dec18SerializationStateE:
  317|  11.9k|bool EncodeSOF(const JPEGData& jpg, uint8_t marker, SerializationState* state) {
  318|  11.9k|  if (marker <= 0xC2) state->is_progressive = (marker == 0xC2);
  ------------------
  |  Branch (318:7): [True: 9.49k, False: 2.45k]
  ------------------
  319|       |
  320|  11.9k|  const size_t n_comps = jpg.components.size();
  321|  11.9k|  const size_t marker_len = 8 + 3 * n_comps;
  322|  11.9k|  state->output_queue.emplace_back(marker_len + 2);
  323|  11.9k|  uint8_t* data = state->output_queue.back().buffer->data();
  324|  11.9k|  size_t pos = 0;
  325|  11.9k|  data[pos++] = 0xFFu;
  326|  11.9k|  data[pos++] = marker;
  327|  11.9k|  data[pos++] = static_cast<uint8_t>(marker_len >> 8u);
  328|  11.9k|  data[pos++] = static_cast<uint8_t>(marker_len);
  329|  11.9k|  data[pos++] = kJpegPrecision;
  330|  11.9k|  data[pos++] = jpg.height >> 8u;
  331|  11.9k|  data[pos++] = jpg.height & 0xFFu;
  332|  11.9k|  data[pos++] = jpg.width >> 8u;
  333|  11.9k|  data[pos++] = jpg.width & 0xFFu;
  334|  11.9k|  data[pos++] = static_cast<uint8_t>(n_comps);
  335|  23.9k|  for (size_t i = 0; i < n_comps; ++i) {
  ------------------
  |  Branch (335:22): [True: 12.0k, False: 11.9k]
  ------------------
  336|  12.0k|    data[pos++] = jpg.components[i].id;
  337|  12.0k|    data[pos++] = ((jpg.components[i].h_samp_factor << 4u) |
  338|  12.0k|                   (jpg.components[i].v_samp_factor));
  339|  12.0k|    const size_t quant_idx = jpg.components[i].quant_idx;
  340|  12.0k|    if (quant_idx >= jpg.quant.size()) return false;
  ------------------
  |  Branch (340:9): [True: 0, False: 12.0k]
  ------------------
  341|  12.0k|    data[pos++] = jpg.quant[quant_idx].index;
  342|  12.0k|  }
  343|  11.9k|  return true;
  344|  11.9k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeDHTERKNS_8JPEGDataEPNS_8internal3dec18SerializationStateE:
  370|  4.64k|bool EncodeDHT(const JPEGData& jpg, SerializationState* state) {
  371|  4.64k|  const std::vector<JPEGHuffmanCode>& huffman_code = jpg.huffman_code;
  372|       |
  373|  4.64k|  size_t marker_len = 2;
  374|  12.1k|  for (size_t i = state->dht_index; i < huffman_code.size(); ++i) {
  ------------------
  |  Branch (374:37): [True: 12.1k, False: 0]
  ------------------
  375|  12.1k|    const JPEGHuffmanCode& huff = huffman_code[i];
  376|  12.1k|    marker_len += kJpegHuffmanMaxBitLength;
  377|   218k|    for (size_t j = 0; j < huff.counts.size(); ++j) {
  ------------------
  |  Branch (377:24): [True: 206k, False: 12.1k]
  ------------------
  378|   206k|      marker_len += huff.counts[j];
  379|   206k|    }
  380|  12.1k|    if (huff.is_last) break;
  ------------------
  |  Branch (380:9): [True: 4.64k, False: 7.51k]
  ------------------
  381|  12.1k|  }
  382|  4.64k|  state->output_queue.emplace_back(marker_len + 2);
  383|  4.64k|  uint8_t* data = state->output_queue.back().buffer->data();
  384|  4.64k|  size_t pos = 0;
  385|  4.64k|  data[pos++] = 0xFFu;
  386|  4.64k|  data[pos++] = 0xC4u;
  387|  4.64k|  data[pos++] = static_cast<uint8_t>(marker_len >> 8u);
  388|  4.64k|  data[pos++] = static_cast<uint8_t>(marker_len);
  389|  12.1k|  while (true) {
  ------------------
  |  Branch (389:10): [True: 12.1k, Folded]
  ------------------
  390|  12.1k|    const size_t huffman_code_index = state->dht_index++;
  391|  12.1k|    if (huffman_code_index >= huffman_code.size()) {
  ------------------
  |  Branch (391:9): [True: 0, False: 12.1k]
  ------------------
  392|      0|      return false;
  393|      0|    }
  394|  12.1k|    const JPEGHuffmanCode& huff = huffman_code[huffman_code_index];
  395|  12.1k|    size_t index = huff.slot_id;
  396|  12.1k|    HuffmanCodeTable* huff_table;
  397|  12.1k|    if (index & 0x10) {
  ------------------
  |  Branch (397:9): [True: 6.98k, False: 5.18k]
  ------------------
  398|  6.98k|      index -= 0x10;
  399|  6.98k|      huff_table = &state->ac_huff_table[index];
  400|  6.98k|    } else {
  401|  5.18k|      huff_table = &state->dc_huff_table[index];
  402|  5.18k|    }
  403|       |    // TODO(eustas): cache
  404|       |    // TODO(eustas): set up non-existing symbols
  405|  12.1k|    if (!BuildHuffmanCodeTable(huff, huff_table)) {
  ------------------
  |  Branch (405:9): [True: 0, False: 12.1k]
  ------------------
  406|      0|      return false;
  407|      0|    }
  408|  12.1k|    size_t total_count = 0;
  409|  12.1k|    size_t max_length = 0;
  410|   218k|    for (size_t i = 0; i < huff.counts.size(); ++i) {
  ------------------
  |  Branch (410:24): [True: 206k, False: 12.1k]
  ------------------
  411|   206k|      if (huff.counts[i] != 0) {
  ------------------
  |  Branch (411:11): [True: 106k, False: 100k]
  ------------------
  412|   106k|        max_length = i;
  413|   106k|      }
  414|   206k|      total_count += huff.counts[i];
  415|   206k|    }
  416|  12.1k|    --total_count;
  417|  12.1k|    data[pos++] = huff.slot_id;
  418|   206k|    for (size_t i = 1; i <= kJpegHuffmanMaxBitLength; ++i) {
  ------------------
  |  Branch (418:24): [True: 194k, False: 12.1k]
  ------------------
  419|   194k|      data[pos++] = (i == max_length ? huff.counts[i] - 1 : huff.counts[i]);
  ------------------
  |  Branch (419:22): [True: 12.1k, False: 182k]
  ------------------
  420|   194k|    }
  421|   926k|    for (size_t i = 0; i < total_count; ++i) {
  ------------------
  |  Branch (421:24): [True: 913k, False: 12.1k]
  ------------------
  422|   913k|      data[pos++] = huff.values[i];
  423|   913k|    }
  424|  12.1k|    if (huff.is_last) break;
  ------------------
  |  Branch (424:9): [True: 4.64k, False: 7.51k]
  ------------------
  425|  12.1k|  }
  426|  4.64k|  return true;
  427|  4.64k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_121BuildHuffmanCodeTableERKNS_15JPEGHuffmanCodeEPNS_16HuffmanCodeTableE:
  266|  12.1k|                           HuffmanCodeTable* table) {
  267|  12.1k|  int huff_code[kJpegHuffmanAlphabetSize];
  268|       |  // +1 for a sentinel element.
  269|  12.1k|  uint32_t huff_size[kJpegHuffmanAlphabetSize + 1];
  270|  12.1k|  int p = 0;
  271|   206k|  for (size_t l = 1; l <= kJpegHuffmanMaxBitLength; ++l) {
  ------------------
  |  Branch (271:22): [True: 194k, False: 12.1k]
  ------------------
  272|   194k|    int i = huff.counts[l];
  273|   194k|    if (p + i > kJpegHuffmanAlphabetSize + 1) {
  ------------------
  |  Branch (273:9): [True: 0, False: 194k]
  ------------------
  274|      0|      return false;
  275|      0|    }
  276|  1.12M|    while (i--) huff_size[p++] = static_cast<uint32_t>(l);
  ------------------
  |  Branch (276:12): [True: 926k, False: 194k]
  ------------------
  277|   194k|  }
  278|       |
  279|  12.1k|  if (p == 0) {
  ------------------
  |  Branch (279:7): [True: 0, False: 12.1k]
  ------------------
  280|      0|    return true;
  281|      0|  }
  282|       |
  283|       |  // Reuse sentinel element.
  284|  12.1k|  int last_p = p - 1;
  285|  12.1k|  huff_size[last_p] = 0;
  286|       |
  287|  12.1k|  int code = 0;
  288|  12.1k|  uint32_t si = huff_size[0];
  289|  12.1k|  p = 0;
  290|   127k|  while (huff_size[p]) {
  ------------------
  |  Branch (290:10): [True: 115k, False: 12.1k]
  ------------------
  291|  1.02M|    while ((huff_size[p]) == si) {
  ------------------
  |  Branch (291:12): [True: 913k, False: 115k]
  ------------------
  292|   913k|      huff_code[p++] = code;
  293|   913k|      code++;
  294|   913k|    }
  295|   115k|    code <<= 1;
  296|   115k|    si++;
  297|   115k|  }
  298|   926k|  for (p = 0; p < last_p; p++) {
  ------------------
  |  Branch (298:15): [True: 913k, False: 12.1k]
  ------------------
  299|   913k|    int i = huff.values[p];
  300|   913k|    table->depth[i] = huff_size[p];
  301|   913k|    table->code[i] = huff_code[p];
  302|   913k|  }
  303|  12.1k|  return true;
  304|  12.1k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_113EncodeRestartEhPNS_8internal3dec18SerializationStateE:
  475|  9.06k|bool EncodeRestart(uint8_t marker, SerializationState* state) {
  476|  9.06k|  state->output_queue.push_back(OutputChunk({0xFF, marker}));
  477|  9.06k|  return true;
  478|  9.06k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeEOIERKNS_8JPEGDataEPNS_8internal3dec18SerializationStateE:
  311|    252|bool EncodeEOI(const JPEGData& jpg, SerializationState* state) {
  312|    252|  state->output_queue.push_back(OutputChunk({0xFF, 0xD9}));
  313|    252|  state->output_queue.emplace_back(jpg.tail_data);
  314|    252|  return true;
  315|    252|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_110EncodeScanERKNS_8JPEGDataERKNS_8internal3dec5StateEPNS5_18SerializationStateE:
  858|  4.95k|           SerializationState* state) {
  859|  4.95k|  const JPEGScanInfo& scan_info = jpg.scan_info[state->scan_index];
  860|  4.95k|  const bool is_progressive = state->is_progressive;
  861|  4.95k|  const int Al = is_progressive ? scan_info.Al : 0;
  ------------------
  |  Branch (861:18): [True: 4.25k, False: 699]
  ------------------
  862|  4.95k|  const int Ah = is_progressive ? scan_info.Ah : 0;
  ------------------
  |  Branch (862:18): [True: 4.25k, False: 699]
  ------------------
  863|  4.95k|  const int Ss = is_progressive ? scan_info.Ss : 0;
  ------------------
  |  Branch (863:18): [True: 4.25k, False: 699]
  ------------------
  864|  4.95k|  const int Se = is_progressive ? scan_info.Se : 63;
  ------------------
  |  Branch (864:18): [True: 4.25k, False: 699]
  ------------------
  865|  4.95k|  const bool need_sequential =
  866|  4.95k|      !is_progressive || (Ah == 0 && Al == 0 && Ss == 0 && Se == 63);
  ------------------
  |  Branch (866:7): [True: 699, False: 4.25k]
  |  Branch (866:27): [True: 1.54k, False: 2.71k]
  |  Branch (866:38): [True: 781, False: 763]
  |  Branch (866:49): [True: 344, False: 437]
  |  Branch (866:60): [True: 17, False: 327]
  ------------------
  867|  4.95k|  if (need_sequential) {
  ------------------
  |  Branch (867:7): [True: 716, False: 4.23k]
  ------------------
  868|    716|    return DoEncodeScan<0>(jpg, parsing_state, state);
  869|  4.23k|  } else if (Ah == 0) {
  ------------------
  |  Branch (869:14): [True: 1.52k, False: 2.71k]
  ------------------
  870|  1.52k|    return DoEncodeScan<1>(jpg, parsing_state, state);
  871|  2.71k|  } else {
  872|  2.71k|    return DoEncodeScan<2>(jpg, parsing_state, state);
  873|  2.71k|  }
  874|  4.95k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_112DoEncodeScanILi0EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateE:
  700|    716|                                                  SerializationState* state) {
  701|    716|  const JPEGScanInfo& scan_info = jpg.scan_info[state->scan_index];
  702|    716|  EncodeScanState& ss = state->scan_state;
  703|       |
  704|    716|  const int restart_interval =
  705|    716|      state->seen_dri_marker ? jpg.restart_interval : 0;
  ------------------
  |  Branch (705:7): [True: 159, False: 557]
  ------------------
  706|       |
  707|    716|  const auto get_next_extra_zero_run_index = [&ss, &scan_info]() -> int {
  708|    716|    if (ss.extra_zero_runs_pos < scan_info.extra_zero_runs.size()) {
  709|    716|      return scan_info.extra_zero_runs[ss.extra_zero_runs_pos].block_idx;
  710|    716|    } else {
  711|    716|      return -1;
  712|    716|    }
  713|    716|  };
  714|       |
  715|    716|  const auto get_next_reset_point = [&ss, &scan_info]() -> int {
  716|    716|    if (ss.next_reset_point_pos < scan_info.reset_points.size()) {
  717|    716|      return scan_info.reset_points[ss.next_reset_point_pos++];
  718|    716|    } else {
  719|    716|      return -1;
  720|    716|    }
  721|    716|  };
  722|       |
  723|    716|  if (ss.stage == EncodeScanState::HEAD) {
  ------------------
  |  Branch (723:7): [True: 716, False: 0]
  ------------------
  724|    716|    if (!EncodeSOS(jpg, scan_info, state)) return SerializationStatus::ERROR;
  ------------------
  |  Branch (724:9): [True: 22, False: 694]
  ------------------
  725|    694|    BitWriterInit(&ss.bw, &state->output_queue);
  726|    694|    DCTCodingStateInit(&ss.coding_state);
  727|    694|    ss.restarts_to_go = restart_interval;
  728|    694|    ss.next_restart_marker = 0;
  729|    694|    ss.block_scan_index = 0;
  730|    694|    ss.extra_zero_runs_pos = 0;
  731|    694|    ss.next_extra_zero_run_index = get_next_extra_zero_run_index();
  732|    694|    ss.next_reset_point_pos = 0;
  733|    694|    ss.next_reset_point = get_next_reset_point();
  734|    694|    ss.mcu_y = 0;
  735|    694|    memset(ss.last_dc_coeff, 0, sizeof(ss.last_dc_coeff));
  736|    694|    ss.stage = EncodeScanState::BODY;
  737|    694|  }
  738|    694|  BitWriter* bw = &ss.bw;
  739|    694|  DCTCodingState* coding_state = &ss.coding_state;
  740|       |
  741|    694|  BRUNSLI_DCHECK(ss.stage == EncodeScanState::BODY);
  742|       |
  743|       |  // "Non-interleaved" means color data comes in separate scans, in other words
  744|       |  // each scan can contain only one color component.
  745|    694|  const bool is_interleaved = (scan_info.num_components > 1);
  746|    694|  const JPEGComponent& base_component =
  747|    694|      jpg.components[scan_info.components[0].comp_idx];
  748|       |  // h_group / v_group act as numerators for converting number of blocks to
  749|       |  // number of MCU. In interleaved mode it is 1, so MCU is represented with
  750|       |  // max_*_samp_factor blocks. In non-interleaved mode we choose numerator to
  751|       |  // be the samping factor, consequently MCU is always represented with single
  752|       |  // block.
  753|    694|  const int h_group = is_interleaved ? 1 : base_component.h_samp_factor;
  ------------------
  |  Branch (753:23): [True: 407, False: 287]
  ------------------
  754|    694|  const int v_group = is_interleaved ? 1 : base_component.v_samp_factor;
  ------------------
  |  Branch (754:23): [True: 407, False: 287]
  ------------------
  755|    694|  const int MCUs_per_row =
  756|    694|      DivCeil(jpg.width * h_group, 8 * jpg.max_h_samp_factor);
  757|    694|  const int MCU_rows = DivCeil(jpg.height * v_group, 8 * jpg.max_v_samp_factor);
  758|    694|  const bool is_progressive = state->is_progressive;
  759|    694|  const int Al = is_progressive ? scan_info.Al : 0;
  ------------------
  |  Branch (759:18): [True: 17, False: 677]
  ------------------
  760|    694|  const int Ss = is_progressive ? scan_info.Ss : 0;
  ------------------
  |  Branch (760:18): [True: 17, False: 677]
  ------------------
  761|    694|  const int Se = is_progressive ? scan_info.Se : 63;
  ------------------
  |  Branch (761:18): [True: 17, False: 677]
  ------------------
  762|       |
  763|       |  // DC-only is defined by [0..0] spectral range.
  764|    694|  const bool want_ac = ((Ss != 0) || (Se != 0));
  ------------------
  |  Branch (764:25): [True: 0, False: 694]
  |  Branch (764:38): [True: 694, False: 0]
  ------------------
  765|    694|  const bool complete_ac = (parsing_state.stage == Stage::DONE);
  766|    694|  const bool has_ac =
  767|    694|      complete_ac || HasSection(&parsing_state, kBrunsliACDataTag);
  ------------------
  |  Branch (767:7): [True: 694, False: 0]
  |  Branch (767:22): [True: 0, False: 0]
  ------------------
  768|    694|  if (want_ac && !has_ac) return SerializationStatus::NEEDS_MORE_INPUT;
  ------------------
  |  Branch (768:7): [True: 694, False: 0]
  |  Branch (768:18): [True: 0, False: 694]
  ------------------
  769|       |
  770|       |  // |has_ac| implies |complete_dc| but not vice versa; for the sake of
  771|       |  // simplicity we pretend they are equal, because they are separated by just a
  772|       |  // few bytes of input.
  773|    694|  const bool complete_dc = has_ac;
  774|    694|  const bool complete = want_ac ? complete_ac : complete_dc;
  ------------------
  |  Branch (774:25): [True: 694, False: 0]
  ------------------
  775|       |  // When "incomplete" |ac_dc| tracks information about current ("incomplete")
  776|       |  // band parsing progress.
  777|    694|  const int last_mcu_y =
  778|    694|      complete ? MCU_rows : parsing_state.internal->ac_dc.next_mcu_y * v_group;
  ------------------
  |  Branch (778:7): [True: 694, False: 0]
  ------------------
  779|       |
  780|  75.5k|  for (; ss.mcu_y < last_mcu_y; ++ss.mcu_y) {
  ------------------
  |  Branch (780:10): [True: 74.8k, False: 690]
  ------------------
  781|   598k|    for (int mcu_x = 0; mcu_x < MCUs_per_row; ++mcu_x) {
  ------------------
  |  Branch (781:25): [True: 523k, False: 74.8k]
  ------------------
  782|       |      // Possibly emit a restart marker.
  783|   523k|      if (restart_interval > 0 && ss.restarts_to_go == 0) {
  ------------------
  |  Branch (783:11): [True: 487k, False: 36.1k]
  |  Branch (783:35): [True: 186k, False: 300k]
  ------------------
  784|   186k|        Flush(coding_state, bw);
  785|   186k|        if (!JumpToByteBoundary(bw, &state->pad_bits, state->pad_bits_end)) {
  ------------------
  |  Branch (785:13): [True: 4, False: 186k]
  ------------------
  786|      4|          return SerializationStatus::ERROR;
  787|      4|        }
  788|   186k|        EmitMarker(bw, 0xD0 + ss.next_restart_marker);
  789|   186k|        ss.next_restart_marker += 1;
  790|   186k|        ss.next_restart_marker &= 0x7;
  791|   186k|        ss.restarts_to_go = restart_interval;
  792|   186k|        memset(ss.last_dc_coeff, 0, sizeof(ss.last_dc_coeff));
  793|   186k|      }
  794|       |      // Encode one MCU
  795|  1.60M|      for (size_t i = 0; i < scan_info.num_components; ++i) {
  ------------------
  |  Branch (795:26): [True: 1.08M, False: 523k]
  ------------------
  796|  1.08M|        const JPEGComponentScanInfo& si = scan_info.components[i];
  797|  1.08M|        const JPEGComponent& c = jpg.components[si.comp_idx];
  798|  1.08M|        const HuffmanCodeTable& dc_huff = state->dc_huff_table[si.dc_tbl_idx];
  799|  1.08M|        const HuffmanCodeTable& ac_huff = state->ac_huff_table[si.ac_tbl_idx];
  800|  1.08M|        int n_blocks_y = is_interleaved ? c.v_samp_factor : 1;
  ------------------
  |  Branch (800:26): [True: 745k, False: 334k]
  ------------------
  801|  1.08M|        int n_blocks_x = is_interleaved ? c.h_samp_factor : 1;
  ------------------
  |  Branch (801:26): [True: 745k, False: 334k]
  ------------------
  802|  3.34M|        for (int iy = 0; iy < n_blocks_y; ++iy) {
  ------------------
  |  Branch (802:26): [True: 2.26M, False: 1.08M]
  ------------------
  803|  6.85M|          for (int ix = 0; ix < n_blocks_x; ++ix) {
  ------------------
  |  Branch (803:28): [True: 4.58M, False: 2.26M]
  ------------------
  804|  4.58M|            int block_y = ss.mcu_y * n_blocks_y + iy;
  805|  4.58M|            int block_x = mcu_x * n_blocks_x + ix;
  806|  4.58M|            int block_idx = block_y * c.width_in_blocks + block_x;
  807|  4.58M|            if (ss.block_scan_index == ss.next_reset_point) {
  ------------------
  |  Branch (807:17): [True: 646, False: 4.58M]
  ------------------
  808|    646|              Flush(coding_state, bw);
  809|    646|              ss.next_reset_point = get_next_reset_point();
  810|    646|            }
  811|  4.58M|            int num_zero_runs = 0;
  812|  4.58M|            if (ss.block_scan_index == ss.next_extra_zero_run_index) {
  ------------------
  |  Branch (812:17): [True: 1.25k, False: 4.58M]
  ------------------
  813|  1.25k|              num_zero_runs = scan_info.extra_zero_runs[ss.extra_zero_runs_pos]
  814|  1.25k|                                  .num_extra_zero_runs;
  815|  1.25k|              ++ss.extra_zero_runs_pos;
  816|  1.25k|              ss.next_extra_zero_run_index = get_next_extra_zero_run_index();
  817|  1.25k|            }
  818|  4.58M|            const coeff_t* coeffs = &c.coeffs[block_idx << 6];
  819|  4.58M|            bool ok;
  820|  4.58M|            if (kMode == 0) {
  ------------------
  |  Branch (820:17): [True: 4.58M, Folded]
  ------------------
  821|  4.58M|              ok = EncodeDCTBlockSequential(coeffs, dc_huff, ac_huff,
  822|  4.58M|                                            num_zero_runs,
  823|  4.58M|                                            ss.last_dc_coeff + si.comp_idx, bw);
  824|  4.58M|            } else if (kMode == 1) {
  ------------------
  |  Branch (824:24): [Folded, False: 0]
  ------------------
  825|      0|              ok = EncodeDCTBlockProgressive(
  826|      0|                  coeffs, dc_huff, ac_huff, Ss, Se, Al, num_zero_runs,
  827|      0|                  coding_state, ss.last_dc_coeff + si.comp_idx, bw);
  828|      0|            } else {
  829|      0|              ok = EncodeRefinementBits(coeffs, ac_huff, Ss, Se, Al,
  830|      0|                                        coding_state, bw);
  831|      0|            }
  832|  4.58M|            if (!ok) return SerializationStatus::ERROR;
  ------------------
  |  Branch (832:17): [True: 0, False: 4.58M]
  ------------------
  833|  4.58M|            ++ss.block_scan_index;
  834|  4.58M|          }
  835|  2.26M|        }
  836|  1.08M|      }
  837|   523k|      --ss.restarts_to_go;
  838|   523k|    }
  839|  74.8k|  }
  840|    690|  if (ss.mcu_y < MCU_rows) {
  ------------------
  |  Branch (840:7): [True: 0, False: 690]
  ------------------
  841|      0|    if (!bw->healthy) return SerializationStatus::ERROR;
  ------------------
  |  Branch (841:9): [True: 0, False: 0]
  ------------------
  842|      0|    return SerializationStatus::NEEDS_MORE_INPUT;
  843|      0|  }
  844|    690|  Flush(coding_state, bw);
  845|    690|  if (!JumpToByteBoundary(bw, &state->pad_bits, state->pad_bits_end)) {
  ------------------
  |  Branch (845:7): [True: 7, False: 683]
  ------------------
  846|      7|    return SerializationStatus::ERROR;
  847|      7|  }
  848|    683|  BitWriterFinish(bw);
  849|    683|  ss.stage = EncodeScanState::HEAD;
  850|    683|  state->scan_index++;
  851|    683|  if (!bw->healthy) return SerializationStatus::ERROR;
  ------------------
  |  Branch (851:7): [True: 530, False: 153]
  ------------------
  852|       |
  853|    153|  return SerializationStatus::DONE;
  854|    683|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeSOSERKNS_8JPEGDataERKNS_12JPEGScanInfoEPNS_8internal3dec18SerializationStateE:
  347|  4.95k|               SerializationState* state) {
  348|  4.95k|  const size_t n_scans = scan_info.num_components;
  349|  4.95k|  const size_t marker_len = 6 + 2 * n_scans;
  350|  4.95k|  state->output_queue.emplace_back(marker_len + 2);
  351|  4.95k|  uint8_t* data = state->output_queue.back().buffer->data();
  352|  4.95k|  size_t pos = 0;
  353|  4.95k|  data[pos++] = 0xFFu;
  354|  4.95k|  data[pos++] = 0xDAu;
  355|  4.95k|  data[pos++] = static_cast<uint8_t>(marker_len >> 8u);
  356|  4.95k|  data[pos++] = static_cast<uint8_t>(marker_len);
  357|  4.95k|  data[pos++] = static_cast<uint8_t>(n_scans);
  358|  17.9k|  for (size_t i = 0; i < n_scans; ++i) {
  ------------------
  |  Branch (358:22): [True: 13.1k, False: 4.84k]
  ------------------
  359|  13.1k|    const JPEGComponentScanInfo& si = scan_info.components[i];
  360|  13.1k|    if (si.comp_idx >= jpg.components.size()) return false;
  ------------------
  |  Branch (360:9): [True: 110, False: 13.0k]
  ------------------
  361|  13.0k|    data[pos++] = jpg.components[si.comp_idx].id;
  362|  13.0k|    data[pos++] = (si.dc_tbl_idx << 4u) + si.ac_tbl_idx;
  363|  13.0k|  }
  364|  4.84k|  data[pos++] = scan_info.Ss;
  365|  4.84k|  data[pos++] = scan_info.Se;
  366|  4.84k|  data[pos++] = ((scan_info.Ah << 4u) | (scan_info.Al));
  367|  4.84k|  return true;
  368|  4.95k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_113BitWriterInitEPNS_8internal3dec9BitWriterEPNSt3__15dequeINS2_11OutputChunkENS5_9allocatorIS7_EEEE:
   52|  4.84k|void BitWriterInit(BitWriter* bw, std::deque<OutputChunk>* output_queue) {
   53|  4.84k|  bw->output = output_queue;
   54|  4.84k|  bw->chunk = OutputChunk(kBitWriterChunkSize);
   55|  4.84k|  bw->pos = 0;
   56|  4.84k|  bw->put_buffer = 0;
   57|  4.84k|  bw->put_bits = 64;
   58|  4.84k|  bw->healthy = true;
   59|  4.84k|  bw->data = bw->chunk.buffer->data();
   60|  4.84k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_118DCTCodingStateInitEPNS_8internal3dec14DCTCodingStateE:
  185|  4.84k|void DCTCodingStateInit(DCTCodingState* s) {
  186|  4.84k|  s->eob_run_ = 0;
  187|  4.84k|  s->cur_ac_huff_ = nullptr;
  188|  4.84k|  s->refinement_bits_.clear();
  189|  4.84k|  s->refinement_bits_.reserve(64);  // 1024 bits most often is more than enough.
  190|  4.84k|  s->refinement_bits_count_ = 0;
  191|  4.84k|}
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_112DoEncodeScanILi0EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateEENKUlvE_clEv:
  707|  1.94k|  const auto get_next_extra_zero_run_index = [&ss, &scan_info]() -> int {
  708|  1.94k|    if (ss.extra_zero_runs_pos < scan_info.extra_zero_runs.size()) {
  ------------------
  |  Branch (708:9): [True: 1.25k, False: 692]
  ------------------
  709|  1.25k|      return scan_info.extra_zero_runs[ss.extra_zero_runs_pos].block_idx;
  710|  1.25k|    } else {
  711|    692|      return -1;
  712|    692|    }
  713|  1.94k|  };
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_112DoEncodeScanILi0EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateEENKUlvE0_clEv:
  715|  1.34k|  const auto get_next_reset_point = [&ss, &scan_info]() -> int {
  716|  1.34k|    if (ss.next_reset_point_pos < scan_info.reset_points.size()) {
  ------------------
  |  Branch (716:9): [True: 651, False: 689]
  ------------------
  717|    651|      return scan_info.reset_points[ss.next_reset_point_pos++];
  718|    689|    } else {
  719|    689|      return -1;
  720|    689|    }
  721|  1.34k|  };
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_17DivCeilEii:
   44|  9.69k|static BRUNSLI_INLINE int DivCeil(int a, int b) { return (a + b - 1) / b; }
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_15FlushEPNS_8internal3dec14DCTCodingStateEPNS2_9BitWriterE:
  195|  8.79M|static BRUNSLI_INLINE void Flush(DCTCodingState* s, BitWriter* bw) {
  196|  8.79M|  if (s->eob_run_ > 0) {
  ------------------
  |  Branch (196:7): [True: 8.41M, False: 373k]
  ------------------
  197|  8.41M|    int nbits = Log2FloorNonZero(s->eob_run_);
  198|  8.41M|    int symbol = nbits << 4u;
  199|  8.41M|    WriteBits(bw, s->cur_ac_huff_->depth[symbol],
  200|  8.41M|              s->cur_ac_huff_->code[symbol]);
  201|  8.41M|    if (nbits > 0) {
  ------------------
  |  Branch (201:9): [True: 35.2k, False: 8.38M]
  ------------------
  202|  35.2k|      WriteBits(bw, nbits, s->eob_run_ & ((1 << nbits) - 1));
  203|  35.2k|    }
  204|  8.41M|    s->eob_run_ = 0;
  205|  8.41M|  }
  206|  8.79M|  size_t num_words = s->refinement_bits_count_ >> 4;
  207|  8.82M|  for (size_t i = 0; i < num_words; ++i) {
  ------------------
  |  Branch (207:22): [True: 34.1k, False: 8.79M]
  ------------------
  208|  34.1k|    WriteBits(bw, 16, s->refinement_bits_[i]);
  209|  34.1k|  }
  210|  8.79M|  size_t tail = s->refinement_bits_count_ & 0xF;
  211|  8.79M|  if (tail) {
  ------------------
  |  Branch (211:7): [True: 40.6k, False: 8.75M]
  ------------------
  212|  40.6k|    WriteBits(bw, tail, s->refinement_bits_.back());
  213|  40.6k|  }
  214|  8.79M|  s->refinement_bits_.clear();
  215|  8.79M|  s->refinement_bits_count_ = 0;
  216|  8.79M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19WriteBitsEPNS_8internal3dec9BitWriterEim:
  117|  30.5M|static BRUNSLI_INLINE void WriteBits(BitWriter* bw, int nbits, uint64_t bits) {
  118|       |  // This is an optimization; if everything goes well,
  119|       |  // then |nbits| is positive; if non-existing Huffman symbol is going to be
  120|       |  // encoded, its length should be zero; later encoder could check the
  121|       |  // "health" of BitWriter.
  122|  30.5M|  if (nbits == 0) {
  ------------------
  |  Branch (122:7): [True: 4.09M, False: 26.4M]
  ------------------
  123|  4.09M|    bw->healthy = false;
  124|  4.09M|    return;
  125|  4.09M|  }
  126|  26.4M|  bw->put_bits -= nbits;
  127|  26.4M|  bw->put_buffer |= (bits << bw->put_bits);
  128|  26.4M|  if (bw->put_bits <= 16) DischargeBitBuffer(bw);
  ------------------
  |  Branch (128:7): [True: 2.43M, False: 24.0M]
  ------------------
  129|  26.4M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_118DischargeBitBufferEPNS_8internal3dec9BitWriterE:
   87|  2.43M|static BRUNSLI_INLINE void DischargeBitBuffer(BitWriter* bw) {
   88|       |  // At this point we are ready to emit the most significant 6 bytes of
   89|       |  // put_buffer_ to the output.
   90|       |  // The JPEG format requires that after every 0xff byte in the entropy
   91|       |  // coded section, there is a zero byte, therefore we first check if any of
   92|       |  // the 6 most significant bytes of put_buffer_ is 0xFF.
   93|  2.43M|  Reserve(bw, 12);
   94|  2.43M|  if (HasZeroByte(~bw->put_buffer | 0xFFFF)) {
  ------------------
  |  Branch (94:7): [True: 765k, False: 1.67M]
  ------------------
   95|       |    // We have a 0xFF byte somewhere, examine each byte and append a zero
   96|       |    // byte if necessary.
   97|   765k|    EmitByte(bw, (bw->put_buffer >> 56) & 0xFF);
   98|   765k|    EmitByte(bw, (bw->put_buffer >> 48) & 0xFF);
   99|   765k|    EmitByte(bw, (bw->put_buffer >> 40) & 0xFF);
  100|   765k|    EmitByte(bw, (bw->put_buffer >> 32) & 0xFF);
  101|   765k|    EmitByte(bw, (bw->put_buffer >> 24) & 0xFF);
  102|   765k|    EmitByte(bw, (bw->put_buffer >> 16) & 0xFF);
  103|  1.67M|  } else {
  104|       |    // We don't have any 0xFF bytes, output all 6 bytes without checking.
  105|  1.67M|    bw->data[bw->pos] = (bw->put_buffer >> 56) & 0xFF;
  106|  1.67M|    bw->data[bw->pos + 1] = (bw->put_buffer >> 48) & 0xFF;
  107|  1.67M|    bw->data[bw->pos + 2] = (bw->put_buffer >> 40) & 0xFF;
  108|  1.67M|    bw->data[bw->pos + 3] = (bw->put_buffer >> 32) & 0xFF;
  109|  1.67M|    bw->data[bw->pos + 4] = (bw->put_buffer >> 24) & 0xFF;
  110|  1.67M|    bw->data[bw->pos + 5] = (bw->put_buffer >> 16) & 0xFF;
  111|  1.67M|    bw->pos += 6;
  112|  1.67M|  }
  113|  2.43M|  bw->put_buffer <<= 48;
  114|  2.43M|  bw->put_bits += 48;
  115|  2.43M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_17ReserveEPNS_8internal3dec9BitWriterEm:
   70|  3.05M|static BRUNSLI_INLINE void Reserve(BitWriter* bw, size_t n_bytes) {
   71|  3.05M|  if (BRUNSLI_PREDICT_FALSE((bw->pos + n_bytes) > kBitWriterChunkSize)) {
  ------------------
  |  |   85|  3.05M|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 905, False: 3.05M]
  |  |  ------------------
  ------------------
   72|    905|    SwapBuffer(bw);
   73|    905|  }
   74|  3.05M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_110SwapBufferEPNS_8internal3dec9BitWriterE:
   62|    905|static BRUNSLI_NOINLINE void SwapBuffer(BitWriter* bw) {
   63|    905|  bw->chunk.len = bw->pos;
   64|    905|  bw->output->emplace_back(std::move(bw->chunk));
   65|    905|  bw->chunk = OutputChunk(kBitWriterChunkSize);
   66|    905|  bw->data = bw->chunk.buffer->data();
   67|    905|  bw->pos = 0;
   68|    905|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_111HasZeroByteEm:
   48|  2.43M|static BRUNSLI_INLINE uint64_t HasZeroByte(uint64_t x) {
   49|  2.43M|  return (x - 0x0101010101010101ULL) & ~x & 0x8080808080808080ULL;
   50|  2.43M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_18EmitByteEPNS_8internal3dec9BitWriterEi:
   82|  5.43M|static BRUNSLI_INLINE void EmitByte(BitWriter* bw, int byte) {
   83|  5.43M|  bw->data[bw->pos++] = byte;
   84|  5.43M|  if (byte == 0xFF) bw->data[bw->pos++] = 0;
  ------------------
  |  Branch (84:7): [True: 1.14M, False: 4.28M]
  ------------------
   85|  5.43M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_118JumpToByteBoundaryEPNS_8internal3dec9BitWriterEPPKiS6_:
  139|   312k|                        const int* pad_bits_end) {
  140|   312k|  size_t n_bits = bw->put_bits & 7u;
  141|   312k|  uint8_t pad_pattern;
  142|   312k|  if (*pad_bits == nullptr) {
  ------------------
  |  Branch (142:7): [True: 311k, False: 1.59k]
  ------------------
  143|   311k|    pad_pattern = (1u << n_bits) - 1;
  144|   311k|  } else {
  145|  1.59k|    pad_pattern = 0;
  146|  1.59k|    const int* src = *pad_bits;
  147|       |    // TODO(eustas): bitwise reading looks insanely ineffective...
  148|  4.99k|    while (n_bits--) {
  ------------------
  |  Branch (148:12): [True: 3.45k, False: 1.54k]
  ------------------
  149|  3.45k|      pad_pattern <<= 1;
  150|  3.45k|      if (src >= pad_bits_end) return false;
  ------------------
  |  Branch (150:11): [True: 45, False: 3.40k]
  ------------------
  151|       |      // TODO(eustas): DCHECK *src == {0, 1}
  152|  3.40k|      pad_pattern |= !!*(src++);
  153|  3.40k|    }
  154|  1.54k|    *pad_bits = src;
  155|  1.54k|  }
  156|       |
  157|   312k|  Reserve(bw, 16);
  158|       |
  159|   960k|  while (bw->put_bits <= 56) {
  ------------------
  |  Branch (159:10): [True: 648k, False: 312k]
  ------------------
  160|   648k|    int c = (bw->put_buffer >> 56) & 0xFF;
  161|   648k|    EmitByte(bw, c);
  162|   648k|    bw->put_buffer <<= 8;
  163|   648k|    bw->put_bits += 8;
  164|   648k|  }
  165|   312k|  if (bw->put_bits < 64) {
  ------------------
  |  Branch (165:7): [True: 192k, False: 120k]
  ------------------
  166|   192k|    int pad_mask = 0xFFu >> (64 - bw->put_bits);
  167|   192k|    int c = ((bw->put_buffer >> 56) & ~pad_mask) | pad_pattern;
  168|   192k|    EmitByte(bw, c);
  169|   192k|  }
  170|   312k|  bw->put_buffer = 0;
  171|   312k|  bw->put_bits = 64;
  172|       |
  173|   312k|  return true;
  174|   312k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_110EmitMarkerEPNS_8internal3dec9BitWriterEi:
  131|   307k|void EmitMarker(BitWriter* bw, int marker) {
  132|   307k|  Reserve(bw, 2);
  133|   307k|  BRUNSLI_DCHECK(marker != 0xFF);
  134|   307k|  bw->data[bw->pos++] = 0xFF;
  135|   307k|  bw->data[bw->pos++] = marker;
  136|   307k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_124EncodeDCTBlockSequentialEPKsRKNS_16HuffmanCodeTableES5_iPsPNS_8internal3dec9BitWriterE:
  510|  4.58M|                              BitWriter* bw) {
  511|  4.58M|  coeff_t temp2;
  512|  4.58M|  coeff_t temp;
  513|  4.58M|  temp2 = coeffs[0];
  514|  4.58M|  temp = temp2 - *last_dc_coeff;
  515|  4.58M|  *last_dc_coeff = temp2;
  516|  4.58M|  temp2 = temp;
  517|  4.58M|  if (temp < 0) {
  ------------------
  |  Branch (517:7): [True: 1.04M, False: 3.54M]
  ------------------
  518|  1.04M|    temp = -temp;
  519|  1.04M|    temp2--;
  520|  1.04M|  }
  521|  4.58M|  int dc_nbits = (temp == 0) ? 0 : (Log2FloorNonZero(temp) + 1);
  ------------------
  |  Branch (521:18): [True: 2.66M, False: 1.92M]
  ------------------
  522|  4.58M|  WriteBits(bw, dc_huff.depth[dc_nbits], dc_huff.code[dc_nbits]);
  523|  4.58M|  if (dc_nbits > 0) {
  ------------------
  |  Branch (523:7): [True: 1.92M, False: 2.66M]
  ------------------
  524|  1.92M|    WriteBits(bw, dc_nbits, temp2 & ((1u << dc_nbits) - 1));
  525|  1.92M|  }
  526|  4.58M|  int r = 0;
  527|   293M|  for (int k = 1; k < 64; ++k) {
  ------------------
  |  Branch (527:19): [True: 288M, False: 4.58M]
  ------------------
  528|   288M|    if ((temp = coeffs[kJPEGNaturalOrder[k]]) == 0) {
  ------------------
  |  Branch (528:9): [True: 288M, False: 39.6k]
  ------------------
  529|   288M|      r++;
  530|   288M|      continue;
  531|   288M|    }
  532|  39.6k|    if (temp < 0) {
  ------------------
  |  Branch (532:9): [True: 26.6k, False: 13.0k]
  ------------------
  533|  26.6k|      temp = -temp;
  534|  26.6k|      temp2 = ~temp;
  535|  26.6k|    } else {
  536|  13.0k|      temp2 = temp;
  537|  13.0k|    }
  538|  70.1k|    while (r > 15) {
  ------------------
  |  Branch (538:12): [True: 30.4k, False: 39.6k]
  ------------------
  539|  30.4k|      WriteBits(bw, ac_huff.depth[0xf0], ac_huff.code[0xf0]);
  540|  30.4k|      r -= 16;
  541|  30.4k|    }
  542|  39.6k|    int ac_nbits = Log2FloorNonZero(temp) + 1;
  543|  39.6k|    int symbol = (r << 4u) + ac_nbits;
  544|  39.6k|    WriteBits(bw, ac_huff.depth[symbol], ac_huff.code[symbol]);
  545|  39.6k|    WriteBits(bw, ac_nbits, temp2 & ((1 << ac_nbits) - 1));
  546|  39.6k|    r = 0;
  547|  39.6k|  }
  548|  4.58M|  for (int i = 0; i < num_zero_runs; ++i) {
  ------------------
  |  Branch (548:19): [True: 3.14k, False: 4.58M]
  ------------------
  549|  3.14k|    WriteBits(bw, ac_huff.depth[0xf0], ac_huff.code[0xf0]);
  550|  3.14k|    r -= 16;
  551|  3.14k|  }
  552|  4.58M|  if (r > 0) {
  ------------------
  |  Branch (552:7): [True: 4.58M, False: 1.06k]
  ------------------
  553|  4.58M|    WriteBits(bw, ac_huff.depth[0], ac_huff.code[0]);
  554|  4.58M|  }
  555|  4.58M|  return true;
  556|  4.58M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_115BitWriterFinishEPNS_8internal3dec9BitWriterE:
  176|  4.80k|void BitWriterFinish(BitWriter* bw) {
  177|  4.80k|  if (bw->pos == 0) return;
  ------------------
  |  Branch (177:7): [True: 241, False: 4.55k]
  ------------------
  178|  4.55k|  bw->chunk.len = bw->pos;
  179|  4.55k|  bw->output->emplace_back(std::move(bw->chunk));
  180|  4.55k|  bw->chunk = OutputChunk(nullptr, 0);
  181|  4.55k|  bw->data = nullptr;
  182|  4.55k|  bw->pos = 0;
  183|  4.55k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_112DoEncodeScanILi1EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateE:
  700|  1.52k|                                                  SerializationState* state) {
  701|  1.52k|  const JPEGScanInfo& scan_info = jpg.scan_info[state->scan_index];
  702|  1.52k|  EncodeScanState& ss = state->scan_state;
  703|       |
  704|  1.52k|  const int restart_interval =
  705|  1.52k|      state->seen_dri_marker ? jpg.restart_interval : 0;
  ------------------
  |  Branch (705:7): [True: 353, False: 1.17k]
  ------------------
  706|       |
  707|  1.52k|  const auto get_next_extra_zero_run_index = [&ss, &scan_info]() -> int {
  708|  1.52k|    if (ss.extra_zero_runs_pos < scan_info.extra_zero_runs.size()) {
  709|  1.52k|      return scan_info.extra_zero_runs[ss.extra_zero_runs_pos].block_idx;
  710|  1.52k|    } else {
  711|  1.52k|      return -1;
  712|  1.52k|    }
  713|  1.52k|  };
  714|       |
  715|  1.52k|  const auto get_next_reset_point = [&ss, &scan_info]() -> int {
  716|  1.52k|    if (ss.next_reset_point_pos < scan_info.reset_points.size()) {
  717|  1.52k|      return scan_info.reset_points[ss.next_reset_point_pos++];
  718|  1.52k|    } else {
  719|  1.52k|      return -1;
  720|  1.52k|    }
  721|  1.52k|  };
  722|       |
  723|  1.52k|  if (ss.stage == EncodeScanState::HEAD) {
  ------------------
  |  Branch (723:7): [True: 1.52k, False: 0]
  ------------------
  724|  1.52k|    if (!EncodeSOS(jpg, scan_info, state)) return SerializationStatus::ERROR;
  ------------------
  |  Branch (724:9): [True: 23, False: 1.50k]
  ------------------
  725|  1.50k|    BitWriterInit(&ss.bw, &state->output_queue);
  726|  1.50k|    DCTCodingStateInit(&ss.coding_state);
  727|  1.50k|    ss.restarts_to_go = restart_interval;
  728|  1.50k|    ss.next_restart_marker = 0;
  729|  1.50k|    ss.block_scan_index = 0;
  730|  1.50k|    ss.extra_zero_runs_pos = 0;
  731|  1.50k|    ss.next_extra_zero_run_index = get_next_extra_zero_run_index();
  732|  1.50k|    ss.next_reset_point_pos = 0;
  733|  1.50k|    ss.next_reset_point = get_next_reset_point();
  734|  1.50k|    ss.mcu_y = 0;
  735|  1.50k|    memset(ss.last_dc_coeff, 0, sizeof(ss.last_dc_coeff));
  736|  1.50k|    ss.stage = EncodeScanState::BODY;
  737|  1.50k|  }
  738|  1.50k|  BitWriter* bw = &ss.bw;
  739|  1.50k|  DCTCodingState* coding_state = &ss.coding_state;
  740|       |
  741|  1.50k|  BRUNSLI_DCHECK(ss.stage == EncodeScanState::BODY);
  742|       |
  743|       |  // "Non-interleaved" means color data comes in separate scans, in other words
  744|       |  // each scan can contain only one color component.
  745|  1.50k|  const bool is_interleaved = (scan_info.num_components > 1);
  746|  1.50k|  const JPEGComponent& base_component =
  747|  1.50k|      jpg.components[scan_info.components[0].comp_idx];
  748|       |  // h_group / v_group act as numerators for converting number of blocks to
  749|       |  // number of MCU. In interleaved mode it is 1, so MCU is represented with
  750|       |  // max_*_samp_factor blocks. In non-interleaved mode we choose numerator to
  751|       |  // be the samping factor, consequently MCU is always represented with single
  752|       |  // block.
  753|  1.50k|  const int h_group = is_interleaved ? 1 : base_component.h_samp_factor;
  ------------------
  |  Branch (753:23): [True: 902, False: 602]
  ------------------
  754|  1.50k|  const int v_group = is_interleaved ? 1 : base_component.v_samp_factor;
  ------------------
  |  Branch (754:23): [True: 902, False: 602]
  ------------------
  755|  1.50k|  const int MCUs_per_row =
  756|  1.50k|      DivCeil(jpg.width * h_group, 8 * jpg.max_h_samp_factor);
  757|  1.50k|  const int MCU_rows = DivCeil(jpg.height * v_group, 8 * jpg.max_v_samp_factor);
  758|  1.50k|  const bool is_progressive = state->is_progressive;
  759|  1.50k|  const int Al = is_progressive ? scan_info.Al : 0;
  ------------------
  |  Branch (759:18): [True: 1.50k, False: 0]
  ------------------
  760|  1.50k|  const int Ss = is_progressive ? scan_info.Ss : 0;
  ------------------
  |  Branch (760:18): [True: 1.50k, False: 0]
  ------------------
  761|  1.50k|  const int Se = is_progressive ? scan_info.Se : 63;
  ------------------
  |  Branch (761:18): [True: 1.50k, False: 0]
  ------------------
  762|       |
  763|       |  // DC-only is defined by [0..0] spectral range.
  764|  1.50k|  const bool want_ac = ((Ss != 0) || (Se != 0));
  ------------------
  |  Branch (764:25): [True: 1.03k, False: 468]
  |  Branch (764:38): [True: 383, False: 85]
  ------------------
  765|  1.50k|  const bool complete_ac = (parsing_state.stage == Stage::DONE);
  766|  1.50k|  const bool has_ac =
  767|  1.50k|      complete_ac || HasSection(&parsing_state, kBrunsliACDataTag);
  ------------------
  |  Branch (767:7): [True: 1.50k, False: 0]
  |  Branch (767:22): [True: 0, False: 0]
  ------------------
  768|  1.50k|  if (want_ac && !has_ac) return SerializationStatus::NEEDS_MORE_INPUT;
  ------------------
  |  Branch (768:7): [True: 1.41k, False: 85]
  |  Branch (768:18): [True: 0, False: 1.41k]
  ------------------
  769|       |
  770|       |  // |has_ac| implies |complete_dc| but not vice versa; for the sake of
  771|       |  // simplicity we pretend they are equal, because they are separated by just a
  772|       |  // few bytes of input.
  773|  1.50k|  const bool complete_dc = has_ac;
  774|  1.50k|  const bool complete = want_ac ? complete_ac : complete_dc;
  ------------------
  |  Branch (774:25): [True: 1.41k, False: 85]
  ------------------
  775|       |  // When "incomplete" |ac_dc| tracks information about current ("incomplete")
  776|       |  // band parsing progress.
  777|  1.50k|  const int last_mcu_y =
  778|  1.50k|      complete ? MCU_rows : parsing_state.internal->ac_dc.next_mcu_y * v_group;
  ------------------
  |  Branch (778:7): [True: 1.50k, False: 0]
  ------------------
  779|       |
  780|  71.0k|  for (; ss.mcu_y < last_mcu_y; ++ss.mcu_y) {
  ------------------
  |  Branch (780:10): [True: 69.5k, False: 1.49k]
  ------------------
  781|   564k|    for (int mcu_x = 0; mcu_x < MCUs_per_row; ++mcu_x) {
  ------------------
  |  Branch (781:25): [True: 494k, False: 69.5k]
  ------------------
  782|       |      // Possibly emit a restart marker.
  783|   494k|      if (restart_interval > 0 && ss.restarts_to_go == 0) {
  ------------------
  |  Branch (783:11): [True: 370k, False: 124k]
  |  Branch (783:35): [True: 54.4k, False: 316k]
  ------------------
  784|  54.4k|        Flush(coding_state, bw);
  785|  54.4k|        if (!JumpToByteBoundary(bw, &state->pad_bits, state->pad_bits_end)) {
  ------------------
  |  Branch (785:13): [True: 7, False: 54.4k]
  ------------------
  786|      7|          return SerializationStatus::ERROR;
  787|      7|        }
  788|  54.4k|        EmitMarker(bw, 0xD0 + ss.next_restart_marker);
  789|  54.4k|        ss.next_restart_marker += 1;
  790|  54.4k|        ss.next_restart_marker &= 0x7;
  791|  54.4k|        ss.restarts_to_go = restart_interval;
  792|  54.4k|        memset(ss.last_dc_coeff, 0, sizeof(ss.last_dc_coeff));
  793|  54.4k|      }
  794|       |      // Encode one MCU
  795|  1.64M|      for (size_t i = 0; i < scan_info.num_components; ++i) {
  ------------------
  |  Branch (795:26): [True: 1.15M, False: 494k]
  ------------------
  796|  1.15M|        const JPEGComponentScanInfo& si = scan_info.components[i];
  797|  1.15M|        const JPEGComponent& c = jpg.components[si.comp_idx];
  798|  1.15M|        const HuffmanCodeTable& dc_huff = state->dc_huff_table[si.dc_tbl_idx];
  799|  1.15M|        const HuffmanCodeTable& ac_huff = state->ac_huff_table[si.ac_tbl_idx];
  800|  1.15M|        int n_blocks_y = is_interleaved ? c.v_samp_factor : 1;
  ------------------
  |  Branch (800:26): [True: 876k, False: 273k]
  ------------------
  801|  1.15M|        int n_blocks_x = is_interleaved ? c.h_samp_factor : 1;
  ------------------
  |  Branch (801:26): [True: 876k, False: 273k]
  ------------------
  802|  5.28M|        for (int iy = 0; iy < n_blocks_y; ++iy) {
  ------------------
  |  Branch (802:26): [True: 4.13M, False: 1.15M]
  ------------------
  803|  15.7M|          for (int ix = 0; ix < n_blocks_x; ++ix) {
  ------------------
  |  Branch (803:28): [True: 11.5M, False: 4.13M]
  ------------------
  804|  11.5M|            int block_y = ss.mcu_y * n_blocks_y + iy;
  805|  11.5M|            int block_x = mcu_x * n_blocks_x + ix;
  806|  11.5M|            int block_idx = block_y * c.width_in_blocks + block_x;
  807|  11.5M|            if (ss.block_scan_index == ss.next_reset_point) {
  ------------------
  |  Branch (807:17): [True: 5.34k, False: 11.5M]
  ------------------
  808|  5.34k|              Flush(coding_state, bw);
  809|  5.34k|              ss.next_reset_point = get_next_reset_point();
  810|  5.34k|            }
  811|  11.5M|            int num_zero_runs = 0;
  812|  11.5M|            if (ss.block_scan_index == ss.next_extra_zero_run_index) {
  ------------------
  |  Branch (812:17): [True: 4.70k, False: 11.5M]
  ------------------
  813|  4.70k|              num_zero_runs = scan_info.extra_zero_runs[ss.extra_zero_runs_pos]
  814|  4.70k|                                  .num_extra_zero_runs;
  815|  4.70k|              ++ss.extra_zero_runs_pos;
  816|  4.70k|              ss.next_extra_zero_run_index = get_next_extra_zero_run_index();
  817|  4.70k|            }
  818|  11.5M|            const coeff_t* coeffs = &c.coeffs[block_idx << 6];
  819|  11.5M|            bool ok;
  820|  11.5M|            if (kMode == 0) {
  ------------------
  |  Branch (820:17): [Folded, False: 11.5M]
  ------------------
  821|      0|              ok = EncodeDCTBlockSequential(coeffs, dc_huff, ac_huff,
  822|      0|                                            num_zero_runs,
  823|      0|                                            ss.last_dc_coeff + si.comp_idx, bw);
  824|  11.5M|            } else if (kMode == 1) {
  ------------------
  |  Branch (824:24): [True: 11.5M, Folded]
  ------------------
  825|  11.5M|              ok = EncodeDCTBlockProgressive(
  826|  11.5M|                  coeffs, dc_huff, ac_huff, Ss, Se, Al, num_zero_runs,
  827|  11.5M|                  coding_state, ss.last_dc_coeff + si.comp_idx, bw);
  828|  11.5M|            } else {
  829|      0|              ok = EncodeRefinementBits(coeffs, ac_huff, Ss, Se, Al,
  830|      0|                                        coding_state, bw);
  831|      0|            }
  832|  11.5M|            if (!ok) return SerializationStatus::ERROR;
  ------------------
  |  Branch (832:17): [True: 0, False: 11.5M]
  ------------------
  833|  11.5M|            ++ss.block_scan_index;
  834|  11.5M|          }
  835|  4.13M|        }
  836|  1.15M|      }
  837|   494k|      --ss.restarts_to_go;
  838|   494k|    }
  839|  69.5k|  }
  840|  1.49k|  if (ss.mcu_y < MCU_rows) {
  ------------------
  |  Branch (840:7): [True: 0, False: 1.49k]
  ------------------
  841|      0|    if (!bw->healthy) return SerializationStatus::ERROR;
  ------------------
  |  Branch (841:9): [True: 0, False: 0]
  ------------------
  842|      0|    return SerializationStatus::NEEDS_MORE_INPUT;
  843|      0|  }
  844|  1.49k|  Flush(coding_state, bw);
  845|  1.49k|  if (!JumpToByteBoundary(bw, &state->pad_bits, state->pad_bits_end)) {
  ------------------
  |  Branch (845:7): [True: 8, False: 1.48k]
  ------------------
  846|      8|    return SerializationStatus::ERROR;
  847|      8|  }
  848|  1.48k|  BitWriterFinish(bw);
  849|  1.48k|  ss.stage = EncodeScanState::HEAD;
  850|  1.48k|  state->scan_index++;
  851|  1.48k|  if (!bw->healthy) return SerializationStatus::ERROR;
  ------------------
  |  Branch (851:7): [True: 1.10k, False: 385]
  ------------------
  852|       |
  853|    385|  return SerializationStatus::DONE;
  854|  1.48k|}
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_112DoEncodeScanILi1EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateEENKUlvE_clEv:
  707|  6.20k|  const auto get_next_extra_zero_run_index = [&ss, &scan_info]() -> int {
  708|  6.20k|    if (ss.extra_zero_runs_pos < scan_info.extra_zero_runs.size()) {
  ------------------
  |  Branch (708:9): [True: 4.71k, False: 1.49k]
  ------------------
  709|  4.71k|      return scan_info.extra_zero_runs[ss.extra_zero_runs_pos].block_idx;
  710|  4.71k|    } else {
  711|  1.49k|      return -1;
  712|  1.49k|    }
  713|  6.20k|  };
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_112DoEncodeScanILi1EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateEENKUlvE0_clEv:
  715|  6.84k|  const auto get_next_reset_point = [&ss, &scan_info]() -> int {
  716|  6.84k|    if (ss.next_reset_point_pos < scan_info.reset_points.size()) {
  ------------------
  |  Branch (716:9): [True: 5.38k, False: 1.46k]
  ------------------
  717|  5.38k|      return scan_info.reset_points[ss.next_reset_point_pos++];
  718|  5.38k|    } else {
  719|  1.46k|      return -1;
  720|  1.46k|    }
  721|  6.84k|  };
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_125EncodeDCTBlockProgressiveEPKsRKNS_16HuffmanCodeTableES5_iiiiPNS_8internal3dec14DCTCodingStateEPsPNS7_9BitWriterE:
  563|  11.5M|                               coeff_t* last_dc_coeff, BitWriter* bw) {
  564|  11.5M|  bool eob_run_allowed = Ss > 0;
  565|  11.5M|  coeff_t temp2;
  566|  11.5M|  coeff_t temp;
  567|  11.5M|  if (Ss == 0) {
  ------------------
  |  Branch (567:7): [True: 3.98M, False: 7.60M]
  ------------------
  568|  3.98M|    temp2 = coeffs[0] >> Al;
  569|  3.98M|    temp = temp2 - *last_dc_coeff;
  570|  3.98M|    *last_dc_coeff = temp2;
  571|  3.98M|    temp2 = temp;
  572|  3.98M|    if (temp < 0) {
  ------------------
  |  Branch (572:9): [True: 1.09M, False: 2.89M]
  ------------------
  573|  1.09M|      temp = -temp;
  574|  1.09M|      temp2--;
  575|  1.09M|    }
  576|  3.98M|    int nbits = (temp == 0) ? 0 : (Log2FloorNonZero(temp) + 1);
  ------------------
  |  Branch (576:17): [True: 1.97M, False: 2.01M]
  ------------------
  577|  3.98M|    WriteBits(bw, dc_huff.depth[nbits], dc_huff.code[nbits]);
  578|  3.98M|    if (nbits > 0) {
  ------------------
  |  Branch (578:9): [True: 2.01M, False: 1.97M]
  ------------------
  579|  2.01M|      WriteBits(bw, nbits, temp2 & ((1 << nbits) - 1));
  580|  2.01M|    }
  581|  3.98M|    ++Ss;
  582|  3.98M|  }
  583|  11.5M|  if (Ss > Se) {
  ------------------
  |  Branch (583:7): [True: 339k, False: 11.2M]
  ------------------
  584|   339k|    return true;
  585|   339k|  }
  586|  11.2M|  int r = 0;
  587|   297M|  for (int k = Ss; k <= Se; ++k) {
  ------------------
  |  Branch (587:20): [True: 286M, False: 11.2M]
  ------------------
  588|   286M|    if ((temp = coeffs[kJPEGNaturalOrder[k]]) == 0) {
  ------------------
  |  Branch (588:9): [True: 286M, False: 45.3k]
  ------------------
  589|   286M|      r++;
  590|   286M|      continue;
  591|   286M|    }
  592|  45.3k|    if (temp < 0) {
  ------------------
  |  Branch (592:9): [True: 32.5k, False: 12.7k]
  ------------------
  593|  32.5k|      temp = -temp;
  594|  32.5k|      temp >>= Al;
  595|  32.5k|      temp2 = ~temp;
  596|  32.5k|    } else {
  597|  12.7k|      temp >>= Al;
  598|  12.7k|      temp2 = temp;
  599|  12.7k|    }
  600|  45.3k|    if (temp == 0) {
  ------------------
  |  Branch (600:9): [True: 924, False: 44.3k]
  ------------------
  601|    924|      r++;
  602|    924|      continue;
  603|    924|    }
  604|  44.3k|    Flush(coding_state, bw);
  605|  73.6k|    while (r > 15) {
  ------------------
  |  Branch (605:12): [True: 29.2k, False: 44.3k]
  ------------------
  606|  29.2k|      WriteBits(bw, ac_huff.depth[0xf0], ac_huff.code[0xf0]);
  607|  29.2k|      r -= 16;
  608|  29.2k|    }
  609|  44.3k|    int nbits = Log2FloorNonZero(temp) + 1;
  610|  44.3k|    int symbol = (r << 4u) + nbits;
  611|  44.3k|    WriteBits(bw, ac_huff.depth[symbol], ac_huff.code[symbol]);
  612|  44.3k|    WriteBits(bw, nbits, temp2 & ((1 << nbits) - 1));
  613|  44.3k|    r = 0;
  614|  44.3k|  }
  615|  11.2M|  if (num_zero_runs > 0) {
  ------------------
  |  Branch (615:7): [True: 4.64k, False: 11.2M]
  ------------------
  616|  4.64k|    Flush(coding_state, bw);
  617|  12.5k|    for (int i = 0; i < num_zero_runs; ++i) {
  ------------------
  |  Branch (617:21): [True: 7.90k, False: 4.64k]
  ------------------
  618|  7.90k|      WriteBits(bw, ac_huff.depth[0xf0], ac_huff.code[0xf0]);
  619|  7.90k|      r -= 16;
  620|  7.90k|    }
  621|  4.64k|  }
  622|  11.2M|  if (r > 0) {
  ------------------
  |  Branch (622:7): [True: 11.2M, False: 2.69k]
  ------------------
  623|       |    // Ignore result: since we do not buffer bits - it can not fail.
  624|  11.2M|    BufferEndOfBand(coding_state, &ac_huff, nullptr, 0, bw);
  625|  11.2M|    if (!eob_run_allowed) {
  ------------------
  |  Branch (625:9): [True: 3.82M, False: 7.42M]
  ------------------
  626|  3.82M|      Flush(coding_state, bw);
  627|  3.82M|    }
  628|  11.2M|  }
  629|  11.2M|  return true;
  630|  11.5M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_115BufferEndOfBandEPNS_8internal3dec14DCTCodingStateEPKNS_16HuffmanCodeTableEPKimPNS2_9BitWriterE:
  224|  39.4M|                                           BitWriter* bw) {
  225|  39.4M|  if (s->eob_run_ == 0) {
  ------------------
  |  Branch (225:7): [True: 8.41M, False: 31.0M]
  ------------------
  226|  8.41M|    s->cur_ac_huff_ = ac_huff;
  227|  8.41M|  }
  228|  39.4M|  ++s->eob_run_;
  229|  39.4M|  if (new_bits_count) {
  ------------------
  |  Branch (229:7): [True: 146k, False: 39.3M]
  ------------------
  230|   146k|    uint64_t new_bits = 0;
  231|   917k|    for (size_t i = 0; i < new_bits_count; ++i) {
  ------------------
  |  Branch (231:24): [True: 771k, False: 146k]
  ------------------
  232|   771k|      new_bits = (new_bits << 1) | new_bits_array[i];
  233|   771k|    }
  234|   146k|    size_t tail = s->refinement_bits_count_ & 0xF;
  235|   146k|    if (tail) {  // First stuff the tail item
  ------------------
  |  Branch (235:9): [True: 99.7k, False: 46.9k]
  ------------------
  236|  99.7k|      size_t stuff_bits_count = std::min(16 - tail, new_bits_count);
  237|  99.7k|      uint16_t stuff_bits = new_bits >> (new_bits_count - stuff_bits_count);
  238|  99.7k|      stuff_bits &= ((1u << stuff_bits_count) - 1);
  239|  99.7k|      s->refinement_bits_.back() =
  240|  99.7k|          (s->refinement_bits_.back() << stuff_bits_count) | stuff_bits;
  241|  99.7k|      new_bits_count -= stuff_bits_count;
  242|  99.7k|      s->refinement_bits_count_ += stuff_bits_count;
  243|  99.7k|    }
  244|   162k|    while (new_bits_count >= 16) {
  ------------------
  |  Branch (244:12): [True: 15.4k, False: 146k]
  ------------------
  245|  15.4k|      s->refinement_bits_.push_back(new_bits >> (new_bits_count - 16));
  246|  15.4k|      new_bits_count -= 16;
  247|  15.4k|      s->refinement_bits_count_ += 16;
  248|  15.4k|    }
  249|   146k|    if (new_bits_count) {
  ------------------
  |  Branch (249:9): [True: 59.3k, False: 87.2k]
  ------------------
  250|  59.3k|      s->refinement_bits_.push_back(new_bits & ((1u << new_bits_count) - 1));
  251|  59.3k|      s->refinement_bits_count_ += new_bits_count;
  252|  59.3k|    }
  253|   146k|  }
  254|       |  // At most we buffer at most ~258041 bytes; that is less than we have reserved
  255|       |  // before; still, let's make sure we don't use more memory ever.
  256|  39.4M|  if (s->refinement_bits_count_ > 0x7FFF * (kDCTBlockSize - 1)) {
  ------------------
  |  Branch (256:7): [True: 0, False: 39.4M]
  ------------------
  257|      0|    return false;
  258|      0|  }
  259|  39.4M|  if (s->eob_run_ == 0x7FFF) {
  ------------------
  |  Branch (259:7): [True: 799, False: 39.4M]
  ------------------
  260|    799|    Flush(s, bw);
  261|    799|  }
  262|  39.4M|  return true;
  263|  39.4M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_112DoEncodeScanILi2EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateE:
  700|  2.71k|                                                  SerializationState* state) {
  701|  2.71k|  const JPEGScanInfo& scan_info = jpg.scan_info[state->scan_index];
  702|  2.71k|  EncodeScanState& ss = state->scan_state;
  703|       |
  704|  2.71k|  const int restart_interval =
  705|  2.71k|      state->seen_dri_marker ? jpg.restart_interval : 0;
  ------------------
  |  Branch (705:7): [True: 971, False: 1.74k]
  ------------------
  706|       |
  707|  2.71k|  const auto get_next_extra_zero_run_index = [&ss, &scan_info]() -> int {
  708|  2.71k|    if (ss.extra_zero_runs_pos < scan_info.extra_zero_runs.size()) {
  709|  2.71k|      return scan_info.extra_zero_runs[ss.extra_zero_runs_pos].block_idx;
  710|  2.71k|    } else {
  711|  2.71k|      return -1;
  712|  2.71k|    }
  713|  2.71k|  };
  714|       |
  715|  2.71k|  const auto get_next_reset_point = [&ss, &scan_info]() -> int {
  716|  2.71k|    if (ss.next_reset_point_pos < scan_info.reset_points.size()) {
  717|  2.71k|      return scan_info.reset_points[ss.next_reset_point_pos++];
  718|  2.71k|    } else {
  719|  2.71k|      return -1;
  720|  2.71k|    }
  721|  2.71k|  };
  722|       |
  723|  2.71k|  if (ss.stage == EncodeScanState::HEAD) {
  ------------------
  |  Branch (723:7): [True: 2.71k, False: 0]
  ------------------
  724|  2.71k|    if (!EncodeSOS(jpg, scan_info, state)) return SerializationStatus::ERROR;
  ------------------
  |  Branch (724:9): [True: 65, False: 2.64k]
  ------------------
  725|  2.64k|    BitWriterInit(&ss.bw, &state->output_queue);
  726|  2.64k|    DCTCodingStateInit(&ss.coding_state);
  727|  2.64k|    ss.restarts_to_go = restart_interval;
  728|  2.64k|    ss.next_restart_marker = 0;
  729|  2.64k|    ss.block_scan_index = 0;
  730|  2.64k|    ss.extra_zero_runs_pos = 0;
  731|  2.64k|    ss.next_extra_zero_run_index = get_next_extra_zero_run_index();
  732|  2.64k|    ss.next_reset_point_pos = 0;
  733|  2.64k|    ss.next_reset_point = get_next_reset_point();
  734|  2.64k|    ss.mcu_y = 0;
  735|  2.64k|    memset(ss.last_dc_coeff, 0, sizeof(ss.last_dc_coeff));
  736|  2.64k|    ss.stage = EncodeScanState::BODY;
  737|  2.64k|  }
  738|  2.64k|  BitWriter* bw = &ss.bw;
  739|  2.64k|  DCTCodingState* coding_state = &ss.coding_state;
  740|       |
  741|  2.64k|  BRUNSLI_DCHECK(ss.stage == EncodeScanState::BODY);
  742|       |
  743|       |  // "Non-interleaved" means color data comes in separate scans, in other words
  744|       |  // each scan can contain only one color component.
  745|  2.64k|  const bool is_interleaved = (scan_info.num_components > 1);
  746|  2.64k|  const JPEGComponent& base_component =
  747|  2.64k|      jpg.components[scan_info.components[0].comp_idx];
  748|       |  // h_group / v_group act as numerators for converting number of blocks to
  749|       |  // number of MCU. In interleaved mode it is 1, so MCU is represented with
  750|       |  // max_*_samp_factor blocks. In non-interleaved mode we choose numerator to
  751|       |  // be the samping factor, consequently MCU is always represented with single
  752|       |  // block.
  753|  2.64k|  const int h_group = is_interleaved ? 1 : base_component.h_samp_factor;
  ------------------
  |  Branch (753:23): [True: 2.06k, False: 587]
  ------------------
  754|  2.64k|  const int v_group = is_interleaved ? 1 : base_component.v_samp_factor;
  ------------------
  |  Branch (754:23): [True: 2.06k, False: 587]
  ------------------
  755|  2.64k|  const int MCUs_per_row =
  756|  2.64k|      DivCeil(jpg.width * h_group, 8 * jpg.max_h_samp_factor);
  757|  2.64k|  const int MCU_rows = DivCeil(jpg.height * v_group, 8 * jpg.max_v_samp_factor);
  758|  2.64k|  const bool is_progressive = state->is_progressive;
  759|  2.64k|  const int Al = is_progressive ? scan_info.Al : 0;
  ------------------
  |  Branch (759:18): [True: 2.64k, False: 0]
  ------------------
  760|  2.64k|  const int Ss = is_progressive ? scan_info.Ss : 0;
  ------------------
  |  Branch (760:18): [True: 2.64k, False: 0]
  ------------------
  761|  2.64k|  const int Se = is_progressive ? scan_info.Se : 63;
  ------------------
  |  Branch (761:18): [True: 2.64k, False: 0]
  ------------------
  762|       |
  763|       |  // DC-only is defined by [0..0] spectral range.
  764|  2.64k|  const bool want_ac = ((Ss != 0) || (Se != 0));
  ------------------
  |  Branch (764:25): [True: 2.08k, False: 565]
  |  Branch (764:38): [True: 546, False: 19]
  ------------------
  765|  2.64k|  const bool complete_ac = (parsing_state.stage == Stage::DONE);
  766|  2.64k|  const bool has_ac =
  767|  2.64k|      complete_ac || HasSection(&parsing_state, kBrunsliACDataTag);
  ------------------
  |  Branch (767:7): [True: 2.64k, False: 0]
  |  Branch (767:22): [True: 0, False: 0]
  ------------------
  768|  2.64k|  if (want_ac && !has_ac) return SerializationStatus::NEEDS_MORE_INPUT;
  ------------------
  |  Branch (768:7): [True: 2.62k, False: 19]
  |  Branch (768:18): [True: 0, False: 2.62k]
  ------------------
  769|       |
  770|       |  // |has_ac| implies |complete_dc| but not vice versa; for the sake of
  771|       |  // simplicity we pretend they are equal, because they are separated by just a
  772|       |  // few bytes of input.
  773|  2.64k|  const bool complete_dc = has_ac;
  774|  2.64k|  const bool complete = want_ac ? complete_ac : complete_dc;
  ------------------
  |  Branch (774:25): [True: 2.62k, False: 19]
  ------------------
  775|       |  // When "incomplete" |ac_dc| tracks information about current ("incomplete")
  776|       |  // band parsing progress.
  777|  2.64k|  const int last_mcu_y =
  778|  2.64k|      complete ? MCU_rows : parsing_state.internal->ac_dc.next_mcu_y * v_group;
  ------------------
  |  Branch (778:7): [True: 2.64k, False: 0]
  ------------------
  779|       |
  780|   121k|  for (; ss.mcu_y < last_mcu_y; ++ss.mcu_y) {
  ------------------
  |  Branch (780:10): [True: 119k, False: 2.63k]
  ------------------
  781|  1.36M|    for (int mcu_x = 0; mcu_x < MCUs_per_row; ++mcu_x) {
  ------------------
  |  Branch (781:25): [True: 1.24M, False: 119k]
  ------------------
  782|       |      // Possibly emit a restart marker.
  783|  1.24M|      if (restart_interval > 0 && ss.restarts_to_go == 0) {
  ------------------
  |  Branch (783:11): [True: 991k, False: 251k]
  |  Branch (783:35): [True: 66.4k, False: 924k]
  ------------------
  784|  66.4k|        Flush(coding_state, bw);
  785|  66.4k|        if (!JumpToByteBoundary(bw, &state->pad_bits, state->pad_bits_end)) {
  ------------------
  |  Branch (785:13): [True: 8, False: 66.4k]
  ------------------
  786|      8|          return SerializationStatus::ERROR;
  787|      8|        }
  788|  66.4k|        EmitMarker(bw, 0xD0 + ss.next_restart_marker);
  789|  66.4k|        ss.next_restart_marker += 1;
  790|  66.4k|        ss.next_restart_marker &= 0x7;
  791|  66.4k|        ss.restarts_to_go = restart_interval;
  792|  66.4k|        memset(ss.last_dc_coeff, 0, sizeof(ss.last_dc_coeff));
  793|  66.4k|      }
  794|       |      // Encode one MCU
  795|  3.46M|      for (size_t i = 0; i < scan_info.num_components; ++i) {
  ------------------
  |  Branch (795:26): [True: 2.21M, False: 1.24M]
  ------------------
  796|  2.21M|        const JPEGComponentScanInfo& si = scan_info.components[i];
  797|  2.21M|        const JPEGComponent& c = jpg.components[si.comp_idx];
  798|  2.21M|        const HuffmanCodeTable& dc_huff = state->dc_huff_table[si.dc_tbl_idx];
  799|  2.21M|        const HuffmanCodeTable& ac_huff = state->ac_huff_table[si.ac_tbl_idx];
  800|  2.21M|        int n_blocks_y = is_interleaved ? c.v_samp_factor : 1;
  ------------------
  |  Branch (800:26): [True: 1.31M, False: 901k]
  ------------------
  801|  2.21M|        int n_blocks_x = is_interleaved ? c.h_samp_factor : 1;
  ------------------
  |  Branch (801:26): [True: 1.31M, False: 901k]
  ------------------
  802|  10.3M|        for (int iy = 0; iy < n_blocks_y; ++iy) {
  ------------------
  |  Branch (802:26): [True: 8.11M, False: 2.21M]
  ------------------
  803|  36.7M|          for (int ix = 0; ix < n_blocks_x; ++ix) {
  ------------------
  |  Branch (803:28): [True: 28.6M, False: 8.11M]
  ------------------
  804|  28.6M|            int block_y = ss.mcu_y * n_blocks_y + iy;
  805|  28.6M|            int block_x = mcu_x * n_blocks_x + ix;
  806|  28.6M|            int block_idx = block_y * c.width_in_blocks + block_x;
  807|  28.6M|            if (ss.block_scan_index == ss.next_reset_point) {
  ------------------
  |  Branch (807:17): [True: 9.69k, False: 28.6M]
  ------------------
  808|  9.69k|              Flush(coding_state, bw);
  809|  9.69k|              ss.next_reset_point = get_next_reset_point();
  810|  9.69k|            }
  811|  28.6M|            int num_zero_runs = 0;
  812|  28.6M|            if (ss.block_scan_index == ss.next_extra_zero_run_index) {
  ------------------
  |  Branch (812:17): [True: 977, False: 28.6M]
  ------------------
  813|    977|              num_zero_runs = scan_info.extra_zero_runs[ss.extra_zero_runs_pos]
  814|    977|                                  .num_extra_zero_runs;
  815|    977|              ++ss.extra_zero_runs_pos;
  816|    977|              ss.next_extra_zero_run_index = get_next_extra_zero_run_index();
  817|    977|            }
  818|  28.6M|            const coeff_t* coeffs = &c.coeffs[block_idx << 6];
  819|  28.6M|            bool ok;
  820|  28.6M|            if (kMode == 0) {
  ------------------
  |  Branch (820:17): [Folded, False: 28.6M]
  ------------------
  821|      0|              ok = EncodeDCTBlockSequential(coeffs, dc_huff, ac_huff,
  822|      0|                                            num_zero_runs,
  823|      0|                                            ss.last_dc_coeff + si.comp_idx, bw);
  824|  28.6M|            } else if (kMode == 1) {
  ------------------
  |  Branch (824:24): [Folded, False: 28.6M]
  ------------------
  825|      0|              ok = EncodeDCTBlockProgressive(
  826|      0|                  coeffs, dc_huff, ac_huff, Ss, Se, Al, num_zero_runs,
  827|      0|                  coding_state, ss.last_dc_coeff + si.comp_idx, bw);
  828|  28.6M|            } else {
  829|  28.6M|              ok = EncodeRefinementBits(coeffs, ac_huff, Ss, Se, Al,
  830|  28.6M|                                        coding_state, bw);
  831|  28.6M|            }
  832|  28.6M|            if (!ok) return SerializationStatus::ERROR;
  ------------------
  |  Branch (832:17): [True: 0, False: 28.6M]
  ------------------
  833|  28.6M|            ++ss.block_scan_index;
  834|  28.6M|          }
  835|  8.11M|        }
  836|  2.21M|      }
  837|  1.24M|      --ss.restarts_to_go;
  838|  1.24M|    }
  839|   119k|  }
  840|  2.63k|  if (ss.mcu_y < MCU_rows) {
  ------------------
  |  Branch (840:7): [True: 0, False: 2.63k]
  ------------------
  841|      0|    if (!bw->healthy) return SerializationStatus::ERROR;
  ------------------
  |  Branch (841:9): [True: 0, False: 0]
  ------------------
  842|      0|    return SerializationStatus::NEEDS_MORE_INPUT;
  843|      0|  }
  844|  2.63k|  Flush(coding_state, bw);
  845|  2.63k|  if (!JumpToByteBoundary(bw, &state->pad_bits, state->pad_bits_end)) {
  ------------------
  |  Branch (845:7): [True: 11, False: 2.62k]
  ------------------
  846|     11|    return SerializationStatus::ERROR;
  847|     11|  }
  848|  2.62k|  BitWriterFinish(bw);
  849|  2.62k|  ss.stage = EncodeScanState::HEAD;
  850|  2.62k|  state->scan_index++;
  851|  2.62k|  if (!bw->healthy) return SerializationStatus::ERROR;
  ------------------
  |  Branch (851:7): [True: 2.05k, False: 576]
  ------------------
  852|       |
  853|    576|  return SerializationStatus::DONE;
  854|  2.62k|}
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_112DoEncodeScanILi2EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateEENKUlvE_clEv:
  707|  3.62k|  const auto get_next_extra_zero_run_index = [&ss, &scan_info]() -> int {
  708|  3.62k|    if (ss.extra_zero_runs_pos < scan_info.extra_zero_runs.size()) {
  ------------------
  |  Branch (708:9): [True: 989, False: 2.63k]
  ------------------
  709|    989|      return scan_info.extra_zero_runs[ss.extra_zero_runs_pos].block_idx;
  710|  2.63k|    } else {
  711|  2.63k|      return -1;
  712|  2.63k|    }
  713|  3.62k|  };
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_112DoEncodeScanILi2EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateEENKUlvE0_clEv:
  715|  12.3k|  const auto get_next_reset_point = [&ss, &scan_info]() -> int {
  716|  12.3k|    if (ss.next_reset_point_pos < scan_info.reset_points.size()) {
  ------------------
  |  Branch (716:9): [True: 9.73k, False: 2.60k]
  ------------------
  717|  9.73k|      return scan_info.reset_points[ss.next_reset_point_pos++];
  718|  9.73k|    } else {
  719|  2.60k|      return -1;
  720|  2.60k|    }
  721|  12.3k|  };
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_120EncodeRefinementBitsEPKsRKNS_16HuffmanCodeTableEiiiPNS_8internal3dec14DCTCodingStateEPNS7_9BitWriterE:
  634|  28.6M|                          int Al, DCTCodingState* coding_state, BitWriter* bw) {
  635|  28.6M|  bool eob_run_allowed = Ss > 0;
  636|  28.6M|  if (Ss == 0) {
  ------------------
  |  Branch (636:7): [True: 4.45M, False: 24.1M]
  ------------------
  637|       |    // Emit next bit of DC component.
  638|  4.45M|    WriteBits(bw, 1, (coeffs[0] >> Al) & 1);
  639|  4.45M|    ++Ss;
  640|  4.45M|  }
  641|  28.6M|  if (Ss > Se) {
  ------------------
  |  Branch (641:7): [True: 393k, False: 28.2M]
  ------------------
  642|   393k|    return true;
  643|   393k|  }
  644|  28.2M|  int abs_values[kDCTBlockSize];
  645|  28.2M|  int eob = 0;
  646|   782M|  for (int k = Ss; k <= Se; k++) {
  ------------------
  |  Branch (646:20): [True: 754M, False: 28.2M]
  ------------------
  647|   754M|    const coeff_t abs_val = std::abs(coeffs[kJPEGNaturalOrder[k]]);
  648|   754M|    abs_values[k] = abs_val >> Al;
  649|   754M|    if (abs_values[k] == 1) {
  ------------------
  |  Branch (649:9): [True: 89.1k, False: 754M]
  ------------------
  650|  89.1k|      eob = k;
  651|  89.1k|    }
  652|   754M|  }
  653|  28.2M|  int r = 0;
  654|  28.2M|  int refinement_bits[kDCTBlockSize];
  655|  28.2M|  size_t refinement_bits_count = 0;
  656|   782M|  for (int k = Ss; k <= Se; k++) {
  ------------------
  |  Branch (656:20): [True: 754M, False: 28.2M]
  ------------------
  657|   754M|    if (abs_values[k] == 0) {
  ------------------
  |  Branch (657:9): [True: 753M, False: 892k]
  ------------------
  658|   753M|      r++;
  659|   753M|      continue;
  660|   753M|    }
  661|   937k|    while (r > 15 && k <= eob) {
  ------------------
  |  Branch (661:12): [True: 115k, False: 821k]
  |  Branch (661:22): [True: 44.2k, False: 71.5k]
  ------------------
  662|  44.2k|      Flush(coding_state, bw);
  663|  44.2k|      WriteBits(bw, ac_huff.depth[0xf0], ac_huff.code[0xf0]);
  664|  44.2k|      r -= 16;
  665|  53.3k|      for (size_t i = 0; i < refinement_bits_count; ++i) {
  ------------------
  |  Branch (665:26): [True: 9.07k, False: 44.2k]
  ------------------
  666|  9.07k|        WriteBits(bw, 1, refinement_bits[i]);
  667|  9.07k|      }
  668|  44.2k|      refinement_bits_count = 0;
  669|  44.2k|    }
  670|   892k|    if (abs_values[k] > 1) {
  ------------------
  |  Branch (670:9): [True: 803k, False: 89.1k]
  ------------------
  671|   803k|      refinement_bits[refinement_bits_count++] = abs_values[k] & 1u;
  672|   803k|      continue;
  673|   803k|    }
  674|  89.1k|    Flush(coding_state, bw);
  675|  89.1k|    int symbol = (r << 4u) + 1;
  676|  89.1k|    int new_non_zero_bit = (coeffs[kJPEGNaturalOrder[k]] < 0) ? 0 : 1;
  ------------------
  |  Branch (676:28): [True: 58.7k, False: 30.3k]
  ------------------
  677|  89.1k|    WriteBits(bw, ac_huff.depth[symbol], ac_huff.code[symbol]);
  678|  89.1k|    WriteBits(bw, 1, new_non_zero_bit);
  679|   112k|    for (size_t i = 0; i < refinement_bits_count; ++i) {
  ------------------
  |  Branch (679:24): [True: 23.4k, False: 89.1k]
  ------------------
  680|  23.4k|      WriteBits(bw, 1, refinement_bits[i]);
  681|  23.4k|    }
  682|  89.1k|    refinement_bits_count = 0;
  683|  89.1k|    r = 0;
  684|  89.1k|  }
  685|  28.2M|  if (r > 0 || refinement_bits_count) {
  ------------------
  |  Branch (685:7): [True: 28.2M, False: 11.3k]
  |  Branch (685:16): [True: 5.58k, False: 5.73k]
  ------------------
  686|  28.2M|    if (!BufferEndOfBand(coding_state, &ac_huff, refinement_bits,
  ------------------
  |  Branch (686:9): [True: 0, False: 28.2M]
  ------------------
  687|  28.2M|                         refinement_bits_count, bw)) {
  688|      0|      return false;
  689|      0|    }
  690|  28.2M|    if (!eob_run_allowed) {
  ------------------
  |  Branch (690:9): [True: 4.45M, False: 23.7M]
  ------------------
  691|  4.45M|      Flush(coding_state, bw);
  692|  4.45M|    }
  693|  28.2M|  }
  694|  28.2M|  return true;
  695|  28.2M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeDQTERKNS_8JPEGDataEPNS_8internal3dec18SerializationStateE:
  429|    212|bool EncodeDQT(const JPEGData& jpg, SerializationState* state) {
  430|    212|  int marker_len = 2;
  431|    212|  for (size_t i = state->dqt_index; i < jpg.quant.size(); ++i) {
  ------------------
  |  Branch (431:37): [True: 204, False: 8]
  ------------------
  432|    204|    const JPEGQuantTable& table = jpg.quant[i];
  433|    204|    marker_len += 1 + (table.precision ? 2 : 1) * kDCTBlockSize;
  ------------------
  |  Branch (433:24): [True: 69, False: 135]
  ------------------
  434|    204|    if (table.is_last) break;
  ------------------
  |  Branch (434:9): [True: 204, False: 0]
  ------------------
  435|    204|  }
  436|    212|  state->output_queue.emplace_back(marker_len + 2);
  437|    212|  uint8_t* data = state->output_queue.back().buffer->data();
  438|    212|  size_t pos = 0;
  439|    212|  data[pos++] = 0xFF;
  440|    212|  data[pos++] = 0xDB;
  441|    212|  data[pos++] = marker_len >> 8u;
  442|    212|  data[pos++] = marker_len & 0xFFu;
  443|    212|  while (true) {
  ------------------
  |  Branch (443:10): [True: 212, Folded]
  ------------------
  444|    212|    const size_t idx = state->dqt_index++;
  445|    212|    if (idx >= jpg.quant.size()) {
  ------------------
  |  Branch (445:9): [True: 8, False: 204]
  ------------------
  446|      8|      return false;  // corrupt input
  447|      8|    }
  448|    204|    const JPEGQuantTable& table = jpg.quant[idx];
  449|    204|    data[pos++] = (table.precision << 4u) + table.index;
  450|  13.2k|    for (size_t i = 0; i < kDCTBlockSize; ++i) {
  ------------------
  |  Branch (450:24): [True: 13.0k, False: 204]
  ------------------
  451|  13.0k|      int val_idx = kJPEGNaturalOrder[i];
  452|  13.0k|      int val = table.values[val_idx];
  453|  13.0k|      if (table.precision) {
  ------------------
  |  Branch (453:11): [True: 4.41k, False: 8.64k]
  ------------------
  454|  4.41k|        data[pos++] = val >> 8u;
  455|  4.41k|      }
  456|  13.0k|      data[pos++] = val & 0xFFu;
  457|  13.0k|    }
  458|    204|    if (table.is_last) break;
  ------------------
  |  Branch (458:9): [True: 204, False: 0]
  ------------------
  459|    204|  }
  460|    204|  return true;
  461|    212|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeDRIERKNS_8JPEGDataEPNS_8internal3dec18SerializationStateE:
  463|  1.85k|bool EncodeDRI(const JPEGData& jpg, SerializationState* state) {
  464|  1.85k|  state->seen_dri_marker = true;
  465|  1.85k|  OutputChunk dri_marker = {0xFF,
  466|  1.85k|                            0xDD,
  467|  1.85k|                            0,
  468|  1.85k|                            4,
  469|  1.85k|                            static_cast<uint8_t>(jpg.restart_interval >> 8),
  470|  1.85k|                            static_cast<uint8_t>(jpg.restart_interval & 0xFF)};
  471|  1.85k|  state->output_queue.push_back(std::move(dri_marker));
  472|  1.85k|  return true;
  473|  1.85k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeAPPERKNS_8JPEGDataEhPNS_8internal3dec18SerializationStateE:
  480|    238|bool EncodeAPP(const JPEGData& jpg, uint8_t marker, SerializationState* state) {
  481|       |  // TODO(eustas): check that marker corresponds to payload?
  482|    238|  (void)marker;
  483|       |
  484|    238|  size_t app_index = state->app_index++;
  485|    238|  if (app_index >= jpg.app_data.size()) return false;
  ------------------
  |  Branch (485:7): [True: 226, False: 12]
  ------------------
  486|     12|  state->output_queue.push_back(OutputChunk({0xFF}));
  487|     12|  state->output_queue.emplace_back(jpg.app_data[app_index]);
  488|     12|  return true;
  489|    238|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeCOMERKNS_8JPEGDataEPNS_8internal3dec18SerializationStateE:
  491|      4|bool EncodeCOM(const JPEGData& jpg, SerializationState* state) {
  492|      4|  size_t com_index = state->com_index++;
  493|      4|  if (com_index >= jpg.com_data.size()) return false;
  ------------------
  |  Branch (493:7): [True: 4, False: 0]
  ------------------
  494|      0|  state->output_queue.push_back(OutputChunk({0xFF}));
  495|      0|  state->output_queue.emplace_back(jpg.com_data[com_index]);
  496|      0|  return true;
  497|      4|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_121EncodeInterMarkerDataERKNS_8JPEGDataEPNS_8internal3dec18SerializationStateE:
  499|     17|bool EncodeInterMarkerData(const JPEGData& jpg, SerializationState* state) {
  500|     17|  size_t index = state->data_index++;
  501|     17|  if (index >= jpg.inter_marker_data.size()) return false;
  ------------------
  |  Branch (501:7): [True: 0, False: 17]
  ------------------
  502|     17|  state->output_queue.emplace_back(jpg.inter_marker_data[index]);
  503|     17|  return true;
  504|     17|}

_ZN7brunsli8internal3dec11OutputChunkC2EPKhm:
   48|  4.56k|  OutputChunk(const uint8_t* data, size_t size) : next(data), len(size) {}
_ZN7brunsli8internal3dec11OutputChunkC2Em:
   51|  48.6k|  explicit OutputChunk(size_t size = 0) {
   52|  48.6k|    buffer.reset(new std::vector<uint8_t>(size));
   53|  48.6k|    next = buffer->data();
   54|  48.6k|    len = size;
   55|  48.6k|  }
_ZN7brunsli8internal3dec11OutputChunkC2ESt16initializer_listIhE:
   58|  15.6k|  OutputChunk(std::initializer_list<uint8_t> bytes) {
   59|  15.6k|    buffer.reset(new std::vector<uint8_t>(bytes));
   60|  15.6k|    next = buffer->data();
   61|  15.6k|    len = bytes.size();
   62|  15.6k|  }
_ZN7brunsli8internal3dec11OutputChunkC2IKNSt3__16vectorIhNS4_9allocatorIhEEEEEERT_:
   41|    281|  OutputChunk(Bytes& bytes) : len(bytes.size()) {
   42|       |    // Deal both with const qualifier and data type.
   43|    281|    const void* src = bytes.data();
   44|    281|    next = reinterpret_cast<const uint8_t*>(src);
   45|    281|  }

_ZN7brunsli8internal3dec5StateC2Ev:
   16|  21.1k|State::State() : internal(new InternalState()) {}
_ZN7brunsli8internal3dec5StateD2Ev:
   20|  21.1k|State::~State() {}
_ZN7brunsli8internal3dec13MetadataStateD2Ev:
   22|  21.1k|MetadataState::~MetadataState() {
   23|  21.1k|  if (brotli != nullptr) {
  ------------------
  |  Branch (23:7): [True: 1.44k, False: 19.6k]
  ------------------
   24|  1.44k|    BrotliDecoderDestroyInstance(brotli);
   25|  1.44k|    brotli = nullptr;
   26|  1.44k|  }
   27|  21.1k|}
_ZN7brunsli8internal3dec10HasSectionEPKNS1_5StateEj:
   29|  40.6k|bool HasSection(const State* state, uint32_t tag) {
   30|  40.6k|  return state->internal->section.tags_met & (1u << tag);
   31|  40.6k|}

_ZN7brunsli8internal3dec13MetadataState9CanFinishEv:
  181|     27|  bool CanFinish() { return (stage == READ_MARKER) || (stage == READ_TAIL); }
  ------------------
  |  Branch (181:29): [True: 21, False: 6]
  |  Branch (181:55): [True: 2, False: 4]
  ------------------

_ZN7brunsli8JPEGDataC2Ev:
  214|  16.6k|  JPEGData() : width(0),
  215|  16.6k|               height(0),
  216|  16.6k|               version(2),  // Use new context modelling by default.
  217|  16.6k|               max_h_samp_factor(1),
  218|  16.6k|               max_v_samp_factor(1),
  219|  16.6k|               MCU_rows(0),
  220|  16.6k|               MCU_cols(0),
  221|  16.6k|               restart_interval(0),
  222|  16.6k|               original_jpg(NULL),
  223|  16.6k|               original_jpg_size(0),
  224|  16.6k|               error(JPEGReadError::OK),
  225|  16.6k|               has_zero_padding_bit(false) {}
_ZN7brunsli13JPEGComponentC2Ev:
  187|  25.7k|  JPEGComponent() : id(0),
  188|  25.7k|                    h_samp_factor(1),
  189|  25.7k|                    v_samp_factor(1),
  190|  25.7k|                    quant_idx(0),
  191|  25.7k|                    width_in_blocks(0),
  192|  25.7k|                    height_in_blocks(0) {}
_ZN7brunsli16PaddingBitsLimitERKNS_8JPEGDataE:
  279|  9.51k|inline uint64_t PaddingBitsLimit(const JPEGData& jpg) {
  280|       |  // Just rough estimate, with MCU = 16px.
  281|  9.51k|  const uint64_t num_blocks = ((static_cast<uint64_t>(jpg.width) + 15u) >> 3u) *
  282|  9.51k|                              ((static_cast<uint64_t>(jpg.height) + 15u) >> 3u);
  283|  9.51k|  return 7u * num_blocks * jpg.components.size() + 256u;
  284|  9.51k|}

_ZN7brunsli10JPEGOutputC2EPFmPvPKhmES1_:
   23|  16.6k|  JPEGOutput(JPEGOutputHook cb, void* data) : cb(cb), data(data) {}
_ZNK7brunsli10JPEGOutput5WriteEPKhm:
   24|    489|  bool Write(const uint8_t* buf, size_t len) const {
   25|    489|    if (len == 0) return true;
  ------------------
  |  Branch (25:9): [True: 8, False: 481]
  ------------------
   26|    481|    size_t bytes_written = cb(data, buf, len);
   27|    481|    return (bytes_written == len);
   28|    489|  }

_Z21DiscardOutputFunctionPvPKhm:
   20|    481|size_t DiscardOutputFunction(void* data, const uint8_t* buf, size_t count) {
   21|    481|  BRUNSLI_UNUSED(data);
  ------------------
  |  |  476|    481|#define BRUNSLI_UNUSED(X) (void)(X)
  ------------------
   22|    481|  BRUNSLI_UNUSED(buf);
  ------------------
  |  |  476|    481|#define BRUNSLI_UNUSED(X) (void)(X)
  ------------------
   23|    481|  return count;
   24|    481|}
_Z14DoTestOneInputPKhm:
   26|  16.6k|int DoTestOneInput(const uint8_t* data, size_t size) {
   27|  16.6k|  brunsli::JPEGOutput out(DiscardOutputFunction, nullptr);
   28|  16.6k|  brunsli::JPEGData jpg;
   29|  16.6k|  brunsli::BrunsliStatus status;
   30|  16.6k|  status = brunsli::BrunsliDecodeJpeg(data, size, &jpg);
   31|  16.6k|  if (status == brunsli::BRUNSLI_OK) {
  ------------------
  |  Branch (31:7): [True: 4.45k, False: 12.2k]
  ------------------
   32|  4.45k|    brunsli::WriteJpeg(jpg, out);
   33|  4.45k|  }
   34|  16.6k|  return 0;
   35|  16.6k|}
LLVMFuzzerTestOneInput:
   38|  16.6k|extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
   39|  16.6k|  return DoTestOneInput(data, size);
   40|  16.6k|}

_ZN12FuzzTestSink9WithSeedsIPFNSt3__16vectorINS1_5tupleIJNS2_IhNS1_9allocatorIhEEEEEEENS4_IS7_EEEEvEEES_T_:
   50|      2|  FuzzTestSink WithSeeds(F) {
   51|      2|    return *this;
   52|      2|  }

