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

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

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

BrotliGetTransforms:
  173|  4.20k|const BrotliTransforms* BrotliGetTransforms(void) {
  174|  4.20k|  return &kBrotliTransforms;
  175|  4.20k|}
BrotliTransformDictionaryWord:
  237|  13.2k|    const BrotliTransforms* transforms, int transform_idx) {
  238|  13.2k|  int idx = 0;
  239|  13.2k|  const uint8_t* prefix = BROTLI_TRANSFORM_PREFIX(transforms, transform_idx);
  ------------------
  |  |   70|  13.2k|#define BROTLI_TRANSFORM_PREFIX(T, I) (&(T)->prefix_suffix[ \
  |  |   71|  13.2k|    (T)->prefix_suffix_map[BROTLI_TRANSFORM_PREFIX_ID(T, I)]])
  |  |  ------------------
  |  |  |  |   65|  13.2k|#define BROTLI_TRANSFORM_PREFIX_ID(T, I) ((T)->transforms[((I) * 3) + 0])
  |  |  ------------------
  ------------------
  240|  13.2k|  uint8_t type = BROTLI_TRANSFORM_TYPE(transforms, transform_idx);
  ------------------
  |  |   66|  13.2k|#define BROTLI_TRANSFORM_TYPE(T, I)      ((T)->transforms[((I) * 3) + 1])
  ------------------
  241|  13.2k|  const uint8_t* suffix = BROTLI_TRANSFORM_SUFFIX(transforms, transform_idx);
  ------------------
  |  |   72|  13.2k|#define BROTLI_TRANSFORM_SUFFIX(T, I) (&(T)->prefix_suffix[ \
  |  |   73|  13.2k|    (T)->prefix_suffix_map[BROTLI_TRANSFORM_SUFFIX_ID(T, I)]])
  |  |  ------------------
  |  |  |  |   67|  13.2k|#define BROTLI_TRANSFORM_SUFFIX_ID(T, I) ((T)->transforms[((I) * 3) + 2])
  |  |  ------------------
  ------------------
  242|  13.2k|  {
  243|  13.2k|    int prefix_len = *prefix++;
  244|  20.0k|    while (prefix_len--) { dst[idx++] = *prefix++; }
  ------------------
  |  Branch (244:12): [True: 6.83k, False: 13.2k]
  ------------------
  245|  13.2k|  }
  246|  13.2k|  {
  247|  13.2k|    const int t = type;
  248|  13.2k|    int i = 0;
  249|  13.2k|    if (t <= BROTLI_TRANSFORM_OMIT_LAST_9) {
  ------------------
  |  Branch (249:9): [True: 9.14k, False: 4.07k]
  ------------------
  250|  9.14k|      len -= t;
  251|  9.14k|    } else if (t >= BROTLI_TRANSFORM_OMIT_FIRST_1
  ------------------
  |  Branch (251:16): [True: 1.06k, False: 3.01k]
  ------------------
  252|  1.06k|        && t <= BROTLI_TRANSFORM_OMIT_FIRST_9) {
  ------------------
  |  Branch (252:12): [True: 1.06k, False: 0]
  ------------------
  253|  1.06k|      int skip = t - (BROTLI_TRANSFORM_OMIT_FIRST_1 - 1);
  254|  1.06k|      word += skip;
  255|  1.06k|      len -= skip;
  256|  1.06k|    }
  257|   104k|    while (i < len) { dst[idx++] = word[i++]; }
  ------------------
  |  Branch (257:12): [True: 91.6k, False: 13.2k]
  ------------------
  258|  13.2k|    if (t == BROTLI_TRANSFORM_UPPERCASE_FIRST) {
  ------------------
  |  Branch (258:9): [True: 2.31k, False: 10.8k]
  ------------------
  259|  2.31k|      ToUpperCase(&dst[idx - len]);
  260|  10.8k|    } else if (t == BROTLI_TRANSFORM_UPPERCASE_ALL) {
  ------------------
  |  Branch (260:16): [True: 696, False: 10.2k]
  ------------------
  261|    696|      uint8_t* uppercase = &dst[idx - len];
  262|  7.52k|      while (len > 0) {
  ------------------
  |  Branch (262:14): [True: 6.83k, False: 696]
  ------------------
  263|  6.83k|        int step = ToUpperCase(uppercase);
  264|  6.83k|        uppercase += step;
  265|  6.83k|        len -= step;
  266|  6.83k|      }
  267|  10.2k|    } else if (t == BROTLI_TRANSFORM_SHIFT_FIRST) {
  ------------------
  |  Branch (267:16): [True: 0, False: 10.2k]
  ------------------
  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|  10.2k|    } else if (t == BROTLI_TRANSFORM_SHIFT_ALL) {
  ------------------
  |  Branch (271:16): [True: 0, False: 10.2k]
  ------------------
  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|  13.2k|  }
  282|  13.2k|  {
  283|  13.2k|    int suffix_len = *suffix++;
  284|  33.5k|    while (suffix_len--) { dst[idx++] = *suffix++; }
  ------------------
  |  Branch (284:12): [True: 20.3k, False: 13.2k]
  ------------------
  285|  13.2k|    return idx;
  286|  13.2k|  }
  287|  13.2k|}
transform.c:ToUpperCase:
  177|  9.14k|static int ToUpperCase(uint8_t* p) {
  178|  9.14k|  if (p[0] < 0xC0) {
  ------------------
  |  Branch (178:7): [True: 7.70k, False: 1.44k]
  ------------------
  179|  7.70k|    if (p[0] >= 'a' && p[0] <= 'z') {
  ------------------
  |  Branch (179:9): [True: 5.86k, False: 1.84k]
  |  Branch (179:24): [True: 5.45k, False: 407]
  ------------------
  180|  5.45k|      p[0] ^= 32;
  181|  5.45k|    }
  182|  7.70k|    return 1;
  183|  7.70k|  }
  184|       |  /* An overly simplified uppercasing model for UTF-8. */
  185|  1.44k|  if (p[0] < 0xE0) {
  ------------------
  |  Branch (185:7): [True: 779, False: 665]
  ------------------
  186|    779|    p[1] ^= 32;
  187|    779|    return 2;
  188|    779|  }
  189|       |  /* An arbitrary transform for three byte characters. */
  190|    665|  p[2] ^= 5;
  191|    665|  return 3;
  192|  1.44k|}

BrotliInitBitReader:
   29|  4.20k|void BrotliInitBitReader(BrotliBitReader* const br) {
   30|  4.20k|  br->val_ = 0;
   31|  4.20k|  br->bit_pos_ = sizeof(br->val_) << 3;
   32|  4.20k|}
BrotliWarmupBitReader:
   34|  72.0k|BROTLI_BOOL BrotliWarmupBitReader(BrotliBitReader* const br) {
   35|  72.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|  72.0k|  if (!BROTLI_ALIGNED_READ) {
  ------------------
  |  |  287|  72.0k|#define BROTLI_ALIGNED_READ (!!0)
  ------------------
  |  Branch (39:7): [True: 72.0k, Folded]
  ------------------
   40|  72.0k|    aligned_read_mask = 0;
   41|  72.0k|  }
   42|  72.0k|  if (BrotliGetAvailableBits(br) == 0) {
  ------------------
  |  Branch (42:7): [True: 23.0k, False: 48.9k]
  ------------------
   43|  23.0k|    if (!BrotliPullByte(br)) {
  ------------------
  |  Branch (43:9): [True: 236, False: 22.8k]
  ------------------
   44|    236|      return BROTLI_FALSE;
  ------------------
  |  |   53|    236|#define BROTLI_FALSE 0
  ------------------
   45|    236|    }
   46|  23.0k|  }
   47|       |
   48|  71.8k|  while ((((size_t)br->next_in) & aligned_read_mask) != 0) {
  ------------------
  |  Branch (48:10): [True: 0, False: 71.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|  71.8k|  return BROTLI_TRUE;
  ------------------
  |  |   51|  71.8k|#define BROTLI_TRUE 1
  ------------------
   55|  71.8k|}

decode.c:BrotliBitReaderUnload:
  223|   166k|static BROTLI_INLINE void BrotliBitReaderUnload(BrotliBitReader* br) {
  224|   166k|  uint32_t unused_bytes = BrotliGetAvailableBits(br) >> 3;
  225|   166k|  uint32_t unused_bits = unused_bytes << 3;
  226|   166k|  br->avail_in += unused_bytes;
  227|   166k|  br->next_in -= unused_bytes;
  228|   166k|  if (unused_bits == sizeof(br->val_) << 3) {
  ------------------
  |  Branch (228:7): [True: 2.17k, False: 164k]
  ------------------
  229|  2.17k|    br->val_ = 0;
  230|   164k|  } else {
  231|   164k|    br->val_ <<= unused_bits;
  232|   164k|  }
  233|   166k|  br->bit_pos_ += unused_bits;
  234|   166k|}
decode.c:BrotliTakeBits:
  239|  85.4M|  BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
  240|  85.4M|  *val = (uint32_t)BrotliGetBitsUnmasked(br) & BitMask(n_bits);
  241|  85.4M|  BROTLI_LOG(("[BrotliTakeBits]  %d %d %d val: %6x\n",
  242|  85.4M|      (int)br->avail_in, (int)br->bit_pos_, (int)n_bits, (int)*val));
  243|  85.4M|  BrotliDropBits(br, n_bits);
  244|  85.4M|}
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.08G|    BrotliBitReader* const br, uint32_t n_bits) {
  220|  2.08G|  br->bit_pos_ += n_bits;
  221|  2.08G|}
decode.c:BrotliSafeReadBits:
  292|   833k|    BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
  293|   833k|  BROTLI_DCHECK(n_bits <= 24);
  294|  1.38M|  while (BrotliGetAvailableBits(br) < n_bits) {
  ------------------
  |  Branch (294:10): [True: 547k, False: 832k]
  ------------------
  295|   547k|    if (!BrotliPullByte(br)) {
  ------------------
  |  Branch (295:9): [True: 1.34k, False: 546k]
  ------------------
  296|  1.34k|      return BROTLI_FALSE;
  ------------------
  |  |   53|  1.34k|#define BROTLI_FALSE 0
  ------------------
  297|  1.34k|    }
  298|   547k|  }
  299|   832k|  BrotliTakeBits(br, n_bits, val);
  300|   832k|  return BROTLI_TRUE;
  ------------------
  |  |   51|   832k|#define BROTLI_TRUE 1
  ------------------
  301|   833k|}
decode.c:BrotliPullByte:
  165|   550M|static BROTLI_INLINE BROTLI_BOOL BrotliPullByte(BrotliBitReader* const br) {
  166|   550M|  if (br->avail_in == 0) {
  ------------------
  |  Branch (166:7): [True: 549M, False: 742k]
  ------------------
  167|   549M|    return BROTLI_FALSE;
  ------------------
  |  |   53|   549M|#define BROTLI_FALSE 0
  ------------------
  168|   549M|  }
  169|   742k|  br->val_ >>= 8;
  170|   742k|#if (BROTLI_64_BITS)
  171|   742k|  br->val_ |= ((uint64_t)*br->next_in) << 56;
  172|       |#else
  173|       |  br->val_ |= ((uint32_t)*br->next_in) << 24;
  174|       |#endif
  175|   742k|  br->bit_pos_ -= 8;
  176|   742k|  --br->avail_in;
  177|   742k|  ++br->next_in;
  178|   742k|  return BROTLI_TRUE;
  ------------------
  |  |   51|   742k|#define BROTLI_TRUE 1
  ------------------
  179|   550M|}
decode.c:BrotliJumpToByteBoundary:
  322|  4.47k|static BROTLI_INLINE BROTLI_BOOL BrotliJumpToByteBoundary(BrotliBitReader* br) {
  323|  4.47k|  uint32_t pad_bits_count = BrotliGetAvailableBits(br) & 0x7;
  324|  4.47k|  uint32_t pad_bits = 0;
  325|  4.47k|  if (pad_bits_count != 0) {
  ------------------
  |  Branch (325:7): [True: 3.62k, False: 844]
  ------------------
  326|  3.62k|    BrotliTakeBits(br, pad_bits_count, &pad_bits);
  327|  3.62k|  }
  328|  4.47k|  return TO_BROTLI_BOOL(pad_bits == 0);
  ------------------
  |  |   55|  4.47k|#define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE)
  |  |  ------------------
  |  |  |  |   51|  4.40k|#define BROTLI_TRUE 1
  |  |  ------------------
  |  |               #define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE)
  |  |  ------------------
  |  |  |  |   53|     61|#define BROTLI_FALSE 0
  |  |  ------------------
  |  |  |  Branch (55:28): [True: 4.40k, False: 61]
  |  |  ------------------
  ------------------
  329|  4.47k|}
decode.c:BrotliSafeGetBits:
  207|  1.47G|    BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
  208|  1.47G|  while (BrotliGetAvailableBits(br) < n_bits) {
  ------------------
  |  Branch (208:10): [True: 549M, False: 925M]
  ------------------
  209|   549M|    if (!BrotliPullByte(br)) {
  ------------------
  |  Branch (209:9): [True: 549M, False: 195k]
  ------------------
  210|   549M|      return BROTLI_FALSE;
  ------------------
  |  |   53|   549M|#define BROTLI_FALSE 0
  ------------------
  211|   549M|    }
  212|   549M|  }
  213|   925M|  *val = (uint32_t)BrotliGetBitsUnmasked(br) & BitMask(n_bits);
  214|   925M|  return BROTLI_TRUE;
  ------------------
  |  |   51|   925M|#define BROTLI_TRUE 1
  ------------------
  215|  1.47G|}
decode.c:BrotliCheckInputAmount:
   99|   573M|    BrotliBitReader* const br, size_t num) {
  100|   573M|  return TO_BROTLI_BOOL(br->avail_in >= num);
  ------------------
  |  |   55|   573M|#define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE)
  |  |  ------------------
  |  |  |  |   51|   573M|#define BROTLI_TRUE 1
  |  |  ------------------
  |  |               #define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE)
  |  |  ------------------
  |  |  |  |   53|   128k|#define BROTLI_FALSE 0
  |  |  ------------------
  |  |  |  Branch (55:28): [True: 573M, False: 128k]
  |  |  ------------------
  ------------------
  101|   573M|}
decode.c:BrotliFillBitWindow16:
  159|   137k|static BROTLI_INLINE void BrotliFillBitWindow16(BrotliBitReader* const br) {
  160|   137k|  BrotliFillBitWindow(br, 17);
  161|   137k|}
decode.c:BrotliFillBitWindow:
  108|   741M|    BrotliBitReader* const br, uint32_t n_bits) {
  109|   741M|#if (BROTLI_64_BITS)
  110|   741M|  if (!BROTLI_ALIGNED_READ && BROTLI_IS_CONSTANT(n_bits) && (n_bits <= 8)) {
  ------------------
  |  |  287|  1.48G|#define BROTLI_ALIGNED_READ (!!0)
  ------------------
                if (!BROTLI_ALIGNED_READ && BROTLI_IS_CONSTANT(n_bits) && (n_bits <= 8)) {
  ------------------
  |  |  459|  1.48G|#define BROTLI_IS_CONSTANT(x) (!!__builtin_constant_p(x))
  |  |  ------------------
  |  |  |  Branch (459:31): [True: 657M, False: 84.5M]
  |  |  ------------------
  ------------------
  |  Branch (110:7): [True: 741M, Folded]
  |  Branch (110:61): [True: 531M, False: 125M]
  ------------------
  111|   531M|    if (br->bit_pos_ >= 56) {
  ------------------
  |  Branch (111:9): [True: 7.57k, False: 531M]
  ------------------
  112|  7.57k|      br->val_ >>= 56;
  113|  7.57k|      br->bit_pos_ ^= 56;  /* here same as -= 56 because of the if condition */
  114|  7.57k|      br->val_ |= BROTLI_UNALIGNED_LOAD64LE(br->next_in) << 8;
  ------------------
  |  |  386|  7.57k|#define BROTLI_UNALIGNED_LOAD64LE BrotliUnalignedRead64
  ------------------
  115|  7.57k|      br->avail_in -= 7;
  116|  7.57k|      br->next_in += 7;
  117|  7.57k|    }
  118|   531M|  } else if (
  119|   209M|      !BROTLI_ALIGNED_READ && BROTLI_IS_CONSTANT(n_bits) && (n_bits <= 16)) {
  ------------------
  |  |  287|   419M|#define BROTLI_ALIGNED_READ (!!0)
  ------------------
                    !BROTLI_ALIGNED_READ && BROTLI_IS_CONSTANT(n_bits) && (n_bits <= 16)) {
  ------------------
  |  |  459|   419M|#define BROTLI_IS_CONSTANT(x) (!!__builtin_constant_p(x))
  |  |  ------------------
  |  |  |  Branch (459:31): [True: 125M, False: 84.5M]
  |  |  ------------------
  ------------------
  |  Branch (119:7): [True: 209M, Folded]
  |  Branch (119:61): [True: 125M, False: 137k]
  ------------------
  120|   125M|    if (br->bit_pos_ >= 48) {
  ------------------
  |  Branch (120:9): [True: 53.1k, False: 125M]
  ------------------
  121|  53.1k|      br->val_ >>= 48;
  122|  53.1k|      br->bit_pos_ ^= 48;  /* here same as -= 48 because of the if condition */
  123|  53.1k|      br->val_ |= BROTLI_UNALIGNED_LOAD64LE(br->next_in) << 16;
  ------------------
  |  |  386|  53.1k|#define BROTLI_UNALIGNED_LOAD64LE BrotliUnalignedRead64
  ------------------
  124|  53.1k|      br->avail_in -= 6;
  125|  53.1k|      br->next_in += 6;
  126|  53.1k|    }
  127|   125M|  } else {
  128|  84.7M|    if (br->bit_pos_ >= 32) {
  ------------------
  |  Branch (128:9): [True: 98.2k, False: 84.6M]
  ------------------
  129|  98.2k|      br->val_ >>= 32;
  130|  98.2k|      br->bit_pos_ ^= 32;  /* here same as -= 32 because of the if condition */
  131|  98.2k|      br->val_ |= ((uint64_t)BROTLI_UNALIGNED_LOAD32LE(br->next_in)) << 32;
  ------------------
  |  |  385|  98.2k|#define BROTLI_UNALIGNED_LOAD32LE BrotliUnalignedRead32
  ------------------
  132|  98.2k|      br->avail_in -= BROTLI_SHORT_FILL_BIT_WINDOW_READ;
  ------------------
  |  |   22|  98.2k|#define BROTLI_SHORT_FILL_BIT_WINDOW_READ (sizeof(brotli_reg_t) >> 1)
  ------------------
  133|  98.2k|      br->next_in += BROTLI_SHORT_FILL_BIT_WINDOW_READ;
  ------------------
  |  |   22|  98.2k|#define BROTLI_SHORT_FILL_BIT_WINDOW_READ (sizeof(brotli_reg_t) >> 1)
  ------------------
  134|  98.2k|    }
  135|  84.7M|  }
  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|   741M|}
decode.c:BrotliGetRemainingBytes:
   90|  2.61k|static BROTLI_INLINE size_t BrotliGetRemainingBytes(BrotliBitReader* br) {
   91|  2.61k|  static const size_t kCap = (size_t)1 << BROTLI_LARGE_MAX_WBITS;
  ------------------
  |  |   57|  2.61k|#define BROTLI_LARGE_MAX_WBITS 30
  ------------------
   92|  2.61k|  if (br->avail_in > kCap) return kCap;
  ------------------
  |  Branch (92:7): [True: 0, False: 2.61k]
  ------------------
   93|  2.61k|  return br->avail_in + (BrotliGetAvailableBits(br) >> 3);
   94|  2.61k|}
decode.c:BrotliCopyBytes:
  335|  2.61k|                                          BrotliBitReader* br, size_t num) {
  336|  3.50k|  while (BrotliGetAvailableBits(br) >= 8 && num > 0) {
  ------------------
  |  Branch (336:10): [True: 1.37k, False: 2.13k]
  |  Branch (336:45): [True: 892, False: 482]
  ------------------
  337|    892|    *dest = (uint8_t)BrotliGetBitsUnmasked(br);
  338|    892|    BrotliDropBits(br, 8);
  339|    892|    ++dest;
  340|    892|    --num;
  341|    892|  }
  342|  2.61k|  memcpy(dest, br->next_in, num);
  343|  2.61k|  br->avail_in -= num;
  344|  2.61k|  br->next_in += num;
  345|  2.61k|}
decode.c:BitMask:
   26|  1.55G|static BROTLI_INLINE uint32_t BitMask(uint32_t n) {
   27|  1.55G|  if (BROTLI_IS_CONSTANT(n) || BROTLI_HAS_UBFX) {
  ------------------
  |  |  459|  3.11G|#define BROTLI_IS_CONSTANT(x) (!!__builtin_constant_p(x))
  |  |  ------------------
  |  |  |  Branch (459:31): [True: 1.45G, False: 98.6M]
  |  |  ------------------
  ------------------
                if (BROTLI_IS_CONSTANT(n) || BROTLI_HAS_UBFX) {
  ------------------
  |  |  467|  98.6M|#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.45G|    return ~((0xFFFFFFFFu) << n);
   31|  1.45G|  } else {
   32|  98.6M|    return kBrotliBitMask[n];
   33|  98.6M|  }
   34|  1.55G|}
decode.c:BrotliReadBits24:
  250|  83.2M|    BrotliBitReader* const br, uint32_t n_bits) {
  251|  83.2M|  BROTLI_DCHECK(n_bits <= 24);
  252|  83.2M|  if (BROTLI_64_BITS || (n_bits <= 16)) {
  ------------------
  |  |  235|   166M|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 83.2M, Folded]
  |  |  ------------------
  ------------------
  |  Branch (252:25): [True: 0, False: 0]
  ------------------
  253|  83.2M|    uint32_t val;
  254|  83.2M|    BrotliFillBitWindow(br, n_bits);
  255|  83.2M|    BrotliTakeBits(br, n_bits, &val);
  256|  83.2M|    return val;
  257|  83.2M|  } 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|  83.2M|}
decode.c:BrotliBitReaderSaveState:
   67|   292M|    BrotliBitReader* const from, BrotliBitReaderState* to) {
   68|   292M|  to->val_ = from->val_;
   69|   292M|  to->bit_pos_ = from->bit_pos_;
   70|   292M|  to->next_in = from->next_in;
   71|   292M|  to->avail_in = from->avail_in;
   72|   292M|}
decode.c:BrotliBitReaderRestoreState:
   75|    825|    BrotliBitReader* const to, BrotliBitReaderState* from) {
   76|    825|  to->val_ = from->val_;
   77|    825|  to->bit_pos_ = from->bit_pos_;
   78|    825|  to->next_in = from->next_in;
   79|    825|  to->avail_in = from->avail_in;
   80|    825|}
decode.c:BrotliGetBits:
  199|   531M|    BrotliBitReader* const br, uint32_t n_bits) {
  200|   531M|  BrotliFillBitWindow(br, n_bits);
  201|   531M|  return (uint32_t)BrotliGetBitsUnmasked(br) & BitMask(n_bits);
  202|   531M|}
decode.c:BrotliGet16BitsUnmasked:
  191|   125M|    BrotliBitReader* const br) {
  192|   125M|  BrotliFillBitWindow(br, 16);
  193|   125M|  return (uint32_t)BrotliGetBitsUnmasked(br);
  194|   125M|}
decode.c:BrotliReadBits32:
  270|  1.31M|    BrotliBitReader* const br, uint32_t n_bits) {
  271|  1.31M|  BROTLI_DCHECK(n_bits <= 32);
  272|  1.31M|  if (BROTLI_64_BITS || (n_bits <= 16)) {
  ------------------
  |  |  235|  2.62M|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 1.31M, Folded]
  |  |  ------------------
  ------------------
  |  Branch (272:25): [True: 0, False: 0]
  ------------------
  273|  1.31M|    uint32_t val;
  274|  1.31M|    BrotliFillBitWindow(br, n_bits);
  275|  1.31M|    BrotliTakeBits(br, n_bits, &val);
  276|  1.31M|    return val;
  277|  1.31M|  } 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.31M|}
decode.c:BrotliSafeReadBits32:
  305|  4.13k|    BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
  306|  4.13k|  BROTLI_DCHECK(n_bits <= 32);
  307|  4.13k|  if (BROTLI_64_BITS || (n_bits <= 24)) {
  ------------------
  |  |  235|  8.26k|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 4.13k, Folded]
  |  |  ------------------
  ------------------
  |  Branch (307:25): [True: 0, False: 0]
  ------------------
  308|  4.23k|    while (BrotliGetAvailableBits(br) < n_bits) {
  ------------------
  |  Branch (308:12): [True: 333, False: 3.90k]
  ------------------
  309|    333|      if (!BrotliPullByte(br)) {
  ------------------
  |  Branch (309:11): [True: 226, False: 107]
  ------------------
  310|    226|        return BROTLI_FALSE;
  ------------------
  |  |   53|    226|#define BROTLI_FALSE 0
  ------------------
  311|    226|      }
  312|    333|    }
  313|  3.90k|    BrotliTakeBits(br, n_bits, val);
  314|  3.90k|    return BROTLI_TRUE;
  ------------------
  |  |   51|  3.90k|#define BROTLI_TRUE 1
  ------------------
  315|  4.13k|  } else {
  316|      0|    return BrotliSafeReadBits32Slow(br, n_bits, val);
  317|      0|  }
  318|  4.13k|}
decode.c:BrotliGetAvailableBits:
   83|  2.02G|    const BrotliBitReader* br) {
   84|  2.02G|  return (BROTLI_64_BITS ? 64 : 32) - br->bit_pos_;
  ------------------
  |  |  235|  2.02G|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 2.02G, Folded]
  |  |  ------------------
  ------------------
   85|  2.02G|}
bit_reader.c:BrotliGetAvailableBits:
   83|  72.0k|    const BrotliBitReader* br) {
   84|  72.0k|  return (BROTLI_64_BITS ? 64 : 32) - br->bit_pos_;
  ------------------
  |  |  235|  72.0k|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 72.0k, Folded]
  |  |  ------------------
  ------------------
   85|  72.0k|}
bit_reader.c:BrotliPullByte:
  165|  23.0k|static BROTLI_INLINE BROTLI_BOOL BrotliPullByte(BrotliBitReader* const br) {
  166|  23.0k|  if (br->avail_in == 0) {
  ------------------
  |  Branch (166:7): [True: 236, False: 22.8k]
  ------------------
  167|    236|    return BROTLI_FALSE;
  ------------------
  |  |   53|    236|#define BROTLI_FALSE 0
  ------------------
  168|    236|  }
  169|  22.8k|  br->val_ >>= 8;
  170|  22.8k|#if (BROTLI_64_BITS)
  171|  22.8k|  br->val_ |= ((uint64_t)*br->next_in) << 56;
  172|       |#else
  173|       |  br->val_ |= ((uint32_t)*br->next_in) << 24;
  174|       |#endif
  175|  22.8k|  br->bit_pos_ -= 8;
  176|  22.8k|  --br->avail_in;
  177|  22.8k|  ++br->next_in;
  178|  22.8k|  return BROTLI_TRUE;
  ------------------
  |  |   51|  22.8k|#define BROTLI_TRUE 1
  ------------------
  179|  23.0k|}

BrotliDecoderCreateInstance:
   78|  4.20k|    brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque) {
   79|  4.20k|  BrotliDecoderState* state = 0;
  ------------------
  |  |  342|  4.20k|#define BrotliDecoderState BrotliDecoderStateInternal
  ------------------
   80|  4.20k|  if (!alloc_func && !free_func) {
  ------------------
  |  Branch (80:7): [True: 4.20k, False: 0]
  |  Branch (80:22): [True: 4.20k, False: 0]
  ------------------
   81|  4.20k|    state = (BrotliDecoderState*)malloc(sizeof(BrotliDecoderState));
   82|  4.20k|  } 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|  4.20k|  if (state == 0) {
  ------------------
  |  Branch (85:7): [True: 0, False: 4.20k]
  ------------------
   86|      0|    BROTLI_DUMP();
  ------------------
  |  |  485|      0|#define BROTLI_DUMP() (void)(0)
  ------------------
   87|      0|    return 0;
   88|      0|  }
   89|  4.20k|  if (!BrotliDecoderStateInit(state, alloc_func, free_func, opaque)) {
  ------------------
  |  Branch (89:7): [True: 0, False: 4.20k]
  ------------------
   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|  4.20k|  return state;
   99|  4.20k|}
BrotliDecoderDestroyInstance:
  102|  4.20k|void BrotliDecoderDestroyInstance(BrotliDecoderState* state) {
  103|  4.20k|  if (!state) {
  ------------------
  |  Branch (103:7): [True: 0, False: 4.20k]
  ------------------
  104|      0|    return;
  105|  4.20k|  } else {
  106|  4.20k|    brotli_free_func free_func = state->free_func;
  107|  4.20k|    void* opaque = state->memory_manager_opaque;
  108|  4.20k|    BrotliDecoderStateCleanup(state);
  109|  4.20k|    free_func(opaque, state);
  110|  4.20k|  }
  111|  4.20k|}
BrotliDecoderDecompressStream:
 2071|   168k|    size_t* available_out, uint8_t** next_out, size_t* total_out) {
 2072|   168k|  BrotliDecoderErrorCode result = BROTLI_DECODER_SUCCESS;
 2073|   168k|  BrotliBitReader* br = &s->br;
 2074|       |  /* Ensure that |total_out| is set, even if no data will ever be pushed out. */
 2075|   168k|  if (total_out) {
  ------------------
  |  Branch (2075:7): [True: 0, False: 168k]
  ------------------
 2076|      0|    *total_out = s->partial_pos_out;
 2077|      0|  }
 2078|       |  /* Do not try to process further in a case of unrecoverable error. */
 2079|   168k|  if ((int)s->error_code < 0) {
  ------------------
  |  Branch (2079:7): [True: 0, False: 168k]
  ------------------
 2080|      0|    return BROTLI_DECODER_RESULT_ERROR;
 2081|      0|  }
 2082|   168k|  if (*available_out && (!next_out || !*next_out)) {
  ------------------
  |  Branch (2082:7): [True: 0, False: 168k]
  |  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|   168k|  if (!*available_out) next_out = 0;
  ------------------
  |  Branch (2086:7): [True: 168k, False: 0]
  ------------------
 2087|   168k|  if (s->buffer_length == 0) {  /* Just connect bit reader to input stream. */
  ------------------
  |  Branch (2087:7): [True: 168k, False: 0]
  ------------------
 2088|   168k|    br->avail_in = *available_in;
 2089|   168k|    br->next_in = *next_in;
 2090|   168k|  } 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|   720k|  for (;;) {
 2099|   720k|    if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (2099:9): [True: 168k, False: 552k]
  ------------------
 2100|       |      /* Error, needs more input/output. */
 2101|   168k|      if (result == BROTLI_DECODER_NEEDS_MORE_INPUT) {
  ------------------
  |  Branch (2101:11): [True: 2.64k, False: 166k]
  ------------------
 2102|  2.64k|        if (s->ringbuffer != 0) {  /* Pro-actively push output. */
  ------------------
  |  Branch (2102:13): [True: 1.51k, False: 1.12k]
  ------------------
 2103|  1.51k|          BrotliDecoderErrorCode intermediate_result = WriteRingBuffer(s,
 2104|  1.51k|              available_out, next_out, total_out, BROTLI_TRUE);
  ------------------
  |  |   51|  1.51k|#define BROTLI_TRUE 1
  ------------------
 2105|       |          /* WriteRingBuffer checks s->meta_block_remaining_len validity. */
 2106|  1.51k|          if ((int)intermediate_result < 0) {
  ------------------
  |  Branch (2106:15): [True: 12, False: 1.50k]
  ------------------
 2107|     12|            result = intermediate_result;
 2108|     12|            break;
 2109|     12|          }
 2110|  1.51k|        }
 2111|  2.62k|        if (s->buffer_length != 0) {  /* Used with internal buffer. */
  ------------------
  |  Branch (2111:13): [True: 0, False: 2.62k]
  ------------------
 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.62k|        } else {  /* Input stream doesn't contain enough input. */
 2137|       |          /* Copy tail to internal buffer and return. */
 2138|  2.62k|          *next_in = br->next_in;
 2139|  2.62k|          *available_in = br->avail_in;
 2140|  2.69k|          while (*available_in) {
  ------------------
  |  Branch (2140:18): [True: 62, False: 2.62k]
  ------------------
 2141|     62|            s->buffer.u8[s->buffer_length] = **next_in;
 2142|     62|            s->buffer_length++;
 2143|     62|            (*next_in)++;
 2144|     62|            (*available_in)--;
 2145|     62|          }
 2146|  2.62k|          break;
 2147|  2.62k|        }
 2148|       |        /* Unreachable. */
 2149|  2.62k|      }
 2150|       |
 2151|       |      /* Fail or needs more output. */
 2152|       |
 2153|   166k|      if (s->buffer_length != 0) {
  ------------------
  |  Branch (2153:11): [True: 0, False: 166k]
  ------------------
 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|   166k|      } 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|   166k|        BrotliBitReaderUnload(br);
 2162|   166k|        *available_in = br->avail_in;
 2163|   166k|        *next_in = br->next_in;
 2164|   166k|      }
 2165|   166k|      break;
 2166|   168k|    }
 2167|   552k|    switch (s->state) {
  ------------------
  |  Branch (2167:13): [True: 552k, False: 0]
  ------------------
 2168|  4.20k|      case BROTLI_STATE_UNINITED:
  ------------------
  |  Branch (2168:7): [True: 4.20k, False: 548k]
  ------------------
 2169|       |        /* Prepare to the first read. */
 2170|  4.20k|        if (!BrotliWarmupBitReader(br)) {
  ------------------
  |  Branch (2170:13): [True: 191, False: 4.01k]
  ------------------
 2171|    191|          result = BROTLI_DECODER_NEEDS_MORE_INPUT;
 2172|    191|          break;
 2173|    191|        }
 2174|       |        /* Decode window size. */
 2175|  4.01k|        result = DecodeWindowBits(s, br);  /* Reads 1..8 bits. */
 2176|  4.01k|        if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (2176:13): [True: 1, False: 4.01k]
  ------------------
 2177|      1|          break;
 2178|      1|        }
 2179|  4.01k|        if (s->large_window) {
  ------------------
  |  Branch (2179:13): [True: 0, False: 4.01k]
  ------------------
 2180|      0|          s->state = BROTLI_STATE_LARGE_WINDOW_BITS;
 2181|      0|          break;
 2182|      0|        }
 2183|  4.01k|        s->state = BROTLI_STATE_INITIALIZE;
 2184|  4.01k|        break;
 2185|       |
 2186|      0|      case BROTLI_STATE_LARGE_WINDOW_BITS:
  ------------------
  |  Branch (2186:7): [True: 0, False: 552k]
  ------------------
 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|  4.01k|      case BROTLI_STATE_INITIALIZE:
  ------------------
  |  Branch (2199:7): [True: 4.01k, False: 548k]
  ------------------
 2200|  4.01k|        BROTLI_LOG_UINT(s->window_bits);
 2201|       |        /* Maximum distance, see section 9.1. of the spec. */
 2202|  4.01k|        s->max_backward_distance = (1 << s->window_bits) - BROTLI_WINDOW_GAP;
  ------------------
  |  |  102|  4.01k|#define BROTLI_WINDOW_GAP 16
  ------------------
 2203|       |
 2204|       |        /* Allocate memory for both block_type_trees and block_len_trees. */
 2205|  4.01k|        s->block_type_trees = (HuffmanCode*)BROTLI_DECODER_ALLOC(s,
  ------------------
  |  |  354|  4.01k|#define BROTLI_DECODER_ALLOC(S, L) S->alloc_func(S->memory_manager_opaque, L)
  ------------------
 2206|  4.01k|            sizeof(HuffmanCode) * 3 *
 2207|  4.01k|                (BROTLI_HUFFMAN_MAX_SIZE_258 + BROTLI_HUFFMAN_MAX_SIZE_26));
 2208|  4.01k|        if (s->block_type_trees == 0) {
  ------------------
  |  Branch (2208:13): [True: 0, False: 4.01k]
  ------------------
 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|  4.01k|        s->block_len_trees =
 2213|  4.01k|            s->block_type_trees + 3 * BROTLI_HUFFMAN_MAX_SIZE_258;
  ------------------
  |  |   24|  4.01k|#define BROTLI_HUFFMAN_MAX_SIZE_258 632
  ------------------
 2214|       |
 2215|  4.01k|        s->state = BROTLI_STATE_METABLOCK_BEGIN;
 2216|       |      /* Fall through. */
 2217|       |
 2218|  14.3k|      case BROTLI_STATE_METABLOCK_BEGIN:
  ------------------
  |  Branch (2218:7): [True: 10.3k, False: 541k]
  ------------------
 2219|  14.3k|        BrotliDecoderStateMetablockBegin(s);
 2220|  14.3k|        BROTLI_LOG_UINT(s->pos);
 2221|  14.3k|        s->state = BROTLI_STATE_METABLOCK_HEADER;
 2222|       |      /* Fall through. */
 2223|       |
 2224|  14.3k|      case BROTLI_STATE_METABLOCK_HEADER:
  ------------------
  |  Branch (2224:7): [True: 0, False: 552k]
  ------------------
 2225|  14.3k|        result = DecodeMetaBlockLength(s, br);  /* Reads 2 - 31 bits. */
 2226|  14.3k|        if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (2226:13): [True: 232, False: 14.1k]
  ------------------
 2227|    232|          break;
 2228|    232|        }
 2229|  14.1k|        BROTLI_LOG_UINT(s->is_last_metablock);
 2230|  14.1k|        BROTLI_LOG_UINT(s->meta_block_remaining_len);
 2231|  14.1k|        BROTLI_LOG_UINT(s->is_metadata);
 2232|  14.1k|        BROTLI_LOG_UINT(s->is_uncompressed);
 2233|  14.1k|        if (s->is_metadata || s->is_uncompressed) {
  ------------------
  |  Branch (2233:13): [True: 2.78k, False: 11.3k]
  |  Branch (2233:31): [True: 1.46k, False: 9.85k]
  ------------------
 2234|  4.25k|          if (!BrotliJumpToByteBoundary(br)) {
  ------------------
  |  Branch (2234:15): [True: 28, False: 4.22k]
  ------------------
 2235|     28|            result = BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_PADDING_1);
  ------------------
  |  |   31|     28|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|     28|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 2236|     28|            break;
 2237|     28|          }
 2238|  4.25k|        }
 2239|  14.0k|        if (s->is_metadata) {
  ------------------
  |  Branch (2239:13): [True: 2.77k, False: 11.3k]
  ------------------
 2240|  2.77k|          s->state = BROTLI_STATE_METADATA;
 2241|  2.77k|          break;
 2242|  2.77k|        }
 2243|  11.3k|        if (s->meta_block_remaining_len == 0) {
  ------------------
  |  Branch (2243:13): [True: 137, False: 11.1k]
  ------------------
 2244|    137|          s->state = BROTLI_STATE_METABLOCK_DONE;
 2245|    137|          break;
 2246|    137|        }
 2247|  11.1k|        BrotliCalculateRingBufferSize(s);
 2248|  11.1k|        if (s->is_uncompressed) {
  ------------------
  |  Branch (2248:13): [True: 1.45k, False: 9.71k]
  ------------------
 2249|  1.45k|          s->state = BROTLI_STATE_UNCOMPRESSED;
 2250|  1.45k|          break;
 2251|  1.45k|        }
 2252|  9.71k|        s->state = BROTLI_STATE_BEFORE_COMPRESSED_METABLOCK_HEADER;
 2253|       |      /* Fall through. */
 2254|       |
 2255|  9.71k|      case BROTLI_STATE_BEFORE_COMPRESSED_METABLOCK_HEADER: {
  ------------------
  |  Branch (2255:7): [True: 0, False: 552k]
  ------------------
 2256|  9.71k|        BrotliMetablockHeaderArena* h = &s->arena.header;
 2257|  9.71k|        s->loop_counter = 0;
 2258|       |        /* Initialize compressed metablock header arena. */
 2259|  9.71k|        h->sub_loop_counter = 0;
 2260|       |        /* Make small negative indexes addressable. */
 2261|  9.71k|        h->symbol_lists =
 2262|  9.71k|            &h->symbols_lists_array[BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1];
  ------------------
  |  |   19|  9.71k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH 15
  ------------------
 2263|  9.71k|        h->substate_huffman = BROTLI_STATE_HUFFMAN_NONE;
 2264|  9.71k|        h->substate_tree_group = BROTLI_STATE_TREE_GROUP_NONE;
 2265|  9.71k|        h->substate_context_map = BROTLI_STATE_CONTEXT_MAP_NONE;
 2266|  9.71k|        s->state = BROTLI_STATE_HUFFMAN_CODE_0;
 2267|  9.71k|      }
 2268|       |      /* Fall through. */
 2269|       |
 2270|  37.7k|      case BROTLI_STATE_HUFFMAN_CODE_0:
  ------------------
  |  Branch (2270:7): [True: 28.0k, False: 524k]
  ------------------
 2271|  37.7k|        if (s->loop_counter >= 3) {
  ------------------
  |  Branch (2271:13): [True: 9.27k, False: 28.5k]
  ------------------
 2272|  9.27k|          s->state = BROTLI_STATE_METABLOCK_HEADER_2;
 2273|  9.27k|          break;
 2274|  9.27k|        }
 2275|       |        /* Reads 1..11 bits. */
 2276|  28.5k|        result = DecodeVarLenUint8(s, br, &s->num_block_types[s->loop_counter]);
 2277|  28.5k|        if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (2277:13): [True: 37, False: 28.4k]
  ------------------
 2278|     37|          break;
 2279|     37|        }
 2280|  28.4k|        s->num_block_types[s->loop_counter]++;
 2281|  28.4k|        BROTLI_LOG_UINT(s->num_block_types[s->loop_counter]);
 2282|  28.4k|        if (s->num_block_types[s->loop_counter] < 2) {
  ------------------
  |  Branch (2282:13): [True: 24.8k, False: 3.64k]
  ------------------
 2283|  24.8k|          s->loop_counter++;
 2284|  24.8k|          break;
 2285|  24.8k|        }
 2286|  3.64k|        s->state = BROTLI_STATE_HUFFMAN_CODE_1;
 2287|       |      /* Fall through. */
 2288|       |
 2289|  3.64k|      case BROTLI_STATE_HUFFMAN_CODE_1: {
  ------------------
  |  Branch (2289:7): [True: 0, False: 552k]
  ------------------
 2290|  3.64k|        uint32_t alphabet_size = s->num_block_types[s->loop_counter] + 2;
 2291|  3.64k|        int tree_offset = s->loop_counter * BROTLI_HUFFMAN_MAX_SIZE_258;
  ------------------
  |  |   24|  3.64k|#define BROTLI_HUFFMAN_MAX_SIZE_258 632
  ------------------
 2292|  3.64k|        result = ReadHuffmanCode(alphabet_size, alphabet_size,
 2293|  3.64k|            &s->block_type_trees[tree_offset], NULL, s);
 2294|  3.64k|        if (result != BROTLI_DECODER_SUCCESS) break;
  ------------------
  |  Branch (2294:13): [True: 246, False: 3.39k]
  ------------------
 2295|  3.39k|        s->state = BROTLI_STATE_HUFFMAN_CODE_2;
 2296|  3.39k|      }
 2297|       |      /* Fall through. */
 2298|       |
 2299|  3.39k|      case BROTLI_STATE_HUFFMAN_CODE_2: {
  ------------------
  |  Branch (2299:7): [True: 0, False: 552k]
  ------------------
 2300|  3.39k|        uint32_t alphabet_size = BROTLI_NUM_BLOCK_LEN_SYMBOLS;
  ------------------
  |  |   28|  3.39k|#define BROTLI_NUM_BLOCK_LEN_SYMBOLS 26
  ------------------
 2301|  3.39k|        int tree_offset = s->loop_counter * BROTLI_HUFFMAN_MAX_SIZE_26;
  ------------------
  |  |   22|  3.39k|#define BROTLI_HUFFMAN_MAX_SIZE_26 396
  ------------------
 2302|  3.39k|        result = ReadHuffmanCode(alphabet_size, alphabet_size,
 2303|  3.39k|            &s->block_len_trees[tree_offset], NULL, s);
 2304|  3.39k|        if (result != BROTLI_DECODER_SUCCESS) break;
  ------------------
  |  Branch (2304:13): [True: 108, False: 3.28k]
  ------------------
 2305|  3.28k|        s->state = BROTLI_STATE_HUFFMAN_CODE_3;
 2306|  3.28k|      }
 2307|       |      /* Fall through. */
 2308|       |
 2309|  3.28k|      case BROTLI_STATE_HUFFMAN_CODE_3: {
  ------------------
  |  Branch (2309:7): [True: 0, False: 552k]
  ------------------
 2310|  3.28k|        int tree_offset = s->loop_counter * BROTLI_HUFFMAN_MAX_SIZE_26;
  ------------------
  |  |   22|  3.28k|#define BROTLI_HUFFMAN_MAX_SIZE_26 396
  ------------------
 2311|  3.28k|        if (!SafeReadBlockLength(s, &s->block_length[s->loop_counter],
  ------------------
  |  Branch (2311:13): [True: 45, False: 3.24k]
  ------------------
 2312|  3.28k|            &s->block_len_trees[tree_offset], br)) {
 2313|     45|          result = BROTLI_DECODER_NEEDS_MORE_INPUT;
 2314|     45|          break;
 2315|     45|        }
 2316|  3.24k|        BROTLI_LOG_UINT(s->block_length[s->loop_counter]);
 2317|  3.24k|        s->loop_counter++;
 2318|  3.24k|        s->state = BROTLI_STATE_HUFFMAN_CODE_0;
 2319|  3.24k|        break;
 2320|  3.28k|      }
 2321|       |
 2322|  2.61k|      case BROTLI_STATE_UNCOMPRESSED: {
  ------------------
  |  Branch (2322:7): [True: 2.61k, False: 549k]
  ------------------
 2323|  2.61k|        result = CopyUncompressedBlockToOutput(
 2324|  2.61k|            available_out, next_out, total_out, s);
 2325|  2.61k|        if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (2325:13): [True: 1.38k, False: 1.23k]
  ------------------
 2326|  1.38k|          break;
 2327|  1.38k|        }
 2328|  1.23k|        s->state = BROTLI_STATE_METABLOCK_DONE;
 2329|  1.23k|        break;
 2330|  2.61k|      }
 2331|       |
 2332|  2.77k|      case BROTLI_STATE_METADATA:
  ------------------
  |  Branch (2332:7): [True: 2.77k, False: 549k]
  ------------------
 2333|   459k|        for (; s->meta_block_remaining_len > 0; --s->meta_block_remaining_len) {
  ------------------
  |  Branch (2333:16): [True: 456k, False: 2.71k]
  ------------------
 2334|   456k|          uint32_t bits;
 2335|       |          /* Read one byte and ignore it. */
 2336|   456k|          if (!BrotliSafeReadBits(br, 8, &bits)) {
  ------------------
  |  Branch (2336:15): [True: 60, False: 456k]
  ------------------
 2337|     60|            result = BROTLI_DECODER_NEEDS_MORE_INPUT;
 2338|     60|            break;
 2339|     60|          }
 2340|   456k|        }
 2341|  2.77k|        if (result == BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (2341:13): [True: 2.71k, False: 60]
  ------------------
 2342|  2.71k|          s->state = BROTLI_STATE_METABLOCK_DONE;
 2343|  2.71k|        }
 2344|  2.77k|        break;
 2345|       |
 2346|  9.27k|      case BROTLI_STATE_METABLOCK_HEADER_2: {
  ------------------
  |  Branch (2346:7): [True: 9.27k, False: 543k]
  ------------------
 2347|  9.27k|        uint32_t bits;
 2348|  9.27k|        if (!BrotliSafeReadBits(br, 6, &bits)) {
  ------------------
  |  Branch (2348:13): [True: 50, False: 9.22k]
  ------------------
 2349|     50|          result = BROTLI_DECODER_NEEDS_MORE_INPUT;
 2350|     50|          break;
 2351|     50|        }
 2352|  9.22k|        s->distance_postfix_bits = bits & BitMask(2);
 2353|  9.22k|        bits >>= 2;
 2354|  9.22k|        s->num_direct_distance_codes = bits << s->distance_postfix_bits;
 2355|  9.22k|        BROTLI_LOG_UINT(s->num_direct_distance_codes);
 2356|  9.22k|        BROTLI_LOG_UINT(s->distance_postfix_bits);
 2357|  9.22k|        s->context_modes =
 2358|  9.22k|            (uint8_t*)BROTLI_DECODER_ALLOC(s, (size_t)s->num_block_types[0]);
  ------------------
  |  |  354|  9.22k|#define BROTLI_DECODER_ALLOC(S, L) S->alloc_func(S->memory_manager_opaque, L)
  ------------------
 2359|  9.22k|        if (s->context_modes == 0) {
  ------------------
  |  Branch (2359:13): [True: 0, False: 9.22k]
  ------------------
 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|  9.22k|        s->loop_counter = 0;
 2364|  9.22k|        s->state = BROTLI_STATE_CONTEXT_MODES;
 2365|  9.22k|      }
 2366|       |      /* Fall through. */
 2367|       |
 2368|  9.22k|      case BROTLI_STATE_CONTEXT_MODES:
  ------------------
  |  Branch (2368:7): [True: 0, False: 552k]
  ------------------
 2369|  9.22k|        result = ReadContextModes(s);
 2370|  9.22k|        if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (2370:13): [True: 23, False: 9.20k]
  ------------------
 2371|     23|          break;
 2372|     23|        }
 2373|  9.20k|        s->state = BROTLI_STATE_CONTEXT_MAP_1;
 2374|       |      /* Fall through. */
 2375|       |
 2376|  9.20k|      case BROTLI_STATE_CONTEXT_MAP_1:
  ------------------
  |  Branch (2376:7): [True: 0, False: 552k]
  ------------------
 2377|  9.20k|        result = DecodeContextMap(
 2378|  9.20k|            s->num_block_types[0] << BROTLI_LITERAL_CONTEXT_BITS,
  ------------------
  |  |   94|  9.20k|#define BROTLI_LITERAL_CONTEXT_BITS 6
  ------------------
 2379|  9.20k|            &s->num_literal_htrees, &s->context_map, s);
 2380|  9.20k|        if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (2380:13): [True: 168, False: 9.03k]
  ------------------
 2381|    168|          break;
 2382|    168|        }
 2383|  9.03k|        DetectTrivialLiteralBlockTypes(s);
 2384|  9.03k|        s->state = BROTLI_STATE_CONTEXT_MAP_2;
 2385|       |      /* Fall through. */
 2386|       |
 2387|  9.03k|      case BROTLI_STATE_CONTEXT_MAP_2: {
  ------------------
  |  Branch (2387:7): [True: 0, False: 552k]
  ------------------
 2388|  9.03k|        uint32_t npostfix = s->distance_postfix_bits;
 2389|  9.03k|        uint32_t ndirect = s->num_direct_distance_codes;
 2390|  9.03k|        uint32_t distance_alphabet_size_max = BROTLI_DISTANCE_ALPHABET_SIZE(
  ------------------
  |  |   69|  9.03k|#define BROTLI_DISTANCE_ALPHABET_SIZE(NPOSTFIX, NDIRECT, MAXNBITS) ( \
  |  |   70|  9.03k|    BROTLI_NUM_DISTANCE_SHORT_CODES + (NDIRECT) +                    \
  |  |  ------------------
  |  |  |  |   60|  9.03k|#define BROTLI_NUM_DISTANCE_SHORT_CODES 16
  |  |  ------------------
  |  |   71|  9.03k|    ((MAXNBITS) << ((NPOSTFIX) + 1)))
  ------------------
 2391|  9.03k|            npostfix, ndirect, BROTLI_MAX_DISTANCE_BITS);
 2392|  9.03k|        uint32_t distance_alphabet_size_limit = distance_alphabet_size_max;
 2393|  9.03k|        BROTLI_BOOL allocation_success = BROTLI_TRUE;
  ------------------
  |  |   49|  9.03k|#define BROTLI_BOOL int
  ------------------
                      BROTLI_BOOL allocation_success = BROTLI_TRUE;
  ------------------
  |  |   51|  9.03k|#define BROTLI_TRUE 1
  ------------------
 2394|  9.03k|        if (s->large_window) {
  ------------------
  |  Branch (2394:13): [True: 0, False: 9.03k]
  ------------------
 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|  9.03k|        result = DecodeContextMap(
 2402|  9.03k|            s->num_block_types[2] << BROTLI_DISTANCE_CONTEXT_BITS,
  ------------------
  |  |   97|  9.03k|#define BROTLI_DISTANCE_CONTEXT_BITS 2
  ------------------
 2403|  9.03k|            &s->num_dist_htrees, &s->dist_context_map, s);
 2404|  9.03k|        if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (2404:13): [True: 138, False: 8.89k]
  ------------------
 2405|    138|          break;
 2406|    138|        }
 2407|  8.89k|        allocation_success &= BrotliDecoderHuffmanTreeGroupInit(
 2408|  8.89k|            s, &s->literal_hgroup, BROTLI_NUM_LITERAL_SYMBOLS,
  ------------------
  |  |   26|  8.89k|#define BROTLI_NUM_LITERAL_SYMBOLS 256
  ------------------
 2409|  8.89k|            BROTLI_NUM_LITERAL_SYMBOLS, s->num_literal_htrees);
  ------------------
  |  |   26|  8.89k|#define BROTLI_NUM_LITERAL_SYMBOLS 256
  ------------------
 2410|  8.89k|        allocation_success &= BrotliDecoderHuffmanTreeGroupInit(
 2411|  8.89k|            s, &s->insert_copy_hgroup, BROTLI_NUM_COMMAND_SYMBOLS,
  ------------------
  |  |   27|  8.89k|#define BROTLI_NUM_COMMAND_SYMBOLS 704
  ------------------
 2412|  8.89k|            BROTLI_NUM_COMMAND_SYMBOLS, s->num_block_types[1]);
  ------------------
  |  |   27|  8.89k|#define BROTLI_NUM_COMMAND_SYMBOLS 704
  ------------------
 2413|  8.89k|        allocation_success &= BrotliDecoderHuffmanTreeGroupInit(
 2414|  8.89k|            s, &s->distance_hgroup, distance_alphabet_size_max,
 2415|  8.89k|            distance_alphabet_size_limit, s->num_dist_htrees);
 2416|  8.89k|        if (!allocation_success) {
  ------------------
  |  Branch (2416:13): [True: 0, False: 8.89k]
  ------------------
 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.89k|        s->loop_counter = 0;
 2421|  8.89k|        s->state = BROTLI_STATE_TREE_GROUP;
 2422|  8.89k|      }
 2423|       |      /* Fall through. */
 2424|       |
 2425|  25.9k|      case BROTLI_STATE_TREE_GROUP: {
  ------------------
  |  Branch (2425:7): [True: 17.0k, False: 535k]
  ------------------
 2426|  25.9k|        HuffmanTreeGroup* hgroup = NULL;
 2427|  25.9k|        switch (s->loop_counter) {
 2428|  8.89k|          case 0: hgroup = &s->literal_hgroup; break;
  ------------------
  |  Branch (2428:11): [True: 8.89k, False: 17.0k]
  ------------------
 2429|  8.61k|          case 1: hgroup = &s->insert_copy_hgroup; break;
  ------------------
  |  Branch (2429:11): [True: 8.61k, False: 17.3k]
  ------------------
 2430|  8.48k|          case 2: hgroup = &s->distance_hgroup; break;
  ------------------
  |  Branch (2430:11): [True: 8.48k, False: 17.5k]
  ------------------
 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: 25.9k]
  ------------------
 2432|      0|              BROTLI_DECODER_ERROR_UNREACHABLE));
 2433|  25.9k|        }
 2434|  25.9k|        result = HuffmanTreeGroupDecode(hgroup, s);
 2435|  25.9k|        if (result != BROTLI_DECODER_SUCCESS) break;
  ------------------
  |  Branch (2435:13): [True: 552, False: 25.4k]
  ------------------
 2436|  25.4k|        s->loop_counter++;
 2437|  25.4k|        if (s->loop_counter < 3) {
  ------------------
  |  Branch (2437:13): [True: 17.0k, False: 8.34k]
  ------------------
 2438|  17.0k|          break;
 2439|  17.0k|        }
 2440|  8.34k|        s->state = BROTLI_STATE_BEFORE_COMPRESSED_METABLOCK_BODY;
 2441|  8.34k|      }
 2442|       |      /* Fall through. */
 2443|       |
 2444|  8.34k|      case BROTLI_STATE_BEFORE_COMPRESSED_METABLOCK_BODY:
  ------------------
  |  Branch (2444:7): [True: 0, False: 552k]
  ------------------
 2445|  8.34k|        PrepareLiteralDecoding(s);
 2446|  8.34k|        s->dist_context_map_slice = s->dist_context_map;
 2447|  8.34k|        s->htree_command = s->insert_copy_hgroup.htrees[0];
 2448|  8.34k|        if (!BrotliEnsureRingBuffer(s)) {
  ------------------
  |  Branch (2448:13): [True: 0, False: 8.34k]
  ------------------
 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|  8.34k|        CalculateDistanceLut(s);
 2453|  8.34k|        s->state = BROTLI_STATE_COMMAND_BEGIN;
 2454|       |      /* Fall through. */
 2455|       |
 2456|  26.2k|      case BROTLI_STATE_COMMAND_BEGIN:
  ------------------
  |  Branch (2456:7): [True: 17.9k, False: 534k]
  ------------------
 2457|       |      /* Fall through. */
 2458|  63.0k|      case BROTLI_STATE_COMMAND_INNER:
  ------------------
  |  Branch (2458:7): [True: 36.7k, False: 515k]
  ------------------
 2459|       |      /* Fall through. */
 2460|  86.1k|      case BROTLI_STATE_COMMAND_POST_DECODE_LITERALS:
  ------------------
  |  Branch (2460:7): [True: 23.1k, False: 529k]
  ------------------
 2461|       |      /* Fall through. */
 2462|   157k|      case BROTLI_STATE_COMMAND_POST_WRAP_COPY:
  ------------------
  |  Branch (2462:7): [True: 71.7k, False: 480k]
  ------------------
 2463|   157k|        result = ProcessCommands(s);
 2464|   157k|        if (result == BROTLI_DECODER_NEEDS_MORE_INPUT) {
  ------------------
  |  Branch (2464:13): [True: 127k, False: 29.9k]
  ------------------
 2465|   127k|          result = SafeProcessCommands(s);
 2466|   127k|        }
 2467|   157k|        break;
 2468|       |
 2469|   120k|      case BROTLI_STATE_COMMAND_INNER_WRITE:
  ------------------
  |  Branch (2469:7): [True: 120k, False: 432k]
  ------------------
 2470|       |      /* Fall through. */
 2471|   169k|      case BROTLI_STATE_COMMAND_POST_WRITE_1:
  ------------------
  |  Branch (2471:7): [True: 49.7k, False: 502k]
  ------------------
 2472|       |      /* Fall through. */
 2473|   313k|      case BROTLI_STATE_COMMAND_POST_WRITE_2:
  ------------------
  |  Branch (2473:7): [True: 143k, False: 408k]
  ------------------
 2474|   313k|        result = WriteRingBuffer(
 2475|   313k|            s, available_out, next_out, total_out, BROTLI_FALSE);
  ------------------
  |  |   53|   313k|#define BROTLI_FALSE 0
  ------------------
 2476|   313k|        if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (2476:13): [True: 163k, False: 149k]
  ------------------
 2477|   163k|          break;
 2478|   163k|        }
 2479|   149k|        WrapRingBuffer(s);
 2480|   149k|        if (s->ringbuffer_size == 1 << s->window_bits) {
  ------------------
  |  Branch (2480:13): [True: 149k, False: 22]
  ------------------
 2481|   149k|          s->max_distance = s->max_backward_distance;
 2482|   149k|        }
 2483|   149k|        if (s->state == BROTLI_STATE_COMMAND_POST_WRITE_1) {
  ------------------
  |  Branch (2483:13): [True: 17.9k, False: 131k]
  ------------------
 2484|  17.9k|          if (s->meta_block_remaining_len == 0) {
  ------------------
  |  Branch (2484:15): [True: 14, False: 17.9k]
  ------------------
 2485|       |            /* Next metablock, if any. */
 2486|     14|            s->state = BROTLI_STATE_METABLOCK_DONE;
 2487|  17.9k|          } else {
 2488|  17.9k|            s->state = BROTLI_STATE_COMMAND_BEGIN;
 2489|  17.9k|          }
 2490|  17.9k|          break;
 2491|   131k|        } else if (s->state == BROTLI_STATE_COMMAND_POST_WRITE_2) {
  ------------------
  |  Branch (2491:20): [True: 71.7k, False: 59.9k]
  ------------------
 2492|  71.7k|          s->state = BROTLI_STATE_COMMAND_POST_WRAP_COPY;
 2493|  71.7k|        } else {  /* BROTLI_STATE_COMMAND_INNER_WRITE */
 2494|  59.9k|          if (s->loop_counter == 0) {
  ------------------
  |  Branch (2494:15): [True: 23.2k, False: 36.7k]
  ------------------
 2495|  23.2k|            if (s->meta_block_remaining_len == 0) {
  ------------------
  |  Branch (2495:17): [True: 128, False: 23.1k]
  ------------------
 2496|    128|              s->state = BROTLI_STATE_METABLOCK_DONE;
 2497|  23.1k|            } else {
 2498|  23.1k|              s->state = BROTLI_STATE_COMMAND_POST_DECODE_LITERALS;
 2499|  23.1k|            }
 2500|  23.2k|            break;
 2501|  23.2k|          }
 2502|  36.7k|          s->state = BROTLI_STATE_COMMAND_INNER;
 2503|  36.7k|        }
 2504|   108k|        break;
 2505|       |
 2506|   108k|      case BROTLI_STATE_METABLOCK_DONE:
  ------------------
  |  Branch (2506:7): [True: 10.9k, False: 541k]
  ------------------
 2507|  10.9k|        if (s->meta_block_remaining_len < 0) {
  ------------------
  |  Branch (2507:13): [True: 374, False: 10.5k]
  ------------------
 2508|    374|          result = BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2);
  ------------------
  |  |   31|    374|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|    374|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 2509|    374|          break;
 2510|    374|        }
 2511|  10.5k|        BrotliDecoderStateCleanupAfterMetablock(s);
 2512|  10.5k|        if (!s->is_last_metablock) {
  ------------------
  |  Branch (2512:13): [True: 10.3k, False: 214]
  ------------------
 2513|  10.3k|          s->state = BROTLI_STATE_METABLOCK_BEGIN;
 2514|  10.3k|          break;
 2515|  10.3k|        }
 2516|    214|        if (!BrotliJumpToByteBoundary(br)) {
  ------------------
  |  Branch (2516:13): [True: 33, False: 181]
  ------------------
 2517|     33|          result = BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_PADDING_2);
  ------------------
  |  |   31|     33|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|     33|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 2518|     33|          break;
 2519|     33|        }
 2520|    181|        if (s->buffer_length == 0) {
  ------------------
  |  Branch (2520:13): [True: 181, False: 0]
  ------------------
 2521|    181|          BrotliBitReaderUnload(br);
 2522|    181|          *available_in = br->avail_in;
 2523|    181|          *next_in = br->next_in;
 2524|    181|        }
 2525|    181|        s->state = BROTLI_STATE_DONE;
 2526|       |      /* Fall through. */
 2527|       |
 2528|    191|      case BROTLI_STATE_DONE:
  ------------------
  |  Branch (2528:7): [True: 10, False: 552k]
  ------------------
 2529|    191|        if (s->ringbuffer != 0) {
  ------------------
  |  Branch (2529:13): [True: 31, False: 160]
  ------------------
 2530|     31|          result = WriteRingBuffer(
 2531|     31|              s, available_out, next_out, total_out, BROTLI_TRUE);
  ------------------
  |  |   51|     31|#define BROTLI_TRUE 1
  ------------------
 2532|     31|          if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (2532:15): [True: 21, False: 10]
  ------------------
 2533|     21|            break;
 2534|     21|          }
 2535|     31|        }
 2536|    170|        return SaveErrorCode(s, result);
 2537|   552k|    }
 2538|   552k|  }
 2539|   168k|  return SaveErrorCode(s, result);
 2540|   168k|}
BrotliDecoderTakeOutput:
 2551|   167k|const uint8_t* BrotliDecoderTakeOutput(BrotliDecoderState* s, size_t* size) {
 2552|   167k|  uint8_t* result = 0;
 2553|   167k|  size_t available_out = *size ? *size : 1u << 24;
  ------------------
  |  Branch (2553:26): [True: 0, False: 167k]
  ------------------
 2554|   167k|  size_t requested_out = available_out;
 2555|   167k|  BrotliDecoderErrorCode status;
 2556|   167k|  if ((s->ringbuffer == 0) || ((int)s->error_code < 0)) {
  ------------------
  |  Branch (2556:7): [True: 1.28k, False: 166k]
  |  Branch (2556:31): [True: 0, False: 166k]
  ------------------
 2557|  1.28k|    *size = 0;
 2558|  1.28k|    return 0;
 2559|  1.28k|  }
 2560|   166k|  WrapRingBuffer(s);
 2561|   166k|  status = WriteRingBuffer(s, &available_out, &result, 0, BROTLI_TRUE);
  ------------------
  |  |   51|   166k|#define BROTLI_TRUE 1
  ------------------
 2562|       |  /* Either WriteRingBuffer returns those "success" codes... */
 2563|   166k|  if (status == BROTLI_DECODER_SUCCESS ||
  ------------------
  |  Branch (2563:7): [True: 166k, False: 0]
  ------------------
 2564|   166k|      status == BROTLI_DECODER_NEEDS_MORE_OUTPUT) {
  ------------------
  |  Branch (2564:7): [True: 0, False: 0]
  ------------------
 2565|   166k|    *size = requested_out - available_out;
 2566|   166k|  } 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|   166k|  return result;
 2574|   167k|}
decode.c:SaveErrorCode:
  115|   168k|    BrotliDecoderState* s, BrotliDecoderErrorCode e) {
  116|   168k|  s->error_code = (int)e;
  117|   168k|  switch (e) {
  118|    170|    case BROTLI_DECODER_SUCCESS:
  ------------------
  |  Branch (118:5): [True: 170, False: 168k]
  ------------------
  119|    170|      return BROTLI_DECODER_RESULT_SUCCESS;
  120|       |
  121|  2.62k|    case BROTLI_DECODER_NEEDS_MORE_INPUT:
  ------------------
  |  Branch (121:5): [True: 2.62k, False: 166k]
  ------------------
  122|  2.62k|      return BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT;
  123|       |
  124|   164k|    case BROTLI_DECODER_NEEDS_MORE_OUTPUT:
  ------------------
  |  Branch (124:5): [True: 164k, False: 3.96k]
  ------------------
  125|   164k|      return BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT;
  126|       |
  127|  1.17k|    default:
  ------------------
  |  Branch (127:5): [True: 1.17k, False: 167k]
  ------------------
  128|  1.17k|      return BROTLI_DECODER_RESULT_ERROR;
  129|   168k|  }
  130|   168k|}
decode.c:WriteRingBuffer:
 1269|   483k|    size_t* total_out, BROTLI_BOOL force) {
 1270|   483k|  uint8_t* start =
 1271|   483k|      s->ringbuffer + (s->partial_pos_out & (size_t)s->ringbuffer_mask);
 1272|   483k|  size_t to_write = UnwrittenBytes(s, BROTLI_TRUE);
  ------------------
  |  |   51|   483k|#define BROTLI_TRUE 1
  ------------------
 1273|   483k|  size_t num_written = *available_out;
 1274|   483k|  if (num_written > to_write) {
  ------------------
  |  Branch (1274:7): [True: 166k, False: 317k]
  ------------------
 1275|   166k|    num_written = to_write;
 1276|   166k|  }
 1277|   483k|  if (s->meta_block_remaining_len < 0) {
  ------------------
  |  Branch (1277:7): [True: 146, False: 483k]
  ------------------
 1278|    146|    return BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1);
  ------------------
  |  |   31|    146|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|    146|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 1279|    146|  }
 1280|   483k|  if (next_out && !*next_out) {
  ------------------
  |  Branch (1280:7): [True: 166k, False: 317k]
  |  Branch (1280:19): [True: 166k, False: 0]
  ------------------
 1281|   166k|    *next_out = start;
 1282|   317k|  } else {
 1283|   317k|    if (next_out) {
  ------------------
  |  Branch (1283:9): [True: 0, False: 317k]
  ------------------
 1284|      0|      memcpy(*next_out, start, num_written);
 1285|      0|      *next_out += num_written;
 1286|      0|    }
 1287|   317k|  }
 1288|   483k|  *available_out -= num_written;
 1289|   483k|  BROTLI_LOG_UINT(to_write);
 1290|   483k|  BROTLI_LOG_UINT(num_written);
 1291|   483k|  s->partial_pos_out += num_written;
 1292|   483k|  if (total_out) {
  ------------------
  |  Branch (1292:7): [True: 0, False: 483k]
  ------------------
 1293|      0|    *total_out = s->partial_pos_out;
 1294|      0|  }
 1295|   483k|  if (num_written < to_write) {
  ------------------
  |  Branch (1295:7): [True: 166k, False: 317k]
  ------------------
 1296|   166k|    if (s->ringbuffer_size == (1 << s->window_bits) || force) {
  ------------------
  |  Branch (1296:9): [True: 165k, False: 834]
  |  Branch (1296:56): [True: 812, False: 22]
  ------------------
 1297|   166k|      return BROTLI_DECODER_NEEDS_MORE_OUTPUT;
 1298|   166k|    } else {
 1299|     22|      return BROTLI_DECODER_SUCCESS;
 1300|     22|    }
 1301|   166k|  }
 1302|       |  /* Wrap ring buffer only if it has reached its maximal size. */
 1303|   317k|  if (s->ringbuffer_size == (1 << s->window_bits) &&
  ------------------
  |  Branch (1303:7): [True: 316k, False: 916]
  ------------------
 1304|   316k|      s->pos >= s->ringbuffer_size) {
  ------------------
  |  Branch (1304:7): [True: 151k, False: 165k]
  ------------------
 1305|   151k|    s->pos -= s->ringbuffer_size;
 1306|   151k|    s->rb_roundtrips++;
 1307|   151k|    s->should_wrap_ringbuffer = (size_t)s->pos != 0 ? 1 : 0;
  ------------------
  |  Branch (1307:33): [True: 13.8k, False: 137k]
  ------------------
 1308|   151k|  }
 1309|   317k|  return BROTLI_DECODER_SUCCESS;
 1310|   483k|}
decode.c:DecodeWindowBits:
  135|  4.01k|                                               BrotliBitReader* br) {
  136|  4.01k|  uint32_t n;
  137|  4.01k|  BROTLI_BOOL large_window = s->large_window;
  ------------------
  |  |   49|  4.01k|#define BROTLI_BOOL int
  ------------------
  138|  4.01k|  s->large_window = BROTLI_FALSE;
  ------------------
  |  |   53|  4.01k|#define BROTLI_FALSE 0
  ------------------
  139|  4.01k|  BrotliTakeBits(br, 1, &n);
  140|  4.01k|  if (n == 0) {
  ------------------
  |  Branch (140:7): [True: 2.73k, False: 1.28k]
  ------------------
  141|  2.73k|    s->window_bits = 16;
  142|  2.73k|    return BROTLI_DECODER_SUCCESS;
  143|  2.73k|  }
  144|  1.28k|  BrotliTakeBits(br, 3, &n);
  145|  1.28k|  if (n != 0) {
  ------------------
  |  Branch (145:7): [True: 707, False: 574]
  ------------------
  146|    707|    s->window_bits = 17 + n;
  147|    707|    return BROTLI_DECODER_SUCCESS;
  148|    707|  }
  149|    574|  BrotliTakeBits(br, 3, &n);
  150|    574|  if (n == 1) {
  ------------------
  |  Branch (150:7): [True: 1, False: 573]
  ------------------
  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|    573|  if (n != 0) {
  ------------------
  |  Branch (162:7): [True: 544, False: 29]
  ------------------
  163|    544|    s->window_bits = 8 + n;
  164|    544|    return BROTLI_DECODER_SUCCESS;
  165|    544|  }
  166|     29|  s->window_bits = 17;
  167|     29|  return BROTLI_DECODER_SUCCESS;
  168|    573|}
decode.c:DecodeMetaBlockLength:
  226|  14.3k|    BrotliDecoderState* s, BrotliBitReader* br) {
  227|  14.3k|  uint32_t bits;
  228|  14.3k|  int i;
  229|  30.4k|  for (;;) {
  230|  30.4k|    switch (s->substate_metablock_header) {
  231|  14.3k|      case BROTLI_STATE_METABLOCK_HEADER_NONE:
  ------------------
  |  Branch (231:7): [True: 14.3k, False: 16.1k]
  ------------------
  232|  14.3k|        if (!BrotliSafeReadBits(br, 1, &bits)) {
  ------------------
  |  Branch (232:13): [True: 54, False: 14.2k]
  ------------------
  233|     54|          return BROTLI_DECODER_NEEDS_MORE_INPUT;
  234|     54|        }
  235|  14.2k|        s->is_last_metablock = bits ? 1 : 0;
  ------------------
  |  Branch (235:32): [True: 986, False: 13.2k]
  ------------------
  236|  14.2k|        s->meta_block_remaining_len = 0;
  237|  14.2k|        s->is_uncompressed = 0;
  238|  14.2k|        s->is_metadata = 0;
  239|  14.2k|        if (!s->is_last_metablock) {
  ------------------
  |  Branch (239:13): [True: 13.2k, False: 986]
  ------------------
  240|  13.2k|          s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_NIBBLES;
  241|  13.2k|          break;
  242|  13.2k|        }
  243|    986|        s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_EMPTY;
  244|       |      /* Fall through. */
  245|       |
  246|    986|      case BROTLI_STATE_METABLOCK_HEADER_EMPTY:
  ------------------
  |  Branch (246:7): [True: 0, False: 30.4k]
  ------------------
  247|    986|        if (!BrotliSafeReadBits(br, 1, &bits)) {
  ------------------
  |  Branch (247:13): [True: 13, False: 973]
  ------------------
  248|     13|          return BROTLI_DECODER_NEEDS_MORE_INPUT;
  249|     13|        }
  250|    973|        if (bits) {
  ------------------
  |  Branch (250:13): [True: 137, False: 836]
  ------------------
  251|    137|          s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_NONE;
  252|    137|          return BROTLI_DECODER_SUCCESS;
  253|    137|        }
  254|    836|        s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_NIBBLES;
  255|       |      /* Fall through. */
  256|       |
  257|  14.1k|      case BROTLI_STATE_METABLOCK_HEADER_NIBBLES:
  ------------------
  |  Branch (257:7): [True: 13.2k, False: 17.1k]
  ------------------
  258|  14.1k|        if (!BrotliSafeReadBits(br, 2, &bits)) {
  ------------------
  |  Branch (258:13): [True: 44, False: 14.0k]
  ------------------
  259|     44|          return BROTLI_DECODER_NEEDS_MORE_INPUT;
  260|     44|        }
  261|  14.0k|        s->size_nibbles = (uint8_t)(bits + 4);
  262|  14.0k|        s->loop_counter = 0;
  263|  14.0k|        if (bits == 3) {
  ------------------
  |  Branch (263:13): [True: 2.82k, False: 11.2k]
  ------------------
  264|  2.82k|          s->is_metadata = 1;
  265|  2.82k|          s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_RESERVED;
  266|  2.82k|          break;
  267|  2.82k|        }
  268|  11.2k|        s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_SIZE;
  269|       |      /* Fall through. */
  270|       |
  271|  11.2k|      case BROTLI_STATE_METABLOCK_HEADER_SIZE:
  ------------------
  |  Branch (271:7): [True: 0, False: 30.4k]
  ------------------
  272|  11.2k|        i = s->loop_counter;
  273|  57.4k|        for (; i < (int)s->size_nibbles; ++i) {
  ------------------
  |  Branch (273:16): [True: 46.2k, False: 11.1k]
  ------------------
  274|  46.2k|          if (!BrotliSafeReadBits(br, 4, &bits)) {
  ------------------
  |  Branch (274:15): [True: 78, False: 46.2k]
  ------------------
  275|     78|            s->loop_counter = i;
  276|     78|            return BROTLI_DECODER_NEEDS_MORE_INPUT;
  277|     78|          }
  278|  46.2k|          if (i + 1 == (int)s->size_nibbles && s->size_nibbles > 4 &&
  ------------------
  |  Branch (278:15): [True: 11.1k, False: 35.0k]
  |  Branch (278:48): [True: 893, False: 10.2k]
  ------------------
  279|    893|              bits == 0) {
  ------------------
  |  Branch (279:15): [True: 5, False: 888]
  ------------------
  280|      5|            return BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE);
  ------------------
  |  |   31|      5|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|      5|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
  281|      5|          }
  282|  46.2k|          s->meta_block_remaining_len |= (int)(bits << (i * 4));
  283|  46.2k|        }
  284|  11.1k|        s->substate_metablock_header =
  285|  11.1k|            BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSED;
  286|       |      /* Fall through. */
  287|       |
  288|  11.1k|      case BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSED:
  ------------------
  |  Branch (288:7): [True: 0, False: 30.4k]
  ------------------
  289|  11.1k|        if (!s->is_last_metablock) {
  ------------------
  |  Branch (289:13): [True: 10.4k, False: 712]
  ------------------
  290|  10.4k|          if (!BrotliSafeReadBits(br, 1, &bits)) {
  ------------------
  |  Branch (290:15): [True: 4, False: 10.4k]
  ------------------
  291|      4|            return BROTLI_DECODER_NEEDS_MORE_INPUT;
  292|      4|          }
  293|  10.4k|          s->is_uncompressed = bits ? 1 : 0;
  ------------------
  |  Branch (293:32): [True: 1.46k, False: 9.00k]
  ------------------
  294|  10.4k|        }
  295|  11.1k|        ++s->meta_block_remaining_len;
  296|  11.1k|        s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_NONE;
  297|  11.1k|        return BROTLI_DECODER_SUCCESS;
  298|       |
  299|  2.82k|      case BROTLI_STATE_METABLOCK_HEADER_RESERVED:
  ------------------
  |  Branch (299:7): [True: 2.82k, False: 27.6k]
  ------------------
  300|  2.82k|        if (!BrotliSafeReadBits(br, 1, &bits)) {
  ------------------
  |  Branch (300:13): [True: 7, False: 2.81k]
  ------------------
  301|      7|          return BROTLI_DECODER_NEEDS_MORE_INPUT;
  302|      7|        }
  303|  2.81k|        if (bits != 0) {
  ------------------
  |  Branch (303:13): [True: 4, False: 2.81k]
  ------------------
  304|      4|          return BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_RESERVED);
  ------------------
  |  |   31|      4|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|      4|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
  305|      4|        }
  306|  2.81k|        s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_BYTES;
  307|       |      /* Fall through. */
  308|       |
  309|  2.81k|      case BROTLI_STATE_METABLOCK_HEADER_BYTES:
  ------------------
  |  Branch (309:7): [True: 0, False: 30.4k]
  ------------------
  310|  2.81k|        if (!BrotliSafeReadBits(br, 2, &bits)) {
  ------------------
  |  Branch (310:13): [True: 3, False: 2.80k]
  ------------------
  311|      3|          return BROTLI_DECODER_NEEDS_MORE_INPUT;
  312|      3|        }
  313|  2.80k|        if (bits == 0) {
  ------------------
  |  Branch (313:13): [True: 1.74k, False: 1.06k]
  ------------------
  314|  1.74k|          s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_NONE;
  315|  1.74k|          return BROTLI_DECODER_SUCCESS;
  316|  1.74k|        }
  317|  1.06k|        s->size_nibbles = (uint8_t)bits;
  318|  1.06k|        s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_METADATA;
  319|       |      /* Fall through. */
  320|       |
  321|  1.06k|      case BROTLI_STATE_METABLOCK_HEADER_METADATA:
  ------------------
  |  Branch (321:7): [True: 0, False: 30.4k]
  ------------------
  322|  1.06k|        i = s->loop_counter;
  323|  2.37k|        for (; i < (int)s->size_nibbles; ++i) {
  ------------------
  |  Branch (323:16): [True: 1.33k, False: 1.04k]
  ------------------
  324|  1.33k|          if (!BrotliSafeReadBits(br, 8, &bits)) {
  ------------------
  |  Branch (324:15): [True: 17, False: 1.31k]
  ------------------
  325|     17|            s->loop_counter = i;
  326|     17|            return BROTLI_DECODER_NEEDS_MORE_INPUT;
  327|     17|          }
  328|  1.31k|          if (i + 1 == (int)s->size_nibbles && s->size_nibbles > 1 &&
  ------------------
  |  Branch (328:15): [True: 1.04k, False: 270]
  |  Branch (328:48): [True: 233, False: 814]
  ------------------
  329|    233|              bits == 0) {
  ------------------
  |  Branch (329:15): [True: 3, False: 230]
  ------------------
  330|      3|            return BROTLI_FAILURE(
  ------------------
  |  |   31|      3|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|      3|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
  331|      3|                BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE);
  332|      3|          }
  333|  1.31k|          s->meta_block_remaining_len |= (int)(bits << (i * 8));
  334|  1.31k|        }
  335|  1.04k|        ++s->meta_block_remaining_len;
  336|  1.04k|        s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_NONE;
  337|  1.04k|        return BROTLI_DECODER_SUCCESS;
  338|       |
  339|      0|      default:
  ------------------
  |  Branch (339:7): [True: 0, False: 30.4k]
  ------------------
  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|  30.4k|    }
  343|  30.4k|  }
  344|  14.3k|}
decode.c:BrotliCalculateRingBufferSize:
 1413|  11.1k|    BrotliDecoderState* s) {
 1414|  11.1k|  int window_size = 1 << s->window_bits;
 1415|  11.1k|  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|  11.1k|  int min_size = s->ringbuffer_size ? s->ringbuffer_size : 1024;
  ------------------
  |  Branch (1418:18): [True: 7.44k, False: 3.72k]
  ------------------
 1419|  11.1k|  int output_size;
 1420|       |
 1421|       |  /* If maximum is already reached, no further extension is retired. */
 1422|  11.1k|  if (s->ringbuffer_size == window_size) {
  ------------------
  |  Branch (1422:7): [True: 834, False: 10.3k]
  ------------------
 1423|    834|    return;
 1424|    834|  }
 1425|       |
 1426|       |  /* Metadata blocks does not touch ring buffer. */
 1427|  10.3k|  if (s->is_metadata) {
  ------------------
  |  Branch (1427:7): [True: 0, False: 10.3k]
  ------------------
 1428|      0|    return;
 1429|      0|  }
 1430|       |
 1431|  10.3k|  if (!s->ringbuffer) {
  ------------------
  |  Branch (1431:7): [True: 3.72k, False: 6.61k]
  ------------------
 1432|  3.72k|    output_size = 0;
 1433|  6.61k|  } else {
 1434|  6.61k|    output_size = s->pos;
 1435|  6.61k|  }
 1436|  10.3k|  output_size += s->meta_block_remaining_len;
 1437|  10.3k|  min_size = min_size < output_size ? output_size : min_size;
  ------------------
  |  Branch (1437:14): [True: 3.47k, False: 6.86k]
  ------------------
 1438|       |
 1439|  10.3k|  if (!!s->canny_ringbuffer_allocation) {
  ------------------
  |  Branch (1439:7): [True: 10.3k, 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|  56.0k|    while ((new_ringbuffer_size >> 1) >= min_size) {
  ------------------
  |  Branch (1443:12): [True: 45.7k, False: 10.3k]
  ------------------
 1444|  45.7k|      new_ringbuffer_size >>= 1;
 1445|  45.7k|    }
 1446|  10.3k|  }
 1447|       |
 1448|  10.3k|  s->new_ringbuffer_size = new_ringbuffer_size;
 1449|  10.3k|}
decode.c:DecodeVarLenUint8:
  182|  46.7k|    BrotliDecoderState* s, BrotliBitReader* br, uint32_t* value) {
  183|  46.7k|  uint32_t bits;
  184|  46.7k|  switch (s->substate_decode_uint8) {
  185|  46.7k|    case BROTLI_STATE_DECODE_UINT8_NONE:
  ------------------
  |  Branch (185:5): [True: 46.7k, False: 0]
  ------------------
  186|  46.7k|      if (BROTLI_PREDICT_FALSE(!BrotliSafeReadBits(br, 1, &bits))) {
  ------------------
  |  |   83|  46.7k|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 21, False: 46.7k]
  |  |  ------------------
  ------------------
  187|     21|        return BROTLI_DECODER_NEEDS_MORE_INPUT;
  188|     21|      }
  189|  46.7k|      if (bits == 0) {
  ------------------
  |  Branch (189:11): [True: 41.0k, False: 5.71k]
  ------------------
  190|  41.0k|        *value = 0;
  191|  41.0k|        return BROTLI_DECODER_SUCCESS;
  192|  41.0k|      }
  193|       |    /* Fall through. */
  194|       |
  195|  5.71k|    case BROTLI_STATE_DECODE_UINT8_SHORT:
  ------------------
  |  Branch (195:5): [True: 0, False: 46.7k]
  ------------------
  196|  5.71k|      if (BROTLI_PREDICT_FALSE(!BrotliSafeReadBits(br, 3, &bits))) {
  ------------------
  |  |   83|  5.71k|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 30, False: 5.68k]
  |  |  ------------------
  ------------------
  197|     30|        s->substate_decode_uint8 = BROTLI_STATE_DECODE_UINT8_SHORT;
  198|     30|        return BROTLI_DECODER_NEEDS_MORE_INPUT;
  199|     30|      }
  200|  5.68k|      if (bits == 0) {
  ------------------
  |  Branch (200:11): [True: 2.21k, False: 3.46k]
  ------------------
  201|  2.21k|        *value = 1;
  202|  2.21k|        s->substate_decode_uint8 = BROTLI_STATE_DECODE_UINT8_NONE;
  203|  2.21k|        return BROTLI_DECODER_SUCCESS;
  204|  2.21k|      }
  205|       |      /* Use output value as a temporary storage. It MUST be persisted. */
  206|  3.46k|      *value = bits;
  207|       |    /* Fall through. */
  208|       |
  209|  3.46k|    case BROTLI_STATE_DECODE_UINT8_LONG:
  ------------------
  |  Branch (209:5): [True: 0, False: 46.7k]
  ------------------
  210|  3.46k|      if (BROTLI_PREDICT_FALSE(!BrotliSafeReadBits(br, *value, &bits))) {
  ------------------
  |  |   83|  3.46k|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 25, False: 3.44k]
  |  |  ------------------
  ------------------
  211|     25|        s->substate_decode_uint8 = BROTLI_STATE_DECODE_UINT8_LONG;
  212|     25|        return BROTLI_DECODER_NEEDS_MORE_INPUT;
  213|     25|      }
  214|  3.44k|      *value = (1U << *value) + bits;
  215|  3.44k|      s->substate_decode_uint8 = BROTLI_STATE_DECODE_UINT8_NONE;
  216|  3.44k|      return BROTLI_DECODER_SUCCESS;
  217|       |
  218|      0|    default:
  ------------------
  |  Branch (218:5): [True: 0, False: 46.7k]
  ------------------
  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|  46.7k|  }
  222|  46.7k|}
decode.c:ReadHuffmanCode:
  752|  46.6k|                                              BrotliDecoderState* s) {
  753|  46.6k|  BrotliBitReader* br = &s->br;
  754|  46.6k|  BrotliMetablockHeaderArena* h = &s->arena.header;
  755|       |  /* State machine. */
  756|  53.1k|  for (;;) {
  757|  53.1k|    switch (h->substate_huffman) {
  758|  46.6k|      case BROTLI_STATE_HUFFMAN_NONE:
  ------------------
  |  Branch (758:7): [True: 46.6k, False: 6.44k]
  ------------------
  759|  46.6k|        if (!BrotliSafeReadBits(br, 2, &h->sub_loop_counter)) {
  ------------------
  |  Branch (759:13): [True: 107, False: 46.5k]
  ------------------
  760|    107|          return BROTLI_DECODER_NEEDS_MORE_INPUT;
  761|    107|        }
  762|  46.5k|        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|  46.5k|        if (h->sub_loop_counter != 1) {
  ------------------
  |  Branch (766:13): [True: 6.44k, False: 40.1k]
  ------------------
  767|  6.44k|          h->space = 32;
  768|  6.44k|          h->repeat = 0;  /* num_codes */
  769|  6.44k|          memset(&h->code_length_histo[0], 0, sizeof(h->code_length_histo[0]) *
  770|  6.44k|              (BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH + 1));
  ------------------
  |  |   28|  6.44k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH 5
  ------------------
  771|  6.44k|          memset(&h->code_length_code_lengths[0], 0,
  772|  6.44k|              sizeof(h->code_length_code_lengths));
  773|  6.44k|          h->substate_huffman = BROTLI_STATE_HUFFMAN_COMPLEX;
  774|  6.44k|          continue;
  775|  6.44k|        }
  776|       |      /* Fall through. */
  777|       |
  778|  40.1k|      case BROTLI_STATE_HUFFMAN_SIMPLE_SIZE:
  ------------------
  |  Branch (778:7): [True: 0, False: 53.1k]
  ------------------
  779|       |        /* Read symbols, codes & code lengths directly. */
  780|  40.1k|        if (!BrotliSafeReadBits(br, 2, &h->symbol)) {  /* num_symbols */
  ------------------
  |  Branch (780:13): [True: 47, False: 40.0k]
  ------------------
  781|     47|          h->substate_huffman = BROTLI_STATE_HUFFMAN_SIMPLE_SIZE;
  782|     47|          return BROTLI_DECODER_NEEDS_MORE_INPUT;
  783|     47|        }
  784|  40.0k|        h->sub_loop_counter = 0;
  785|       |      /* Fall through. */
  786|       |
  787|  40.0k|      case BROTLI_STATE_HUFFMAN_SIMPLE_READ: {
  ------------------
  |  Branch (787:7): [True: 0, False: 53.1k]
  ------------------
  788|  40.0k|        BrotliDecoderErrorCode result =
  789|  40.0k|            ReadSimpleHuffmanSymbols(alphabet_size_max, alphabet_size_limit, s);
  790|  40.0k|        if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (790:13): [True: 125, False: 39.9k]
  ------------------
  791|    125|          return result;
  792|    125|        }
  793|  40.0k|      }
  794|       |      /* Fall through. */
  795|       |
  796|  39.9k|      case BROTLI_STATE_HUFFMAN_SIMPLE_BUILD: {
  ------------------
  |  Branch (796:7): [True: 0, False: 53.1k]
  ------------------
  797|  39.9k|        uint32_t table_size;
  798|  39.9k|        if (h->symbol == 3) {
  ------------------
  |  Branch (798:13): [True: 3.29k, False: 36.6k]
  ------------------
  799|  3.29k|          uint32_t bits;
  800|  3.29k|          if (!BrotliSafeReadBits(br, 1, &bits)) {
  ------------------
  |  Branch (800:15): [True: 6, False: 3.29k]
  ------------------
  801|      6|            h->substate_huffman = BROTLI_STATE_HUFFMAN_SIMPLE_BUILD;
  802|      6|            return BROTLI_DECODER_NEEDS_MORE_INPUT;
  803|      6|          }
  804|  3.29k|          h->symbol += bits;
  805|  3.29k|        }
  806|  39.9k|        BROTLI_LOG_UINT(h->symbol);
  807|  39.9k|        table_size = BrotliBuildSimpleHuffmanTable(
  808|  39.9k|            table, HUFFMAN_TABLE_BITS, h->symbols_lists_array, h->symbol);
  ------------------
  |  |   39|  39.9k|#define HUFFMAN_TABLE_BITS 8U
  ------------------
  809|  39.9k|        if (opt_table_size) {
  ------------------
  |  Branch (809:13): [True: 32.4k, False: 7.52k]
  ------------------
  810|  32.4k|          *opt_table_size = table_size;
  811|  32.4k|        }
  812|  39.9k|        h->substate_huffman = BROTLI_STATE_HUFFMAN_NONE;
  813|  39.9k|        return BROTLI_DECODER_SUCCESS;
  814|  39.9k|      }
  815|       |
  816|       |      /* Decode Huffman-coded code lengths. */
  817|  6.44k|      case BROTLI_STATE_HUFFMAN_COMPLEX: {
  ------------------
  |  Branch (817:7): [True: 6.44k, False: 46.6k]
  ------------------
  818|  6.44k|        uint32_t i;
  819|  6.44k|        BrotliDecoderErrorCode result = ReadCodeLengthCodeLengths(s);
  820|  6.44k|        if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (820:13): [True: 357, False: 6.09k]
  ------------------
  821|    357|          return result;
  822|    357|        }
  823|  6.09k|        BrotliBuildCodeLengthsHuffmanTable(h->table,
  824|  6.09k|                                           h->code_length_code_lengths,
  825|  6.09k|                                           h->code_length_histo);
  826|  6.09k|        memset(&h->code_length_histo[0], 0, sizeof(h->code_length_histo));
  827|   103k|        for (i = 0; i <= BROTLI_HUFFMAN_MAX_CODE_LENGTH; ++i) {
  ------------------
  |  |   19|   103k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH 15
  ------------------
  |  Branch (827:21): [True: 97.4k, False: 6.09k]
  ------------------
  828|  97.4k|          h->next_symbol[i] = (int)i - (BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1);
  ------------------
  |  |   19|  97.4k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH 15
  ------------------
  829|  97.4k|          h->symbol_lists[h->next_symbol[i]] = 0xFFFF;
  830|  97.4k|        }
  831|       |
  832|  6.09k|        h->symbol = 0;
  833|  6.09k|        h->prev_code_len = BROTLI_INITIAL_REPEATED_CODE_LENGTH;
  ------------------
  |  |   38|  6.09k|#define BROTLI_INITIAL_REPEATED_CODE_LENGTH 8
  ------------------
  834|  6.09k|        h->repeat = 0;
  835|  6.09k|        h->repeat_code_len = 0;
  836|  6.09k|        h->space = 32768;
  837|  6.09k|        h->substate_huffman = BROTLI_STATE_HUFFMAN_LENGTH_SYMBOLS;
  838|  6.09k|      }
  839|       |      /* Fall through. */
  840|       |
  841|  6.09k|      case BROTLI_STATE_HUFFMAN_LENGTH_SYMBOLS: {
  ------------------
  |  Branch (841:7): [True: 0, False: 53.1k]
  ------------------
  842|  6.09k|        uint32_t table_size;
  843|  6.09k|        BrotliDecoderErrorCode result = ReadSymbolCodeLengths(
  844|  6.09k|            alphabet_size_limit, s);
  845|  6.09k|        if (result == BROTLI_DECODER_NEEDS_MORE_INPUT) {
  ------------------
  |  Branch (845:13): [True: 729, False: 5.36k]
  ------------------
  846|    729|          result = SafeReadSymbolCodeLengths(alphabet_size_limit, s);
  847|    729|        }
  848|  6.09k|        if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (848:13): [True: 157, False: 5.93k]
  ------------------
  849|    157|          return result;
  850|    157|        }
  851|       |
  852|  5.93k|        if (h->space != 0) {
  ------------------
  |  Branch (852:13): [True: 197, False: 5.73k]
  ------------------
  853|    197|          BROTLI_LOG(("[ReadHuffmanCode] space = %d\n", (int)h->space));
  854|    197|          return BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE);
  ------------------
  |  |   31|    197|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|    197|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
  855|    197|        }
  856|  5.73k|        table_size = BrotliBuildHuffmanTable(
  857|  5.73k|            table, HUFFMAN_TABLE_BITS, h->symbol_lists, h->code_length_histo);
  ------------------
  |  |   39|  5.73k|#define HUFFMAN_TABLE_BITS 8U
  ------------------
  858|  5.73k|        if (opt_table_size) {
  ------------------
  |  Branch (858:13): [True: 4.67k, False: 1.06k]
  ------------------
  859|  4.67k|          *opt_table_size = table_size;
  860|  4.67k|        }
  861|  5.73k|        h->substate_huffman = BROTLI_STATE_HUFFMAN_NONE;
  862|  5.73k|        return BROTLI_DECODER_SUCCESS;
  863|  5.93k|      }
  864|       |
  865|      0|      default:
  ------------------
  |  Branch (865:7): [True: 0, False: 53.1k]
  ------------------
  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|  53.1k|    }
  869|  53.1k|  }
  870|  46.6k|}
decode.c:ReadSimpleHuffmanSymbols:
  477|  40.0k|    BrotliDecoderState* s) {
  478|       |  /* max_bits == 1..11; symbol == 0..3; 1..44 bits will be read. */
  479|  40.0k|  BrotliBitReader* br = &s->br;
  480|  40.0k|  BrotliMetablockHeaderArena* h = &s->arena.header;
  481|  40.0k|  uint32_t max_bits = Log2Floor(alphabet_size_max - 1);
  482|  40.0k|  uint32_t i = h->sub_loop_counter;
  483|  40.0k|  uint32_t num_symbols = h->symbol;
  484|   104k|  while (i <= num_symbols) {
  ------------------
  |  Branch (484:10): [True: 64.4k, False: 39.9k]
  ------------------
  485|  64.4k|    uint32_t v;
  486|  64.4k|    if (BROTLI_PREDICT_FALSE(!BrotliSafeReadBits(br, max_bits, &v))) {
  ------------------
  |  |   83|  64.4k|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 84, False: 64.3k]
  |  |  ------------------
  ------------------
  487|     84|      h->sub_loop_counter = i;
  488|     84|      h->substate_huffman = BROTLI_STATE_HUFFMAN_SIMPLE_READ;
  489|     84|      return BROTLI_DECODER_NEEDS_MORE_INPUT;
  490|     84|    }
  491|  64.3k|    if (v >= alphabet_size_limit) {
  ------------------
  |  Branch (491:9): [True: 26, False: 64.3k]
  ------------------
  492|     26|      return
  493|     26|          BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET);
  ------------------
  |  |   31|     26|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|     26|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
  494|     26|    }
  495|  64.3k|    h->symbols_lists_array[i] = (uint16_t)v;
  496|  64.3k|    BROTLI_LOG_UINT(h->symbols_lists_array[i]);
  497|  64.3k|    ++i;
  498|  64.3k|  }
  499|       |
  500|  64.2k|  for (i = 0; i < num_symbols; ++i) {
  ------------------
  |  Branch (500:15): [True: 24.3k, False: 39.9k]
  ------------------
  501|  24.3k|    uint32_t k = i + 1;
  502|  61.5k|    for (; k <= num_symbols; ++k) {
  ------------------
  |  Branch (502:12): [True: 37.2k, False: 24.3k]
  ------------------
  503|  37.2k|      if (h->symbols_lists_array[i] == h->symbols_lists_array[k]) {
  ------------------
  |  Branch (503:11): [True: 15, False: 37.2k]
  ------------------
  504|     15|        return BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME);
  ------------------
  |  |   31|     15|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|     15|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
  505|     15|      }
  506|  37.2k|    }
  507|  24.3k|  }
  508|       |
  509|  39.9k|  return BROTLI_DECODER_SUCCESS;
  510|  39.9k|}
decode.c:Log2Floor:
  463|  40.0k|static BROTLI_INLINE uint32_t Log2Floor(uint32_t x) {
  464|  40.0k|  uint32_t result = 0;
  465|   335k|  while (x) {
  ------------------
  |  Branch (465:10): [True: 295k, False: 40.0k]
  ------------------
  466|   295k|    x >>= 1;
  467|   295k|    ++result;
  468|   295k|  }
  469|  40.0k|  return result;
  470|  40.0k|}
decode.c:ReadCodeLengthCodeLengths:
  692|  6.44k|static BrotliDecoderErrorCode ReadCodeLengthCodeLengths(BrotliDecoderState* s) {
  693|  6.44k|  BrotliBitReader* br = &s->br;
  694|  6.44k|  BrotliMetablockHeaderArena* h = &s->arena.header;
  695|  6.44k|  uint32_t num_codes = h->repeat;
  696|  6.44k|  unsigned space = h->space;
  697|  6.44k|  uint32_t i = h->sub_loop_counter;
  698|  50.2k|  for (; i < BROTLI_CODE_LENGTH_CODES; ++i) {
  ------------------
  |  |   36|  50.2k|#define BROTLI_CODE_LENGTH_CODES (BROTLI_REPEAT_ZERO_CODE_LENGTH + 1)
  |  |  ------------------
  |  |  |  |   35|  50.2k|#define BROTLI_REPEAT_ZERO_CODE_LENGTH 17
  |  |  ------------------
  ------------------
  |  Branch (698:10): [True: 49.8k, False: 381]
  ------------------
  699|  49.8k|    const uint8_t code_len_idx = kCodeLengthCodeOrder[i];
  700|  49.8k|    uint32_t ix;
  701|  49.8k|    uint32_t v;
  702|  49.8k|    if (BROTLI_PREDICT_FALSE(!BrotliSafeGetBits(br, 4, &ix))) {
  ------------------
  |  |   83|  49.8k|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 418, False: 49.4k]
  |  |  ------------------
  ------------------
  703|    418|      uint32_t available_bits = BrotliGetAvailableBits(br);
  704|    418|      if (available_bits != 0) {
  ------------------
  |  Branch (704:11): [True: 280, False: 138]
  ------------------
  705|    280|        ix = BrotliGetBitsUnmasked(br) & 0xF;
  706|    280|      } else {
  707|    138|        ix = 0;
  708|    138|      }
  709|    418|      if (kCodeLengthPrefixLength[ix] > available_bits) {
  ------------------
  |  Branch (709:11): [True: 238, False: 180]
  ------------------
  710|    238|        h->sub_loop_counter = i;
  711|    238|        h->repeat = num_codes;
  712|    238|        h->space = space;
  713|    238|        h->substate_huffman = BROTLI_STATE_HUFFMAN_COMPLEX;
  714|    238|        return BROTLI_DECODER_NEEDS_MORE_INPUT;
  715|    238|      }
  716|    418|    }
  717|  49.6k|    v = kCodeLengthPrefixValue[ix];
  718|  49.6k|    BrotliDropBits(br, kCodeLengthPrefixLength[ix]);
  719|  49.6k|    h->code_length_code_lengths[code_len_idx] = (uint8_t)v;
  720|  49.6k|    BROTLI_LOG_ARRAY_INDEX(h->code_length_code_lengths, code_len_idx);
  721|  49.6k|    if (v != 0) {
  ------------------
  |  Branch (721:9): [True: 31.1k, False: 18.4k]
  ------------------
  722|  31.1k|      space = space - (32U >> v);
  723|  31.1k|      ++num_codes;
  724|  31.1k|      ++h->code_length_histo[v];
  725|  31.1k|      if (space - 1U >= 32U) {
  ------------------
  |  Branch (725:11): [True: 5.82k, False: 25.3k]
  ------------------
  726|       |        /* space is 0 or wrapped around. */
  727|  5.82k|        break;
  728|  5.82k|      }
  729|  31.1k|    }
  730|  49.6k|  }
  731|  6.21k|  if (!(num_codes == 1 || space == 0)) {
  ------------------
  |  Branch (731:9): [True: 321, False: 5.88k]
  |  Branch (731:27): [True: 5.77k, False: 119]
  ------------------
  732|    119|    return BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_CL_SPACE);
  ------------------
  |  |   31|    119|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|    119|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
  733|    119|  }
  734|  6.09k|  return BROTLI_DECODER_SUCCESS;
  735|  6.21k|}
decode.c:ReadSymbolCodeLengths:
  594|  6.09k|    uint32_t alphabet_size, BrotliDecoderState* s) {
  595|  6.09k|  BrotliBitReader* br = &s->br;
  596|  6.09k|  BrotliMetablockHeaderArena* h = &s->arena.header;
  597|  6.09k|  uint32_t symbol = h->symbol;
  598|  6.09k|  uint32_t repeat = h->repeat;
  599|  6.09k|  uint32_t space = h->space;
  600|  6.09k|  uint32_t prev_code_len = h->prev_code_len;
  601|  6.09k|  uint32_t repeat_code_len = h->repeat_code_len;
  602|  6.09k|  uint16_t* symbol_lists = h->symbol_lists;
  603|  6.09k|  uint16_t* code_length_histo = h->code_length_histo;
  604|  6.09k|  int* next_symbol = h->next_symbol;
  605|  6.09k|  if (!BrotliWarmupBitReader(br)) {
  ------------------
  |  Branch (605:7): [True: 45, False: 6.04k]
  ------------------
  606|     45|    return BROTLI_DECODER_NEEDS_MORE_INPUT;
  607|     45|  }
  608|   143k|  while (symbol < alphabet_size && space > 0) {
  ------------------
  |  Branch (608:10): [True: 143k, False: 353]
  |  Branch (608:36): [True: 138k, False: 5.00k]
  ------------------
  609|   138k|    const HuffmanCode* p = h->table;
  610|   138k|    uint32_t code_len;
  611|   138k|    BROTLI_HC_MARK_TABLE_FOR_FAST_LOAD(p);
  612|   138k|    if (!BrotliCheckInputAmount(br, BROTLI_SHORT_FILL_BIT_WINDOW_READ)) {
  ------------------
  |  |   22|   138k|#define BROTLI_SHORT_FILL_BIT_WINDOW_READ (sizeof(brotli_reg_t) >> 1)
  ------------------
  |  Branch (612:9): [True: 684, False: 137k]
  ------------------
  613|    684|      h->symbol = symbol;
  614|    684|      h->repeat = repeat;
  615|    684|      h->prev_code_len = prev_code_len;
  616|    684|      h->repeat_code_len = repeat_code_len;
  617|    684|      h->space = space;
  618|    684|      return BROTLI_DECODER_NEEDS_MORE_INPUT;
  619|    684|    }
  620|   137k|    BrotliFillBitWindow16(br);
  621|   137k|    BROTLI_HC_ADJUST_TABLE_INDEX(p, BrotliGetBitsUnmasked(br) &
  ------------------
  |  |   67|   137k|#define BROTLI_HC_ADJUST_TABLE_INDEX(H, V) H += (V)
  ------------------
  622|   137k|        BitMask(BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH));
  623|   137k|    BrotliDropBits(br, BROTLI_HC_FAST_LOAD_BITS(p));  /* Use 1..5 bits. */
  ------------------
  |  |   70|   137k|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  624|   137k|    code_len = BROTLI_HC_FAST_LOAD_VALUE(p);  /* code_len == 0..17 */
  ------------------
  |  |   71|   137k|#define BROTLI_HC_FAST_LOAD_VALUE(H) (H->value)
  ------------------
  625|   137k|    if (code_len < BROTLI_REPEAT_PREVIOUS_CODE_LENGTH) {
  ------------------
  |  |   34|   137k|#define BROTLI_REPEAT_PREVIOUS_CODE_LENGTH 16
  ------------------
  |  Branch (625:9): [True: 133k, False: 3.90k]
  ------------------
  626|   133k|      ProcessSingleCodeLength(code_len, &symbol, &repeat, &space,
  627|   133k|          &prev_code_len, symbol_lists, code_length_histo, next_symbol);
  628|   133k|    } else {  /* code_len == 16..17, extra_bits == 2..3 */
  629|  3.90k|      uint32_t extra_bits =
  630|  3.90k|          (code_len == BROTLI_REPEAT_PREVIOUS_CODE_LENGTH) ? 2 : 3;
  ------------------
  |  |   34|  3.90k|#define BROTLI_REPEAT_PREVIOUS_CODE_LENGTH 16
  ------------------
  |  Branch (630:11): [True: 1.46k, False: 2.44k]
  ------------------
  631|  3.90k|      uint32_t repeat_delta =
  632|  3.90k|          (uint32_t)BrotliGetBitsUnmasked(br) & BitMask(extra_bits);
  633|  3.90k|      BrotliDropBits(br, extra_bits);
  634|  3.90k|      ProcessRepeatedCodeLength(code_len, repeat_delta, alphabet_size,
  635|  3.90k|          &symbol, &repeat, &space, &prev_code_len, &repeat_code_len,
  636|  3.90k|          symbol_lists, code_length_histo, next_symbol);
  637|  3.90k|    }
  638|   137k|  }
  639|  5.36k|  h->space = space;
  640|  5.36k|  return BROTLI_DECODER_SUCCESS;
  641|  6.04k|}
decode.c:ProcessSingleCodeLength:
  521|   155k|    uint16_t* code_length_histo, int* next_symbol) {
  522|   155k|  *repeat = 0;
  523|   155k|  if (code_len != 0) {  /* code_len == 1..15 */
  ------------------
  |  Branch (523:7): [True: 143k, False: 12.6k]
  ------------------
  524|   143k|    symbol_lists[next_symbol[code_len]] = (uint16_t)(*symbol);
  525|   143k|    next_symbol[code_len] = (int)(*symbol);
  526|   143k|    *prev_code_len = code_len;
  527|   143k|    *space -= 32768U >> code_len;
  528|   143k|    code_length_histo[code_len]++;
  529|   143k|    BROTLI_LOG(("[ReadHuffmanCode] code_length[%d] = %d\n",
  530|   143k|        (int)*symbol, (int)code_len));
  531|   143k|  }
  532|   155k|  (*symbol)++;
  533|   155k|}
decode.c:ProcessRepeatedCodeLength:
  549|  4.93k|    uint16_t* code_length_histo, int* next_symbol) {
  550|  4.93k|  uint32_t old_repeat;
  551|  4.93k|  uint32_t extra_bits = 3;  /* for BROTLI_REPEAT_ZERO_CODE_LENGTH */
  552|  4.93k|  uint32_t new_len = 0;  /* for BROTLI_REPEAT_ZERO_CODE_LENGTH */
  553|  4.93k|  if (code_len == BROTLI_REPEAT_PREVIOUS_CODE_LENGTH) {
  ------------------
  |  |   34|  4.93k|#define BROTLI_REPEAT_PREVIOUS_CODE_LENGTH 16
  ------------------
  |  Branch (553:7): [True: 2.28k, False: 2.64k]
  ------------------
  554|  2.28k|    new_len = *prev_code_len;
  555|  2.28k|    extra_bits = 2;
  556|  2.28k|  }
  557|  4.93k|  if (*repeat_code_len != new_len) {
  ------------------
  |  Branch (557:7): [True: 997, False: 3.93k]
  ------------------
  558|    997|    *repeat = 0;
  559|    997|    *repeat_code_len = new_len;
  560|    997|  }
  561|  4.93k|  old_repeat = *repeat;
  562|  4.93k|  if (*repeat > 0) {
  ------------------
  |  Branch (562:7): [True: 719, False: 4.21k]
  ------------------
  563|    719|    *repeat -= 2;
  564|    719|    *repeat <<= extra_bits;
  565|    719|  }
  566|  4.93k|  *repeat += repeat_delta + 3U;
  567|  4.93k|  repeat_delta = *repeat - old_repeat;
  568|  4.93k|  if (*symbol + repeat_delta > alphabet_size) {
  ------------------
  |  Branch (568:7): [True: 97, False: 4.83k]
  ------------------
  569|     97|    BROTLI_DUMP();
  ------------------
  |  |  485|     97|#define BROTLI_DUMP() (void)(0)
  ------------------
  570|     97|    *symbol = alphabet_size;
  571|     97|    *space = 0xFFFFF;
  572|     97|    return;
  573|     97|  }
  574|  4.83k|  BROTLI_LOG(("[ReadHuffmanCode] code_length[%d..%d] = %d\n",
  575|  4.83k|      (int)*symbol, (int)(*symbol + repeat_delta - 1), (int)*repeat_code_len));
  576|  4.83k|  if (*repeat_code_len != 0) {
  ------------------
  |  Branch (576:7): [True: 2.23k, False: 2.60k]
  ------------------
  577|  2.23k|    unsigned last = *symbol + repeat_delta;
  578|  2.23k|    int next = next_symbol[*repeat_code_len];
  579|  26.0k|    do {
  580|  26.0k|      symbol_lists[next] = (uint16_t)*symbol;
  581|  26.0k|      next = (int)*symbol;
  582|  26.0k|    } while (++(*symbol) != last);
  ------------------
  |  Branch (582:14): [True: 23.7k, False: 2.23k]
  ------------------
  583|  2.23k|    next_symbol[*repeat_code_len] = next;
  584|  2.23k|    *space -= repeat_delta << (15 - *repeat_code_len);
  585|  2.23k|    code_length_histo[*repeat_code_len] =
  586|  2.23k|        (uint16_t)(code_length_histo[*repeat_code_len] + repeat_delta);
  587|  2.60k|  } else {
  588|  2.60k|    *symbol += repeat_delta;
  589|  2.60k|  }
  590|  4.83k|}
decode.c:SafeReadSymbolCodeLengths:
  644|    729|    uint32_t alphabet_size, BrotliDecoderState* s) {
  645|    729|  BrotliBitReader* br = &s->br;
  646|    729|  BrotliMetablockHeaderArena* h = &s->arena.header;
  647|    729|  BROTLI_BOOL get_byte = BROTLI_FALSE;
  ------------------
  |  |   49|    729|#define BROTLI_BOOL int
  ------------------
                BROTLI_BOOL get_byte = BROTLI_FALSE;
  ------------------
  |  |   53|    729|#define BROTLI_FALSE 0
  ------------------
  648|  24.5k|  while (h->symbol < alphabet_size && h->space > 0) {
  ------------------
  |  Branch (648:10): [True: 24.4k, False: 152]
  |  Branch (648:39): [True: 23.9k, False: 420]
  ------------------
  649|  23.9k|    const HuffmanCode* p = h->table;
  650|  23.9k|    uint32_t code_len;
  651|  23.9k|    uint32_t available_bits;
  652|  23.9k|    uint32_t bits = 0;
  653|  23.9k|    BROTLI_HC_MARK_TABLE_FOR_FAST_LOAD(p);
  654|  23.9k|    if (get_byte && !BrotliPullByte(br)) return BROTLI_DECODER_NEEDS_MORE_INPUT;
  ------------------
  |  Branch (654:9): [True: 386, False: 23.6k]
  |  Branch (654:21): [True: 157, False: 229]
  ------------------
  655|  23.8k|    get_byte = BROTLI_FALSE;
  ------------------
  |  |   53|  23.8k|#define BROTLI_FALSE 0
  ------------------
  656|  23.8k|    available_bits = BrotliGetAvailableBits(br);
  657|  23.8k|    if (available_bits != 0) {
  ------------------
  |  Branch (657:9): [True: 21.0k, False: 2.81k]
  ------------------
  658|  21.0k|      bits = (uint32_t)BrotliGetBitsUnmasked(br);
  659|  21.0k|    }
  660|  23.8k|    BROTLI_HC_ADJUST_TABLE_INDEX(p,
  ------------------
  |  |   67|  23.8k|#define BROTLI_HC_ADJUST_TABLE_INDEX(H, V) H += (V)
  ------------------
  661|  23.8k|        bits & BitMask(BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH));
  662|  23.8k|    if (BROTLI_HC_FAST_LOAD_BITS(p) > available_bits) {
  ------------------
  |  |   70|  23.8k|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  |  Branch (662:9): [True: 305, False: 23.5k]
  ------------------
  663|    305|      get_byte = BROTLI_TRUE;
  ------------------
  |  |   51|    305|#define BROTLI_TRUE 1
  ------------------
  664|    305|      continue;
  665|    305|    }
  666|  23.5k|    code_len = BROTLI_HC_FAST_LOAD_VALUE(p);  /* code_len == 0..17 */
  ------------------
  |  |   71|  23.5k|#define BROTLI_HC_FAST_LOAD_VALUE(H) (H->value)
  ------------------
  667|  23.5k|    if (code_len < BROTLI_REPEAT_PREVIOUS_CODE_LENGTH) {
  ------------------
  |  |   34|  23.5k|#define BROTLI_REPEAT_PREVIOUS_CODE_LENGTH 16
  ------------------
  |  Branch (667:9): [True: 22.4k, False: 1.10k]
  ------------------
  668|  22.4k|      BrotliDropBits(br, BROTLI_HC_FAST_LOAD_BITS(p));
  ------------------
  |  |   70|  22.4k|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  669|  22.4k|      ProcessSingleCodeLength(code_len, &h->symbol, &h->repeat, &h->space,
  670|  22.4k|          &h->prev_code_len, h->symbol_lists, h->code_length_histo,
  671|  22.4k|          h->next_symbol);
  672|  22.4k|    } else {  /* code_len == 16..17, extra_bits == 2..3 */
  673|  1.10k|      uint32_t extra_bits = code_len - 14U;
  674|  1.10k|      uint32_t repeat_delta = (bits >> BROTLI_HC_FAST_LOAD_BITS(p)) &
  ------------------
  |  |   70|  1.10k|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  675|  1.10k|          BitMask(extra_bits);
  676|  1.10k|      if (available_bits < BROTLI_HC_FAST_LOAD_BITS(p) + extra_bits) {
  ------------------
  |  |   70|  1.10k|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  |  Branch (676:11): [True: 81, False: 1.02k]
  ------------------
  677|     81|        get_byte = BROTLI_TRUE;
  ------------------
  |  |   51|     81|#define BROTLI_TRUE 1
  ------------------
  678|     81|        continue;
  679|     81|      }
  680|  1.02k|      BrotliDropBits(br, BROTLI_HC_FAST_LOAD_BITS(p) + extra_bits);
  ------------------
  |  |   70|  1.02k|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  681|  1.02k|      ProcessRepeatedCodeLength(code_len, repeat_delta, alphabet_size,
  682|  1.02k|          &h->symbol, &h->repeat, &h->space, &h->prev_code_len,
  683|  1.02k|          &h->repeat_code_len, h->symbol_lists, h->code_length_histo,
  684|  1.02k|          h->next_symbol);
  685|  1.02k|    }
  686|  23.5k|  }
  687|    572|  return BROTLI_DECODER_SUCCESS;
  688|    729|}
decode.c:SafeReadBlockLength:
  886|  22.9k|    BrotliBitReader* br) {
  887|  22.9k|  uint32_t index;
  888|  22.9k|  if (s->substate_read_block_length == BROTLI_STATE_READ_BLOCK_LENGTH_NONE) {
  ------------------
  |  Branch (888:7): [True: 22.9k, False: 0]
  ------------------
  889|  22.9k|    if (!SafeReadSymbol(table, br, &index)) {
  ------------------
  |  Branch (889:9): [True: 50, False: 22.8k]
  ------------------
  890|     50|      return BROTLI_FALSE;
  ------------------
  |  |   53|     50|#define BROTLI_FALSE 0
  ------------------
  891|     50|    }
  892|  22.9k|  } else {
  893|      0|    index = s->block_length_index;
  894|      0|  }
  895|  22.8k|  {
  896|  22.8k|    uint32_t bits;
  897|  22.8k|    uint32_t nbits = _kBrotliPrefixCodeRanges[index].nbits;
  898|  22.8k|    uint32_t offset = _kBrotliPrefixCodeRanges[index].offset;
  899|  22.8k|    if (!BrotliSafeReadBits(br, nbits, &bits)) {
  ------------------
  |  Branch (899:9): [True: 329, False: 22.5k]
  ------------------
  900|    329|      s->block_length_index = index;
  901|    329|      s->substate_read_block_length = BROTLI_STATE_READ_BLOCK_LENGTH_SUFFIX;
  902|    329|      return BROTLI_FALSE;
  ------------------
  |  |   53|    329|#define BROTLI_FALSE 0
  ------------------
  903|    329|    }
  904|  22.5k|    *result = offset + bits;
  905|  22.5k|    s->substate_read_block_length = BROTLI_STATE_READ_BLOCK_LENGTH_NONE;
  906|  22.5k|    return BROTLI_TRUE;
  ------------------
  |  |   51|  22.5k|#define BROTLI_TRUE 1
  ------------------
  907|  22.8k|  }
  908|  22.8k|}
decode.c:SafeReadSymbol:
  416|  1.47G|    const HuffmanCode* table, BrotliBitReader* br, uint32_t* result) {
  417|  1.47G|  uint32_t val;
  418|  1.47G|  if (BROTLI_PREDICT_TRUE(BrotliSafeGetBits(br, 15, &val))) {
  ------------------
  |  |   82|  1.47G|#define BROTLI_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
  |  |  ------------------
  |  |  |  Branch (82:32): [True: 925M, False: 549M]
  |  |  ------------------
  ------------------
  419|   925M|    *result = DecodeSymbol(val, table, br);
  420|   925M|    return BROTLI_TRUE;
  ------------------
  |  |   51|   925M|#define BROTLI_TRUE 1
  ------------------
  421|   925M|  }
  422|   549M|  return SafeDecodeSymbol(table, br, result);
  423|  1.47G|}
decode.c:DecodeSymbol:
  352|  1.05G|                                           BrotliBitReader* br) {
  353|  1.05G|  BROTLI_HC_MARK_TABLE_FOR_FAST_LOAD(table);
  354|  1.05G|  BROTLI_HC_ADJUST_TABLE_INDEX(table, bits & HUFFMAN_TABLE_MASK);
  ------------------
  |  |   67|  1.05G|#define BROTLI_HC_ADJUST_TABLE_INDEX(H, V) H += (V)
  ------------------
  355|  1.05G|  if (BROTLI_HC_FAST_LOAD_BITS(table) > HUFFMAN_TABLE_BITS) {
  ------------------
  |  |   70|  1.05G|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
                if (BROTLI_HC_FAST_LOAD_BITS(table) > HUFFMAN_TABLE_BITS) {
  ------------------
  |  |   39|  1.05G|#define HUFFMAN_TABLE_BITS 8U
  ------------------
  |  Branch (355:7): [True: 18.2k, False: 1.05G]
  ------------------
  356|  18.2k|    uint32_t nbits = BROTLI_HC_FAST_LOAD_BITS(table) - HUFFMAN_TABLE_BITS;
  ------------------
  |  |   70|  18.2k|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
                  uint32_t nbits = BROTLI_HC_FAST_LOAD_BITS(table) - HUFFMAN_TABLE_BITS;
  ------------------
  |  |   39|  18.2k|#define HUFFMAN_TABLE_BITS 8U
  ------------------
  357|  18.2k|    BrotliDropBits(br, HUFFMAN_TABLE_BITS);
  ------------------
  |  |   39|  18.2k|#define HUFFMAN_TABLE_BITS 8U
  ------------------
  358|  18.2k|    BROTLI_HC_ADJUST_TABLE_INDEX(table,
  ------------------
  |  |   67|  18.2k|#define BROTLI_HC_ADJUST_TABLE_INDEX(H, V) H += (V)
  ------------------
  359|  18.2k|        BROTLI_HC_FAST_LOAD_VALUE(table) +
  360|  18.2k|        ((bits >> HUFFMAN_TABLE_BITS) & BitMask(nbits)));
  361|  18.2k|  }
  362|  1.05G|  BrotliDropBits(br, BROTLI_HC_FAST_LOAD_BITS(table));
  ------------------
  |  |   70|  1.05G|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  363|  1.05G|  return BROTLI_HC_FAST_LOAD_VALUE(table);
  ------------------
  |  |   71|  1.05G|#define BROTLI_HC_FAST_LOAD_VALUE(H) (H->value)
  ------------------
  364|  1.05G|}
decode.c:SafeDecodeSymbol:
  376|   549M|    const HuffmanCode* table, BrotliBitReader* br, uint32_t* result) {
  377|   549M|  uint32_t val;
  378|   549M|  uint32_t available_bits = BrotliGetAvailableBits(br);
  379|   549M|  BROTLI_HC_MARK_TABLE_FOR_FAST_LOAD(table);
  380|   549M|  if (available_bits == 0) {
  ------------------
  |  Branch (380:7): [True: 58.2M, False: 491M]
  ------------------
  381|  58.2M|    if (BROTLI_HC_FAST_LOAD_BITS(table) == 0) {
  ------------------
  |  |   70|  58.2M|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  |  Branch (381:9): [True: 58.2M, False: 139]
  ------------------
  382|  58.2M|      *result = BROTLI_HC_FAST_LOAD_VALUE(table);
  ------------------
  |  |   71|  58.2M|#define BROTLI_HC_FAST_LOAD_VALUE(H) (H->value)
  ------------------
  383|  58.2M|      return BROTLI_TRUE;
  ------------------
  |  |   51|  58.2M|#define BROTLI_TRUE 1
  ------------------
  384|  58.2M|    }
  385|    139|    return BROTLI_FALSE;  /* No valid bits at all. */
  ------------------
  |  |   53|    139|#define BROTLI_FALSE 0
  ------------------
  386|  58.2M|  }
  387|   491M|  val = (uint32_t)BrotliGetBitsUnmasked(br);
  388|   491M|  BROTLI_HC_ADJUST_TABLE_INDEX(table, val & HUFFMAN_TABLE_MASK);
  ------------------
  |  |   67|   491M|#define BROTLI_HC_ADJUST_TABLE_INDEX(H, V) H += (V)
  ------------------
  389|   491M|  if (BROTLI_HC_FAST_LOAD_BITS(table) <= HUFFMAN_TABLE_BITS) {
  ------------------
  |  |   70|   491M|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
                if (BROTLI_HC_FAST_LOAD_BITS(table) <= HUFFMAN_TABLE_BITS) {
  ------------------
  |  |   39|   491M|#define HUFFMAN_TABLE_BITS 8U
  ------------------
  |  Branch (389:7): [True: 491M, False: 55]
  ------------------
  390|   491M|    if (BROTLI_HC_FAST_LOAD_BITS(table) <= available_bits) {
  ------------------
  |  |   70|   491M|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  |  Branch (390:9): [True: 491M, False: 63]
  ------------------
  391|   491M|      BrotliDropBits(br, BROTLI_HC_FAST_LOAD_BITS(table));
  ------------------
  |  |   70|   491M|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  392|   491M|      *result = BROTLI_HC_FAST_LOAD_VALUE(table);
  ------------------
  |  |   71|   491M|#define BROTLI_HC_FAST_LOAD_VALUE(H) (H->value)
  ------------------
  393|   491M|      return BROTLI_TRUE;
  ------------------
  |  |   51|   491M|#define BROTLI_TRUE 1
  ------------------
  394|   491M|    } else {
  395|     63|      return BROTLI_FALSE;  /* Not enough bits for the first level. */
  ------------------
  |  |   53|     63|#define BROTLI_FALSE 0
  ------------------
  396|     63|    }
  397|   491M|  }
  398|     55|  if (available_bits <= HUFFMAN_TABLE_BITS) {
  ------------------
  |  |   39|     55|#define HUFFMAN_TABLE_BITS 8U
  ------------------
  |  Branch (398:7): [True: 40, False: 15]
  ------------------
  399|     40|    return BROTLI_FALSE;  /* Not enough bits to move to the second level. */
  ------------------
  |  |   53|     40|#define BROTLI_FALSE 0
  ------------------
  400|     40|  }
  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|  2.61k|    BrotliDecoderState* s) {
 1358|       |  /* TODO: avoid allocation for single uncompressed block. */
 1359|  2.61k|  if (!BrotliEnsureRingBuffer(s)) {
  ------------------
  |  Branch (1359:7): [True: 0, False: 2.61k]
  ------------------
 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|  3.77k|  for (;;) {
 1365|  3.77k|    switch (s->substate_uncompressed) {
  ------------------
  |  Branch (1365:13): [True: 3.77k, False: 0]
  ------------------
 1366|  2.61k|      case BROTLI_STATE_UNCOMPRESSED_NONE: {
  ------------------
  |  Branch (1366:7): [True: 2.61k, False: 1.15k]
  ------------------
 1367|  2.61k|        int nbytes = (int)BrotliGetRemainingBytes(&s->br);
 1368|  2.61k|        if (nbytes > s->meta_block_remaining_len) {
  ------------------
  |  Branch (1368:13): [True: 1.22k, False: 1.38k]
  ------------------
 1369|  1.22k|          nbytes = s->meta_block_remaining_len;
 1370|  1.22k|        }
 1371|  2.61k|        if (s->pos + nbytes > s->ringbuffer_size) {
  ------------------
  |  Branch (1371:13): [True: 1.15k, False: 1.46k]
  ------------------
 1372|  1.15k|          nbytes = s->ringbuffer_size - s->pos;
 1373|  1.15k|        }
 1374|       |        /* Copy remaining bytes from s->br.buf_ to ring-buffer. */
 1375|  2.61k|        BrotliCopyBytes(&s->ringbuffer[s->pos], &s->br, (size_t)nbytes);
 1376|  2.61k|        s->pos += nbytes;
 1377|  2.61k|        s->meta_block_remaining_len -= nbytes;
 1378|  2.61k|        if (s->pos < 1 << s->window_bits) {
  ------------------
  |  Branch (1378:13): [True: 1.45k, False: 1.16k]
  ------------------
 1379|  1.45k|          if (s->meta_block_remaining_len == 0) {
  ------------------
  |  Branch (1379:15): [True: 1.23k, False: 219]
  ------------------
 1380|  1.23k|            return BROTLI_DECODER_SUCCESS;
 1381|  1.23k|          }
 1382|    219|          return BROTLI_DECODER_NEEDS_MORE_INPUT;
 1383|  1.45k|        }
 1384|  1.16k|        s->substate_uncompressed = BROTLI_STATE_UNCOMPRESSED_WRITE;
 1385|  1.16k|      }
 1386|       |      /* Fall through. */
 1387|       |
 1388|  2.32k|      case BROTLI_STATE_UNCOMPRESSED_WRITE: {
  ------------------
  |  Branch (1388:7): [True: 1.15k, False: 2.61k]
  ------------------
 1389|  2.32k|        BrotliDecoderErrorCode result;
 1390|  2.32k|        result = WriteRingBuffer(
 1391|  2.32k|            s, available_out, next_out, total_out, BROTLI_FALSE);
  ------------------
  |  |   53|  2.32k|#define BROTLI_FALSE 0
  ------------------
 1392|  2.32k|        if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (1392:13): [True: 1.16k, False: 1.15k]
  ------------------
 1393|  1.16k|          return result;
 1394|  1.16k|        }
 1395|  1.15k|        if (s->ringbuffer_size == 1 << s->window_bits) {
  ------------------
  |  Branch (1395:13): [True: 1.15k, False: 0]
  ------------------
 1396|  1.15k|          s->max_distance = s->max_backward_distance;
 1397|  1.15k|        }
 1398|  1.15k|        s->substate_uncompressed = BROTLI_STATE_UNCOMPRESSED_NONE;
 1399|  1.15k|        break;
 1400|  2.32k|      }
 1401|  3.77k|    }
 1402|  3.77k|  }
 1403|      0|  BROTLI_DCHECK(0);  /* Unreachable */
 1404|      0|}
decode.c:ReadContextModes:
 1452|  9.22k|static BrotliDecoderErrorCode ReadContextModes(BrotliDecoderState* s) {
 1453|  9.22k|  BrotliBitReader* br = &s->br;
 1454|  9.22k|  int i = s->loop_counter;
 1455|       |
 1456|  37.4k|  while (i < (int)s->num_block_types[0]) {
  ------------------
  |  Branch (1456:10): [True: 28.2k, False: 9.20k]
  ------------------
 1457|  28.2k|    uint32_t bits;
 1458|  28.2k|    if (!BrotliSafeReadBits(br, 2, &bits)) {
  ------------------
  |  Branch (1458:9): [True: 23, False: 28.2k]
  ------------------
 1459|     23|      s->loop_counter = i;
 1460|     23|      return BROTLI_DECODER_NEEDS_MORE_INPUT;
 1461|     23|    }
 1462|  28.2k|    s->context_modes[i] = (uint8_t)bits;
 1463|  28.2k|    BROTLI_LOG_ARRAY_INDEX(s->context_modes, i);
 1464|  28.2k|    i++;
 1465|  28.2k|  }
 1466|  9.20k|  return BROTLI_DECODER_SUCCESS;
 1467|  9.22k|}
decode.c:DecodeContextMap:
  994|  18.2k|                                               BrotliDecoderState* s) {
  995|  18.2k|  BrotliBitReader* br = &s->br;
  996|  18.2k|  BrotliDecoderErrorCode result = BROTLI_DECODER_SUCCESS;
  997|  18.2k|  BrotliMetablockHeaderArena* h = &s->arena.header;
  998|       |
  999|  18.2k|  switch ((int)h->substate_context_map) {
 1000|  18.2k|    case BROTLI_STATE_CONTEXT_MAP_NONE:
  ------------------
  |  Branch (1000:5): [True: 18.2k, False: 0]
  ------------------
 1001|  18.2k|      result = DecodeVarLenUint8(s, br, num_htrees);
 1002|  18.2k|      if (result != BROTLI_DECODER_SUCCESS) {
  ------------------
  |  Branch (1002:11): [True: 39, False: 18.2k]
  ------------------
 1003|     39|        return result;
 1004|     39|      }
 1005|  18.2k|      (*num_htrees)++;
 1006|  18.2k|      h->context_index = 0;
 1007|  18.2k|      BROTLI_LOG_UINT(context_map_size);
 1008|  18.2k|      BROTLI_LOG_UINT(*num_htrees);
 1009|  18.2k|      *context_map_arg =
 1010|  18.2k|          (uint8_t*)BROTLI_DECODER_ALLOC(s, (size_t)context_map_size);
  ------------------
  |  |  354|  18.2k|#define BROTLI_DECODER_ALLOC(S, L) S->alloc_func(S->memory_manager_opaque, L)
  ------------------
 1011|  18.2k|      if (*context_map_arg == 0) {
  ------------------
  |  Branch (1011:11): [True: 0, False: 18.2k]
  ------------------
 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|  18.2k|      if (*num_htrees <= 1) {
  ------------------
  |  Branch (1014:11): [True: 16.1k, False: 2.01k]
  ------------------
 1015|  16.1k|        memset(*context_map_arg, 0, (size_t)context_map_size);
 1016|  16.1k|        return BROTLI_DECODER_SUCCESS;
 1017|  16.1k|      }
 1018|  2.01k|      h->substate_context_map = BROTLI_STATE_CONTEXT_MAP_READ_PREFIX;
 1019|       |    /* Fall through. */
 1020|       |
 1021|  2.01k|    case BROTLI_STATE_CONTEXT_MAP_READ_PREFIX: {
  ------------------
  |  Branch (1021:5): [True: 0, False: 18.2k]
  ------------------
 1022|  2.01k|      uint32_t bits;
 1023|       |      /* In next stage ReadHuffmanCode uses at least 4 bits, so it is safe
 1024|       |         to peek 4 bits ahead. */
 1025|  2.01k|      if (!BrotliSafeGetBits(br, 5, &bits)) {
  ------------------
  |  Branch (1025:11): [True: 23, False: 1.99k]
  ------------------
 1026|     23|        return BROTLI_DECODER_NEEDS_MORE_INPUT;
 1027|     23|      }
 1028|  1.99k|      if ((bits & 1) != 0) { /* Use RLE for zeros. */
  ------------------
  |  Branch (1028:11): [True: 229, False: 1.76k]
  ------------------
 1029|    229|        h->max_run_length_prefix = (bits >> 1) + 1;
 1030|    229|        BrotliDropBits(br, 5);
 1031|  1.76k|      } else {
 1032|  1.76k|        h->max_run_length_prefix = 0;
 1033|  1.76k|        BrotliDropBits(br, 1);
 1034|  1.76k|      }
 1035|  1.99k|      BROTLI_LOG_UINT(h->max_run_length_prefix);
 1036|  1.99k|      h->substate_context_map = BROTLI_STATE_CONTEXT_MAP_HUFFMAN;
 1037|  1.99k|    }
 1038|       |    /* Fall through. */
 1039|       |
 1040|  1.99k|    case BROTLI_STATE_CONTEXT_MAP_HUFFMAN: {
  ------------------
  |  Branch (1040:5): [True: 0, False: 18.2k]
  ------------------
 1041|  1.99k|      uint32_t alphabet_size = *num_htrees + h->max_run_length_prefix;
 1042|  1.99k|      result = ReadHuffmanCode(alphabet_size, alphabet_size,
 1043|  1.99k|                               h->context_map_table, NULL, s);
 1044|  1.99k|      if (result != BROTLI_DECODER_SUCCESS) return result;
  ------------------
  |  Branch (1044:11): [True: 90, False: 1.90k]
  ------------------
 1045|  1.90k|      h->code = 0xFFFF;
 1046|  1.90k|      h->substate_context_map = BROTLI_STATE_CONTEXT_MAP_DECODE;
 1047|  1.90k|    }
 1048|       |    /* Fall through. */
 1049|       |
 1050|  1.90k|    case BROTLI_STATE_CONTEXT_MAP_DECODE: {
  ------------------
  |  Branch (1050:5): [True: 0, False: 18.2k]
  ------------------
 1051|  1.90k|      uint32_t context_index = h->context_index;
 1052|  1.90k|      uint32_t max_run_length_prefix = h->max_run_length_prefix;
 1053|  1.90k|      uint8_t* context_map = *context_map_arg;
 1054|  1.90k|      uint32_t code = h->code;
 1055|  1.90k|      BROTLI_BOOL skip_preamble = (code != 0xFFFF);
  ------------------
  |  |   49|  1.90k|#define BROTLI_BOOL int
  ------------------
 1056|   246k|      while (context_index < context_map_size || skip_preamble) {
  ------------------
  |  Branch (1056:14): [True: 245k, False: 1.76k]
  |  Branch (1056:50): [True: 0, False: 1.76k]
  ------------------
 1057|   245k|        if (!skip_preamble) {
  ------------------
  |  Branch (1057:13): [True: 245k, False: 0]
  ------------------
 1058|   245k|          if (!SafeReadSymbol(h->context_map_table, br, &code)) {
  ------------------
  |  Branch (1058:15): [True: 37, False: 245k]
  ------------------
 1059|     37|            h->code = 0xFFFF;
 1060|     37|            h->context_index = context_index;
 1061|     37|            return BROTLI_DECODER_NEEDS_MORE_INPUT;
 1062|     37|          }
 1063|   245k|          BROTLI_LOG_UINT(code);
 1064|       |
 1065|   245k|          if (code == 0) {
  ------------------
  |  Branch (1065:15): [True: 28.8k, False: 216k]
  ------------------
 1066|  28.8k|            context_map[context_index++] = 0;
 1067|  28.8k|            continue;
 1068|  28.8k|          }
 1069|   216k|          if (code > max_run_length_prefix) {
  ------------------
  |  Branch (1069:15): [True: 214k, False: 2.09k]
  ------------------
 1070|   214k|            context_map[context_index++] =
 1071|   214k|                (uint8_t)(code - max_run_length_prefix);
 1072|   214k|            continue;
 1073|   214k|          }
 1074|   216k|        } else {
 1075|      0|          skip_preamble = BROTLI_FALSE;
  ------------------
  |  |   53|      0|#define BROTLI_FALSE 0
  ------------------
 1076|      0|        }
 1077|       |        /* RLE sub-stage. */
 1078|  2.09k|        {
 1079|  2.09k|          uint32_t reps;
 1080|  2.09k|          if (!BrotliSafeReadBits(br, code, &reps)) {
  ------------------
  |  Branch (1080:15): [True: 60, False: 2.03k]
  ------------------
 1081|     60|            h->code = code;
 1082|     60|            h->context_index = context_index;
 1083|     60|            return BROTLI_DECODER_NEEDS_MORE_INPUT;
 1084|     60|          }
 1085|  2.03k|          reps += 1U << code;
 1086|  2.03k|          BROTLI_LOG_UINT(reps);
 1087|  2.03k|          if (context_index + reps > context_map_size) {
  ------------------
  |  Branch (1087:15): [True: 42, False: 1.99k]
  ------------------
 1088|     42|            return
 1089|     42|                BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT);
  ------------------
  |  |   31|     42|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|     42|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 1090|     42|          }
 1091|   169k|          do {
 1092|   169k|            context_map[context_index++] = 0;
 1093|   169k|          } while (--reps);
  ------------------
  |  Branch (1093:20): [True: 167k, False: 1.99k]
  ------------------
 1094|  1.99k|        }
 1095|  1.99k|      }
 1096|  1.90k|    }
 1097|       |    /* Fall through. */
 1098|       |
 1099|  1.76k|    case BROTLI_STATE_CONTEXT_MAP_TRANSFORM: {
  ------------------
  |  Branch (1099:5): [True: 0, False: 18.2k]
  ------------------
 1100|  1.76k|      uint32_t bits;
 1101|  1.76k|      if (!BrotliSafeReadBits(br, 1, &bits)) {
  ------------------
  |  Branch (1101:11): [True: 15, False: 1.74k]
  ------------------
 1102|     15|        h->substate_context_map = BROTLI_STATE_CONTEXT_MAP_TRANSFORM;
 1103|     15|        return BROTLI_DECODER_NEEDS_MORE_INPUT;
 1104|     15|      }
 1105|  1.74k|      if (bits != 0) {
  ------------------
  |  Branch (1105:11): [True: 1.38k, False: 358]
  ------------------
 1106|  1.38k|        InverseMoveToFrontTransform(*context_map_arg, context_map_size, s);
 1107|  1.38k|      }
 1108|  1.74k|      h->substate_context_map = BROTLI_STATE_CONTEXT_MAP_NONE;
 1109|  1.74k|      return BROTLI_DECODER_SUCCESS;
 1110|  1.76k|    }
 1111|       |
 1112|      0|    default:
  ------------------
  |  Branch (1112:5): [True: 0, False: 18.2k]
  ------------------
 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|  18.2k|  }
 1116|  18.2k|}
decode.c:InverseMoveToFrontTransform:
  925|  1.38k|    uint8_t* v, uint32_t v_len, BrotliDecoderState* state) {
  926|       |  /* Reinitialize elements that could have been changed. */
  927|  1.38k|  uint32_t i = 1;
  928|  1.38k|  uint32_t upper_bound = state->mtf_upper_bound;
  929|  1.38k|  uint32_t* mtf = &state->mtf[1];  /* Make mtf[-1] addressable. */
  930|  1.38k|  uint8_t* mtf_u8 = (uint8_t*)mtf;
  931|       |  /* Load endian-aware constant. */
  932|  1.38k|  const uint8_t b0123[4] = {0, 1, 2, 3};
  933|  1.38k|  uint32_t pattern;
  934|  1.38k|  memcpy(&pattern, &b0123, 4);
  935|       |
  936|       |  /* Initialize list using 4 consequent values pattern. */
  937|  1.38k|  mtf[0] = pattern;
  938|  21.3k|  do {
  939|  21.3k|    pattern += 0x04040404;  /* Advance all 4 values by 4. */
  940|  21.3k|    mtf[i] = pattern;
  941|  21.3k|    i++;
  942|  21.3k|  } while (i <= upper_bound);
  ------------------
  |  Branch (942:12): [True: 19.9k, False: 1.38k]
  ------------------
  943|       |
  944|       |  /* Transform the input. */
  945|  1.38k|  upper_bound = 0;
  946|   142k|  for (i = 0; i < v_len; ++i) {
  ------------------
  |  Branch (946:15): [True: 140k, False: 1.38k]
  ------------------
  947|   140k|    int index = v[i];
  948|   140k|    uint8_t value = mtf_u8[index];
  949|   140k|    upper_bound |= v[i];
  950|   140k|    v[i] = value;
  951|   140k|    mtf_u8[-1] = value;
  952|  1.74M|    do {
  953|  1.74M|      index--;
  954|  1.74M|      mtf_u8[index + 1] = mtf_u8[index];
  955|  1.74M|    } while (index >= 0);
  ------------------
  |  Branch (955:14): [True: 1.60M, False: 140k]
  ------------------
  956|   140k|  }
  957|       |  /* Remember amount of elements to be reinitialized. */
  958|  1.38k|  state->mtf_upper_bound = upper_bound >> 2;
  959|  1.38k|}
decode.c:DetectTrivialLiteralBlockTypes:
 1165|  9.03k|    BrotliDecoderState* s) {
 1166|  9.03k|  size_t i;
 1167|  81.3k|  for (i = 0; i < 8; ++i) s->trivial_literal_contexts[i] = 0;
  ------------------
  |  Branch (1167:15): [True: 72.2k, False: 9.03k]
  ------------------
 1168|  33.1k|  for (i = 0; i < s->num_block_types[0]; i++) {
  ------------------
  |  Branch (1168:15): [True: 24.1k, False: 9.03k]
  ------------------
 1169|  24.1k|    size_t offset = i << BROTLI_LITERAL_CONTEXT_BITS;
  ------------------
  |  |   94|  24.1k|#define BROTLI_LITERAL_CONTEXT_BITS 6
  ------------------
 1170|  24.1k|    size_t error = 0;
 1171|  24.1k|    size_t sample = s->context_map[offset];
 1172|  24.1k|    size_t j;
 1173|   410k|    for (j = 0; j < (1u << BROTLI_LITERAL_CONTEXT_BITS);) {
  ------------------
  |  |   94|   410k|#define BROTLI_LITERAL_CONTEXT_BITS 6
  ------------------
  |  Branch (1173:17): [True: 386k, False: 24.1k]
  ------------------
 1174|   386k|      BROTLI_REPEAT(4, error |= s->context_map[offset + j++] ^ sample;)
  ------------------
  |  |  505|   386k|#define BROTLI_REPEAT(N, X) {     \
  |  |  506|   386k|  if ((N & 1) != 0) {X;}          \
  |  |  ------------------
  |  |  |  Branch (506:7): [Folded, False: 386k]
  |  |  ------------------
  |  |  507|   386k|  if ((N & 2) != 0) {X; X;}       \
  |  |  ------------------
  |  |  |  Branch (507:7): [Folded, False: 386k]
  |  |  ------------------
  |  |  508|   386k|  if ((N & 4) != 0) {X; X; X; X;} \
  |  |  ------------------
  |  |  |  Branch (508:7): [True: 386k, Folded]
  |  |  ------------------
  |  |  509|   386k|}
  ------------------
 1175|   386k|    }
 1176|  24.1k|    if (error == 0) {
  ------------------
  |  Branch (1176:9): [True: 21.2k, False: 2.93k]
  ------------------
 1177|  21.2k|      s->trivial_literal_contexts[i >> 5] |= 1u << (i & 31);
 1178|  21.2k|    }
 1179|  24.1k|  }
 1180|  9.03k|}
decode.c:HuffmanTreeGroupDecode:
  963|  25.9k|    HuffmanTreeGroup* group, BrotliDecoderState* s) {
  964|  25.9k|  BrotliMetablockHeaderArena* h = &s->arena.header;
  965|  25.9k|  if (h->substate_tree_group != BROTLI_STATE_TREE_GROUP_LOOP) {
  ------------------
  |  Branch (965:7): [True: 25.9k, False: 0]
  ------------------
  966|  25.9k|    h->next = group->codes;
  967|  25.9k|    h->htree_index = 0;
  968|  25.9k|    h->substate_tree_group = BROTLI_STATE_TREE_GROUP_LOOP;
  969|  25.9k|  }
  970|  63.0k|  while (h->htree_index < group->num_htrees) {
  ------------------
  |  Branch (970:10): [True: 37.6k, False: 25.4k]
  ------------------
  971|  37.6k|    uint32_t table_size;
  972|  37.6k|    BrotliDecoderErrorCode result = ReadHuffmanCode(group->alphabet_size_max,
  973|  37.6k|        group->alphabet_size_limit, h->next, &table_size, s);
  974|  37.6k|    if (result != BROTLI_DECODER_SUCCESS) return result;
  ------------------
  |  Branch (974:9): [True: 552, False: 37.1k]
  ------------------
  975|  37.1k|    group->htrees[h->htree_index] = h->next;
  976|  37.1k|    h->next += table_size;
  977|  37.1k|    ++h->htree_index;
  978|  37.1k|  }
  979|  25.4k|  h->substate_tree_group = BROTLI_STATE_TREE_GROUP_NONE;
  980|  25.4k|  return BROTLI_DECODER_SUCCESS;
  981|  25.9k|}
decode.c:PrepareLiteralDecoding:
 1182|   107k|static BROTLI_INLINE void PrepareLiteralDecoding(BrotliDecoderState* s) {
 1183|   107k|  uint8_t context_mode;
 1184|   107k|  size_t trivial;
 1185|   107k|  uint32_t block_type = s->block_type_rb[1];
 1186|   107k|  uint32_t context_offset = block_type << BROTLI_LITERAL_CONTEXT_BITS;
  ------------------
  |  |   94|   107k|#define BROTLI_LITERAL_CONTEXT_BITS 6
  ------------------
 1187|   107k|  s->context_map_slice = s->context_map + context_offset;
 1188|   107k|  trivial = s->trivial_literal_contexts[block_type >> 5];
 1189|   107k|  s->trivial_literal_context = (trivial >> (block_type & 31)) & 1;
 1190|   107k|  s->literal_htree = s->literal_hgroup.htrees[s->context_map_slice[0]];
 1191|   107k|  context_mode = s->context_modes[block_type] & 3;
 1192|   107k|  s->context_lookup = BROTLI_CONTEXT_LUT(context_mode);
  ------------------
  |  |  108|   107k|#define BROTLI_CONTEXT_LUT(MODE) (&_kBrotliContextLookupTable[(MODE) << 9])
  ------------------
 1193|   107k|}
decode.c:BrotliEnsureRingBuffer:
 1327|  10.9k|    BrotliDecoderState* s) {
 1328|  10.9k|  uint8_t* old_ringbuffer = s->ringbuffer;
 1329|  10.9k|  if (s->ringbuffer_size == s->new_ringbuffer_size) {
  ------------------
  |  Branch (1329:7): [True: 8.12k, False: 2.84k]
  ------------------
 1330|  8.12k|    return BROTLI_TRUE;
  ------------------
  |  |   51|  8.12k|#define BROTLI_TRUE 1
  ------------------
 1331|  8.12k|  }
 1332|       |
 1333|  2.84k|  s->ringbuffer = (uint8_t*)BROTLI_DECODER_ALLOC(s,
  ------------------
  |  |  354|  2.84k|#define BROTLI_DECODER_ALLOC(S, L) S->alloc_func(S->memory_manager_opaque, L)
  ------------------
 1334|  2.84k|      (size_t)(s->new_ringbuffer_size) + kRingBufferWriteAheadSlack);
 1335|  2.84k|  if (s->ringbuffer == 0) {
  ------------------
  |  Branch (1335:7): [True: 0, False: 2.84k]
  ------------------
 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.84k|  s->ringbuffer[s->new_ringbuffer_size - 2] = 0;
 1341|  2.84k|  s->ringbuffer[s->new_ringbuffer_size - 1] = 0;
 1342|       |
 1343|  2.84k|  if (!!old_ringbuffer) {
  ------------------
  |  Branch (1343:7): [True: 277, False: 2.56k]
  ------------------
 1344|    277|    memcpy(s->ringbuffer, old_ringbuffer, (size_t)s->pos);
 1345|    277|    BROTLI_DECODER_FREE(s, old_ringbuffer);
  ------------------
  |  |  356|    277|#define BROTLI_DECODER_FREE(S, X) {          \
  |  |  357|    277|  S->free_func(S->memory_manager_opaque, X); \
  |  |  358|    277|  X = NULL;                                  \
  |  |  359|    277|}
  ------------------
 1346|    277|  }
 1347|       |
 1348|  2.84k|  s->ringbuffer_size = s->new_ringbuffer_size;
 1349|  2.84k|  s->ringbuffer_mask = s->new_ringbuffer_size - 1;
 1350|  2.84k|  s->ringbuffer_end = s->ringbuffer + s->ringbuffer_size;
 1351|       |
 1352|  2.84k|  return BROTLI_TRUE;
  ------------------
  |  |   51|  2.84k|#define BROTLI_TRUE 1
  ------------------
 1353|  2.84k|}
decode.c:CalculateDistanceLut:
 1583|  8.34k|static void CalculateDistanceLut(BrotliDecoderState* s) {
 1584|  8.34k|  BrotliMetablockBodyArena* b = &s->arena.body;
 1585|  8.34k|  uint32_t npostfix = s->distance_postfix_bits;
 1586|  8.34k|  uint32_t ndirect = s->num_direct_distance_codes;
 1587|  8.34k|  uint32_t alphabet_size_limit = s->distance_hgroup.alphabet_size_limit;
 1588|  8.34k|  uint32_t postfix = 1u << npostfix;
 1589|  8.34k|  uint32_t j;
 1590|  8.34k|  uint32_t bits = 1;
 1591|  8.34k|  uint32_t half = 0;
 1592|       |
 1593|       |  /* Skip short codes. */
 1594|  8.34k|  uint32_t i = BROTLI_NUM_DISTANCE_SHORT_CODES;
  ------------------
  |  |   60|  8.34k|#define BROTLI_NUM_DISTANCE_SHORT_CODES 16
  ------------------
 1595|       |
 1596|       |  /* Fill direct codes. */
 1597|   129k|  for (j = 0; j < ndirect; ++j) {
  ------------------
  |  Branch (1597:15): [True: 121k, False: 8.34k]
  ------------------
 1598|   121k|    b->dist_extra_bits[i] = 0;
 1599|   121k|    b->dist_offset[i] = j + 1;
 1600|   121k|    ++i;
 1601|   121k|  }
 1602|       |
 1603|       |  /* Fill regular distance codes. */
 1604|   408k|  while (i < alphabet_size_limit) {
  ------------------
  |  Branch (1604:10): [True: 400k, False: 8.34k]
  ------------------
 1605|   400k|    uint32_t base = ndirect + ((((2 + half) << bits) - 4) << npostfix) + 1;
 1606|       |    /* Always fill the complete group. */
 1607|  1.21M|    for (j = 0; j < postfix; ++j) {
  ------------------
  |  Branch (1607:17): [True: 815k, False: 400k]
  ------------------
 1608|   815k|      b->dist_extra_bits[i] = (uint8_t)bits;
 1609|   815k|      b->dist_offset[i] = base + j;
 1610|   815k|      ++i;
 1611|   815k|    }
 1612|   400k|    bits = bits + half;
 1613|   400k|    half = half ^ 1;
 1614|   400k|  }
 1615|  8.34k|}
decode.c:ProcessCommands:
 2026|   157k|    BrotliDecoderState* s) {
 2027|   157k|  return ProcessCommandsInternal(0, s);
 2028|   157k|}
decode.c:ProcessCommandsInternal:
 1735|   285k|    int safe, BrotliDecoderState* s) {
 1736|   285k|  int pos = s->pos;
 1737|   285k|  int i = s->loop_counter;
 1738|   285k|  BrotliDecoderErrorCode result = BROTLI_DECODER_SUCCESS;
 1739|   285k|  BrotliBitReader* br = &s->br;
 1740|       |
 1741|   285k|  if (!CheckInputAmount(safe, br, 28)) {
  ------------------
  |  Branch (1741:7): [True: 96.1k, False: 189k]
  ------------------
 1742|  96.1k|    result = BROTLI_DECODER_NEEDS_MORE_INPUT;
 1743|  96.1k|    goto saveStateAndReturn;
 1744|  96.1k|  }
 1745|   189k|  if (!safe) {
  ------------------
  |  Branch (1745:7): [True: 61.7k, False: 127k]
  ------------------
 1746|  61.7k|    BROTLI_UNUSED(BrotliWarmupBitReader(br));
  ------------------
  |  |  511|  61.7k|#define BROTLI_UNUSED(X) (void)(X)
  ------------------
 1747|  61.7k|  }
 1748|       |
 1749|       |  /* Jump into state machine. */
 1750|   189k|  if (s->state == BROTLI_STATE_COMMAND_BEGIN) {
  ------------------
  |  Branch (1750:7): [True: 40.6k, False: 149k]
  ------------------
 1751|  40.6k|    goto CommandBegin;
 1752|   149k|  } else if (s->state == BROTLI_STATE_COMMAND_INNER) {
  ------------------
  |  Branch (1752:14): [True: 54.2k, False: 94.8k]
  ------------------
 1753|  54.2k|    goto CommandInner;
 1754|  94.8k|  } else if (s->state == BROTLI_STATE_COMMAND_POST_DECODE_LITERALS) {
  ------------------
  |  Branch (1754:14): [True: 23.1k, False: 71.7k]
  ------------------
 1755|  23.1k|    goto CommandPostDecodeLiterals;
 1756|  71.7k|  } else if (s->state == BROTLI_STATE_COMMAND_POST_WRAP_COPY) {
  ------------------
  |  Branch (1756:14): [True: 71.7k, False: 0]
  ------------------
 1757|  71.7k|    goto CommandPostWrapCopy;
 1758|  71.7k|  } 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|   335M|CommandBegin:
 1763|   335M|  if (safe) {
  ------------------
  |  Branch (1763:7): [True: 252M, False: 83.0M]
  ------------------
 1764|   252M|    s->state = BROTLI_STATE_COMMAND_BEGIN;
 1765|   252M|  }
 1766|   335M|  if (!CheckInputAmount(safe, br, 28)) {  /* 156 bits + 7 bytes */
  ------------------
  |  Branch (1766:7): [True: 14.3k, False: 335M]
  ------------------
 1767|  14.3k|    s->state = BROTLI_STATE_COMMAND_BEGIN;
 1768|  14.3k|    result = BROTLI_DECODER_NEEDS_MORE_INPUT;
 1769|  14.3k|    goto saveStateAndReturn;
 1770|  14.3k|  }
 1771|   335M|  if (BROTLI_PREDICT_FALSE(s->block_length[1] == 0)) {
  ------------------
  |  |   83|   335M|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 15.6k, False: 335M]
  |  |  ------------------
  ------------------
 1772|  15.6k|    BROTLI_SAFE(DecodeCommandBlockSwitch(s));
  ------------------
  |  | 1723|  15.6k|  {                                               \
  |  | 1724|  15.6k|    if (safe) {                                   \
  |  |  ------------------
  |  |  |  Branch (1724:9): [True: 5.12k, False: 10.5k]
  |  |  ------------------
  |  | 1725|  5.12k|      if (!Safe##METHOD) {                        \
  |  |  ------------------
  |  |  |  Branch (1725:11): [True: 97, False: 5.02k]
  |  |  ------------------
  |  | 1726|     97|        result = BROTLI_DECODER_NEEDS_MORE_INPUT; \
  |  | 1727|     97|        goto saveStateAndReturn;                  \
  |  | 1728|     97|      }                                           \
  |  | 1729|  10.5k|    } else {                                      \
  |  | 1730|  10.5k|      METHOD;                                     \
  |  | 1731|  10.5k|    }                                             \
  |  | 1732|  15.6k|  }
  ------------------
 1773|  15.5k|    goto CommandBegin;
 1774|  15.6k|  }
 1775|       |  /* Read the insert/copy length in the command. */
 1776|   335M|  BROTLI_SAFE(ReadCommand(s, br, &i));
  ------------------
  |  | 1723|   335M|  {                                               \
  |  | 1724|   335M|    if (safe) {                                   \
  |  |  ------------------
  |  |  |  Branch (1724:9): [True: 252M, False: 83.0M]
  |  |  ------------------
  |  | 1725|   252M|      if (!Safe##METHOD) {                        \
  |  |  ------------------
  |  |  |  Branch (1725:11): [True: 300, False: 252M]
  |  |  ------------------
  |  | 1726|    300|        result = BROTLI_DECODER_NEEDS_MORE_INPUT; \
  |  | 1727|    300|        goto saveStateAndReturn;                  \
  |  | 1728|    300|      }                                           \
  |  | 1729|   252M|    } else {                                      \
  |  | 1730|  83.0M|      METHOD;                                     \
  |  | 1731|  83.0M|    }                                             \
  |  | 1732|   335M|  }
  ------------------
 1777|   335M|  BROTLI_LOG(("[ProcessCommandsInternal] pos = %d insert = %d copy = %d\n",
 1778|   335M|              pos, i, s->copy_length));
 1779|   335M|  if (i == 0) {
  ------------------
  |  Branch (1779:7): [True: 21.9M, False: 313M]
  ------------------
 1780|  21.9M|    goto CommandPostDecodeLiterals;
 1781|  21.9M|  }
 1782|   313M|  s->meta_block_remaining_len -= i;
 1783|       |
 1784|   313M|CommandInner:
 1785|   313M|  if (safe) {
  ------------------
  |  Branch (1785:7): [True: 234M, False: 78.8M]
  ------------------
 1786|   234M|    s->state = BROTLI_STATE_COMMAND_INNER;
 1787|   234M|  }
 1788|       |  /* Read the literals in the command. */
 1789|   313M|  if (s->trivial_literal_context) {
  ------------------
  |  Branch (1789:7): [True: 309M, False: 3.97M]
  ------------------
 1790|   309M|    uint32_t bits;
 1791|   309M|    uint32_t value;
 1792|   309M|    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: 5.55k, False: 1.56G]
  ------------------
 1795|  5.55k|        s->state = BROTLI_STATE_COMMAND_INNER;
 1796|  5.55k|        result = BROTLI_DECODER_NEEDS_MORE_INPUT;
 1797|  5.55k|        goto saveStateAndReturn;
 1798|  5.55k|      }
 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: 15.5k, False: 1.56G]
  |  |  ------------------
  ------------------
 1800|  15.5k|        BROTLI_SAFE(DecodeLiteralBlockSwitch(s));
  ------------------
  |  | 1723|  15.5k|  {                                               \
  |  | 1724|  15.5k|    if (safe) {                                   \
  |  |  ------------------
  |  |  |  Branch (1724:9): [True: 6.49k, False: 9.09k]
  |  |  ------------------
  |  | 1725|  6.49k|      if (!Safe##METHOD) {                        \
  |  |  ------------------
  |  |  |  Branch (1725:11): [True: 121, False: 6.37k]
  |  |  ------------------
  |  | 1726|    121|        result = BROTLI_DECODER_NEEDS_MORE_INPUT; \
  |  | 1727|    121|        goto saveStateAndReturn;                  \
  |  | 1728|    121|      }                                           \
  |  | 1729|  9.09k|    } else {                                      \
  |  | 1730|  9.09k|      METHOD;                                     \
  |  | 1731|  9.09k|    }                                             \
  |  | 1732|  15.5k|  }
  ------------------
 1801|  15.4k|        PreloadSymbol(safe, s->literal_htree, br, &bits, &value);
 1802|  15.4k|        if (!s->trivial_literal_context) goto CommandInner;
  ------------------
  |  Branch (1802:13): [True: 834, False: 14.6k]
  ------------------
 1803|  15.4k|      }
 1804|  1.56G|      if (!safe) {
  ------------------
  |  Branch (1804:11): [True: 453M, False: 1.11G]
  ------------------
 1805|   453M|        s->ringbuffer[pos] =
 1806|   453M|            (uint8_t)ReadPreloadedSymbol(s->literal_htree, br, &bits, &value);
 1807|  1.11G|      } else {
 1808|  1.11G|        uint32_t literal;
 1809|  1.11G|        if (!SafeReadSymbol(s->literal_htree, br, &literal)) {
  ------------------
  |  Branch (1809:13): [True: 55, False: 1.11G]
  ------------------
 1810|     55|          result = BROTLI_DECODER_NEEDS_MORE_INPUT;
 1811|     55|          goto saveStateAndReturn;
 1812|     55|        }
 1813|  1.11G|        s->ringbuffer[pos] = (uint8_t)literal;
 1814|  1.11G|      }
 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: 32.8k, False: 1.56G]
  |  |  ------------------
  ------------------
 1819|  32.8k|        s->state = BROTLI_STATE_COMMAND_INNER_WRITE;
 1820|  32.8k|        --i;
 1821|  32.8k|        goto saveStateAndReturn;
 1822|  32.8k|      }
 1823|  1.56G|    } while (--i != 0);
  ------------------
  |  Branch (1823:14): [True: 1.25G, False: 309M]
  ------------------
 1824|   309M|  } else {
 1825|  3.97M|    uint8_t p1 = s->ringbuffer[(pos - 1) & s->ringbuffer_mask];
 1826|  3.97M|    uint8_t p2 = s->ringbuffer[(pos - 2) & s->ringbuffer_mask];
 1827|   107M|    do {
 1828|   107M|      const HuffmanCode* hc;
 1829|   107M|      uint8_t context;
 1830|   107M|      if (!CheckInputAmount(safe, br, 28)) {  /* 162 bits + 7 bytes */
  ------------------
  |  Branch (1830:11): [True: 11.9k, False: 107M]
  ------------------
 1831|  11.9k|        s->state = BROTLI_STATE_COMMAND_INNER;
 1832|  11.9k|        result = BROTLI_DECODER_NEEDS_MORE_INPUT;
 1833|  11.9k|        goto saveStateAndReturn;
 1834|  11.9k|      }
 1835|   107M|      if (BROTLI_PREDICT_FALSE(s->block_length[0] == 0)) {
  ------------------
  |  |   83|   107M|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 83.5k, False: 107M]
  |  |  ------------------
  ------------------
 1836|  83.5k|        BROTLI_SAFE(DecodeLiteralBlockSwitch(s));
  ------------------
  |  | 1723|  83.5k|  {                                               \
  |  | 1724|  83.5k|    if (safe) {                                   \
  |  |  ------------------
  |  |  |  Branch (1724:9): [True: 2.10k, False: 81.4k]
  |  |  ------------------
  |  | 1725|  2.10k|      if (!Safe##METHOD) {                        \
  |  |  ------------------
  |  |  |  Branch (1725:11): [True: 28, False: 2.07k]
  |  |  ------------------
  |  | 1726|     28|        result = BROTLI_DECODER_NEEDS_MORE_INPUT; \
  |  | 1727|     28|        goto saveStateAndReturn;                  \
  |  | 1728|     28|      }                                           \
  |  | 1729|  81.4k|    } else {                                      \
  |  | 1730|  81.4k|      METHOD;                                     \
  |  | 1731|  81.4k|    }                                             \
  |  | 1732|  83.5k|  }
  ------------------
 1837|  83.5k|        if (s->trivial_literal_context) goto CommandInner;
  ------------------
  |  Branch (1837:13): [True: 827, False: 82.6k]
  ------------------
 1838|  83.5k|      }
 1839|   107M|      context = BROTLI_CONTEXT(p1, p2, s->context_lookup);
  ------------------
  |  |  111|   107M|#define BROTLI_CONTEXT(P1, P2, LUT) ((LUT)[P1] | ((LUT) + 256)[P2])
  ------------------
 1840|   107M|      BROTLI_LOG_UINT(context);
 1841|   107M|      hc = s->literal_hgroup.htrees[s->context_map_slice[context]];
 1842|   107M|      p2 = p1;
 1843|   107M|      if (!safe) {
  ------------------
  |  Branch (1843:11): [True: 36.8M, False: 71.0M]
  ------------------
 1844|  36.8M|        p1 = (uint8_t)ReadSymbol(hc, br);
 1845|  71.0M|      } else {
 1846|  71.0M|        uint32_t literal;
 1847|  71.0M|        if (!SafeReadSymbol(hc, br, &literal)) {
  ------------------
  |  Branch (1847:13): [True: 9, False: 71.0M]
  ------------------
 1848|      9|          result = BROTLI_DECODER_NEEDS_MORE_INPUT;
 1849|      9|          goto saveStateAndReturn;
 1850|      9|        }
 1851|  71.0M|        p1 = (uint8_t)literal;
 1852|  71.0M|      }
 1853|   107M|      s->ringbuffer[pos] = p1;
 1854|   107M|      --s->block_length[0];
 1855|   107M|      BROTLI_LOG_UINT(s->context_map_slice[context]);
 1856|   107M|      BROTLI_LOG_ARRAY_INDEX(s->ringbuffer, pos & s->ringbuffer_mask);
 1857|   107M|      ++pos;
 1858|   107M|      if (BROTLI_PREDICT_FALSE(pos == s->ringbuffer_size)) {
  ------------------
  |  |   83|   107M|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 27.2k, False: 107M]
  |  |  ------------------
  ------------------
 1859|  27.2k|        s->state = BROTLI_STATE_COMMAND_INNER_WRITE;
 1860|  27.2k|        --i;
 1861|  27.2k|        goto saveStateAndReturn;
 1862|  27.2k|      }
 1863|   107M|    } while (--i != 0);
  ------------------
  |  Branch (1863:14): [True: 103M, False: 3.93M]
  ------------------
 1864|  3.97M|  }
 1865|   313M|  BROTLI_LOG_UINT(s->meta_block_remaining_len);
 1866|   313M|  if (BROTLI_PREDICT_FALSE(s->meta_block_remaining_len <= 0)) {
  ------------------
  |  |   83|   313M|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 3.76k, False: 313M]
  |  |  ------------------
  ------------------
 1867|  3.76k|    s->state = BROTLI_STATE_METABLOCK_DONE;
 1868|  3.76k|    goto saveStateAndReturn;
 1869|  3.76k|  }
 1870|       |
 1871|   335M|CommandPostDecodeLiterals:
 1872|   335M|  if (safe) {
  ------------------
  |  Branch (1872:7): [True: 252M, False: 83.0M]
  ------------------
 1873|   252M|    s->state = BROTLI_STATE_COMMAND_POST_DECODE_LITERALS;
 1874|   252M|  }
 1875|   335M|  if (s->distance_code >= 0) {
  ------------------
  |  Branch (1875:7): [True: 289M, False: 45.7M]
  ------------------
 1876|       |    /* Implicit distance case. */
 1877|   289M|    s->distance_context = s->distance_code ? 0 : 1;
  ------------------
  |  Branch (1877:27): [True: 0, False: 289M]
  ------------------
 1878|   289M|    --s->dist_rb_idx;
 1879|   289M|    s->distance_code = s->dist_rb[s->dist_rb_idx & 3];
 1880|   289M|  } else {
 1881|       |    /* Read distance code in the command, unless it was implicitly zero. */
 1882|  45.7M|    if (BROTLI_PREDICT_FALSE(s->block_length[2] == 0)) {
  ------------------
  |  |   83|  45.7M|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 17.2k, False: 45.6M]
  |  |  ------------------
  ------------------
 1883|  17.2k|      BROTLI_SAFE(DecodeDistanceBlockSwitch(s));
  ------------------
  |  | 1723|  17.2k|  {                                               \
  |  | 1724|  17.2k|    if (safe) {                                   \
  |  |  ------------------
  |  |  |  Branch (1724:9): [True: 5.98k, False: 11.2k]
  |  |  ------------------
  |  | 1725|  5.98k|      if (!Safe##METHOD) {                        \
  |  |  ------------------
  |  |  |  Branch (1725:11): [True: 131, False: 5.85k]
  |  |  ------------------
  |  | 1726|    131|        result = BROTLI_DECODER_NEEDS_MORE_INPUT; \
  |  | 1727|    131|        goto saveStateAndReturn;                  \
  |  | 1728|    131|      }                                           \
  |  | 1729|  11.2k|    } else {                                      \
  |  | 1730|  11.2k|      METHOD;                                     \
  |  | 1731|  11.2k|    }                                             \
  |  | 1732|  17.2k|  }
  ------------------
 1884|  17.1k|    }
 1885|  45.7M|    BROTLI_SAFE(ReadDistance(s, br));
  ------------------
  |  | 1723|  45.7M|  {                                               \
  |  | 1724|  45.7M|    if (safe) {                                   \
  |  |  ------------------
  |  |  |  Branch (1724:9): [True: 40.5M, False: 5.13M]
  |  |  ------------------
  |  | 1725|  40.5M|      if (!Safe##METHOD) {                        \
  |  |  ------------------
  |  |  |  Branch (1725:11): [True: 242, False: 40.5M]
  |  |  ------------------
  |  | 1726|    242|        result = BROTLI_DECODER_NEEDS_MORE_INPUT; \
  |  | 1727|    242|        goto saveStateAndReturn;                  \
  |  | 1728|    242|      }                                           \
  |  | 1729|  40.5M|    } else {                                      \
  |  | 1730|  5.13M|      METHOD;                                     \
  |  | 1731|  5.13M|    }                                             \
  |  | 1732|  45.7M|  }
  ------------------
 1886|  45.7M|  }
 1887|   335M|  BROTLI_LOG(("[ProcessCommandsInternal] pos = %d distance = %d\n",
 1888|   335M|              pos, s->distance_code));
 1889|   335M|  if (s->max_distance != s->max_backward_distance) {
  ------------------
  |  Branch (1889:7): [True: 139M, False: 195M]
  ------------------
 1890|   139M|    s->max_distance =
 1891|   139M|        (pos < s->max_backward_distance) ? pos : s->max_backward_distance;
  ------------------
  |  Branch (1891:9): [True: 139M, False: 526]
  ------------------
 1892|   139M|  }
 1893|   335M|  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|   335M|  if (s->distance_code > s->max_distance) {
  ------------------
  |  Branch (1896:7): [True: 13.9M, False: 321M]
  ------------------
 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|  13.9M|    if (s->distance_code > BROTLI_MAX_ALLOWED_DISTANCE) {
  ------------------
  |  |   86|  13.9M|#define BROTLI_MAX_ALLOWED_DISTANCE 0x7FFFFFFC
  ------------------
  |  Branch (1900:9): [True: 34, False: 13.9M]
  ------------------
 1901|     34|      BROTLI_LOG(("Invalid backward reference. pos: %d distance: %d "
 1902|     34|          "len: %d bytes left: %d\n",
 1903|     34|          pos, s->distance_code, i, s->meta_block_remaining_len));
 1904|     34|      return BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_DISTANCE);
  ------------------
  |  |   31|     34|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|     34|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 1905|     34|    }
 1906|  13.9M|    if (i >= BROTLI_MIN_DICTIONARY_WORD_LENGTH &&
  ------------------
  |  |   57|  27.9M|#define BROTLI_MIN_DICTIONARY_WORD_LENGTH 4
  ------------------
  |  Branch (1906:9): [True: 13.9M, False: 8]
  ------------------
 1907|  13.9M|        i <= BROTLI_MAX_DICTIONARY_WORD_LENGTH) {
  ------------------
  |  |   58|  13.9M|#define BROTLI_MAX_DICTIONARY_WORD_LENGTH 24
  ------------------
  |  Branch (1907:9): [True: 13.9M, False: 42]
  ------------------
 1908|  13.9M|      int address = s->distance_code - s->max_distance - 1;
 1909|  13.9M|      const BrotliDictionary* words = s->dictionary;
 1910|  13.9M|      const BrotliTransforms* transforms = s->transforms;
 1911|  13.9M|      int offset = (int)s->dictionary->offsets_by_length[i];
 1912|  13.9M|      uint32_t shift = s->dictionary->size_bits_by_length[i];
 1913|       |
 1914|  13.9M|      int mask = (int)BitMask(shift);
 1915|  13.9M|      int word_idx = address & mask;
 1916|  13.9M|      int transform_idx = address >> shift;
 1917|       |      /* Compensate double distance-ring-buffer roll. */
 1918|  13.9M|      s->dist_rb_idx += s->distance_context;
 1919|  13.9M|      offset += word_idx * i;
 1920|  13.9M|      if (BROTLI_PREDICT_FALSE(!words->data)) {
  ------------------
  |  |   83|  13.9M|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 0, False: 13.9M]
  |  |  ------------------
  ------------------
 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|  13.9M|      if (transform_idx < (int)transforms->num_transforms) {
  ------------------
  |  Branch (1923:11): [True: 13.9M, False: 93]
  ------------------
 1924|  13.9M|        const uint8_t* word = &words->data[offset];
 1925|  13.9M|        int len = i;
 1926|  13.9M|        if (transform_idx == transforms->cutOffTransforms[0]) {
  ------------------
  |  Branch (1926:13): [True: 13.9M, False: 13.2k]
  ------------------
 1927|  13.9M|          memcpy(&s->ringbuffer[pos], word, (size_t)len);
 1928|  13.9M|          BROTLI_LOG(("[ProcessCommandsInternal] dictionary word: [%.*s]\n",
 1929|  13.9M|                      len, word));
 1930|  13.9M|        } else {
 1931|  13.2k|          len = BrotliTransformDictionaryWord(&s->ringbuffer[pos], word, len,
 1932|  13.2k|              transforms, transform_idx);
 1933|  13.2k|          BROTLI_LOG(("[ProcessCommandsInternal] dictionary word: [%.*s],"
 1934|  13.2k|                      " transform_idx = %d, transformed: [%.*s]\n",
 1935|  13.2k|                      i, word, transform_idx, len, &s->ringbuffer[pos]));
 1936|  13.2k|        }
 1937|  13.9M|        pos += len;
 1938|  13.9M|        s->meta_block_remaining_len -= len;
 1939|  13.9M|        if (pos >= s->ringbuffer_size) {
  ------------------
  |  Branch (1939:13): [True: 18.0k, False: 13.9M]
  ------------------
 1940|  18.0k|          s->state = BROTLI_STATE_COMMAND_POST_WRITE_1;
 1941|  18.0k|          goto saveStateAndReturn;
 1942|  18.0k|        }
 1943|  13.9M|      } else {
 1944|     93|        BROTLI_LOG(("Invalid backward reference. pos: %d distance: %d "
 1945|     93|            "len: %d bytes left: %d\n",
 1946|     93|            pos, s->distance_code, i, s->meta_block_remaining_len));
 1947|     93|        return BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_TRANSFORM);
  ------------------
  |  |   31|     93|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|     93|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 1948|     93|      }
 1949|  13.9M|    } else {
 1950|     50|      BROTLI_LOG(("Invalid backward reference. pos: %d distance: %d "
 1951|     50|          "len: %d bytes left: %d\n",
 1952|     50|          pos, s->distance_code, i, s->meta_block_remaining_len));
 1953|     50|      return BROTLI_FAILURE(BROTLI_DECODER_ERROR_FORMAT_DICTIONARY);
  ------------------
  |  |   31|     50|#define BROTLI_FAILURE(CODE) (BROTLI_DUMP(), CODE)
  |  |  ------------------
  |  |  |  |  485|     50|#define BROTLI_DUMP() (void)(0)
  |  |  ------------------
  ------------------
 1954|     50|    }
 1955|   321M|  } else {
 1956|   321M|    int src_start = (pos - s->distance_code) & s->ringbuffer_mask;
 1957|   321M|    uint8_t* copy_dst = &s->ringbuffer[pos];
 1958|   321M|    uint8_t* copy_src = &s->ringbuffer[src_start];
 1959|   321M|    int dst_end = pos + i;
 1960|   321M|    int src_end = src_start + i;
 1961|       |    /* Update the recent distances cache. */
 1962|   321M|    s->dist_rb[s->dist_rb_idx & 3] = s->distance_code;
 1963|   321M|    ++s->dist_rb_idx;
 1964|   321M|    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|   321M|    memmove16(copy_dst, copy_src);
 1969|   321M|    if (src_end > pos && dst_end > src_start) {
  ------------------
  |  Branch (1969:9): [True: 237M, False: 83.4M]
  |  Branch (1969:26): [True: 236M, False: 1.95M]
  ------------------
 1970|       |      /* Regions intersect. */
 1971|   236M|      goto CommandPostWrapCopy;
 1972|   236M|    }
 1973|  85.4M|    if (dst_end >= s->ringbuffer_size || src_end >= s->ringbuffer_size) {
  ------------------
  |  Branch (1973:9): [True: 49.8k, False: 85.3M]
  |  Branch (1973:42): [True: 60.8k, False: 85.3M]
  ------------------
 1974|       |      /* At least one region wraps. */
 1975|   110k|      goto CommandPostWrapCopy;
 1976|   110k|    }
 1977|  85.3M|    pos += i;
 1978|  85.3M|    if (i > 16) {
  ------------------
  |  Branch (1978:9): [True: 33.2k, False: 85.2M]
  ------------------
 1979|  33.2k|      if (i > 32) {
  ------------------
  |  Branch (1979:11): [True: 3.64k, False: 29.6k]
  ------------------
 1980|  3.64k|        memcpy(copy_dst + 16, copy_src + 16, (size_t)(i - 16));
 1981|  29.6k|      } else {
 1982|       |        /* This branch covers about 45% cases.
 1983|       |           Fixed size short copy allows more compiler optimizations. */
 1984|  29.6k|        memmove16(copy_dst + 16, copy_src + 16);
 1985|  29.6k|      }
 1986|  33.2k|    }
 1987|  85.3M|  }
 1988|  99.2M|  BROTLI_LOG_UINT(s->meta_block_remaining_len);
 1989|  99.2M|  if (s->meta_block_remaining_len <= 0) {
  ------------------
  |  Branch (1989:7): [True: 864, False: 99.2M]
  ------------------
 1990|       |    /* Next metablock, if any. */
 1991|    864|    s->state = BROTLI_STATE_METABLOCK_DONE;
 1992|    864|    goto saveStateAndReturn;
 1993|  99.2M|  } else {
 1994|  99.2M|    goto CommandBegin;
 1995|  99.2M|  }
 1996|   236M|CommandPostWrapCopy:
 1997|   236M|  {
 1998|   236M|    int wrap_guard = s->ringbuffer_size - pos;
 1999|  2.35G|    while (--i >= 0) {
  ------------------
  |  Branch (1999:12): [True: 2.12G, False: 236M]
  ------------------
 2000|  2.12G|      s->ringbuffer[pos] =
 2001|  2.12G|          s->ringbuffer[(pos - s->distance_code) & s->ringbuffer_mask];
 2002|  2.12G|      ++pos;
 2003|  2.12G|      if (BROTLI_PREDICT_FALSE(--wrap_guard == 0)) {
  ------------------
  |  |   83|  2.12G|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 71.9k, False: 2.12G]
  |  |  ------------------
  ------------------
 2004|  71.9k|        s->state = BROTLI_STATE_COMMAND_POST_WRITE_2;
 2005|  71.9k|        goto saveStateAndReturn;
 2006|  71.9k|      }
 2007|  2.12G|    }
 2008|   236M|  }
 2009|   236M|  if (s->meta_block_remaining_len <= 0) {
  ------------------
  |  Branch (2009:7): [True: 2.06k, False: 236M]
  ------------------
 2010|       |    /* Next metablock, if any. */
 2011|  2.06k|    s->state = BROTLI_STATE_METABLOCK_DONE;
 2012|  2.06k|    goto saveStateAndReturn;
 2013|   236M|  } else {
 2014|   236M|    goto CommandBegin;
 2015|   236M|  }
 2016|       |
 2017|   285k|saveStateAndReturn:
 2018|   285k|  s->pos = pos;
 2019|   285k|  s->loop_counter = i;
 2020|   285k|  return result;
 2021|   236M|}
decode.c:CheckInputAmount:
 1715|  2.00G|    int safe, BrotliBitReader* const br, size_t num) {
 1716|  2.00G|  if (safe) {
  ------------------
  |  Branch (1716:7): [True: 1.43G, False: 573M]
  ------------------
 1717|  1.43G|    return BROTLI_TRUE;
  ------------------
  |  |   51|  1.43G|#define BROTLI_TRUE 1
  ------------------
 1718|  1.43G|  }
 1719|   573M|  return BrotliCheckInputAmount(br, num);
 1720|  2.00G|}
decode.c:SafeDecodeCommandBlockSwitch:
 1231|  5.12k|    BrotliDecoderState* s) {
 1232|  5.12k|  return DecodeCommandBlockSwitchInternal(1, s);
 1233|  5.12k|}
decode.c:DecodeCommandBlockSwitchInternal:
 1218|  15.6k|    int safe, BrotliDecoderState* s) {
 1219|  15.6k|  if (!DecodeBlockTypeAndLength(safe, s, 1)) {
  ------------------
  |  Branch (1219:7): [True: 97, False: 15.5k]
  ------------------
 1220|     97|    return BROTLI_FALSE;
  ------------------
  |  |   53|     97|#define BROTLI_FALSE 0
  ------------------
 1221|     97|  }
 1222|  15.5k|  s->htree_command = s->insert_copy_hgroup.htrees[s->block_type_rb[3]];
 1223|  15.5k|  return BROTLI_TRUE;
  ------------------
  |  |   51|  15.5k|#define BROTLI_TRUE 1
  ------------------
 1224|  15.6k|}
decode.c:DecodeBlockTypeAndLength:
 1121|   132k|    int safe, BrotliDecoderState* s, int tree_type) {
 1122|   132k|  uint32_t max_block_type = s->num_block_types[tree_type];
 1123|   132k|  const HuffmanCode* type_tree = &s->block_type_trees[
 1124|   132k|      tree_type * BROTLI_HUFFMAN_MAX_SIZE_258];
  ------------------
  |  |   24|   132k|#define BROTLI_HUFFMAN_MAX_SIZE_258 632
  ------------------
 1125|   132k|  const HuffmanCode* len_tree = &s->block_len_trees[
 1126|   132k|      tree_type * BROTLI_HUFFMAN_MAX_SIZE_26];
  ------------------
  |  |   22|   132k|#define BROTLI_HUFFMAN_MAX_SIZE_26 396
  ------------------
 1127|   132k|  BrotliBitReader* br = &s->br;
 1128|   132k|  uint32_t* ringbuffer = &s->block_type_rb[tree_type * 2];
 1129|   132k|  uint32_t block_type;
 1130|   132k|  if (max_block_type <= 1) {
  ------------------
  |  Branch (1130:7): [True: 2, False: 132k]
  ------------------
 1131|      2|    return BROTLI_FALSE;
  ------------------
  |  |   53|      2|#define BROTLI_FALSE 0
  ------------------
 1132|      2|  }
 1133|       |
 1134|       |  /* Read 0..15 + 3..39 bits. */
 1135|   132k|  if (!safe) {
  ------------------
  |  Branch (1135:7): [True: 112k, False: 19.7k]
  ------------------
 1136|   112k|    block_type = ReadSymbol(type_tree, br);
 1137|   112k|    s->block_length[tree_type] = ReadBlockLength(len_tree, br);
 1138|   112k|  } else {
 1139|  19.7k|    BrotliBitReaderState memento;
 1140|  19.7k|    BrotliBitReaderSaveState(br, &memento);
 1141|  19.7k|    if (!SafeReadSymbol(type_tree, br, &block_type)) return BROTLI_FALSE;
  ------------------
  |  |   53|     42|#define BROTLI_FALSE 0
  ------------------
  |  Branch (1141:9): [True: 42, False: 19.6k]
  ------------------
 1142|  19.6k|    if (!SafeReadBlockLength(s, &s->block_length[tree_type], len_tree, br)) {
  ------------------
  |  Branch (1142:9): [True: 334, False: 19.3k]
  ------------------
 1143|    334|      s->substate_read_block_length = BROTLI_STATE_READ_BLOCK_LENGTH_NONE;
 1144|    334|      BrotliBitReaderRestoreState(br, &memento);
 1145|    334|      return BROTLI_FALSE;
  ------------------
  |  |   53|    334|#define BROTLI_FALSE 0
  ------------------
 1146|    334|    }
 1147|  19.6k|  }
 1148|       |
 1149|   131k|  if (block_type == 1) {
  ------------------
  |  Branch (1149:7): [True: 18.5k, False: 113k]
  ------------------
 1150|  18.5k|    block_type = ringbuffer[1] + 1;
 1151|   113k|  } else if (block_type == 0) {
  ------------------
  |  Branch (1151:14): [True: 80.5k, False: 32.5k]
  ------------------
 1152|  80.5k|    block_type = ringbuffer[0];
 1153|  80.5k|  } else {
 1154|  32.5k|    block_type -= 2;
 1155|  32.5k|  }
 1156|   131k|  if (block_type >= max_block_type) {
  ------------------
  |  Branch (1156:7): [True: 8.12k, False: 123k]
  ------------------
 1157|  8.12k|    block_type -= max_block_type;
 1158|  8.12k|  }
 1159|   131k|  ringbuffer[0] = ringbuffer[1];
 1160|   131k|  ringbuffer[1] = block_type;
 1161|   131k|  return BROTLI_TRUE;
  ------------------
  |  |   51|   131k|#define BROTLI_TRUE 1
  ------------------
 1162|   132k|}
decode.c:ReadBlockLength:
  874|   112k|                                              BrotliBitReader* br) {
  875|   112k|  uint32_t code;
  876|   112k|  uint32_t nbits;
  877|   112k|  code = ReadSymbol(table, br);
  878|   112k|  nbits = _kBrotliPrefixCodeRanges[code].nbits;  /* nbits == 2..24 */
  879|   112k|  return _kBrotliPrefixCodeRanges[code].offset + BrotliReadBits24(br, nbits);
  880|   112k|}
decode.c:DecodeCommandBlockSwitch:
 1226|  10.5k|static void BROTLI_NOINLINE DecodeCommandBlockSwitch(BrotliDecoderState* s) {
 1227|  10.5k|  DecodeCommandBlockSwitchInternal(0, s);
 1228|  10.5k|}
decode.c:SafeReadCommand:
 1710|   252M|    BrotliDecoderState* s, BrotliBitReader* br, int* insert_length) {
 1711|   252M|  return ReadCommandInternal(1, s, br, insert_length);
 1712|   252M|}
decode.c:ReadCommandInternal:
 1667|   335M|    int safe, BrotliDecoderState* s, BrotliBitReader* br, int* insert_length) {
 1668|   335M|  uint32_t cmd_code;
 1669|   335M|  uint32_t insert_len_extra = 0;
 1670|   335M|  uint32_t copy_length;
 1671|   335M|  CmdLutElement v;
 1672|   335M|  BrotliBitReaderState memento;
 1673|   335M|  if (!safe) {
  ------------------
  |  Branch (1673:7): [True: 83.0M, False: 252M]
  ------------------
 1674|  83.0M|    cmd_code = ReadSymbol(s->htree_command, br);
 1675|   252M|  } else {
 1676|   252M|    BrotliBitReaderSaveState(br, &memento);
 1677|   252M|    if (!SafeReadSymbol(s->htree_command, br, &cmd_code)) {
  ------------------
  |  Branch (1677:9): [True: 35, False: 252M]
  ------------------
 1678|     35|      return BROTLI_FALSE;
  ------------------
  |  |   53|     35|#define BROTLI_FALSE 0
  ------------------
 1679|     35|    }
 1680|   252M|  }
 1681|   335M|  v = kCmdLut[cmd_code];
 1682|   335M|  s->distance_code = v.distance_code;
 1683|   335M|  s->distance_context = v.context;
 1684|   335M|  s->dist_htree_index = s->dist_context_map_slice[s->distance_context];
 1685|   335M|  *insert_length = v.insert_len_offset;
 1686|   335M|  if (!safe) {
  ------------------
  |  Branch (1686:7): [True: 83.0M, False: 252M]
  ------------------
 1687|  83.0M|    if (BROTLI_PREDICT_FALSE(v.insert_len_extra_bits != 0)) {
  ------------------
  |  |   83|  83.0M|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 88.2k, False: 82.9M]
  |  |  ------------------
  ------------------
 1688|  88.2k|      insert_len_extra = BrotliReadBits24(br, v.insert_len_extra_bits);
 1689|  88.2k|    }
 1690|  83.0M|    copy_length = BrotliReadBits24(br, v.copy_len_extra_bits);
 1691|   252M|  } else {
 1692|   252M|    if (!SafeReadBits(br, v.insert_len_extra_bits, &insert_len_extra) ||
  ------------------
  |  Branch (1692:9): [True: 96, False: 252M]
  ------------------
 1693|   252M|        !SafeReadBits(br, v.copy_len_extra_bits, &copy_length)) {
  ------------------
  |  Branch (1693:9): [True: 169, False: 252M]
  ------------------
 1694|    265|      BrotliBitReaderRestoreState(br, &memento);
 1695|    265|      return BROTLI_FALSE;
  ------------------
  |  |   53|    265|#define BROTLI_FALSE 0
  ------------------
 1696|    265|    }
 1697|   252M|  }
 1698|   335M|  s->copy_length = (int)copy_length + v.copy_len_offset;
 1699|   335M|  --s->block_length[1];
 1700|   335M|  *insert_length += (int)insert_len_extra;
 1701|   335M|  return BROTLI_TRUE;
  ------------------
  |  |   51|   335M|#define BROTLI_TRUE 1
  ------------------
 1702|   335M|}
decode.c:SafeReadBits:
 1497|   504M|    BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
 1498|   504M|  if (n_bits != 0) {
  ------------------
  |  Branch (1498:7): [True: 9.01k, False: 504M]
  ------------------
 1499|  9.01k|    return BrotliSafeReadBits(br, n_bits, val);
 1500|   504M|  } else {
 1501|   504M|    *val = 0;
 1502|   504M|    return BROTLI_TRUE;
  ------------------
  |  |   51|   504M|#define BROTLI_TRUE 1
  ------------------
 1503|   504M|  }
 1504|   504M|}
decode.c:ReadCommand:
 1705|  83.0M|    BrotliDecoderState* s, BrotliBitReader* br, int* insert_length) {
 1706|  83.0M|  ReadCommandInternal(0, s, br, insert_length);
 1707|  83.0M|}
decode.c:PreloadSymbol:
  430|   762M|                                        uint32_t* value) {
  431|   762M|  if (safe) {
  ------------------
  |  Branch (431:7): [True: 230M, False: 531M]
  ------------------
  432|   230M|    return;
  433|   230M|  }
  434|   531M|  BROTLI_HC_MARK_TABLE_FOR_FAST_LOAD(table);
  435|   531M|  BROTLI_HC_ADJUST_TABLE_INDEX(table, BrotliGetBits(br, HUFFMAN_TABLE_BITS));
  ------------------
  |  |   67|   531M|#define BROTLI_HC_ADJUST_TABLE_INDEX(H, V) H += (V)
  ------------------
  436|   531M|  *bits = BROTLI_HC_FAST_LOAD_BITS(table);
  ------------------
  |  |   70|   531M|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  437|   531M|  *value = BROTLI_HC_FAST_LOAD_VALUE(table);
  ------------------
  |  |   71|   531M|#define BROTLI_HC_FAST_LOAD_VALUE(H) (H->value)
  ------------------
  438|   531M|}
decode.c:SafeDecodeLiteralBlockSwitch:
 1211|  8.60k|    BrotliDecoderState* s) {
 1212|  8.60k|  return DecodeLiteralBlockSwitchInternal(1, s);
 1213|  8.60k|}
decode.c:DecodeLiteralBlockSwitchInternal:
 1198|  99.1k|    int safe, BrotliDecoderState* s) {
 1199|  99.1k|  if (!DecodeBlockTypeAndLength(safe, s, 0)) {
  ------------------
  |  Branch (1199:7): [True: 150, False: 98.9k]
  ------------------
 1200|    150|    return BROTLI_FALSE;
  ------------------
  |  |   53|    150|#define BROTLI_FALSE 0
  ------------------
 1201|    150|  }
 1202|  98.9k|  PrepareLiteralDecoding(s);
 1203|  98.9k|  return BROTLI_TRUE;
  ------------------
  |  |   51|  98.9k|#define BROTLI_TRUE 1
  ------------------
 1204|  99.1k|}
decode.c:DecodeLiteralBlockSwitch:
 1206|  90.5k|static void BROTLI_NOINLINE DecodeLiteralBlockSwitch(BrotliDecoderState* s) {
 1207|  90.5k|  DecodeLiteralBlockSwitchInternal(0, s);
 1208|  90.5k|}
decode.c:ReadPreloadedSymbol:
  445|   453M|                                                  uint32_t* value) {
  446|   453M|  uint32_t result = *value;
  447|   453M|  if (BROTLI_PREDICT_FALSE(*bits > HUFFMAN_TABLE_BITS)) {
  ------------------
  |  |   83|   453M|#define BROTLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (83:33): [True: 1.19k, False: 453M]
  |  |  ------------------
  ------------------
  448|  1.19k|    uint32_t val = BrotliGet16BitsUnmasked(br);
  449|  1.19k|    const HuffmanCode* ext = table + (val & HUFFMAN_TABLE_MASK) + *value;
  ------------------
  |  |   40|  1.19k|#define HUFFMAN_TABLE_MASK 0xFF
  ------------------
  450|  1.19k|    uint32_t mask = BitMask((*bits - HUFFMAN_TABLE_BITS));
  ------------------
  |  |   39|  1.19k|#define HUFFMAN_TABLE_BITS 8U
  ------------------
  451|  1.19k|    BROTLI_HC_MARK_TABLE_FOR_FAST_LOAD(ext);
  452|  1.19k|    BrotliDropBits(br, HUFFMAN_TABLE_BITS);
  ------------------
  |  |   39|  1.19k|#define HUFFMAN_TABLE_BITS 8U
  ------------------
  453|  1.19k|    BROTLI_HC_ADJUST_TABLE_INDEX(ext, (val >> HUFFMAN_TABLE_BITS) & mask);
  ------------------
  |  |   67|  1.19k|#define BROTLI_HC_ADJUST_TABLE_INDEX(H, V) H += (V)
  ------------------
  454|  1.19k|    BrotliDropBits(br, BROTLI_HC_FAST_LOAD_BITS(ext));
  ------------------
  |  |   70|  1.19k|#define BROTLI_HC_FAST_LOAD_BITS(H) (H->bits)
  ------------------
  455|  1.19k|    result = BROTLI_HC_FAST_LOAD_VALUE(ext);
  ------------------
  |  |   71|  1.19k|#define BROTLI_HC_FAST_LOAD_VALUE(H) (H->value)
  ------------------
  456|   453M|  } else {
  457|   453M|    BrotliDropBits(br, *bits);
  458|   453M|  }
  459|   453M|  PreloadSymbol(0, table, br, bits, value);
  460|   453M|  return result;
  461|   453M|}
decode.c:ReadSymbol:
  369|   125M|                                         BrotliBitReader* br) {
  370|   125M|  return DecodeSymbol(BrotliGet16BitsUnmasked(br), table, br);
  371|   125M|}
decode.c:SafeDecodeDistanceBlockSwitch:
 1253|  5.98k|    BrotliDecoderState* s) {
 1254|  5.98k|  return DecodeDistanceBlockSwitchInternal(1, s);
 1255|  5.98k|}
decode.c:DecodeDistanceBlockSwitchInternal:
 1238|  17.2k|    int safe, BrotliDecoderState* s) {
 1239|  17.2k|  if (!DecodeBlockTypeAndLength(safe, s, 2)) {
  ------------------
  |  Branch (1239:7): [True: 131, False: 17.1k]
  ------------------
 1240|    131|    return BROTLI_FALSE;
  ------------------
  |  |   53|    131|#define BROTLI_FALSE 0
  ------------------
 1241|    131|  }
 1242|  17.1k|  s->dist_context_map_slice = s->dist_context_map +
 1243|  17.1k|      (s->block_type_rb[5] << BROTLI_DISTANCE_CONTEXT_BITS);
  ------------------
  |  |   97|  17.1k|#define BROTLI_DISTANCE_CONTEXT_BITS 2
  ------------------
 1244|  17.1k|  s->dist_htree_index = s->dist_context_map_slice[s->distance_context];
 1245|  17.1k|  return BROTLI_TRUE;
  ------------------
  |  |   51|  17.1k|#define BROTLI_TRUE 1
  ------------------
 1246|  17.2k|}
decode.c:DecodeDistanceBlockSwitch:
 1248|  11.2k|static void BROTLI_NOINLINE DecodeDistanceBlockSwitch(BrotliDecoderState* s) {
 1249|  11.2k|  DecodeDistanceBlockSwitchInternal(0, s);
 1250|  11.2k|}
decode.c:SafeReadDistance:
 1662|  40.5M|    BrotliDecoderState* s, BrotliBitReader* br) {
 1663|  40.5M|  return ReadDistanceInternal(1, s, br);
 1664|  40.5M|}
decode.c:ReadDistanceInternal:
 1619|  45.7M|    int safe, BrotliDecoderState* s, BrotliBitReader* br) {
 1620|  45.7M|  BrotliMetablockBodyArena* b = &s->arena.body;
 1621|  45.7M|  uint32_t code;
 1622|  45.7M|  uint32_t bits;
 1623|  45.7M|  BrotliBitReaderState memento;
 1624|  45.7M|  HuffmanCode* distance_tree = s->distance_hgroup.htrees[s->dist_htree_index];
 1625|  45.7M|  if (!safe) {
  ------------------
  |  Branch (1625:7): [True: 5.13M, False: 40.5M]
  ------------------
 1626|  5.13M|    code = ReadSymbol(distance_tree, br);
 1627|  40.5M|  } else {
 1628|  40.5M|    BrotliBitReaderSaveState(br, &memento);
 1629|  40.5M|    if (!SafeReadSymbol(distance_tree, br, &code)) {
  ------------------
  |  Branch (1629:9): [True: 16, False: 40.5M]
  ------------------
 1630|     16|      return BROTLI_FALSE;
  ------------------
  |  |   53|     16|#define BROTLI_FALSE 0
  ------------------
 1631|     16|    }
 1632|  40.5M|  }
 1633|  45.7M|  --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|  45.7M|  s->distance_context = 0;
 1637|  45.7M|  if ((code & ~0xFu) == 0) {
  ------------------
  |  Branch (1637:7): [True: 42.7M, False: 2.92M]
  ------------------
 1638|  42.7M|    s->distance_code = (int)code;
 1639|  42.7M|    TakeDistanceFromRingBuffer(s);
 1640|  42.7M|    return BROTLI_TRUE;
  ------------------
  |  |   51|  42.7M|#define BROTLI_TRUE 1
  ------------------
 1641|  42.7M|  }
 1642|  2.92M|  if (!safe) {
  ------------------
  |  Branch (1642:7): [True: 1.31M, False: 1.61M]
  ------------------
 1643|  1.31M|    bits = BrotliReadBits32(br, b->dist_extra_bits[code]);
 1644|  1.61M|  } else {
 1645|  1.61M|    if (!SafeReadBits32(br, b->dist_extra_bits[code], &bits)) {
  ------------------
  |  Branch (1645:9): [True: 226, False: 1.61M]
  ------------------
 1646|    226|      ++s->block_length[2];
 1647|    226|      BrotliBitReaderRestoreState(br, &memento);
 1648|    226|      return BROTLI_FALSE;
  ------------------
  |  |   53|    226|#define BROTLI_FALSE 0
  ------------------
 1649|    226|    }
 1650|  1.61M|  }
 1651|  2.92M|  s->distance_code =
 1652|  2.92M|      (int)(b->dist_offset[code] + (bits << s->distance_postfix_bits));
 1653|  2.92M|  return BROTLI_TRUE;
  ------------------
  |  |   51|  2.92M|#define BROTLI_TRUE 1
  ------------------
 1654|  2.92M|}
decode.c:TakeDistanceFromRingBuffer:
 1469|  42.7M|static BROTLI_INLINE void TakeDistanceFromRingBuffer(BrotliDecoderState* s) {
 1470|  42.7M|  int offset = s->distance_code - 3;
 1471|  42.7M|  if (s->distance_code <= 3) {
  ------------------
  |  Branch (1471:7): [True: 19.4M, False: 23.3M]
  ------------------
 1472|       |    /* Compensate double distance-ring-buffer roll for dictionary items. */
 1473|  19.4M|    s->distance_context = 1 >> s->distance_code;
 1474|  19.4M|    s->distance_code = s->dist_rb[(s->dist_rb_idx - offset) & 3];
 1475|  19.4M|    s->dist_rb_idx -= s->distance_context;
 1476|  23.3M|  } else {
 1477|  23.3M|    int index_delta = 3;
 1478|  23.3M|    int delta;
 1479|  23.3M|    int base = s->distance_code - 10;
 1480|  23.3M|    if (s->distance_code < 10) {
  ------------------
  |  Branch (1480:9): [True: 20.0M, False: 3.28M]
  ------------------
 1481|  20.0M|      base = s->distance_code - 4;
 1482|  20.0M|    } else {
 1483|  3.28M|      index_delta = 2;
 1484|  3.28M|    }
 1485|       |    /* Unpack one of six 4-bit values. */
 1486|  23.3M|    delta = ((0x605142 >> (4 * base)) & 0xF) - 3;
 1487|  23.3M|    s->distance_code = s->dist_rb[(s->dist_rb_idx + index_delta) & 0x3] + delta;
 1488|  23.3M|    if (s->distance_code <= 0) {
  ------------------
  |  Branch (1488:9): [True: 34, False: 23.3M]
  ------------------
 1489|       |      /* A huge distance will cause a BROTLI_FAILURE() soon.
 1490|       |         This is a little faster than failing here. */
 1491|     34|      s->distance_code = 0x7FFFFFFF;
 1492|     34|    }
 1493|  23.3M|  }
 1494|  42.7M|}
decode.c:SafeReadBits32:
 1507|  1.61M|    BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
 1508|  1.61M|  if (n_bits != 0) {
  ------------------
  |  Branch (1508:7): [True: 4.13k, False: 1.60M]
  ------------------
 1509|  4.13k|    return BrotliSafeReadBits32(br, n_bits, val);
 1510|  1.60M|  } else {
 1511|  1.60M|    *val = 0;
 1512|  1.60M|    return BROTLI_TRUE;
  ------------------
  |  |   51|  1.60M|#define BROTLI_TRUE 1
  ------------------
 1513|  1.60M|  }
 1514|  1.61M|}
decode.c:ReadDistance:
 1657|  5.13M|    BrotliDecoderState* s, BrotliBitReader* br) {
 1658|  5.13M|  ReadDistanceInternal(0, s, br);
 1659|  5.13M|}
decode.c:memmove16:
  170|   321M|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|   321M|  uint32_t buffer[4];
  175|   321M|  memcpy(buffer, src, 16);
  176|   321M|  memcpy(dst, buffer, 16);
  177|   321M|#endif
  178|   321M|}
decode.c:SafeProcessCommands:
 2031|   127k|    BrotliDecoderState* s) {
 2032|   127k|  return ProcessCommandsInternal(1, s);
 2033|   127k|}
decode.c:WrapRingBuffer:
 1312|   316k|static void BROTLI_NOINLINE WrapRingBuffer(BrotliDecoderState* s) {
 1313|   316k|  if (s->should_wrap_ringbuffer) {
  ------------------
  |  Branch (1313:7): [True: 13.7k, False: 302k]
  ------------------
 1314|  13.7k|    memcpy(s->ringbuffer, s->ringbuffer_end, (size_t)s->pos);
 1315|  13.7k|    s->should_wrap_ringbuffer = 0;
 1316|  13.7k|  }
 1317|   316k|}
decode.c:UnwrittenBytes:
 1257|   483k|static size_t UnwrittenBytes(const BrotliDecoderState* s, BROTLI_BOOL wrap) {
 1258|   483k|  size_t pos = wrap && s->pos > s->ringbuffer_size ?
  ------------------
  |  Branch (1258:16): [True: 483k, False: 0]
  |  Branch (1258:24): [True: 27.6k, False: 456k]
  ------------------
 1259|   456k|      (size_t)s->ringbuffer_size : (size_t)(s->pos);
 1260|   483k|  size_t partial_pos_rb = (s->rb_roundtrips * (size_t)s->ringbuffer_size) + pos;
 1261|   483k|  return partial_pos_rb - s->partial_pos_out;
 1262|   483k|}

BrotliBuildCodeLengthsHuffmanTable:
  106|  6.09k|                                        uint16_t* count) {
  107|  6.09k|  HuffmanCode code;       /* current table entry */
  108|  6.09k|  int symbol;             /* symbol index in original or sorted table */
  109|  6.09k|  brotli_reg_t key;       /* prefix code */
  ------------------
  |  |  241|  6.09k|#define brotli_reg_t uint64_t
  ------------------
  110|  6.09k|  brotli_reg_t key_step;  /* prefix code addend */
  ------------------
  |  |  241|  6.09k|#define brotli_reg_t uint64_t
  ------------------
  111|  6.09k|  int step;               /* step size to replicate values in current table */
  112|  6.09k|  int table_size;         /* size of current table */
  113|  6.09k|  int sorted[BROTLI_CODE_LENGTH_CODES];  /* symbols sorted by code length */
  114|       |  /* offsets in sorted table for each length */
  115|  6.09k|  int offset[BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH + 1];
  116|  6.09k|  int bits;
  117|  6.09k|  int bits_count;
  118|  6.09k|  BROTLI_DCHECK(BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH <=
  119|  6.09k|                BROTLI_REVERSE_BITS_MAX);
  120|       |
  121|       |  /* Generate offsets into sorted symbol table by code length. */
  122|  6.09k|  symbol = -1;
  123|  6.09k|  bits = 1;
  124|  6.09k|  BROTLI_REPEAT(BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH, {
  ------------------
  |  |  505|  6.09k|#define BROTLI_REPEAT(N, X) {     \
  |  |  506|  6.09k|  if ((N & 1) != 0) {X;}          \
  |  |  ------------------
  |  |  |  Branch (506:7): [True: 6.09k, Folded]
  |  |  ------------------
  |  |  507|  6.09k|  if ((N & 2) != 0) {X; X;}       \
  |  |  ------------------
  |  |  |  Branch (507:7): [Folded, False: 6.09k]
  |  |  ------------------
  |  |  508|  6.09k|  if ((N & 4) != 0) {X; X; X; X;} \
  |  |  ------------------
  |  |  |  Branch (508:7): [True: 6.09k, Folded]
  |  |  ------------------
  |  |  509|  6.09k|}
  ------------------
  125|  6.09k|    symbol += count[bits];
  126|  6.09k|    offset[bits] = symbol;
  127|  6.09k|    bits++;
  128|  6.09k|  });
  129|       |  /* Symbols with code length 0 are placed after all other symbols. */
  130|  6.09k|  offset[0] = BROTLI_CODE_LENGTH_CODES - 1;
  ------------------
  |  |   36|  6.09k|#define BROTLI_CODE_LENGTH_CODES (BROTLI_REPEAT_ZERO_CODE_LENGTH + 1)
  |  |  ------------------
  |  |  |  |   35|  6.09k|#define BROTLI_REPEAT_ZERO_CODE_LENGTH 17
  |  |  ------------------
  ------------------
  131|       |
  132|       |  /* Sort symbols by length, by symbol order within each length. */
  133|  6.09k|  symbol = BROTLI_CODE_LENGTH_CODES;
  ------------------
  |  |   36|  6.09k|#define BROTLI_CODE_LENGTH_CODES (BROTLI_REPEAT_ZERO_CODE_LENGTH + 1)
  |  |  ------------------
  |  |  |  |   35|  6.09k|#define BROTLI_REPEAT_ZERO_CODE_LENGTH 17
  |  |  ------------------
  ------------------
  134|  18.2k|  do {
  135|  18.2k|    BROTLI_REPEAT(6, {
  ------------------
  |  |  505|  18.2k|#define BROTLI_REPEAT(N, X) {     \
  |  |  506|  18.2k|  if ((N & 1) != 0) {X;}          \
  |  |  ------------------
  |  |  |  Branch (506:7): [Folded, False: 18.2k]
  |  |  ------------------
  |  |  507|  18.2k|  if ((N & 2) != 0) {X; X;}       \
  |  |  ------------------
  |  |  |  Branch (507:7): [True: 18.2k, Folded]
  |  |  ------------------
  |  |  508|  18.2k|  if ((N & 4) != 0) {X; X; X; X;} \
  |  |  ------------------
  |  |  |  Branch (508:7): [True: 18.2k, Folded]
  |  |  ------------------
  |  |  509|  18.2k|}
  ------------------
  136|  18.2k|      symbol--;
  137|  18.2k|      sorted[offset[code_lengths[symbol]]--] = symbol;
  138|  18.2k|    });
  139|  18.2k|  } while (symbol != 0);
  ------------------
  |  Branch (139:12): [True: 12.1k, False: 6.09k]
  ------------------
  140|       |
  141|  6.09k|  table_size = 1 << BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH;
  ------------------
  |  |   28|  6.09k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH 5
  ------------------
  142|       |
  143|       |  /* Special case: all symbols but one have 0 code length. */
  144|  6.09k|  if (offset[0] == 0) {
  ------------------
  |  Branch (144:7): [True: 321, False: 5.77k]
  ------------------
  145|    321|    code = ConstructHuffmanCode(0, (uint16_t)sorted[0]);
  146|  10.5k|    for (key = 0; key < (brotli_reg_t)table_size; ++key) {
  ------------------
  |  Branch (146:19): [True: 10.2k, False: 321]
  ------------------
  147|  10.2k|      table[key] = code;
  148|  10.2k|    }
  149|    321|    return;
  150|    321|  }
  151|       |
  152|       |  /* Fill in table. */
  153|  5.77k|  key = 0;
  154|  5.77k|  key_step = BROTLI_REVERSE_BITS_LOWEST;
  ------------------
  |  |   65|  5.77k|  ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   21|  5.77k|#define BROTLI_REVERSE_BITS_MAX 8
  |  |  ------------------
  |  |                 ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   27|  5.77k|#define BROTLI_REVERSE_BITS_BASE 0
  |  |  ------------------
  ------------------
  155|  5.77k|  symbol = 0;
  156|  5.77k|  bits = 1;
  157|  5.77k|  step = 2;
  158|  28.8k|  do {
  159|  58.6k|    for (bits_count = count[bits]; bits_count != 0; --bits_count) {
  ------------------
  |  Branch (159:36): [True: 29.8k, False: 28.8k]
  ------------------
  160|  29.8k|      code = ConstructHuffmanCode((uint8_t)bits, (uint16_t)sorted[symbol++]);
  161|  29.8k|      ReplicateValue(&table[BrotliReverseBits(key)], step, table_size, code);
  162|  29.8k|      key += key_step;
  163|  29.8k|    }
  164|  28.8k|    step <<= 1;
  165|  28.8k|    key_step >>= 1;
  166|  28.8k|  } while (++bits <= BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH);
  ------------------
  |  |   28|  28.8k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH 5
  ------------------
  |  Branch (166:12): [True: 23.0k, False: 5.77k]
  ------------------
  167|  5.77k|}
BrotliBuildHuffmanTable:
  172|  5.73k|                                 uint16_t* count) {
  173|  5.73k|  HuffmanCode code;       /* current table entry */
  174|  5.73k|  HuffmanCode* table;     /* next available space in table */
  175|  5.73k|  int len;                /* current code length */
  176|  5.73k|  int symbol;             /* symbol index in original or sorted table */
  177|  5.73k|  brotli_reg_t key;       /* prefix code */
  ------------------
  |  |  241|  5.73k|#define brotli_reg_t uint64_t
  ------------------
  178|  5.73k|  brotli_reg_t key_step;  /* prefix code addend */
  ------------------
  |  |  241|  5.73k|#define brotli_reg_t uint64_t
  ------------------
  179|  5.73k|  brotli_reg_t sub_key;   /* 2nd level table prefix code */
  ------------------
  |  |  241|  5.73k|#define brotli_reg_t uint64_t
  ------------------
  180|  5.73k|  brotli_reg_t sub_key_step;  /* 2nd level table prefix code addend */
  ------------------
  |  |  241|  5.73k|#define brotli_reg_t uint64_t
  ------------------
  181|  5.73k|  int step;               /* step size to replicate values in current table */
  182|  5.73k|  int table_bits;         /* key length of current table */
  183|  5.73k|  int table_size;         /* size of current table */
  184|  5.73k|  int total_size;         /* sum of root table size and 2nd level table sizes */
  185|  5.73k|  int max_length = -1;
  186|  5.73k|  int bits;
  187|  5.73k|  int bits_count;
  188|       |
  189|  5.73k|  BROTLI_DCHECK(root_bits <= BROTLI_REVERSE_BITS_MAX);
  190|  5.73k|  BROTLI_DCHECK(BROTLI_HUFFMAN_MAX_CODE_LENGTH - root_bits <=
  191|  5.73k|                BROTLI_REVERSE_BITS_MAX);
  192|       |
  193|  76.7k|  while (symbol_lists[max_length] == 0xFFFF) max_length--;
  ------------------
  |  Branch (193:10): [True: 70.9k, False: 5.73k]
  ------------------
  194|  5.73k|  max_length += BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1;
  ------------------
  |  |   19|  5.73k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH 15
  ------------------
  195|       |
  196|  5.73k|  table = root_table;
  197|  5.73k|  table_bits = root_bits;
  198|  5.73k|  table_size = 1 << table_bits;
  199|  5.73k|  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.73k|  if (table_bits > max_length) {
  ------------------
  |  Branch (203:7): [True: 5.05k, False: 685]
  ------------------
  204|  5.05k|    table_bits = max_length;
  205|  5.05k|    table_size = 1 << table_bits;
  206|  5.05k|  }
  207|  5.73k|  key = 0;
  208|  5.73k|  key_step = BROTLI_REVERSE_BITS_LOWEST;
  ------------------
  |  |   65|  5.73k|  ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   21|  5.73k|#define BROTLI_REVERSE_BITS_MAX 8
  |  |  ------------------
  |  |                 ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   27|  5.73k|#define BROTLI_REVERSE_BITS_BASE 0
  |  |  ------------------
  ------------------
  209|  5.73k|  bits = 1;
  210|  5.73k|  step = 2;
  211|  13.8k|  do {
  212|  13.8k|    symbol = bits - (BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1);
  ------------------
  |  |   19|  13.8k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH 15
  ------------------
  213|   115k|    for (bits_count = count[bits]; bits_count != 0; --bits_count) {
  ------------------
  |  Branch (213:36): [True: 101k, False: 13.8k]
  ------------------
  214|   101k|      symbol = symbol_lists[symbol];
  215|   101k|      code = ConstructHuffmanCode((uint8_t)bits, (uint16_t)symbol);
  216|   101k|      ReplicateValue(&table[BrotliReverseBits(key)], step, table_size, code);
  217|   101k|      key += key_step;
  218|   101k|    }
  219|  13.8k|    step <<= 1;
  220|  13.8k|    key_step >>= 1;
  221|  13.8k|  } while (++bits <= table_bits);
  ------------------
  |  Branch (221:12): [True: 8.15k, False: 5.73k]
  ------------------
  222|       |
  223|       |  /* If root_bits != table_bits then replicate to fill the remaining slots. */
  224|  37.7k|  while (total_size != table_size) {
  ------------------
  |  Branch (224:10): [True: 32.0k, False: 5.73k]
  ------------------
  225|  32.0k|    memcpy(&table[table_size], &table[0],
  226|  32.0k|           (size_t)table_size * sizeof(table[0]));
  227|  32.0k|    table_size <<= 1;
  228|  32.0k|  }
  229|       |
  230|       |  /* Fill in 2nd level tables and add pointers to root table. */
  231|  5.73k|  key_step = BROTLI_REVERSE_BITS_LOWEST >> (root_bits - 1);
  ------------------
  |  |   65|  5.73k|  ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   21|  5.73k|#define BROTLI_REVERSE_BITS_MAX 8
  |  |  ------------------
  |  |                 ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   27|  5.73k|#define BROTLI_REVERSE_BITS_BASE 0
  |  |  ------------------
  ------------------
  232|  5.73k|  sub_key = (BROTLI_REVERSE_BITS_LOWEST << 1);
  ------------------
  |  |   65|  5.73k|  ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   21|  5.73k|#define BROTLI_REVERSE_BITS_MAX 8
  |  |  ------------------
  |  |                 ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   27|  5.73k|#define BROTLI_REVERSE_BITS_BASE 0
  |  |  ------------------
  ------------------
  233|  5.73k|  sub_key_step = BROTLI_REVERSE_BITS_LOWEST;
  ------------------
  |  |   65|  5.73k|  ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   21|  5.73k|#define BROTLI_REVERSE_BITS_MAX 8
  |  |  ------------------
  |  |                 ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   27|  5.73k|#define BROTLI_REVERSE_BITS_BASE 0
  |  |  ------------------
  ------------------
  234|  6.92k|  for (len = root_bits + 1, step = 2; len <= max_length; ++len) {
  ------------------
  |  Branch (234:39): [True: 1.18k, False: 5.73k]
  ------------------
  235|  1.18k|    symbol = len - (BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1);
  ------------------
  |  |   19|  1.18k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH 15
  ------------------
  236|  41.6k|    for (; count[len] != 0; --count[len]) {
  ------------------
  |  Branch (236:12): [True: 40.4k, False: 1.18k]
  ------------------
  237|  40.4k|      if (sub_key == (BROTLI_REVERSE_BITS_LOWEST << 1U)) {
  ------------------
  |  |   65|  40.4k|  ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   21|  40.4k|#define BROTLI_REVERSE_BITS_MAX 8
  |  |  ------------------
  |  |                 ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   27|  40.4k|#define BROTLI_REVERSE_BITS_BASE 0
  |  |  ------------------
  ------------------
  |  Branch (237:11): [True: 17.2k, False: 23.1k]
  ------------------
  238|  17.2k|        table += table_size;
  239|  17.2k|        table_bits = NextTableBitSize(count, len, root_bits);
  240|  17.2k|        table_size = 1 << table_bits;
  241|  17.2k|        total_size += table_size;
  242|  17.2k|        sub_key = BrotliReverseBits(key);
  243|  17.2k|        key += key_step;
  244|  17.2k|        root_table[sub_key] = ConstructHuffmanCode(
  245|  17.2k|            (uint8_t)(table_bits + root_bits),
  246|  17.2k|            (uint16_t)(((size_t)(table - root_table)) - sub_key));
  247|  17.2k|        sub_key = 0;
  248|  17.2k|      }
  249|  40.4k|      symbol = symbol_lists[symbol];
  250|  40.4k|      code = ConstructHuffmanCode((uint8_t)(len - root_bits), (uint16_t)symbol);
  251|  40.4k|      ReplicateValue(
  252|  40.4k|          &table[BrotliReverseBits(sub_key)], step, table_size, code);
  253|  40.4k|      sub_key += sub_key_step;
  254|  40.4k|    }
  255|  1.18k|    step <<= 1;
  256|  1.18k|    sub_key_step >>= 1;
  257|  1.18k|  }
  258|  5.73k|  return (uint32_t)total_size;
  259|  5.73k|}
BrotliBuildSimpleHuffmanTable:
  264|  39.9k|                                       uint32_t num_symbols) {
  265|  39.9k|  uint32_t table_size = 1;
  266|  39.9k|  const uint32_t goal_size = 1U << root_bits;
  267|  39.9k|  switch (num_symbols) {
  ------------------
  |  Branch (267:11): [True: 39.9k, False: 0]
  ------------------
  268|  25.3k|    case 0:
  ------------------
  |  Branch (268:5): [True: 25.3k, False: 14.6k]
  ------------------
  269|  25.3k|      table[0] = ConstructHuffmanCode(0, val[0]);
  270|  25.3k|      break;
  271|  8.29k|    case 1:
  ------------------
  |  Branch (271:5): [True: 8.29k, False: 31.6k]
  ------------------
  272|  8.29k|      if (val[1] > val[0]) {
  ------------------
  |  Branch (272:11): [True: 5.67k, False: 2.62k]
  ------------------
  273|  5.67k|        table[0] = ConstructHuffmanCode(1, val[0]);
  274|  5.67k|        table[1] = ConstructHuffmanCode(1, val[1]);
  275|  5.67k|      } else {
  276|  2.62k|        table[0] = ConstructHuffmanCode(1, val[1]);
  277|  2.62k|        table[1] = ConstructHuffmanCode(1, val[0]);
  278|  2.62k|      }
  279|  8.29k|      table_size = 2;
  280|  8.29k|      break;
  281|  3.06k|    case 2:
  ------------------
  |  Branch (281:5): [True: 3.06k, False: 36.8k]
  ------------------
  282|  3.06k|      table[0] = ConstructHuffmanCode(1, val[0]);
  283|  3.06k|      table[2] = ConstructHuffmanCode(1, val[0]);
  284|  3.06k|      if (val[2] > val[1]) {
  ------------------
  |  Branch (284:11): [True: 1.99k, False: 1.07k]
  ------------------
  285|  1.99k|        table[1] = ConstructHuffmanCode(2, val[1]);
  286|  1.99k|        table[3] = ConstructHuffmanCode(2, val[2]);
  287|  1.99k|      } else {
  288|  1.07k|        table[1] = ConstructHuffmanCode(2, val[2]);
  289|  1.07k|        table[3] = ConstructHuffmanCode(2, val[1]);
  290|  1.07k|      }
  291|  3.06k|      table_size = 4;
  292|  3.06k|      break;
  293|  2.28k|    case 3: {
  ------------------
  |  Branch (293:5): [True: 2.28k, False: 37.6k]
  ------------------
  294|  2.28k|      int i, k;
  295|  9.14k|      for (i = 0; i < 3; ++i) {
  ------------------
  |  Branch (295:19): [True: 6.85k, False: 2.28k]
  ------------------
  296|  20.5k|        for (k = i + 1; k < 4; ++k) {
  ------------------
  |  Branch (296:25): [True: 13.7k, False: 6.85k]
  ------------------
  297|  13.7k|          if (val[k] < val[i]) {
  ------------------
  |  Branch (297:15): [True: 5.70k, False: 8.00k]
  ------------------
  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|  13.7k|        }
  303|  6.85k|      }
  304|  2.28k|      table[0] = ConstructHuffmanCode(2, val[0]);
  305|  2.28k|      table[2] = ConstructHuffmanCode(2, val[1]);
  306|  2.28k|      table[1] = ConstructHuffmanCode(2, val[2]);
  307|  2.28k|      table[3] = ConstructHuffmanCode(2, val[3]);
  308|  2.28k|      table_size = 4;
  309|  2.28k|      break;
  310|      0|    }
  311|  1.00k|    case 4: {
  ------------------
  |  Branch (311:5): [True: 1.00k, False: 38.9k]
  ------------------
  312|  1.00k|      if (val[3] < val[2]) {
  ------------------
  |  Branch (312:11): [True: 688, False: 317]
  ------------------
  313|    688|        uint16_t t = val[3];
  314|    688|        val[3] = val[2];
  315|    688|        val[2] = t;
  316|    688|      }
  317|  1.00k|      table[0] = ConstructHuffmanCode(1, val[0]);
  318|  1.00k|      table[1] = ConstructHuffmanCode(2, val[1]);
  319|  1.00k|      table[2] = ConstructHuffmanCode(1, val[0]);
  320|  1.00k|      table[3] = ConstructHuffmanCode(3, val[2]);
  321|  1.00k|      table[4] = ConstructHuffmanCode(1, val[0]);
  322|  1.00k|      table[5] = ConstructHuffmanCode(2, val[1]);
  323|  1.00k|      table[6] = ConstructHuffmanCode(1, val[0]);
  324|  1.00k|      table[7] = ConstructHuffmanCode(3, val[3]);
  325|  1.00k|      table_size = 8;
  326|  1.00k|      break;
  327|      0|    }
  328|  39.9k|  }
  329|   337k|  while (table_size != goal_size) {
  ------------------
  |  Branch (329:10): [True: 297k, False: 39.9k]
  ------------------
  330|   297k|    memcpy(&table[table_size], &table[0],
  331|   297k|           (size_t)table_size * sizeof(table[0]));
  332|   297k|    table_size <<= 1;
  333|   297k|  }
  334|  39.9k|  return goal_size;
  335|  39.9k|}
huffman.c:ReplicateValue:
   82|   172k|                                         HuffmanCode code) {
   83|   419k|  do {
   84|   419k|    end -= step;
   85|   419k|    table[end] = code;
   86|   419k|  } while (end > 0);
  ------------------
  |  Branch (86:12): [True: 247k, False: 172k]
  ------------------
   87|   172k|}
huffman.c:BrotliReverseBits:
   70|   189k|static BROTLI_INLINE brotli_reg_t BrotliReverseBits(brotli_reg_t num) {
   71|       |#if defined(BROTLI_RBIT)
   72|       |  return BROTLI_RBIT(num);
   73|       |#else
   74|   189k|  return kReverseBits[num];
   75|   189k|#endif
   76|   189k|}
huffman.c:NextTableBitSize:
   93|  17.2k|                                          int len, int root_bits) {
   94|  17.2k|  int left = 1 << (len - root_bits);
   95|  17.9k|  while (len < BROTLI_HUFFMAN_MAX_CODE_LENGTH) {
  ------------------
  |  |   19|  17.9k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH 15
  ------------------
  |  Branch (95:10): [True: 17.8k, False: 125]
  ------------------
   96|  17.8k|    left -= count[len];
   97|  17.8k|    if (left <= 0) break;
  ------------------
  |  Branch (97:9): [True: 17.1k, False: 628]
  ------------------
   98|    628|    ++len;
   99|    628|    left <<= 1;
  100|    628|  }
  101|  17.2k|  return len - root_bits;
  102|  17.2k|}

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

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

_ZN7brunsli27ComputeACPredictMultipliersEPKiPiS2_:
   20|  6.25k|                                 int* mult_col) {
   21|  56.2k|  for (size_t y = 0; y < 8; ++y) {
  ------------------
  |  Branch (21:22): [True: 50.0k, False: 6.25k]
  ------------------
   22|   450k|    for (size_t x = 0; x < 8; ++x) {
  ------------------
  |  Branch (22:24): [True: 400k, False: 50.0k]
  ------------------
   23|   400k|      mult_row[x + 8 * y] =
   24|   400k|          (quant[x + 8 * y] * kSqrt2FixedPoint) / quant[y * 8];
   25|       |      // mult_col is transposed i.e. destination rows and columns are swapped.
   26|   400k|      mult_col[x * 8 + y] = (quant[x + 8 * y] * kSqrt2FixedPoint) / quant[x];
   27|   400k|    }
   28|  50.0k|  }
   29|  6.25k|}
_ZN7brunsli16ComponentStateDC7InitAllEv:
   33|  6.88k|void ComponentStateDC::InitAll() {
   34|  6.88k|  is_zero_prob.Init(135);
   35|  68.8k|  for (size_t i = 0; i < sign_prob.size(); ++i) {
  ------------------
  |  Branch (35:22): [True: 61.9k, False: 6.88k]
  ------------------
   36|  61.9k|    sign_prob[i].Init(128);
   37|  61.9k|  }
   38|  27.5k|  for (size_t i = 0; i < is_empty_block_prob.size(); ++i) {
  ------------------
  |  Branch (38:22): [True: 20.6k, False: 6.88k]
  ------------------
   39|  20.6k|    is_empty_block_prob[i].Init(74);
   40|  20.6k|  }
   41|  75.7k|  for (size_t i = 0; i < first_extra_bit_prob.size(); ++i) {
  ------------------
  |  Branch (41:22): [True: 68.8k, False: 6.88k]
  ------------------
   42|  68.8k|    first_extra_bit_prob[i].Init(150);
   43|  68.8k|  }
   44|  6.88k|}
_ZN7brunsli14ComponentState7InitAllEv:
  223|  6.25k|void ComponentState::InitAll() {
  224|  75.0k|  for (int i = 0; i < kNumNonzeroBuckets; ++i) {
  ------------------
  |  Branch (224:19): [True: 68.7k, False: 6.25k]
  ------------------
  225|  4.47M|    for (int k = 0; k < kDCTBlockSize; ++k) {
  ------------------
  |  Branch (225:21): [True: 4.40M, False: 68.7k]
  ------------------
  226|  4.40M|      const int v = kInitProb[k] + 9 * (i - 7);
  227|  4.40M|      BRUNSLI_DCHECK(v <= 255);
  228|  4.40M|      is_zero_prob[i * kDCTBlockSize + k].Init(v);
  229|  4.40M|    }
  230|  68.7k|  }
  231|  6.80M|  for (size_t i = 0; i < sign_prob.size(); ++i) {
  ------------------
  |  Branch (231:22): [True: 6.80M, False: 6.25k]
  ------------------
  232|  6.80M|    if (i < kMaxAverageContext * kDCTBlockSize) {
  ------------------
  |  Branch (232:9): [True: 3.20M, False: 3.60M]
  ------------------
  233|  3.20M|      sign_prob[i].Init(108);
  234|  3.60M|    } else if (i < (kMaxAverageContext + 1) * kDCTBlockSize) {
  ------------------
  |  Branch (234:16): [True: 400k, False: 3.20M]
  ------------------
  235|   400k|      sign_prob[i].Init(128);
  236|  3.20M|    } else {
  237|  3.20M|      sign_prob[i].Init(148);
  238|  3.20M|    }
  239|  6.80M|  }
  240|  4.00M|  for (size_t i = 0; i < first_extra_bit_prob.size(); ++i) {
  ------------------
  |  Branch (240:22): [True: 4.00M, False: 6.25k]
  ------------------
  241|  4.00M|    first_extra_bit_prob[i].Init(158);
  242|  4.00M|  }
  243|       |
  244|   206k|  for (size_t i = 0; i < kNumNonZeroContextCount; ++i) {
  ------------------
  |  Branch (244:22): [True: 200k, False: 6.25k]
  ------------------
  245|   200k|    Prob* non_zero_probs = num_nonzero_prob + i * kNumNonZeroTreeSize;
  246|  12.8M|    for (size_t j = 0; j < kNumNonZeroTreeSize; ++j) {
  ------------------
  |  Branch (246:24): [True: 12.6M, False: 200k]
  ------------------
  247|  12.6M|      non_zero_probs[j].Init(kInitProbNonzero[i][j]);
  248|  12.6M|    }
  249|   200k|  }
  250|  6.25k|}

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

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

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

_ZN7brunsli16DecodeLehmerCodeEPKjmPj:
   30|  5.80k|bool DecodeLehmerCode(const uint32_t* code, size_t len, uint32_t* sigma) {
   31|  5.80k|  std::vector<uint32_t> items(len);
   32|   377k|  for (size_t i = 0; i < len; ++i) items[i] = static_cast<uint32_t>(i);
  ------------------
  |  Branch (32:22): [True: 371k, False: 5.80k]
  ------------------
   33|   376k|  for (size_t i = 0; i < len; ++i) {
  ------------------
  |  Branch (33:22): [True: 370k, False: 5.79k]
  ------------------
   34|   370k|    uint32_t index = code[i];
   35|   370k|    if (index >= items.size()) return false;
  ------------------
  |  Branch (35:9): [True: 11, False: 370k]
  ------------------
   36|   370k|    const uint32_t value = items[index];
   37|   370k|    items.erase(items.begin() + index);
   38|   370k|    sigma[i] = value;
   39|   370k|  }
   40|  5.79k|  return true;
   41|  5.80k|}

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

_Z16Log2FloorNonZeroj:
  472|  17.6M|inline int Log2FloorNonZero(uint32_t n) {
  473|  17.6M|#ifdef __GNUC__
  474|  17.6M|  return 31 ^ __builtin_clz(n);
  475|       |#else
  476|       |  unsigned int result = 0;
  477|       |  while (n >>= 1) result++;
  478|       |  return result;
  479|       |#endif
  480|  17.6M|}
brunsli_decode.cc:_ZN7brunsliL6AppendEPNSt3__16vectorIhNS0_9allocatorIhEEEEPKhS7_:
  443|   621k|                                  const uint8_t* begin, const uint8_t* end) {
  444|   621k|  dst->insert(dst->end(), begin, end);
  445|   621k|}
brunsli_decode.cc:_ZN7brunsliL6AppendEPNSt3__16vectorIhNS0_9allocatorIhEEEEPKhm:
  447|   589k|                                  const uint8_t* begin, size_t length) {
  448|   589k|  Append(dst, begin, begin + length);
  449|   589k|}
brunsli_decode.cc:_ZL22BrunsliUnalignedRead16PKv:
  290|  3.80M|static BRUNSLI_INLINE uint16_t BrunsliUnalignedRead16(const void* p) {
  291|  3.80M|  uint16_t t;
  292|  3.80M|  memcpy(&t, p, sizeof t);
  293|  3.80M|  return t;
  294|  3.80M|}

_ZN7brunsli25PredictWithAdaptiveMedianEPKsiii:
   29|  45.2M|int PredictWithAdaptiveMedian(const coeff_t* coeffs, int x, int y, int stride) {
   30|  45.2M|  const int offset1 = -kDCTBlockSize;
   31|  45.2M|  const int offset2 = -stride;
   32|  45.2M|  const int offset3 = offset2 + offset1;
   33|  45.2M|  if (y != 0) {
  ------------------
  |  Branch (33:7): [True: 44.2M, False: 1.01M]
  ------------------
   34|  44.2M|    if (x != 0) {
  ------------------
  |  Branch (34:9): [True: 43.9M, False: 363k]
  ------------------
   35|  43.9M|      return AdaptiveMedian(coeffs[offset1], coeffs[offset2], coeffs[offset3]);
   36|  43.9M|    } else {
   37|   363k|      return coeffs[offset2];
   38|   363k|    }
   39|  44.2M|  } else {
   40|  1.01M|    return x ? coeffs[offset1] : 0;
  ------------------
  |  Branch (40:12): [True: 1.00M, False: 6.75k]
  ------------------
   41|  1.01M|  }
   42|  45.2M|}
predict.cc:_ZN7brunsli12_GLOBAL__N_114AdaptiveMedianEiii:
   15|  43.9M|int AdaptiveMedian(int w, int n, int nw) {
   16|  43.9M|  const int mx = (w > n) ? w : n;
  ------------------
  |  Branch (16:18): [True: 6.38M, False: 37.5M]
  ------------------
   17|  43.9M|  const int mn = w + n - mx;
   18|  43.9M|  if (nw > mx) {
  ------------------
  |  Branch (18:7): [True: 1.28M, False: 42.6M]
  ------------------
   19|  1.28M|    return mn;
   20|  42.6M|  } else if (nw < mn) {
  ------------------
  |  Branch (20:14): [True: 952k, False: 41.6M]
  ------------------
   21|   952k|    return mx;
   22|  41.6M|  } else {
   23|  41.6M|    return n + w - nw;
   24|  41.6M|  }
   25|  43.9M|}

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

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

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

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

_ZN7brunsli20BrunsliBitReaderInitEPNS_16BrunsliBitReaderE:
   13|  27.8k|void BrunsliBitReaderInit(BrunsliBitReader* br) {
   14|  27.8k|  br->num_bits_ = 0;
   15|  27.8k|  br->bits_ = 0;
   16|  27.8k|  br->num_debt_bytes_ = 0;
   17|  27.8k|  br->is_healthy_ = true;
   18|  27.8k|  br->is_optimistic_ = false;
   19|  27.8k|}
_ZN7brunsli22BrunsliBitReaderResumeEPNS_16BrunsliBitReaderEPKhm:
   22|  27.8k|                              size_t length) {
   23|  27.8k|  br->next_ = buffer;
   24|  27.8k|  br->end_ = buffer + length;
   25|  27.8k|  br->is_optimistic_ = false;
   26|  27.8k|}
_ZN7brunsli23BrunsliBitReaderSuspendEPNS_16BrunsliBitReaderE:
   49|  27.8k|size_t BrunsliBitReaderSuspend(BrunsliBitReader* br) {
   50|  27.8k|  BrunsliBitReaderUnload(br);
   51|  27.8k|  size_t unused_bytes = br->end_ - br->next_;
   52|  27.8k|  br->next_ = nullptr;
   53|  27.8k|  br->end_ = nullptr;
   54|  27.8k|  return unused_bytes;
   55|  27.8k|}
_ZN7brunsli22BrunsliBitReaderFinishEPNS_16BrunsliBitReaderE:
   57|  22.8k|void BrunsliBitReaderFinish(BrunsliBitReader* br) {
   58|  22.8k|  uint32_t n_bits = br->num_bits_;
   59|       |  // Likely, did not invoke Suspend before.
   60|  22.8k|  if (n_bits >= 8) {
  ------------------
  |  Branch (60:7): [True: 0, False: 22.8k]
  ------------------
   61|      0|    br->is_healthy_ = false;
   62|      0|    return;
   63|      0|  }
   64|  22.8k|  if (n_bits > 0) {
  ------------------
  |  Branch (64:7): [True: 16.1k, False: 6.68k]
  ------------------
   65|  16.1k|    uint32_t padding_bits = BrunsliBitReaderRead(br, n_bits);
   66|  16.1k|    if (padding_bits != 0) br->is_healthy_ = false;
  ------------------
  |  Branch (66:9): [True: 32, False: 16.1k]
  ------------------
   67|  16.1k|  }
   68|  22.8k|}
_ZN7brunsli25BrunsliBitReaderIsHealthyEPNS_16BrunsliBitReaderE:
   70|  51.4k|bool BrunsliBitReaderIsHealthy(BrunsliBitReader* br) {
   71|  51.4k|  BrunsliBitReaderUnload(br);
   72|  51.4k|  return (br->num_debt_bytes_ == 0) && (br->is_healthy_);
  ------------------
  |  Branch (72:10): [True: 51.0k, False: 374]
  |  Branch (72:40): [True: 51.0k, False: 32]
  ------------------
   73|  51.4k|}
_ZN7brunsli29BrunsliBitReaderSetOptimisticEPNS_16BrunsliBitReaderE:
   75|  6.96k|void BrunsliBitReaderSetOptimistic(BrunsliBitReader* br) {
   76|  6.96k|  br->is_optimistic_ = true;
   77|  6.96k|}
_ZN7brunsli23BrunsliBitReaderCanReadEPNS_16BrunsliBitReaderEm:
   79|  8.75M|bool BrunsliBitReaderCanRead(BrunsliBitReader* br, size_t n_bits) {
   80|  8.75M|  if (br->is_optimistic_) return true;
  ------------------
  |  Branch (80:7): [True: 977k, False: 7.78M]
  ------------------
   81|  7.78M|  if (br->num_debt_bytes_ != 0) return false;
  ------------------
  |  Branch (81:7): [True: 0, False: 7.78M]
  ------------------
   82|  7.78M|  if (br->num_bits_ >= n_bits) return true;
  ------------------
  |  Branch (82:7): [True: 2.32M, False: 5.45M]
  ------------------
   83|  5.45M|  size_t num_extra_bytes = (n_bits - br->num_bits_ + 7) >> 3;
   84|  5.45M|  return (br->next_ + num_extra_bytes <= br->end_);
   85|  7.78M|}
bit_reader.cc:_ZN7brunsliL22BrunsliBitReaderUnloadEPNS_16BrunsliBitReaderE:
   35|  79.2k|static BRUNSLI_INLINE void BrunsliBitReaderUnload(BrunsliBitReader* br) {
   36|       |  // Cancel the overdraft.
   37|  79.4k|  while ((br->num_debt_bytes_ > 0) && (br->num_bits_ >= 8)) {
  ------------------
  |  Branch (37:10): [True: 1.12k, False: 78.3k]
  |  Branch (37:39): [True: 190, False: 939]
  ------------------
   38|    190|    br->num_debt_bytes_--;
   39|    190|    br->num_bits_ -= 8;
   40|    190|  }
   41|       |  // Return unused bytes.
   42|  79.7k|  while (br->num_bits_ >= 8) {
  ------------------
  |  Branch (42:10): [True: 466, False: 79.2k]
  ------------------
   43|    466|    br->next_--;
   44|    466|    br->num_bits_ -= 8;
   45|    466|  }
   46|  79.2k|  br->bits_ &= BrunsliBitReaderBitMask(br->num_bits_);
   47|  79.2k|}

_ZN7brunsli20BrunsliBitReaderReadEPNS_16BrunsliBitReaderEj:
  127|  8.06M|                                                    uint32_t n_bits) {
  128|  8.06M|  uint32_t result = BrunsliBitReaderGet(br, n_bits);
  129|  8.06M|  BrunsliBitReaderDrop(br, n_bits);
  130|  8.06M|  return result;
  131|  8.06M|}
brunsli_decode.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|  7.90M|                                                   uint32_t n_bits) {
  110|  7.90M|  BRUNSLI_DCHECK(n_bits <= 24);
  111|  7.90M|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|  7.90M|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 2.13k, False: 7.90M]
  ------------------
  113|  2.13k|    BrunsliBitReaderMaybeFetchByte(br, n_bits);
  114|  2.13k|    if (n_bits > 16) BrunsliBitReaderMaybeFetchByte(br, n_bits);
  ------------------
  |  Branch (114:9): [True: 0, False: 2.13k]
  ------------------
  115|  2.13k|  }
  116|  7.90M|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|  7.90M|}
brunsli_decode.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|  7.90M|                                                          uint32_t n_bits) {
   81|  7.90M|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 5.39M, False: 2.51M]
  ------------------
   82|  5.39M|    if (BRUNSLI_PREDICT_FALSE(br->next_ >= br->end_)) {
  ------------------
  |  |   85|  5.39M|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 39, False: 5.39M]
  |  |  ------------------
  ------------------
   83|     39|      BrunsliBitReaderOweByte(br);
   84|  5.39M|    } else {
   85|  5.39M|      br->bits_ |= static_cast<uint32_t>(*br->next_) << br->num_bits_;
   86|  5.39M|      br->num_bits_ += 8;
   87|  5.39M|      br->next_++;
   88|  5.39M|    }
   89|  5.39M|  }
   90|  7.90M|}
brunsli_decode.cc:_ZN7brunsliL23BrunsliBitReaderOweByteEPNS_16BrunsliBitReaderE:
   73|     39|static BRUNSLI_INLINE void BrunsliBitReaderOweByte(BrunsliBitReader* br) {
   74|     39|  br->num_bits_ += 8;
   75|     39|  br->num_debt_bytes_++;
   76|     39|}
brunsli_decode.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|  7.90M|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|  7.90M|  return ~((0xFFFFFFFFu) << n);
   70|  7.90M|}
brunsli_decode.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|  7.90M|                                                uint32_t n_bits) {
  121|  7.90M|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|  7.90M|  br->bits_ >>= n_bits;
  123|  7.90M|  br->num_bits_ -= n_bits;
  124|  7.90M|}
context_map_decode.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|  13.7k|                                                   uint32_t n_bits) {
  110|  13.7k|  BRUNSLI_DCHECK(n_bits <= 24);
  111|  13.7k|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|  13.7k|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 127, False: 13.5k]
  ------------------
  113|    127|    BrunsliBitReaderMaybeFetchByte(br, n_bits);
  114|    127|    if (n_bits > 16) BrunsliBitReaderMaybeFetchByte(br, n_bits);
  ------------------
  |  Branch (114:9): [True: 0, False: 127]
  ------------------
  115|    127|  }
  116|  13.7k|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|  13.7k|}
context_map_decode.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|  13.8k|                                                          uint32_t n_bits) {
   81|  13.8k|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 769, False: 13.0k]
  ------------------
   82|    769|    if (BRUNSLI_PREDICT_FALSE(br->next_ >= br->end_)) {
  ------------------
  |  |   85|    769|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 480, False: 289]
  |  |  ------------------
  ------------------
   83|    480|      BrunsliBitReaderOweByte(br);
   84|    480|    } else {
   85|    289|      br->bits_ |= static_cast<uint32_t>(*br->next_) << br->num_bits_;
   86|    289|      br->num_bits_ += 8;
   87|    289|      br->next_++;
   88|    289|    }
   89|    769|  }
   90|  13.8k|}
context_map_decode.cc:_ZN7brunsliL23BrunsliBitReaderOweByteEPNS_16BrunsliBitReaderE:
   73|    480|static BRUNSLI_INLINE void BrunsliBitReaderOweByte(BrunsliBitReader* br) {
   74|    480|  br->num_bits_ += 8;
   75|    480|  br->num_debt_bytes_++;
   76|    480|}
context_map_decode.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|  13.7k|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|  13.7k|  return ~((0xFFFFFFFFu) << n);
   70|  13.7k|}
context_map_decode.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|  13.7k|                                                uint32_t n_bits) {
  121|  13.7k|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|  13.7k|  br->bits_ >>= n_bits;
  123|  13.7k|  br->num_bits_ -= n_bits;
  124|  13.7k|}
histogram_decode.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|   128k|                                                   uint32_t n_bits) {
  110|   128k|  BRUNSLI_DCHECK(n_bits <= 24);
  111|   128k|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|   128k|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 2.24k, False: 125k]
  ------------------
  113|  2.24k|    BrunsliBitReaderMaybeFetchByte(br, n_bits);
  114|  2.24k|    if (n_bits > 16) BrunsliBitReaderMaybeFetchByte(br, n_bits);
  ------------------
  |  Branch (114:9): [True: 0, False: 2.24k]
  ------------------
  115|  2.24k|  }
  116|   128k|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|   128k|}
histogram_decode.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|   130k|                                                          uint32_t n_bits) {
   81|   130k|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 28.9k, False: 101k]
  ------------------
   82|  28.9k|    if (BRUNSLI_PREDICT_FALSE(br->next_ >= br->end_)) {
  ------------------
  |  |   85|  28.9k|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 1.00k, False: 27.9k]
  |  |  ------------------
  ------------------
   83|  1.00k|      BrunsliBitReaderOweByte(br);
   84|  27.9k|    } else {
   85|  27.9k|      br->bits_ |= static_cast<uint32_t>(*br->next_) << br->num_bits_;
   86|  27.9k|      br->num_bits_ += 8;
   87|  27.9k|      br->next_++;
   88|  27.9k|    }
   89|  28.9k|  }
   90|   130k|}
histogram_decode.cc:_ZN7brunsliL23BrunsliBitReaderOweByteEPNS_16BrunsliBitReaderE:
   73|  1.00k|static BRUNSLI_INLINE void BrunsliBitReaderOweByte(BrunsliBitReader* br) {
   74|  1.00k|  br->num_bits_ += 8;
   75|  1.00k|  br->num_debt_bytes_++;
   76|  1.00k|}
histogram_decode.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|   128k|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|   128k|  return ~((0xFFFFFFFFu) << n);
   70|   128k|}
histogram_decode.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|   128k|                                                uint32_t n_bits) {
  121|   128k|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|   128k|  br->bits_ >>= n_bits;
  123|   128k|  br->num_bits_ -= n_bits;
  124|   128k|}
huffman_decode.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|  1.04M|                                                   uint32_t n_bits) {
  110|  1.04M|  BRUNSLI_DCHECK(n_bits <= 24);
  111|  1.04M|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|  1.04M|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 152, False: 1.04M]
  ------------------
  113|    152|    BrunsliBitReaderMaybeFetchByte(br, n_bits);
  114|    152|    if (n_bits > 16) BrunsliBitReaderMaybeFetchByte(br, n_bits);
  ------------------
  |  Branch (114:9): [True: 0, False: 152]
  ------------------
  115|    152|  }
  116|  1.04M|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|  1.04M|}
huffman_decode.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|  1.04M|                                                          uint32_t n_bits) {
   81|  1.04M|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 100k, False: 947k]
  ------------------
   82|   100k|    if (BRUNSLI_PREDICT_FALSE(br->next_ >= br->end_)) {
  ------------------
  |  |   85|   100k|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 90.3k, False: 10.4k]
  |  |  ------------------
  ------------------
   83|  90.3k|      BrunsliBitReaderOweByte(br);
   84|  90.3k|    } else {
   85|  10.4k|      br->bits_ |= static_cast<uint32_t>(*br->next_) << br->num_bits_;
   86|  10.4k|      br->num_bits_ += 8;
   87|  10.4k|      br->next_++;
   88|  10.4k|    }
   89|   100k|  }
   90|  1.04M|}
huffman_decode.cc:_ZN7brunsliL23BrunsliBitReaderOweByteEPNS_16BrunsliBitReaderE:
   73|  90.3k|static BRUNSLI_INLINE void BrunsliBitReaderOweByte(BrunsliBitReader* br) {
   74|  90.3k|  br->num_bits_ += 8;
   75|  90.3k|  br->num_debt_bytes_++;
   76|  90.3k|}
huffman_decode.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|  1.04M|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|  1.04M|  return ~((0xFFFFFFFFu) << n);
   70|  1.04M|}
huffman_decode.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|  1.04M|                                                uint32_t n_bits) {
  121|  1.04M|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|  1.04M|  br->bits_ >>= n_bits;
  123|  1.04M|  br->num_bits_ -= n_bits;
  124|  1.04M|}
bit_reader.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|  95.4k|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|  95.4k|  return ~((0xFFFFFFFFu) << n);
   70|  95.4k|}
bit_reader.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|  16.1k|                                                   uint32_t n_bits) {
  110|  16.1k|  BRUNSLI_DCHECK(n_bits <= 24);
  111|  16.1k|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|  16.1k|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 0, False: 16.1k]
  ------------------
  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|  16.1k|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|  16.1k|}
bit_reader.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|  16.1k|                                                          uint32_t n_bits) {
   81|  16.1k|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 0, False: 16.1k]
  ------------------
   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|  16.1k|}
bit_reader.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|  16.1k|                                                uint32_t n_bits) {
  121|  16.1k|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|  16.1k|  br->bits_ >>= n_bits;
  123|  16.1k|  br->num_bits_ -= n_bits;
  124|  16.1k|}

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

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

_ZN7brunsli16DecodeContextMapERKNS_19HuffmanDecodingDataEmPmPNSt3__16vectorIhNS4_9allocatorIhEEEEPNS_16BrunsliBitReaderE:
   44|    800|                               BrunsliBitReader* br) {
   45|    800|  size_t& i = *index;
   46|    800|  uint8_t* map = context_map->data();
   47|    800|  const size_t length = context_map->size();
   48|  1.02M|  while (i < length) {
  ------------------
  |  Branch (48:10): [True: 1.02M, False: 576]
  ------------------
   49|       |    // Check there is enough deta for Huffman code, RLE and IMTF bit.
   50|  1.02M|    if (!BrunsliBitReaderCanRead(br, 15 + max_run_length_prefix + 1)) {
  ------------------
  |  Branch (50:9): [True: 143, False: 1.02M]
  ------------------
   51|    143|      return BRUNSLI_NOT_ENOUGH_DATA;
   52|    143|    }
   53|  1.02M|    uint32_t code = entropy.ReadSymbol(br);
   54|  1.02M|    if (code == 0) {
  ------------------
  |  Branch (54:9): [True: 170k, False: 859k]
  ------------------
   55|   170k|      map[i] = 0;
   56|   170k|      ++i;
   57|   859k|    } else if (code <= max_run_length_prefix) {
  ------------------
  |  Branch (57:16): [True: 13.1k, False: 845k]
  ------------------
   58|  13.1k|      size_t reps = 1u + (1u << code) + (int)BrunsliBitReaderRead(br, code);
   59|   253k|      while (--reps) {
  ------------------
  |  Branch (59:14): [True: 240k, False: 13.0k]
  ------------------
   60|   240k|        if (i >= length) return BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (60:13): [True: 81, False: 240k]
  ------------------
   61|   240k|        map[i] = 0;
   62|   240k|        ++i;
   63|   240k|      }
   64|   845k|    } else {
   65|   845k|      map[i] = (uint8_t)(code - max_run_length_prefix);
   66|   845k|      ++i;
   67|   845k|    }
   68|  1.02M|  }
   69|    576|  if (BrunsliBitReaderRead(br, 1)) {
  ------------------
  |  Branch (69:7): [True: 405, False: 171]
  ------------------
   70|    405|    InverseMoveToFrontTransform(map, length);
   71|    405|  }
   72|    576|  return BrunsliBitReaderIsHealthy(br) ? BRUNSLI_OK : BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (72:10): [True: 484, False: 92]
  ------------------
   73|    800|}
context_map_decode.cc:_ZN7brunsli12_GLOBAL__N_127InverseMoveToFrontTransformEPhm:
   27|    405|void InverseMoveToFrontTransform(uint8_t* v, size_t v_len) {
   28|    405|  uint8_t mtf[256];
   29|   104k|  for (size_t i = 0; i < 256; ++i) {
  ------------------
  |  Branch (29:22): [True: 103k, False: 405]
  ------------------
   30|   103k|    mtf[i] = static_cast<uint8_t>(i);
   31|   103k|  }
   32|   737k|  for (size_t i = 0; i < v_len; ++i) {
  ------------------
  |  Branch (32:22): [True: 736k, False: 405]
  ------------------
   33|   736k|    uint8_t index = v[i];
   34|   736k|    v[i] = mtf[index];
   35|   736k|    if (index) MoveToFront(mtf, index);
  ------------------
  |  Branch (35:9): [True: 717k, False: 19.7k]
  ------------------
   36|   736k|  }
   37|    405|}
context_map_decode.cc:_ZN7brunsli12_GLOBAL__N_111MoveToFrontEPhh:
   20|   717k|void MoveToFront(uint8_t* v, uint8_t index) {
   21|   717k|  uint8_t value = v[index];
   22|   717k|  uint8_t i = index;
   23|  27.2M|  for (; i; --i) v[i] = v[i - 1];
  ------------------
  |  Branch (23:10): [True: 26.4M, False: 717k]
  ------------------
   24|   717k|  v[0] = value;
   25|   717k|}

_ZN7brunsli13ReadHistogramEjPNSt3__16vectorIjNS0_9allocatorIjEEEEPNS_16BrunsliBitReaderE:
   40|  11.9k|                   BrunsliBitReader* br) {
   41|  11.9k|  BRUNSLI_DCHECK(!counts->empty());
   42|  11.9k|  uint32_t space = 1u << precision_bits;
   43|  11.9k|  const size_t length = counts->size();
   44|  11.9k|  std::fill(counts->begin(), counts->end(), 0);
   45|  11.9k|  uint32_t* histogram = counts->data();
   46|  11.9k|  int simple_code = BrunsliBitReaderRead(br, 1);
   47|  11.9k|  if (simple_code == 1) {
  ------------------
  |  Branch (47:7): [True: 9.80k, False: 2.13k]
  ------------------
   48|  9.80k|    size_t max_bits_counter = length - 1;
   49|  9.80k|    uint32_t max_bits = 0;
   50|  9.80k|    int symbols[2] = {0};
   51|  9.80k|    const size_t num_symbols = BrunsliBitReaderRead(br, 1) + 1u;
   52|  58.8k|    while (max_bits_counter) {
  ------------------
  |  Branch (52:12): [True: 49.0k, False: 9.80k]
  ------------------
   53|  49.0k|      max_bits_counter >>= 1;
   54|  49.0k|      ++max_bits;
   55|  49.0k|    }
   56|  21.8k|    for (size_t i = 0; i < num_symbols; ++i) {
  ------------------
  |  Branch (56:24): [True: 12.0k, False: 9.80k]
  ------------------
   57|  12.0k|      symbols[i] = BrunsliBitReaderRead(br, max_bits) % length;
   58|  12.0k|    }
   59|  9.80k|    if (num_symbols == 1) {
  ------------------
  |  Branch (59:9): [True: 7.55k, False: 2.25k]
  ------------------
   60|  7.55k|      histogram[symbols[0]] = space;
   61|  7.55k|    } else {
   62|  2.25k|      if (symbols[0] == symbols[1]) {  // corrupt data
  ------------------
  |  Branch (62:11): [True: 7, False: 2.24k]
  ------------------
   63|      7|        return false;
   64|      7|      }
   65|  2.24k|      uint32_t value = BrunsliBitReaderRead(br, precision_bits);
   66|  2.24k|      histogram[symbols[0]] = value;
   67|  2.24k|      histogram[symbols[1]] = space - value;
   68|  2.24k|    }
   69|  9.80k|  } 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|  25.5k|    for (size_t i = 0; i < real_length; ++i) {
  ------------------
  |  Branch (75:24): [True: 23.4k, False: 2.13k]
  ------------------
   76|  23.4k|      log_counts[i] =
   77|  23.4k|          static_cast<uint32_t>(ReadShortHuffmanCode(br, kLogCountTree));
   78|  23.4k|      if (log_counts[i] > log_counts[omit_pos]) omit_pos = i;
  ------------------
  |  Branch (78:11): [True: 2.05k, False: 21.3k]
  ------------------
   79|  23.4k|    }
   80|  2.13k|    BRUNSLI_DCHECK(omit_pos >= 0);
   81|  25.5k|    for (size_t i = 0; i < real_length; ++i) {
  ------------------
  |  Branch (81:24): [True: 23.4k, False: 2.13k]
  ------------------
   82|  23.4k|      uint32_t code = log_counts[i];
   83|  23.4k|      if (i == omit_pos) {
  ------------------
  |  Branch (83:11): [True: 2.13k, False: 21.3k]
  ------------------
   84|  2.13k|        continue;
   85|  21.3k|      } else if (code == 0) {
  ------------------
  |  Branch (85:18): [True: 699, False: 20.6k]
  ------------------
   86|    699|        continue;
   87|  20.6k|      } else if (code == 1) {
  ------------------
  |  Branch (87:18): [True: 2.13k, False: 18.4k]
  ------------------
   88|  2.13k|        histogram[i] = 1;
   89|  18.4k|      } else {
   90|  18.4k|        uint32_t bit_count = GetPopulationCountPrecision(code - 1);
   91|  18.4k|        histogram[i] = (1u << (code - 1)) + (BrunsliBitReaderRead(br, bit_count)
   92|  18.4k|                                             << (code - 1 - bit_count));
   93|  18.4k|      }
   94|  20.6k|      total_count += histogram[i];
   95|  20.6k|    }
   96|  2.13k|    if (total_count >= space) {
  ------------------
  |  Branch (96:9): [True: 18, 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|     18|      return false;
  100|     18|    }
  101|  2.11k|    histogram[omit_pos] = space - total_count;
  102|  2.11k|  }
  103|  11.9k|  return BrunsliBitReaderIsHealthy(br);
  104|  11.9k|}
histogram_decode.cc:_ZN7brunsli12_GLOBAL__N_120ReadShortHuffmanCodeEPNS_16BrunsliBitReaderEPKa:
   27|  25.5k|size_t ReadShortHuffmanCode(BrunsliBitReader* br, const int8_t* tree) {
   28|  25.5k|  size_t pos = 0;
   29|  25.5k|  int8_t delta = 1;
   30|  99.1k|  while (delta > 0) {
  ------------------
  |  Branch (30:10): [True: 73.5k, False: 25.5k]
  ------------------
   31|  73.5k|    pos += delta + BrunsliBitReaderRead(br, 1);
   32|  73.5k|    delta = tree[pos];
   33|  73.5k|  }
   34|  25.5k|  return static_cast<size_t>(-delta);
   35|  25.5k|}

_ZN7brunsli22ReadHuffmanCodeLengthsEPKhmPhPNS_16BrunsliBitReaderE:
   29|    330|                           BrunsliBitReader* br) {
   30|    330|  size_t symbol = 0;
   31|    330|  uint8_t prev_code_len = kDefaultCodeLength;
   32|    330|  size_t repeat = 0;
   33|    330|  uint8_t repeat_code_len = 0;
   34|    330|  const int kFullSpace = 1 << 15;
   35|    330|  int space = kFullSpace;
   36|    330|  HuffmanCode table[32];
   37|       |
   38|    330|  uint16_t counts[16] = {0};
   39|  6.27k|  for (int i = 0; i < kCodeLengthCodes; ++i) {
  ------------------
  |  Branch (39:19): [True: 5.94k, False: 330]
  ------------------
   40|  5.94k|    ++counts[code_length_code_lengths[i]];
   41|  5.94k|  }
   42|    330|  if (!BuildHuffmanTable(table, 5, code_length_code_lengths, kCodeLengthCodes,
  ------------------
  |  Branch (42:7): [True: 0, False: 330]
  ------------------
   43|    330|                         &counts[0])) {
   44|      0|    return false;
   45|      0|  }
   46|       |
   47|  9.69k|  while (symbol < num_symbols && space > 0) {
  ------------------
  |  Branch (47:10): [True: 9.57k, False: 116]
  |  Branch (47:34): [True: 9.40k, False: 176]
  ------------------
   48|  9.40k|    const HuffmanCode* p = table;
   49|  9.40k|    uint8_t code_len;
   50|  9.40k|    p += BrunsliBitReaderGet(br, 5);
   51|  9.40k|    BrunsliBitReaderDrop(br, p->bits);
   52|  9.40k|    code_len = (uint8_t)p->value;
   53|  9.40k|    if (code_len < kCodeLengthRepeatCode) {
  ------------------
  |  Branch (53:9): [True: 8.65k, False: 752]
  ------------------
   54|  8.65k|      repeat = 0;
   55|  8.65k|      code_lengths[symbol++] = code_len;
   56|  8.65k|      if (code_len != 0) {
  ------------------
  |  Branch (56:11): [True: 7.01k, False: 1.63k]
  ------------------
   57|  7.01k|        prev_code_len = code_len;
   58|  7.01k|        space -= kFullSpace >> code_len;
   59|  7.01k|      }
   60|  8.65k|    } else {
   61|    752|      uint32_t extra_bits = code_len - 14;  // >= 2
   62|    752|      size_t old_repeat;
   63|    752|      size_t repeat_delta;
   64|    752|      uint8_t new_len = 0;
   65|    752|      if (code_len == kCodeLengthRepeatCode) {
  ------------------
  |  Branch (65:11): [True: 509, False: 243]
  ------------------
   66|    509|        new_len = prev_code_len;
   67|    509|      }
   68|    752|      if (repeat_code_len != new_len) {
  ------------------
  |  Branch (68:11): [True: 213, False: 539]
  ------------------
   69|    213|        repeat = 0;
   70|    213|        repeat_code_len = new_len;
   71|    213|      }
   72|    752|      old_repeat = repeat;
   73|    752|      if (repeat > 0) {  // >= 3
  ------------------
  |  Branch (73:11): [True: 234, False: 518]
  ------------------
   74|    234|        repeat -= 2;
   75|    234|        repeat <<= extra_bits;
   76|    234|      }
   77|    752|      repeat += BrunsliBitReaderRead(br, extra_bits) + 3u;
   78|    752|      repeat_delta = repeat - old_repeat;
   79|    752|      if (symbol + repeat_delta > num_symbols) {
  ------------------
  |  Branch (79:11): [True: 38, False: 714]
  ------------------
   80|     38|        return false;
   81|     38|      }
   82|    714|      memset(&code_lengths[symbol], repeat_code_len, (size_t)repeat_delta);
   83|    714|      symbol += repeat_delta;
   84|    714|      if (repeat_code_len != 0) {
  ------------------
  |  Branch (84:11): [True: 492, False: 222]
  ------------------
   85|    492|        space -= static_cast<int>(repeat_delta * kFullSpace) >> repeat_code_len;
   86|    492|      }
   87|    714|    }
   88|  9.40k|  }
   89|    292|  if (space != 0) {
  ------------------
  |  Branch (89:7): [True: 96, False: 196]
  ------------------
   90|     96|    return false;
   91|     96|  }
   92|    196|  memset(&code_lengths[symbol], 0, (size_t)(num_symbols - symbol));
   93|    196|  return BrunsliBitReaderIsHealthy(br);
   94|    292|}
_ZN7brunsli19HuffmanDecodingData17ReadFromBitStreamEmPNS_16BrunsliBitReaderEPNS_5ArenaINS_11HuffmanCodeEEE:
  191|  1.12k|    Arena<HuffmanCode>* arena) {
  192|  1.12k|  Arena<HuffmanCode> local_arena;
  193|  1.12k|  if (arena == nullptr) arena = &local_arena;
  ------------------
  |  Branch (193:7): [True: 0, False: 1.12k]
  ------------------
  194|       |
  195|  1.12k|  if (alphabet_size > (1 << kMaxHuffmanBits)) return false;
  ------------------
  |  Branch (195:7): [True: 0, False: 1.12k]
  ------------------
  196|       |
  197|  1.12k|  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.12k|  uint32_t simple_code_or_skip = BrunsliBitReaderRead(br, 2);
  202|  1.12k|  if (simple_code_or_skip == 1u) {
  ------------------
  |  Branch (202:7): [True: 710, False: 411]
  ------------------
  203|    710|    table_.resize(1u << kHuffmanTableBits);
  204|    710|    return ReadSimpleCode(static_cast<uint16_t>(alphabet_size), br,
  205|    710|                          table_.data());
  206|    710|  }
  207|       |
  208|    411|  uint8_t code_length_code_lengths[kCodeLengthCodes] = {0};
  209|    411|  int space = 32;
  210|    411|  int num_codes = 0;
  211|       |  /* Static Huffman code for the code length code lengths */
  212|    411|  static const HuffmanCode huff[16] = {
  213|    411|      {2, 0}, {2, 4}, {2, 3}, {3, 2}, {2, 0}, {2, 4}, {2, 3}, {4, 1},
  214|    411|      {2, 0}, {2, 4}, {2, 3}, {3, 2}, {2, 0}, {2, 4}, {2, 3}, {4, 5},
  215|    411|  };
  216|  5.41k|  for (size_t i = simple_code_or_skip; i < kCodeLengthCodes && space > 0; ++i) {
  ------------------
  |  Branch (216:40): [True: 5.27k, False: 141]
  |  Branch (216:64): [True: 5.00k, False: 270]
  ------------------
  217|  5.00k|    const int code_len_idx = kCodeLengthCodeOrder[i];
  218|  5.00k|    const HuffmanCode* p = huff;
  219|  5.00k|    uint8_t v;
  220|  5.00k|    p += BrunsliBitReaderGet(br, 4);
  221|  5.00k|    BrunsliBitReaderDrop(br, p->bits);
  222|  5.00k|    v = (uint8_t)p->value;
  223|  5.00k|    code_length_code_lengths[code_len_idx] = v;
  224|  5.00k|    if (v != 0) {
  ------------------
  |  Branch (224:9): [True: 2.35k, False: 2.64k]
  ------------------
  225|  2.35k|      space -= (32u >> v);
  226|  2.35k|      ++num_codes;
  227|  2.35k|    }
  228|  5.00k|  }
  229|    411|  bool ok = (num_codes == 1 || space == 0) &&
  ------------------
  |  Branch (229:14): [True: 65, False: 346]
  |  Branch (229:32): [True: 265, False: 81]
  ------------------
  230|    330|       ReadHuffmanCodeLengths(code_length_code_lengths, alphabet_size,
  ------------------
  |  Branch (230:8): [True: 189, False: 141]
  ------------------
  231|    330|                              &code_lengths[0], br);
  232|       |
  233|    411|  if (!ok || !BrunsliBitReaderIsHealthy(br)) return false;
  ------------------
  |  Branch (233:7): [True: 222, False: 189]
  |  Branch (233:14): [True: 0, False: 189]
  ------------------
  234|    189|  uint16_t counts[16] = {0};
  235|  20.8k|  for (size_t i = 0; i < alphabet_size; ++i) {
  ------------------
  |  Branch (235:22): [True: 20.6k, False: 189]
  ------------------
  236|  20.6k|    ++counts[code_lengths[i]];
  237|  20.6k|  }
  238|    189|  arena->reserve(alphabet_size + 376);
  239|    189|  uint32_t table_size =
  240|    189|      BuildHuffmanTable(arena->data(), kHuffmanTableBits, &code_lengths[0],
  241|    189|                        alphabet_size, &counts[0]);
  242|    189|  table_ = std::vector<HuffmanCode>(arena->data(), arena->data() + table_size);
  243|    189|  return (table_size > 0);
  244|    411|}
_ZNK7brunsli19HuffmanDecodingData10ReadSymbolEPNS_16BrunsliBitReaderE:
  247|  1.02M|uint16_t HuffmanDecodingData::ReadSymbol(BrunsliBitReader* br) const {
  248|  1.02M|  uint32_t n_bits;
  249|  1.02M|  const HuffmanCode* table = table_.data();
  250|  1.02M|  table += BrunsliBitReaderGet(br, kHuffmanTableBits);
  251|  1.02M|  n_bits = table->bits;
  252|  1.02M|  if (n_bits > kHuffmanTableBits) {
  ------------------
  |  Branch (252:7): [True: 613, False: 1.02M]
  ------------------
  253|    613|    BrunsliBitReaderDrop(br, kHuffmanTableBits);
  254|    613|    n_bits -= kHuffmanTableBits;
  255|    613|    table += table->value;
  256|    613|    table += BrunsliBitReaderGet(br, n_bits);
  257|    613|  }
  258|  1.02M|  BrunsliBitReaderDrop(br, table->bits);
  259|  1.02M|  return table->value;
  260|  1.02M|}
huffman_decode.cc:_ZN7brunsliL14ReadSimpleCodeEtPNS_16BrunsliBitReaderEPNS_11HuffmanCodeE:
   98|    710|                                          HuffmanCode* table) {
   99|    710|  uint32_t max_bits =
  100|    710|      (alphabet_size > 1u) ? Log2FloorNonZero(alphabet_size - 1u) + 1 : 0;
  ------------------
  |  Branch (100:7): [True: 710, False: 0]
  ------------------
  101|       |
  102|    710|  size_t num_symbols = BrunsliBitReaderRead(br, 2) + 1;
  103|       |
  104|    710|  uint16_t symbols[4] = {0};
  105|  1.80k|  for (size_t i = 0; i < num_symbols; ++i) {
  ------------------
  |  Branch (105:22): [True: 1.12k, False: 678]
  ------------------
  106|  1.12k|    uint16_t symbol = BrunsliBitReaderRead(br, max_bits);
  107|  1.12k|    if (symbol >= alphabet_size) {
  ------------------
  |  Branch (107:9): [True: 32, False: 1.09k]
  ------------------
  108|     32|      return false;
  109|     32|    }
  110|  1.09k|    symbols[i] = symbol;
  111|  1.09k|  }
  112|       |
  113|  1.01k|  for (size_t i = 0; i < num_symbols - 1; ++i) {
  ------------------
  |  Branch (113:22): [True: 353, False: 657]
  ------------------
  114|    901|    for (size_t j = i + 1; j < num_symbols; ++j) {
  ------------------
  |  Branch (114:28): [True: 569, False: 332]
  ------------------
  115|    569|      if (symbols[i] == symbols[j]) return false;
  ------------------
  |  Branch (115:11): [True: 21, False: 548]
  ------------------
  116|    569|    }
  117|    353|  }
  118|       |
  119|       |  // 4 symbols have to option to encode.
  120|    657|  if (num_symbols == 4) num_symbols += BrunsliBitReaderRead(br, 1);
  ------------------
  |  Branch (120:7): [True: 52, False: 605]
  ------------------
  121|       |
  122|    657|  const auto swap_symbols = [&symbols] (size_t i, size_t j) {
  123|    657|    uint16_t t = symbols[j];
  124|    657|    symbols[j] = symbols[i];
  125|    657|    symbols[i] = t;
  126|    657|  };
  127|       |
  128|    657|  size_t table_size = 1;
  129|    657|  switch (num_symbols) {
  130|    476|    case 1:
  ------------------
  |  Branch (130:5): [True: 476, False: 181]
  ------------------
  131|    476|      table[0] = {0, symbols[0]};
  132|    476|      break;
  133|    102|    case 2:
  ------------------
  |  Branch (133:5): [True: 102, False: 555]
  ------------------
  134|    102|      if (symbols[0] > symbols[1]) swap_symbols(0, 1);
  ------------------
  |  Branch (134:11): [True: 61, False: 41]
  ------------------
  135|    102|      table[0] = {1, symbols[0]};
  136|    102|      table[1] = {1, symbols[1]};
  137|    102|      table_size = 2;
  138|    102|      break;
  139|     27|    case 3:
  ------------------
  |  Branch (139:5): [True: 27, False: 630]
  ------------------
  140|     27|      if (symbols[1] > symbols[2]) swap_symbols(1, 2);
  ------------------
  |  Branch (140:11): [True: 17, False: 10]
  ------------------
  141|     27|      table[0] = {1, symbols[0]};
  142|     27|      table[2] = {1, symbols[0]};
  143|     27|      table[1] = {2, symbols[1]};
  144|     27|      table[3] = {2, symbols[2]};
  145|     27|      table_size = 4;
  146|     27|      break;
  147|     34|    case 4: {
  ------------------
  |  Branch (147:5): [True: 34, False: 623]
  ------------------
  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: 152, False: 52]
  ------------------
  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|     18|    case 5: {
  ------------------
  |  Branch (160:5): [True: 18, False: 639]
  ------------------
  161|     18|      if (symbols[2] > symbols[3]) swap_symbols(2, 3);
  ------------------
  |  Branch (161:11): [True: 12, False: 6]
  ------------------
  162|     18|      table[0] = {1, symbols[0]};
  163|     18|      table[1] = {2, symbols[1]};
  164|     18|      table[2] = {1, symbols[0]};
  165|     18|      table[3] = {3, symbols[2]};
  166|     18|      table[4] = {1, symbols[0]};
  167|     18|      table[5] = {2, symbols[1]};
  168|     18|      table[6] = {1, symbols[0]};
  169|     18|      table[7] = {3, symbols[3]};
  170|     18|      table_size = 8;
  171|     18|      break;
  172|      0|    }
  173|      0|    default: {
  ------------------
  |  Branch (173:5): [True: 0, False: 657]
  ------------------
  174|       |      // Unreachable.
  175|      0|      return false;
  176|      0|    }
  177|    657|  }
  178|       |
  179|    657|  const uint32_t goal_size = 1u << kHuffmanTableBits;
  180|  5.63k|  while (table_size != goal_size) {
  ------------------
  |  Branch (180:10): [True: 4.97k, False: 657]
  ------------------
  181|  4.97k|    memcpy(&table[table_size], &table[0],
  182|  4.97k|           (size_t)table_size * sizeof(table[0]));
  183|  4.97k|    table_size <<= 1;
  184|  4.97k|  }
  185|       |
  186|    657|  return BrunsliBitReaderIsHealthy(br);
  187|    657|}
huffman_decode.cc:_ZZN7brunsliL14ReadSimpleCodeEtPNS_16BrunsliBitReaderEPNS_11HuffmanCodeEENKUlmmE_clEmm:
  122|    242|  const auto swap_symbols = [&symbols] (size_t i, size_t j) {
  123|    242|    uint16_t t = symbols[j];
  124|    242|    symbols[j] = symbols[i];
  125|    242|    symbols[i] = t;
  126|    242|  };

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

_ZN7brunsli17BuildHuffmanTableEPNS_11HuffmanCodeEmPKhmPt:
   55|    519|                           size_t code_lengths_size, uint16_t* count) {
   56|    519|  HuffmanCode code;    /* current table entry */
   57|    519|  HuffmanCode* table;  /* next available space in table */
   58|    519|  size_t len;          /* current code length */
   59|    519|  size_t symbol;       /* symbol index in original or sorted table */
   60|    519|  int key;             /* reversed prefix code */
   61|    519|  int step;            /* step size to replicate values in current table */
   62|    519|  int low;             /* low bits for current root entry */
   63|    519|  int mask;            /* mask for low bits */
   64|    519|  size_t table_bits;   /* key length of current table */
   65|    519|  int table_size;      /* size of current table */
   66|    519|  int total_size;      /* sum of root table size and 2nd level table sizes */
   67|       |  /* offsets in sorted table for each length */
   68|    519|  uint16_t offset[kMaxHuffmanBits + 1];
   69|    519|  size_t max_length = 1;
   70|       |
   71|    519|  if (code_lengths_size > 1u << kMaxHuffmanBits) return 0;
  ------------------
  |  Branch (71:7): [True: 0, False: 519]
  ------------------
   72|       |
   73|       |  /* symbols sorted by code length */
   74|    519|  std::vector<uint16_t> sorted_storage(code_lengths_size);
   75|    519|  uint16_t* sorted = sorted_storage.data();
   76|       |
   77|       |  /* generate offsets into sorted symbol table by code length */
   78|    519|  {
   79|    519|    uint16_t sum = 0;
   80|  8.30k|    for (len = 1; len <= kMaxHuffmanBits; len++) {
  ------------------
  |  Branch (80:19): [True: 7.78k, False: 519]
  ------------------
   81|  7.78k|      offset[len] = sum;
   82|  7.78k|      if (count[len]) {
  ------------------
  |  Branch (82:11): [True: 1.25k, False: 6.53k]
  ------------------
   83|  1.25k|        sum = static_cast<uint16_t>(sum + count[len]);
   84|  1.25k|        max_length = len;
   85|  1.25k|      }
   86|  7.78k|    }
   87|    519|  }
   88|       |
   89|       |  /* sort symbols by length, by symbol order within each length */
   90|  27.1k|  for (symbol = 0; symbol < code_lengths_size; symbol++) {
  ------------------
  |  Branch (90:20): [True: 26.5k, False: 519]
  ------------------
   91|  26.5k|    if (code_lengths[symbol] != 0) {
  ------------------
  |  Branch (91:9): [True: 10.5k, False: 16.0k]
  ------------------
   92|  10.5k|      sorted[offset[code_lengths[symbol]]++] = static_cast<uint16_t>(symbol);
   93|  10.5k|    }
   94|  26.5k|  }
   95|       |
   96|    519|  table = root_table;
   97|    519|  table_bits = root_bits;
   98|    519|  table_size = 1u << table_bits;
   99|    519|  total_size = table_size;
  100|       |
  101|       |  /* special case code with only one value */
  102|    519|  if (offset[kMaxHuffmanBits] == 1) {
  ------------------
  |  Branch (102:7): [True: 65, False: 454]
  ------------------
  103|     65|    code.bits = 0;
  104|     65|    code.value = static_cast<uint16_t>(sorted[0]);
  105|  2.14k|    for (key = 0; key < total_size; ++key) {
  ------------------
  |  Branch (105:19): [True: 2.08k, False: 65]
  ------------------
  106|  2.08k|      table[key] = code;
  107|  2.08k|    }
  108|     65|    return total_size;
  109|     65|  }
  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|    454|  if (table_bits > max_length) {
  ------------------
  |  Branch (114:7): [True: 355, False: 99]
  ------------------
  115|    355|    table_bits = max_length;
  116|    355|    table_size = 1u << table_bits;
  117|    355|  }
  118|    454|  key = 0;
  119|    454|  symbol = 0;
  120|    454|  code.bits = 1;
  121|    454|  step = 2;
  122|  1.79k|  do {
  123|  8.57k|    for (; count[code.bits] != 0; --count[code.bits]) {
  ------------------
  |  Branch (123:12): [True: 6.78k, False: 1.79k]
  ------------------
  124|  6.78k|      code.value = static_cast<uint16_t>(sorted[symbol++]);
  125|  6.78k|      ReplicateValue(&table[key], step, table_size, code);
  126|  6.78k|      key = GetNextKey(key, code.bits);
  127|  6.78k|    }
  128|  1.79k|    step <<= 1;
  129|  1.79k|  } while (++code.bits <= table_bits);
  ------------------
  |  Branch (129:12): [True: 1.33k, False: 454]
  ------------------
  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.49k|  while (total_size != table_size) {
  ------------------
  |  Branch (133:10): [True: 1.04k, False: 454]
  ------------------
  134|  1.04k|    memcpy(&table[table_size], &table[0], table_size * sizeof(table[0]));
  135|  1.04k|    table_size <<= 1;
  136|  1.04k|  }
  137|       |
  138|       |  /* fill in 2nd level tables and add pointers to root table */
  139|    454|  mask = total_size - 1;
  140|    454|  low = -1;
  141|    624|  for (len = root_bits + 1, step = 2; len <= max_length; ++len, step <<= 1) {
  ------------------
  |  Branch (141:39): [True: 170, False: 454]
  ------------------
  142|  3.85k|    for (; count[len] != 0; --count[len]) {
  ------------------
  |  Branch (142:12): [True: 3.68k, False: 170]
  ------------------
  143|  3.68k|      if ((key & mask) != low) {
  ------------------
  |  Branch (143:11): [True: 1.24k, False: 2.44k]
  ------------------
  144|  1.24k|        table += table_size;
  145|  1.24k|        table_bits = NextTableBitSize(count, len, root_bits);
  146|  1.24k|        table_size = 1u << table_bits;
  147|  1.24k|        total_size += table_size;
  148|  1.24k|        low = key & mask;
  149|  1.24k|        root_table[low].bits = static_cast<uint8_t>(table_bits + root_bits);
  150|  1.24k|        root_table[low].value =
  151|  1.24k|            static_cast<uint16_t>((table - root_table) - low);
  152|  1.24k|      }
  153|  3.68k|      code.bits = static_cast<uint8_t>(len - root_bits);
  154|  3.68k|      code.value = static_cast<uint16_t>(sorted[symbol++]);
  155|  3.68k|      ReplicateValue(&table[key >> root_bits], step, table_size, code);
  156|  3.68k|      key = GetNextKey(key, len);
  157|  3.68k|    }
  158|    170|  }
  159|       |
  160|    454|  return total_size;
  161|    519|}
huffman_table.cc:_ZN7brunsliL14ReplicateValueEPNS_11HuffmanCodeEiiS0_:
   31|  10.4k|                                  HuffmanCode code) {
   32|  26.1k|  do {
   33|  26.1k|    end -= step;
   34|  26.1k|    table[end] = code;
   35|  26.1k|  } while (end > 0);
  ------------------
  |  Branch (35:12): [True: 15.6k, False: 10.4k]
  ------------------
   36|  10.4k|}
huffman_table.cc:_ZN7brunsliL10GetNextKeyEim:
   20|  10.4k|static inline int GetNextKey(int key, size_t len) {
   21|  10.4k|  int step = 1u << (len - 1);
   22|  20.4k|  while (key & step) {
  ------------------
  |  Branch (22:10): [True: 10.0k, False: 10.4k]
  ------------------
   23|  10.0k|    step >>= 1;
   24|  10.0k|  }
   25|  10.4k|  return (key & (step - 1)) + step;
   26|  10.4k|}
huffman_table.cc:_ZN7brunsliL16NextTableBitSizeEPKtmm:
   42|  1.24k|                                      size_t root_bits) {
   43|  1.24k|  size_t left = size_t(1) << (len - root_bits);
   44|  1.30k|  while (len < kMaxHuffmanBits) {
  ------------------
  |  Branch (44:10): [True: 1.29k, False: 13]
  ------------------
   45|  1.29k|    if (left <= count[len]) break;
  ------------------
  |  Branch (45:9): [True: 1.22k, False: 66]
  ------------------
   46|     66|    left -= count[len];
   47|     66|    ++len;
   48|     66|    left <<= 1;
   49|     66|  }
   50|  1.24k|  return len - root_bits;
   51|  1.24k|}

_ZN7brunsli9WriteJpegERKNS_8JPEGDataENS_10JPEGOutputE:
  982|  4.84k|bool WriteJpeg(const JPEGData& jpg, JPEGOutput out) {
  983|  4.84k|  State state;
  984|  4.84k|  state.stage = Stage::DONE;
  985|  4.84k|  std::vector<uint8_t> buffer(16384);
  986|  5.07k|  while (true) {
  ------------------
  |  Branch (986:10): [True: 5.07k, Folded]
  ------------------
  987|  5.07k|    uint8_t* next_out = buffer.data();
  988|  5.07k|    size_t available_out = buffer.size();
  989|  5.07k|    SerializationStatus status =
  990|  5.07k|        SerializeJpeg(&state, jpg, &available_out, &next_out);
  991|  5.07k|    if (status != SerializationStatus::DONE &&
  ------------------
  |  Branch (991:9): [True: 4.74k, False: 335]
  ------------------
  992|  4.74k|        status != SerializationStatus::NEEDS_MORE_OUTPUT) {
  ------------------
  |  Branch (992:9): [True: 4.51k, False: 230]
  ------------------
  993|  4.51k|      return false;
  994|  4.51k|    }
  995|    565|    size_t to_write = buffer.size() - available_out;
  996|    565|    if (!out.Write(buffer.data(), to_write)) return false;
  ------------------
  |  Branch (996:9): [True: 0, False: 565]
  ------------------
  997|    565|    if (status == SerializationStatus::DONE) return true;
  ------------------
  |  Branch (997:9): [True: 335, False: 230]
  ------------------
  998|    565|  }
  999|  4.84k|}
_ZN7brunsli8internal3dec13SerializeJpegEPNS1_5StateERKNS_8JPEGDataEPmPPh:
 1004|  5.07k|                                  size_t* available_out, uint8_t** next_out) {
 1005|  5.07k|  SerializationState& ss = state->internal->serialization;
 1006|       |
 1007|  5.07k|  const auto maybe_push_output = [&]() {
 1008|  5.07k|    if (ss.stage != SerializationState::ERROR) {
 1009|  5.07k|      PushOutput(&ss.output_queue, available_out, next_out);
 1010|  5.07k|    }
 1011|  5.07k|  };
 1012|       |
 1013|       |  // Push remaining output from prevoius session.
 1014|  5.07k|  maybe_push_output();
 1015|       |
 1016|  45.5k|  while (true) {
  ------------------
  |  Branch (1016:10): [True: 45.5k, Folded]
  ------------------
 1017|  45.5k|    switch (ss.stage) {
 1018|  4.84k|      case SerializationState::INIT: {
  ------------------
  |  Branch (1018:7): [True: 4.84k, False: 40.6k]
  ------------------
 1019|       |        // If parsing is complete, serialization is possible.
 1020|  4.84k|        bool can_start_serialization = (state->stage == Stage::DONE);
 1021|       |        // Parsing of AC/DC has started; i.e. quant/huffman/metadata is ready
 1022|       |        // to be used.
 1023|  4.84k|        if (HasSection(state, kBrunsliDCDataTag) ||
  ------------------
  |  Branch (1023:13): [True: 0, False: 4.84k]
  ------------------
 1024|  4.84k|            HasSection(state, kBrunsliACDataTag)) {
  ------------------
  |  Branch (1024:13): [True: 0, False: 4.84k]
  ------------------
 1025|      0|          can_start_serialization = true;
 1026|      0|        }
 1027|  4.84k|        if (!can_start_serialization) {
  ------------------
  |  Branch (1027:13): [True: 0, False: 4.84k]
  ------------------
 1028|      0|          return SerializationStatus::NEEDS_MORE_INPUT;
 1029|      0|        }
 1030|       |        // JpegBypass is a very simple / special case.
 1031|  4.84k|        if (jpg.version == kFallbackVersion) {
  ------------------
  |  Branch (1031:13): [True: 9, False: 4.83k]
  ------------------
 1032|      9|          if (jpg.original_jpg == nullptr) {
  ------------------
  |  Branch (1032:15): [True: 1, False: 8]
  ------------------
 1033|      1|            ss.stage = SerializationState::ERROR;
 1034|      1|            break;
 1035|      1|          }
 1036|       |          // TODO(eustas): investigate if bad things can happen when complete
 1037|       |          //               file is passed to parser, but it is impossible to
 1038|       |          //               push complete output.
 1039|      8|          ss.output_queue.emplace_back(jpg.original_jpg, jpg.original_jpg_size);
 1040|      8|          ss.stage = SerializationState::DONE;
 1041|      8|          break;
 1042|      9|        }
 1043|       |
 1044|       |        // Invalid mode - fallback + something else.
 1045|  4.83k|        if ((jpg.version & 1) == kFallbackVersion) {
  ------------------
  |  Branch (1045:13): [True: 0, False: 4.83k]
  ------------------
 1046|      0|          ss.stage = SerializationState::ERROR;
 1047|      0|          break;
 1048|      0|        }
 1049|       |
 1050|       |        // Valid Brunsli requires, at least, 0xD9 marker.
 1051|       |        // This might happen on corrupted stream, or on unconditioned JPEGData.
 1052|       |        // TODO(eustas): check D9 in the only one and is the last one.
 1053|  4.83k|        if (jpg.marker_order.empty()) {
  ------------------
  |  Branch (1053:13): [True: 0, False: 4.83k]
  ------------------
 1054|      0|          ss.stage = SerializationState::ERROR;
 1055|      0|          break;
 1056|      0|        }
 1057|       |
 1058|  4.83k|        ss.dc_huff_table.resize(kMaxHuffmanTables);
 1059|  4.83k|        ss.ac_huff_table.resize(kMaxHuffmanTables);
 1060|  4.83k|        if (jpg.has_zero_padding_bit) {
  ------------------
  |  Branch (1060:13): [True: 236, False: 4.60k]
  ------------------
 1061|    236|          ss.pad_bits = jpg.padding_bits.data();
 1062|    236|          ss.pad_bits_end = ss.pad_bits + jpg.padding_bits.size();
 1063|    236|        }
 1064|       |
 1065|  4.83k|        EncodeSOI(&ss);
 1066|  4.83k|        maybe_push_output();
 1067|  4.83k|        ss.stage = SerializationState::SERIALIZE_SECTION;
 1068|  4.83k|        break;
 1069|  4.83k|      }
 1070|       |
 1071|  35.5k|      case SerializationState::SERIALIZE_SECTION: {
  ------------------
  |  Branch (1071:7): [True: 35.5k, False: 9.92k]
  ------------------
 1072|  35.5k|        if (ss.section_index >= jpg.marker_order.size()) {
  ------------------
  |  Branch (1072:13): [True: 327, False: 35.2k]
  ------------------
 1073|    327|          ss.stage = SerializationState::DONE;
 1074|    327|          break;
 1075|    327|        }
 1076|  35.2k|        uint8_t marker = jpg.marker_order[ss.section_index];
 1077|  35.2k|        SerializationStatus status = SerializeSection(marker, *state, &ss, jpg);
 1078|  35.2k|        if (status == SerializationStatus::ERROR) {
  ------------------
  |  Branch (1078:13): [True: 4.51k, False: 30.7k]
  ------------------
 1079|  4.51k|          BRUNSLI_LOG_DEBUG() << "Failed to encode marker " << std::hex
  ------------------
  |  |  433|  4.51k|#define BRUNSLI_LOG_DEBUG() BRUNSLI_VOID_LOG()
  |  |  ------------------
  |  |  |  |  412|  4.51k|#define BRUNSLI_VOID_LOG() if (true) {} else std::cerr
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (412:32): [True: 4.51k, Folded]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1080|      0|                              << marker << BRUNSLI_ENDL();
  ------------------
  |  |  420|      0|#define BRUNSLI_ENDL() std::endl
  ------------------
 1081|  4.51k|          ss.stage = SerializationState::ERROR;
 1082|  4.51k|          break;
 1083|  4.51k|        }
 1084|  30.7k|        maybe_push_output();
 1085|  30.7k|        if (status == SerializationStatus::NEEDS_MORE_INPUT) {
  ------------------
  |  Branch (1085:13): [True: 0, False: 30.7k]
  ------------------
 1086|      0|          return SerializationStatus::NEEDS_MORE_INPUT;
 1087|  30.7k|        } else if (status != SerializationStatus::DONE) {
  ------------------
  |  Branch (1087:20): [True: 0, False: 30.7k]
  ------------------
 1088|      0|          BRUNSLI_DCHECK(false);
 1089|      0|          ss.stage = SerializationState::ERROR;
 1090|      0|          break;
 1091|      0|        }
 1092|  30.7k|        ++ss.section_index;
 1093|  30.7k|        break;
 1094|  30.7k|      }
 1095|       |
 1096|    565|      case SerializationState::DONE: {
  ------------------
  |  Branch (1096:7): [True: 565, False: 44.9k]
  ------------------
 1097|    565|        if (!ss.output_queue.empty()) {
  ------------------
  |  Branch (1097:13): [True: 230, False: 335]
  ------------------
 1098|    230|          return SerializationStatus::NEEDS_MORE_OUTPUT;
 1099|    335|        } else {
 1100|    335|          return SerializationStatus::DONE;
 1101|    335|        }
 1102|    565|      }
 1103|       |
 1104|  4.51k|      default:
  ------------------
  |  Branch (1104:7): [True: 4.51k, False: 41.0k]
  ------------------
 1105|  4.51k|        return SerializationStatus::ERROR;
 1106|  45.5k|    }
 1107|  45.5k|  }
 1108|  5.07k|}
jpeg_data_writer.cc:_ZZN7brunsli8internal3dec13SerializeJpegEPNS1_5StateERKNS_8JPEGDataEPmPPhENK3$_0clEv:
 1007|  40.6k|  const auto maybe_push_output = [&]() {
 1008|  40.6k|    if (ss.stage != SerializationState::ERROR) {
  ------------------
  |  Branch (1008:9): [True: 40.6k, False: 0]
  ------------------
 1009|  40.6k|      PushOutput(&ss.output_queue, available_out, next_out);
 1010|  40.6k|    }
 1011|  40.6k|  };
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_110PushOutputEPNSt3__15dequeINS_8internal3dec11OutputChunkENS1_9allocatorIS5_EEEEPmPPh:
  961|  40.6k|                uint8_t** next_out) {
  962|  77.7k|  while (*available_out > 0) {
  ------------------
  |  Branch (962:10): [True: 77.0k, False: 715]
  ------------------
  963|       |    // No more data.
  964|  77.0k|    if (in->empty()) return;
  ------------------
  |  Branch (964:9): [True: 39.9k, False: 37.1k]
  ------------------
  965|  37.1k|    OutputChunk& chunk = in->front();
  966|  37.1k|    size_t to_copy = std::min(*available_out, chunk.len);
  967|  37.1k|    if (to_copy > 0) {
  ------------------
  |  Branch (967:9): [True: 36.7k, False: 341]
  ------------------
  968|  36.7k|      memcpy(*next_out, chunk.next, to_copy);
  969|  36.7k|      *next_out += to_copy;
  970|  36.7k|      *available_out -= to_copy;
  971|  36.7k|      chunk.next += to_copy;
  972|  36.7k|      chunk.len -= to_copy;
  973|  36.7k|    }
  974|  37.1k|    if (chunk.len == 0) in->pop_front();
  ------------------
  |  Branch (974:9): [True: 36.8k, False: 297]
  ------------------
  975|  37.1k|  }
  976|  40.6k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeSOIEPNS_8internal3dec18SerializationStateE:
  308|  4.83k|bool EncodeSOI(SerializationState* state) {
  309|  4.83k|  state->output_queue.push_back(OutputChunk({0xFF, 0xD8}));
  310|  4.83k|  return true;
  311|  4.83k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_116SerializeSectionEhRKNS_8internal3dec5StateEPNS2_18SerializationStateERKNS_8JPEGDataE:
  893|  35.2k|                                     const JPEGData& jpg) {
  894|  35.2k|  const auto to_status = [](bool result) {
  895|  35.2k|    return result ? SerializationStatus::DONE : SerializationStatus::ERROR;
  896|  35.2k|  };
  897|       |  // TODO(eustas): add and use marker enum
  898|  35.2k|  switch (marker) {
  899|  3.62k|    case 0xC0:
  ------------------
  |  Branch (899:5): [True: 3.62k, False: 31.6k]
  ------------------
  900|  4.68k|    case 0xC1:
  ------------------
  |  Branch (900:5): [True: 1.05k, False: 34.2k]
  ------------------
  901|  9.64k|    case 0xC2:
  ------------------
  |  Branch (901:5): [True: 4.96k, False: 30.3k]
  ------------------
  902|  11.1k|    case 0xC9:
  ------------------
  |  Branch (902:5): [True: 1.46k, False: 33.7k]
  ------------------
  903|  12.3k|    case 0xCA:
  ------------------
  |  Branch (903:5): [True: 1.20k, False: 34.0k]
  ------------------
  904|  12.3k|      return to_status(EncodeSOF(jpg, marker, state));
  905|       |
  906|  5.03k|    case 0xC4:
  ------------------
  |  Branch (906:5): [True: 5.03k, False: 30.2k]
  ------------------
  907|  5.03k|      return to_status(EncodeDHT(jpg, state));
  908|       |
  909|  2.03k|    case 0xD0:
  ------------------
  |  Branch (909:5): [True: 2.03k, False: 33.2k]
  ------------------
  910|  3.17k|    case 0xD1:
  ------------------
  |  Branch (910:5): [True: 1.14k, False: 34.1k]
  ------------------
  911|  3.97k|    case 0xD2:
  ------------------
  |  Branch (911:5): [True: 795, False: 34.4k]
  ------------------
  912|  4.98k|    case 0xD3:
  ------------------
  |  Branch (912:5): [True: 1.00k, False: 34.2k]
  ------------------
  913|  6.02k|    case 0xD4:
  ------------------
  |  Branch (913:5): [True: 1.04k, False: 34.2k]
  ------------------
  914|  7.20k|    case 0xD5:
  ------------------
  |  Branch (914:5): [True: 1.18k, False: 34.0k]
  ------------------
  915|  8.73k|    case 0xD6:
  ------------------
  |  Branch (915:5): [True: 1.52k, False: 33.7k]
  ------------------
  916|  9.69k|    case 0xD7:
  ------------------
  |  Branch (916:5): [True: 958, False: 34.3k]
  ------------------
  917|  9.69k|      return to_status(EncodeRestart(marker, state));
  918|       |
  919|    327|    case 0xD9:
  ------------------
  |  Branch (919:5): [True: 327, False: 34.9k]
  ------------------
  920|    327|      return to_status(EncodeEOI(jpg, state));
  921|       |
  922|  5.37k|    case 0xDA:
  ------------------
  |  Branch (922:5): [True: 5.37k, False: 29.8k]
  ------------------
  923|  5.37k|      return EncodeScan(jpg, parsing_state, state);
  924|       |
  925|    175|    case 0xDB:
  ------------------
  |  Branch (925:5): [True: 175, False: 35.0k]
  ------------------
  926|    175|      return to_status(EncodeDQT(jpg, state));
  927|       |
  928|  1.94k|    case 0xDD:
  ------------------
  |  Branch (928:5): [True: 1.94k, False: 33.3k]
  ------------------
  929|  1.94k|      return to_status(EncodeDRI(jpg, state));
  930|       |
  931|     28|    case 0xE0:
  ------------------
  |  Branch (931:5): [True: 28, False: 35.2k]
  ------------------
  932|     40|    case 0xE1:
  ------------------
  |  Branch (932:5): [True: 12, False: 35.2k]
  ------------------
  933|     47|    case 0xE2:
  ------------------
  |  Branch (933:5): [True: 7, False: 35.2k]
  ------------------
  934|     57|    case 0xE3:
  ------------------
  |  Branch (934:5): [True: 10, False: 35.2k]
  ------------------
  935|     69|    case 0xE4:
  ------------------
  |  Branch (935:5): [True: 12, False: 35.2k]
  ------------------
  936|     81|    case 0xE5:
  ------------------
  |  Branch (936:5): [True: 12, False: 35.2k]
  ------------------
  937|    105|    case 0xE6:
  ------------------
  |  Branch (937:5): [True: 24, False: 35.2k]
  ------------------
  938|    124|    case 0xE7:
  ------------------
  |  Branch (938:5): [True: 19, False: 35.2k]
  ------------------
  939|    138|    case 0xE8:
  ------------------
  |  Branch (939:5): [True: 14, False: 35.2k]
  ------------------
  940|    150|    case 0xE9:
  ------------------
  |  Branch (940:5): [True: 12, False: 35.2k]
  ------------------
  941|    159|    case 0xEA:
  ------------------
  |  Branch (941:5): [True: 9, False: 35.2k]
  ------------------
  942|    173|    case 0xEB:
  ------------------
  |  Branch (942:5): [True: 14, False: 35.2k]
  ------------------
  943|    191|    case 0xEC:
  ------------------
  |  Branch (943:5): [True: 18, False: 35.2k]
  ------------------
  944|    201|    case 0xED:
  ------------------
  |  Branch (944:5): [True: 10, False: 35.2k]
  ------------------
  945|    213|    case 0xEE:
  ------------------
  |  Branch (945:5): [True: 12, False: 35.2k]
  ------------------
  946|    226|    case 0xEF:
  ------------------
  |  Branch (946:5): [True: 13, False: 35.2k]
  ------------------
  947|    226|      return to_status(EncodeAPP(jpg, marker, state));
  948|       |
  949|      5|    case 0xFE:
  ------------------
  |  Branch (949:5): [True: 5, False: 35.2k]
  ------------------
  950|      5|      return to_status(EncodeCOM(jpg, state));
  951|       |
  952|     23|    case 0xFF:
  ------------------
  |  Branch (952:5): [True: 23, False: 35.2k]
  ------------------
  953|     23|      return to_status(EncodeInterMarkerData(jpg, state));
  954|       |
  955|    157|    default:
  ------------------
  |  Branch (955:5): [True: 157, False: 35.1k]
  ------------------
  956|    157|      return SerializationStatus::ERROR;
  957|  35.2k|  }
  958|  35.2k|}
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_116SerializeSectionEhRKNS_8internal3dec5StateEPNS2_18SerializationStateERKNS_8JPEGDataEENK3$_0clEb:
  894|  29.7k|  const auto to_status = [](bool result) {
  895|  29.7k|    return result ? SerializationStatus::DONE : SerializationStatus::ERROR;
  ------------------
  |  Branch (895:12): [True: 29.5k, False: 223]
  ------------------
  896|  29.7k|  };
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeSOFERKNS_8JPEGDataEhPNS_8internal3dec18SerializationStateE:
  319|  12.3k|bool EncodeSOF(const JPEGData& jpg, uint8_t marker, SerializationState* state) {
  320|  12.3k|  if (marker <= 0xC2) state->is_progressive = (marker == 0xC2);
  ------------------
  |  Branch (320:7): [True: 9.64k, False: 2.67k]
  ------------------
  321|       |
  322|  12.3k|  const size_t n_comps = jpg.components.size();
  323|  12.3k|  const size_t marker_len = 8 + 3 * n_comps;
  324|  12.3k|  state->output_queue.emplace_back(marker_len + 2);
  325|  12.3k|  uint8_t* data = state->output_queue.back().buffer->data();
  326|  12.3k|  size_t pos = 0;
  327|  12.3k|  data[pos++] = 0xFFu;
  328|  12.3k|  data[pos++] = marker;
  329|  12.3k|  data[pos++] = static_cast<uint8_t>(marker_len >> 8u);
  330|  12.3k|  data[pos++] = static_cast<uint8_t>(marker_len);
  331|  12.3k|  data[pos++] = kJpegPrecision;
  332|  12.3k|  data[pos++] = jpg.height >> 8u;
  333|  12.3k|  data[pos++] = jpg.height & 0xFFu;
  334|  12.3k|  data[pos++] = jpg.width >> 8u;
  335|  12.3k|  data[pos++] = jpg.width & 0xFFu;
  336|  12.3k|  data[pos++] = static_cast<uint8_t>(n_comps);
  337|  24.7k|  for (size_t i = 0; i < n_comps; ++i) {
  ------------------
  |  Branch (337:22): [True: 12.3k, False: 12.3k]
  ------------------
  338|  12.3k|    data[pos++] = jpg.components[i].id;
  339|  12.3k|    data[pos++] = ((jpg.components[i].h_samp_factor << 4u) |
  340|  12.3k|                   (jpg.components[i].v_samp_factor));
  341|  12.3k|    const size_t quant_idx = jpg.components[i].quant_idx;
  342|  12.3k|    if (quant_idx >= jpg.quant.size()) return false;
  ------------------
  |  Branch (342:9): [True: 0, False: 12.3k]
  ------------------
  343|  12.3k|    data[pos++] = jpg.quant[quant_idx].index;
  344|  12.3k|  }
  345|  12.3k|  return true;
  346|  12.3k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeDHTERKNS_8JPEGDataEPNS_8internal3dec18SerializationStateE:
  372|  5.03k|bool EncodeDHT(const JPEGData& jpg, SerializationState* state) {
  373|  5.03k|  const std::vector<JPEGHuffmanCode>& huffman_code = jpg.huffman_code;
  374|       |
  375|  5.03k|  size_t marker_len = 2;
  376|  13.1k|  for (size_t i = state->dht_index; i < huffman_code.size(); ++i) {
  ------------------
  |  Branch (376:37): [True: 13.1k, False: 0]
  ------------------
  377|  13.1k|    const JPEGHuffmanCode& huff = huffman_code[i];
  378|  13.1k|    marker_len += kJpegHuffmanMaxBitLength;
  379|   236k|    for (size_t j = 0; j < huff.counts.size(); ++j) {
  ------------------
  |  Branch (379:24): [True: 223k, False: 13.1k]
  ------------------
  380|   223k|      marker_len += huff.counts[j];
  381|   223k|    }
  382|  13.1k|    if (huff.is_last) break;
  ------------------
  |  Branch (382:9): [True: 5.03k, False: 8.08k]
  ------------------
  383|  13.1k|  }
  384|  5.03k|  state->output_queue.emplace_back(marker_len + 2);
  385|  5.03k|  uint8_t* data = state->output_queue.back().buffer->data();
  386|  5.03k|  size_t pos = 0;
  387|  5.03k|  data[pos++] = 0xFFu;
  388|  5.03k|  data[pos++] = 0xC4u;
  389|  5.03k|  data[pos++] = static_cast<uint8_t>(marker_len >> 8u);
  390|  5.03k|  data[pos++] = static_cast<uint8_t>(marker_len);
  391|  13.1k|  while (true) {
  ------------------
  |  Branch (391:10): [True: 13.1k, Folded]
  ------------------
  392|  13.1k|    const size_t huffman_code_index = state->dht_index++;
  393|  13.1k|    if (huffman_code_index >= huffman_code.size()) {
  ------------------
  |  Branch (393:9): [True: 0, False: 13.1k]
  ------------------
  394|      0|      return false;
  395|      0|    }
  396|  13.1k|    const JPEGHuffmanCode& huff = huffman_code[huffman_code_index];
  397|  13.1k|    size_t index = huff.slot_id;
  398|  13.1k|    HuffmanCodeTable* huff_table;
  399|  13.1k|    if (index & 0x10) {
  ------------------
  |  Branch (399:9): [True: 7.40k, False: 5.71k]
  ------------------
  400|  7.40k|      index -= 0x10;
  401|  7.40k|      huff_table = &state->ac_huff_table[index];
  402|  7.40k|    } else {
  403|  5.71k|      huff_table = &state->dc_huff_table[index];
  404|  5.71k|    }
  405|       |    // TODO(eustas): cache
  406|       |    // TODO(eustas): set up non-existing symbols
  407|  13.1k|    if (!BuildHuffmanCodeTable(huff, huff_table)) {
  ------------------
  |  Branch (407:9): [True: 0, False: 13.1k]
  ------------------
  408|      0|      return false;
  409|      0|    }
  410|  13.1k|    size_t total_count = 0;
  411|  13.1k|    size_t max_length = 0;
  412|   236k|    for (size_t i = 0; i < huff.counts.size(); ++i) {
  ------------------
  |  Branch (412:24): [True: 223k, False: 13.1k]
  ------------------
  413|   223k|      if (huff.counts[i] != 0) {
  ------------------
  |  Branch (413:11): [True: 112k, False: 110k]
  ------------------
  414|   112k|        max_length = i;
  415|   112k|      }
  416|   223k|      total_count += huff.counts[i];
  417|   223k|    }
  418|  13.1k|    --total_count;
  419|  13.1k|    data[pos++] = huff.slot_id;
  420|   223k|    for (size_t i = 1; i <= kJpegHuffmanMaxBitLength; ++i) {
  ------------------
  |  Branch (420:24): [True: 209k, False: 13.1k]
  ------------------
  421|   209k|      data[pos++] = (i == max_length ? huff.counts[i] - 1 : huff.counts[i]);
  ------------------
  |  Branch (421:22): [True: 13.1k, False: 196k]
  ------------------
  422|   209k|    }
  423|   982k|    for (size_t i = 0; i < total_count; ++i) {
  ------------------
  |  Branch (423:24): [True: 969k, False: 13.1k]
  ------------------
  424|   969k|      data[pos++] = huff.values[i];
  425|   969k|    }
  426|  13.1k|    if (huff.is_last) break;
  ------------------
  |  Branch (426:9): [True: 5.03k, False: 8.08k]
  ------------------
  427|  13.1k|  }
  428|  5.03k|  return true;
  429|  5.03k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_121BuildHuffmanCodeTableERKNS_15JPEGHuffmanCodeEPNS_16HuffmanCodeTableE:
  268|  13.1k|                           HuffmanCodeTable* table) {
  269|  13.1k|  int huff_code[kJpegHuffmanAlphabetSize];
  270|       |  // +1 for a sentinel element.
  271|  13.1k|  uint32_t huff_size[kJpegHuffmanAlphabetSize + 1];
  272|  13.1k|  int p = 0;
  273|   223k|  for (size_t l = 1; l <= kJpegHuffmanMaxBitLength; ++l) {
  ------------------
  |  Branch (273:22): [True: 209k, False: 13.1k]
  ------------------
  274|   209k|    int i = huff.counts[l];
  275|   209k|    if (p + i > kJpegHuffmanAlphabetSize + 1) {
  ------------------
  |  Branch (275:9): [True: 0, False: 209k]
  ------------------
  276|      0|      return false;
  277|      0|    }
  278|  1.19M|    while (i--) huff_size[p++] = static_cast<uint32_t>(l);
  ------------------
  |  Branch (278:12): [True: 982k, False: 209k]
  ------------------
  279|   209k|  }
  280|       |
  281|  13.1k|  if (p == 0) {
  ------------------
  |  Branch (281:7): [True: 0, False: 13.1k]
  ------------------
  282|      0|    return true;
  283|      0|  }
  284|       |
  285|       |  // Reuse sentinel element.
  286|  13.1k|  int last_p = p - 1;
  287|  13.1k|  huff_size[last_p] = 0;
  288|       |
  289|  13.1k|  int code = 0;
  290|  13.1k|  uint32_t si = huff_size[0];
  291|  13.1k|  p = 0;
  292|   135k|  while (huff_size[p]) {
  ------------------
  |  Branch (292:10): [True: 122k, False: 13.1k]
  ------------------
  293|  1.09M|    while ((huff_size[p]) == si) {
  ------------------
  |  Branch (293:12): [True: 969k, False: 122k]
  ------------------
  294|   969k|      huff_code[p++] = code;
  295|   969k|      code++;
  296|   969k|    }
  297|   122k|    code <<= 1;
  298|   122k|    si++;
  299|   122k|  }
  300|   982k|  for (p = 0; p < last_p; p++) {
  ------------------
  |  Branch (300:15): [True: 969k, False: 13.1k]
  ------------------
  301|   969k|    int i = huff.values[p];
  302|   969k|    table->depth[i] = huff_size[p];
  303|   969k|    table->code[i] = huff_code[p];
  304|   969k|  }
  305|  13.1k|  return true;
  306|  13.1k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_113EncodeRestartEhPNS_8internal3dec18SerializationStateE:
  477|  9.69k|bool EncodeRestart(uint8_t marker, SerializationState* state) {
  478|  9.69k|  state->output_queue.push_back(OutputChunk({0xFF, marker}));
  479|  9.69k|  return true;
  480|  9.69k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeEOIERKNS_8JPEGDataEPNS_8internal3dec18SerializationStateE:
  313|    327|bool EncodeEOI(const JPEGData& jpg, SerializationState* state) {
  314|    327|  state->output_queue.push_back(OutputChunk({0xFF, 0xD9}));
  315|    327|  state->output_queue.emplace_back(jpg.tail_data);
  316|    327|  return true;
  317|    327|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_110EncodeScanERKNS_8JPEGDataERKNS_8internal3dec5StateEPNS5_18SerializationStateE:
  873|  5.37k|           SerializationState* state) {
  874|  5.37k|  const JPEGScanInfo& scan_info = jpg.scan_info[state->scan_index];
  875|  5.37k|  const bool is_progressive = state->is_progressive;
  876|  5.37k|  const int Al = is_progressive ? scan_info.Al : 0;
  ------------------
  |  Branch (876:18): [True: 4.59k, False: 782]
  ------------------
  877|  5.37k|  const int Ah = is_progressive ? scan_info.Ah : 0;
  ------------------
  |  Branch (877:18): [True: 4.59k, False: 782]
  ------------------
  878|  5.37k|  const int Ss = is_progressive ? scan_info.Ss : 0;
  ------------------
  |  Branch (878:18): [True: 4.59k, False: 782]
  ------------------
  879|  5.37k|  const int Se = is_progressive ? scan_info.Se : 63;
  ------------------
  |  Branch (879:18): [True: 4.59k, False: 782]
  ------------------
  880|  5.37k|  const bool need_sequential =
  881|  5.37k|      !is_progressive || (Ah == 0 && Al == 0 && Ss == 0 && Se == 63);
  ------------------
  |  Branch (881:7): [True: 782, False: 4.59k]
  |  Branch (881:27): [True: 1.67k, False: 2.92k]
  |  Branch (881:38): [True: 852, False: 818]
  |  Branch (881:49): [True: 349, False: 503]
  |  Branch (881:60): [True: 25, False: 324]
  ------------------
  882|  5.37k|  if (need_sequential) {
  ------------------
  |  Branch (882:7): [True: 807, False: 4.56k]
  ------------------
  883|    807|    return DoEncodeScan<0>(jpg, parsing_state, state);
  884|  4.56k|  } else if (Ah == 0) {
  ------------------
  |  Branch (884:14): [True: 1.64k, False: 2.92k]
  ------------------
  885|  1.64k|    return DoEncodeScan<1>(jpg, parsing_state, state);
  886|  2.92k|  } else {
  887|  2.92k|    return DoEncodeScan<2>(jpg, parsing_state, state);
  888|  2.92k|  }
  889|  5.37k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_112DoEncodeScanILi0EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateE:
  715|    807|                                                  SerializationState* state) {
  716|    807|  const JPEGScanInfo& scan_info = jpg.scan_info[state->scan_index];
  717|    807|  EncodeScanState& ss = state->scan_state;
  718|       |
  719|    807|  const int restart_interval =
  720|    807|      state->seen_dri_marker ? jpg.restart_interval : 0;
  ------------------
  |  Branch (720:7): [True: 180, False: 627]
  ------------------
  721|       |
  722|    807|  const auto get_next_extra_zero_run_index = [&ss, &scan_info]() -> int {
  723|    807|    if (ss.extra_zero_runs_pos < scan_info.extra_zero_runs.size()) {
  724|    807|      return scan_info.extra_zero_runs[ss.extra_zero_runs_pos].block_idx;
  725|    807|    } else {
  726|    807|      return -1;
  727|    807|    }
  728|    807|  };
  729|       |
  730|    807|  const auto get_next_reset_point = [&ss, &scan_info]() -> int {
  731|    807|    if (ss.next_reset_point_pos < scan_info.reset_points.size()) {
  732|    807|      return scan_info.reset_points[ss.next_reset_point_pos++];
  733|    807|    } else {
  734|    807|      return -1;
  735|    807|    }
  736|    807|  };
  737|       |
  738|    807|  if (ss.stage == EncodeScanState::HEAD) {
  ------------------
  |  Branch (738:7): [True: 807, False: 0]
  ------------------
  739|    807|    if (!EncodeSOS(jpg, scan_info, state)) return SerializationStatus::ERROR;
  ------------------
  |  Branch (739:9): [True: 36, False: 771]
  ------------------
  740|    771|    BitWriterInit(&ss.bw, &state->output_queue);
  741|    771|    DCTCodingStateInit(&ss.coding_state);
  742|    771|    ss.restarts_to_go = restart_interval;
  743|    771|    ss.next_restart_marker = 0;
  744|    771|    ss.block_scan_index = 0;
  745|    771|    ss.extra_zero_runs_pos = 0;
  746|    771|    ss.next_extra_zero_run_index = get_next_extra_zero_run_index();
  747|    771|    ss.next_reset_point_pos = 0;
  748|    771|    ss.next_reset_point = get_next_reset_point();
  749|    771|    ss.mcu_y = 0;
  750|    771|    memset(ss.last_dc_coeff, 0, sizeof(ss.last_dc_coeff));
  751|    771|    ss.stage = EncodeScanState::BODY;
  752|    771|  }
  753|    771|  BitWriter* bw = &ss.bw;
  754|    771|  DCTCodingState* coding_state = &ss.coding_state;
  755|       |
  756|    771|  BRUNSLI_DCHECK(ss.stage == EncodeScanState::BODY);
  757|       |
  758|       |  // "Non-interleaved" means color data comes in separate scans, in other words
  759|       |  // each scan can contain only one color component.
  760|    771|  const bool is_interleaved = (scan_info.num_components > 1);
  761|    771|  const JPEGComponent& base_component =
  762|    771|      jpg.components[scan_info.components[0].comp_idx];
  763|       |  // h_group / v_group act as numerators for converting number of blocks to
  764|       |  // number of MCU. In interleaved mode it is 1, so MCU is represented with
  765|       |  // max_*_samp_factor blocks. In non-interleaved mode we choose numerator to
  766|       |  // be the samping factor, consequently MCU is always represented with single
  767|       |  // block.
  768|    771|  const int h_group = is_interleaved ? 1 : base_component.h_samp_factor;
  ------------------
  |  Branch (768:23): [True: 430, False: 341]
  ------------------
  769|    771|  const int v_group = is_interleaved ? 1 : base_component.v_samp_factor;
  ------------------
  |  Branch (769:23): [True: 430, False: 341]
  ------------------
  770|    771|  const int MCUs_per_row =
  771|    771|      DivCeil(jpg.width * h_group, 8 * jpg.max_h_samp_factor);
  772|    771|  const int MCU_rows = DivCeil(jpg.height * v_group, 8 * jpg.max_v_samp_factor);
  773|    771|  const bool is_progressive = state->is_progressive;
  774|    771|  const int Al = is_progressive ? scan_info.Al : 0;
  ------------------
  |  Branch (774:18): [True: 24, False: 747]
  ------------------
  775|    771|  const int Ss = is_progressive ? scan_info.Ss : 0;
  ------------------
  |  Branch (775:18): [True: 24, False: 747]
  ------------------
  776|    771|  const int Se = is_progressive ? scan_info.Se : 63;
  ------------------
  |  Branch (776:18): [True: 24, False: 747]
  ------------------
  777|       |
  778|       |  // DC-only is defined by [0..0] spectral range.
  779|    771|  const bool want_ac = ((Ss != 0) || (Se != 0));
  ------------------
  |  Branch (779:25): [True: 0, False: 771]
  |  Branch (779:38): [True: 771, False: 0]
  ------------------
  780|    771|  const bool complete_ac = (parsing_state.stage == Stage::DONE);
  781|    771|  const bool has_ac =
  782|    771|      complete_ac || HasSection(&parsing_state, kBrunsliACDataTag);
  ------------------
  |  Branch (782:7): [True: 771, False: 0]
  |  Branch (782:22): [True: 0, False: 0]
  ------------------
  783|    771|  if (want_ac && !has_ac) return SerializationStatus::NEEDS_MORE_INPUT;
  ------------------
  |  Branch (783:7): [True: 771, False: 0]
  |  Branch (783:18): [True: 0, False: 771]
  ------------------
  784|       |
  785|       |  // |has_ac| implies |complete_dc| but not vice versa; for the sake of
  786|       |  // simplicity we pretend they are equal, because they are separated by just a
  787|       |  // few bytes of input.
  788|    771|  const bool complete_dc = has_ac;
  789|    771|  const bool complete = want_ac ? complete_ac : complete_dc;
  ------------------
  |  Branch (789:25): [True: 771, False: 0]
  ------------------
  790|       |  // When "incomplete" |ac_dc| tracks information about current ("incomplete")
  791|       |  // band parsing progress.
  792|    771|  const int last_mcu_y =
  793|    771|      complete ? MCU_rows : parsing_state.internal->ac_dc.next_mcu_y * v_group;
  ------------------
  |  Branch (793:7): [True: 771, False: 0]
  ------------------
  794|       |
  795|  58.3k|  for (; ss.mcu_y < last_mcu_y; ++ss.mcu_y) {
  ------------------
  |  Branch (795:10): [True: 57.6k, False: 763]
  ------------------
  796|   441k|    for (int mcu_x = 0; mcu_x < MCUs_per_row; ++mcu_x) {
  ------------------
  |  Branch (796:25): [True: 384k, False: 57.6k]
  ------------------
  797|       |      // Possibly emit a restart marker.
  798|   384k|      if (restart_interval > 0 && ss.restarts_to_go == 0) {
  ------------------
  |  Branch (798:11): [True: 348k, False: 35.1k]
  |  Branch (798:35): [True: 31.8k, False: 317k]
  ------------------
  799|  31.8k|        Flush(coding_state, bw);
  800|  31.8k|        if (!JumpToByteBoundary(bw, &state->pad_bits, state->pad_bits_end)) {
  ------------------
  |  Branch (800:13): [True: 8, False: 31.8k]
  ------------------
  801|      8|          return SerializationStatus::ERROR;
  802|      8|        }
  803|  31.8k|        EmitMarker(bw, 0xD0 + ss.next_restart_marker);
  804|  31.8k|        ss.next_restart_marker += 1;
  805|  31.8k|        ss.next_restart_marker &= 0x7;
  806|  31.8k|        ss.restarts_to_go = restart_interval;
  807|  31.8k|        memset(ss.last_dc_coeff, 0, sizeof(ss.last_dc_coeff));
  808|  31.8k|      }
  809|       |      // Encode one MCU
  810|  1.05M|      for (size_t i = 0; i < scan_info.num_components; ++i) {
  ------------------
  |  Branch (810:26): [True: 674k, False: 383k]
  ------------------
  811|   674k|        const JPEGComponentScanInfo& si = scan_info.components[i];
  812|   674k|        const JPEGComponent& c = jpg.components[si.comp_idx];
  813|   674k|        const HuffmanCodeTable& dc_huff = state->dc_huff_table[si.dc_tbl_idx];
  814|   674k|        const HuffmanCodeTable& ac_huff = state->ac_huff_table[si.ac_tbl_idx];
  815|   674k|        int n_blocks_y = is_interleaved ? c.v_samp_factor : 1;
  ------------------
  |  Branch (815:26): [True: 389k, False: 285k]
  ------------------
  816|   674k|        int n_blocks_x = is_interleaved ? c.h_samp_factor : 1;
  ------------------
  |  Branch (816:26): [True: 389k, False: 285k]
  ------------------
  817|  2.51M|        for (int iy = 0; iy < n_blocks_y; ++iy) {
  ------------------
  |  Branch (817:26): [True: 1.84M, False: 674k]
  ------------------
  818|  5.86M|          for (int ix = 0; ix < n_blocks_x; ++ix) {
  ------------------
  |  Branch (818:28): [True: 4.02M, False: 1.84M]
  ------------------
  819|  4.02M|            int block_y = ss.mcu_y * n_blocks_y + iy;
  820|  4.02M|            int block_x = mcu_x * n_blocks_x + ix;
  821|  4.02M|            int block_idx = block_y * c.width_in_blocks + block_x;
  822|  4.02M|            if (ss.block_scan_index == ss.next_reset_point) {
  ------------------
  |  Branch (822:17): [True: 751, False: 4.02M]
  ------------------
  823|    751|              Flush(coding_state, bw);
  824|    751|              ss.next_reset_point = get_next_reset_point();
  825|    751|            }
  826|  4.02M|            int num_zero_runs = 0;
  827|  4.02M|            if (ss.block_scan_index == ss.next_extra_zero_run_index) {
  ------------------
  |  Branch (827:17): [True: 1.17k, False: 4.02M]
  ------------------
  828|  1.17k|              num_zero_runs = scan_info.extra_zero_runs[ss.extra_zero_runs_pos]
  829|  1.17k|                                  .num_extra_zero_runs;
  830|  1.17k|              ++ss.extra_zero_runs_pos;
  831|  1.17k|              ss.next_extra_zero_run_index = get_next_extra_zero_run_index();
  832|  1.17k|            }
  833|  4.02M|            const coeff_t* coeffs = &c.coeffs[block_idx << 6];
  834|  4.02M|            bool ok;
  835|  4.02M|            if (kMode == 0) {
  ------------------
  |  Branch (835:17): [True: 4.02M, Folded]
  ------------------
  836|  4.02M|              ok = EncodeDCTBlockSequential(coeffs, dc_huff, ac_huff,
  837|  4.02M|                                            num_zero_runs,
  838|  4.02M|                                            ss.last_dc_coeff + si.comp_idx, bw);
  839|  4.02M|            } else if (kMode == 1) {
  ------------------
  |  Branch (839:24): [Folded, False: 0]
  ------------------
  840|      0|              ok = EncodeDCTBlockProgressive(
  841|      0|                  coeffs, dc_huff, ac_huff, Ss, Se, Al, num_zero_runs,
  842|      0|                  coding_state, ss.last_dc_coeff + si.comp_idx, bw);
  843|      0|            } else {
  844|      0|              ok = EncodeRefinementBits(coeffs, ac_huff, Ss, Se, Al,
  845|      0|                                        coding_state, bw);
  846|      0|            }
  847|  4.02M|            if (!ok) return SerializationStatus::ERROR;
  ------------------
  |  Branch (847:17): [True: 0, False: 4.02M]
  ------------------
  848|  4.02M|            ++ss.block_scan_index;
  849|  4.02M|          }
  850|  1.84M|        }
  851|   674k|      }
  852|   383k|      --ss.restarts_to_go;
  853|   383k|    }
  854|  57.6k|  }
  855|    763|  if (ss.mcu_y < MCU_rows) {
  ------------------
  |  Branch (855:7): [True: 0, False: 763]
  ------------------
  856|      0|    if (!bw->healthy) return SerializationStatus::ERROR;
  ------------------
  |  Branch (856:9): [True: 0, False: 0]
  ------------------
  857|      0|    return SerializationStatus::NEEDS_MORE_INPUT;
  858|      0|  }
  859|    763|  Flush(coding_state, bw);
  860|    763|  if (!JumpToByteBoundary(bw, &state->pad_bits, state->pad_bits_end)) {
  ------------------
  |  Branch (860:7): [True: 5, False: 758]
  ------------------
  861|      5|    return SerializationStatus::ERROR;
  862|      5|  }
  863|    758|  BitWriterFinish(bw);
  864|    758|  ss.stage = EncodeScanState::HEAD;
  865|    758|  state->scan_index++;
  866|    758|  if (!bw->healthy) return SerializationStatus::ERROR;
  ------------------
  |  Branch (866:7): [True: 582, False: 176]
  ------------------
  867|       |
  868|    176|  return SerializationStatus::DONE;
  869|    758|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeSOSERKNS_8JPEGDataERKNS_12JPEGScanInfoEPNS_8internal3dec18SerializationStateE:
  349|  5.37k|               SerializationState* state) {
  350|  5.37k|  const size_t n_scans = scan_info.num_components;
  351|  5.37k|  const size_t marker_len = 6 + 2 * n_scans;
  352|  5.37k|  state->output_queue.emplace_back(marker_len + 2);
  353|  5.37k|  uint8_t* data = state->output_queue.back().buffer->data();
  354|  5.37k|  size_t pos = 0;
  355|  5.37k|  data[pos++] = 0xFFu;
  356|  5.37k|  data[pos++] = 0xDAu;
  357|  5.37k|  data[pos++] = static_cast<uint8_t>(marker_len >> 8u);
  358|  5.37k|  data[pos++] = static_cast<uint8_t>(marker_len);
  359|  5.37k|  data[pos++] = static_cast<uint8_t>(n_scans);
  360|  19.3k|  for (size_t i = 0; i < n_scans; ++i) {
  ------------------
  |  Branch (360:22): [True: 14.0k, False: 5.22k]
  ------------------
  361|  14.0k|    const JPEGComponentScanInfo& si = scan_info.components[i];
  362|  14.0k|    if (si.comp_idx >= jpg.components.size()) return false;
  ------------------
  |  Branch (362:9): [True: 143, False: 13.9k]
  ------------------
  363|  13.9k|    data[pos++] = jpg.components[si.comp_idx].id;
  364|  13.9k|    data[pos++] = (si.dc_tbl_idx << 4u) + si.ac_tbl_idx;
  365|  13.9k|  }
  366|  5.22k|  data[pos++] = scan_info.Ss;
  367|  5.22k|  data[pos++] = scan_info.Se;
  368|  5.22k|  data[pos++] = ((scan_info.Ah << 4u) | (scan_info.Al));
  369|  5.22k|  return true;
  370|  5.37k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_113BitWriterInitEPNS_8internal3dec9BitWriterEPNSt3__15dequeINS2_11OutputChunkENS5_9allocatorIS7_EEEE:
   54|  5.22k|void BitWriterInit(BitWriter* bw, std::deque<OutputChunk>* output_queue) {
   55|  5.22k|  bw->output = output_queue;
   56|  5.22k|  bw->chunk = OutputChunk(kBitWriterChunkSize);
   57|  5.22k|  bw->pos = 0;
   58|  5.22k|  bw->put_buffer = 0;
   59|  5.22k|  bw->put_bits = 64;
   60|  5.22k|  bw->healthy = true;
   61|  5.22k|  bw->data = bw->chunk.buffer->data();
   62|  5.22k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_118DCTCodingStateInitEPNS_8internal3dec14DCTCodingStateE:
  187|  5.22k|void DCTCodingStateInit(DCTCodingState* s) {
  188|  5.22k|  s->eob_run_ = 0;
  189|  5.22k|  s->cur_ac_huff_ = nullptr;
  190|  5.22k|  s->refinement_bits_.clear();
  191|  5.22k|  s->refinement_bits_.reserve(64);  // 1024 bits most often is more than enough.
  192|  5.22k|  s->refinement_bits_count_ = 0;
  193|  5.22k|}
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_112DoEncodeScanILi0EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateEENKUlvE_clEv:
  722|  1.94k|  const auto get_next_extra_zero_run_index = [&ss, &scan_info]() -> int {
  723|  1.94k|    if (ss.extra_zero_runs_pos < scan_info.extra_zero_runs.size()) {
  ------------------
  |  Branch (723:9): [True: 1.17k, False: 767]
  ------------------
  724|  1.17k|      return scan_info.extra_zero_runs[ss.extra_zero_runs_pos].block_idx;
  725|  1.17k|    } else {
  726|    767|      return -1;
  727|    767|    }
  728|  1.94k|  };
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_112DoEncodeScanILi0EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateEENKUlvE0_clEv:
  730|  1.52k|  const auto get_next_reset_point = [&ss, &scan_info]() -> int {
  731|  1.52k|    if (ss.next_reset_point_pos < scan_info.reset_points.size()) {
  ------------------
  |  Branch (731:9): [True: 759, False: 763]
  ------------------
  732|    759|      return scan_info.reset_points[ss.next_reset_point_pos++];
  733|    763|    } else {
  734|    763|      return -1;
  735|    763|    }
  736|  1.52k|  };
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_17DivCeilEii:
   46|  10.4k|static BRUNSLI_INLINE int DivCeil(int a, int b) { return (a + b - 1) / b; }
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_15FlushEPNS_8internal3dec14DCTCodingStateEPNS2_9BitWriterE:
  197|  8.72M|static BRUNSLI_INLINE void Flush(DCTCodingState* s, BitWriter* bw) {
  198|  8.72M|  if (s->eob_run_ > 0) {
  ------------------
  |  Branch (198:7): [True: 8.28M, False: 436k]
  ------------------
  199|  8.28M|    int nbits = Log2FloorNonZero(s->eob_run_);
  200|  8.28M|    int symbol = nbits << 4u;
  201|  8.28M|    WriteBits(bw, s->cur_ac_huff_->depth[symbol],
  202|  8.28M|              s->cur_ac_huff_->code[symbol]);
  203|  8.28M|    if (nbits > 0) {
  ------------------
  |  Branch (203:9): [True: 35.9k, False: 8.25M]
  ------------------
  204|  35.9k|      WriteBits(bw, nbits, s->eob_run_ & ((1 << nbits) - 1));
  205|  35.9k|    }
  206|  8.28M|    s->eob_run_ = 0;
  207|  8.28M|  }
  208|  8.72M|  size_t num_words = s->refinement_bits_count_ >> 4;
  209|  8.75M|  for (size_t i = 0; i < num_words; ++i) {
  ------------------
  |  Branch (209:22): [True: 35.0k, False: 8.72M]
  ------------------
  210|  35.0k|    WriteBits(bw, 16, s->refinement_bits_[i]);
  211|  35.0k|  }
  212|  8.72M|  size_t tail = s->refinement_bits_count_ & 0xF;
  213|  8.72M|  if (tail) {
  ------------------
  |  Branch (213:7): [True: 45.1k, False: 8.67M]
  ------------------
  214|  45.1k|    WriteBits(bw, tail, s->refinement_bits_.back());
  215|  45.1k|  }
  216|  8.72M|  s->refinement_bits_.clear();
  217|  8.72M|  s->refinement_bits_count_ = 0;
  218|  8.72M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19WriteBitsEPNS_8internal3dec9BitWriterEim:
  119|  29.2M|static BRUNSLI_INLINE void WriteBits(BitWriter* bw, int nbits, uint64_t bits) {
  120|       |  // This is an optimization; if everything goes well,
  121|       |  // then |nbits| is positive; if non-existing Huffman symbol is going to be
  122|       |  // encoded, its length should be zero; later encoder could check the
  123|       |  // "health" of BitWriter.
  124|  29.2M|  if (nbits == 0) {
  ------------------
  |  Branch (124:7): [True: 3.38M, False: 25.9M]
  ------------------
  125|  3.38M|    bw->healthy = false;
  126|  3.38M|    return;
  127|  3.38M|  }
  128|  25.9M|  bw->put_bits -= nbits;
  129|  25.9M|  bw->put_buffer |= (bits << bw->put_bits);
  130|  25.9M|  if (bw->put_bits <= 16) DischargeBitBuffer(bw);
  ------------------
  |  Branch (130:7): [True: 2.43M, False: 23.4M]
  ------------------
  131|  25.9M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_118DischargeBitBufferEPNS_8internal3dec9BitWriterE:
   89|  2.43M|static BRUNSLI_INLINE void DischargeBitBuffer(BitWriter* bw) {
   90|       |  // At this point we are ready to emit the most significant 6 bytes of
   91|       |  // put_buffer_ to the output.
   92|       |  // The JPEG format requires that after every 0xff byte in the entropy
   93|       |  // coded section, there is a zero byte, therefore we first check if any of
   94|       |  // the 6 most significant bytes of put_buffer_ is 0xFF.
   95|  2.43M|  Reserve(bw, 12);
   96|  2.43M|  if (HasZeroByte(~bw->put_buffer | 0xFFFF)) {
  ------------------
  |  Branch (96:7): [True: 777k, False: 1.65M]
  ------------------
   97|       |    // We have a 0xFF byte somewhere, examine each byte and append a zero
   98|       |    // byte if necessary.
   99|   777k|    EmitByte(bw, (bw->put_buffer >> 56) & 0xFF);
  100|   777k|    EmitByte(bw, (bw->put_buffer >> 48) & 0xFF);
  101|   777k|    EmitByte(bw, (bw->put_buffer >> 40) & 0xFF);
  102|   777k|    EmitByte(bw, (bw->put_buffer >> 32) & 0xFF);
  103|   777k|    EmitByte(bw, (bw->put_buffer >> 24) & 0xFF);
  104|   777k|    EmitByte(bw, (bw->put_buffer >> 16) & 0xFF);
  105|  1.65M|  } else {
  106|       |    // We don't have any 0xFF bytes, output all 6 bytes without checking.
  107|  1.65M|    bw->data[bw->pos] = (bw->put_buffer >> 56) & 0xFF;
  108|  1.65M|    bw->data[bw->pos + 1] = (bw->put_buffer >> 48) & 0xFF;
  109|  1.65M|    bw->data[bw->pos + 2] = (bw->put_buffer >> 40) & 0xFF;
  110|  1.65M|    bw->data[bw->pos + 3] = (bw->put_buffer >> 32) & 0xFF;
  111|  1.65M|    bw->data[bw->pos + 4] = (bw->put_buffer >> 24) & 0xFF;
  112|  1.65M|    bw->data[bw->pos + 5] = (bw->put_buffer >> 16) & 0xFF;
  113|  1.65M|    bw->pos += 6;
  114|  1.65M|  }
  115|  2.43M|  bw->put_buffer <<= 48;
  116|  2.43M|  bw->put_bits += 48;
  117|  2.43M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_17ReserveEPNS_8internal3dec9BitWriterEm:
   72|  3.19M|static BRUNSLI_INLINE void Reserve(BitWriter* bw, size_t n_bytes) {
   73|  3.19M|  if (BRUNSLI_PREDICT_FALSE((bw->pos + n_bytes) > kBitWriterChunkSize)) {
  ------------------
  |  |   85|  3.19M|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 903, False: 3.19M]
  |  |  ------------------
  ------------------
   74|    903|    SwapBuffer(bw);
   75|    903|  }
   76|  3.19M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_110SwapBufferEPNS_8internal3dec9BitWriterE:
   64|    903|static BRUNSLI_NOINLINE void SwapBuffer(BitWriter* bw) {
   65|    903|  bw->chunk.len = bw->pos;
   66|    903|  bw->output->emplace_back(std::move(bw->chunk));
   67|    903|  bw->chunk = OutputChunk(kBitWriterChunkSize);
   68|    903|  bw->data = bw->chunk.buffer->data();
   69|    903|  bw->pos = 0;
   70|    903|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_111HasZeroByteEm:
   50|  2.43M|static BRUNSLI_INLINE uint64_t HasZeroByte(uint64_t x) {
   51|  2.43M|  return (x - 0x0101010101010101ULL) & ~x & 0x8080808080808080ULL;
   52|  2.43M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_18EmitByteEPNS_8internal3dec9BitWriterEi:
   84|  5.47M|static BRUNSLI_INLINE void EmitByte(BitWriter* bw, int byte) {
   85|  5.47M|  bw->data[bw->pos++] = byte;
   86|  5.47M|  if (byte == 0xFF) bw->data[bw->pos++] = 0;
  ------------------
  |  Branch (86:7): [True: 1.08M, False: 4.38M]
  ------------------
   87|  5.47M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_118JumpToByteBoundaryEPNS_8internal3dec9BitWriterEPPKiS6_:
  141|   383k|                        const int* pad_bits_end) {
  142|   383k|  size_t n_bits = bw->put_bits & 7u;
  143|   383k|  uint8_t pad_pattern;
  144|   383k|  if (*pad_bits == nullptr) {
  ------------------
  |  Branch (144:7): [True: 381k, False: 1.63k]
  ------------------
  145|   381k|    pad_pattern = (1u << n_bits) - 1;
  146|   381k|  } else {
  147|  1.63k|    pad_pattern = 0;
  148|  1.63k|    const int* src = *pad_bits;
  149|       |    // TODO(eustas): bitwise reading looks insanely ineffective...
  150|  5.02k|    while (n_bits--) {
  ------------------
  |  Branch (150:12): [True: 3.44k, False: 1.58k]
  ------------------
  151|  3.44k|      pad_pattern <<= 1;
  152|  3.44k|      if (src >= pad_bits_end) return false;
  ------------------
  |  Branch (152:11): [True: 51, False: 3.39k]
  ------------------
  153|       |      // TODO(eustas): DCHECK *src == {0, 1}
  154|  3.39k|      pad_pattern |= !!*(src++);
  155|  3.39k|    }
  156|  1.58k|    *pad_bits = src;
  157|  1.58k|  }
  158|       |
  159|   382k|  Reserve(bw, 16);
  160|       |
  161|   901k|  while (bw->put_bits <= 56) {
  ------------------
  |  Branch (161:10): [True: 518k, False: 382k]
  ------------------
  162|   518k|    int c = (bw->put_buffer >> 56) & 0xFF;
  163|   518k|    EmitByte(bw, c);
  164|   518k|    bw->put_buffer <<= 8;
  165|   518k|    bw->put_bits += 8;
  166|   518k|  }
  167|   382k|  if (bw->put_bits < 64) {
  ------------------
  |  Branch (167:7): [True: 295k, False: 87.6k]
  ------------------
  168|   295k|    int pad_mask = 0xFFu >> (64 - bw->put_bits);
  169|   295k|    int c = ((bw->put_buffer >> 56) & ~pad_mask) | pad_pattern;
  170|   295k|    EmitByte(bw, c);
  171|   295k|  }
  172|   382k|  bw->put_buffer = 0;
  173|   382k|  bw->put_bits = 64;
  174|       |
  175|   382k|  return true;
  176|   383k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_110EmitMarkerEPNS_8internal3dec9BitWriterEi:
  133|   377k|void EmitMarker(BitWriter* bw, int marker) {
  134|   377k|  Reserve(bw, 2);
  135|   377k|  BRUNSLI_DCHECK(marker != 0xFF);
  136|   377k|  bw->data[bw->pos++] = 0xFF;
  137|   377k|  bw->data[bw->pos++] = marker;
  138|   377k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_124EncodeDCTBlockSequentialEPKsRKNS_16HuffmanCodeTableES5_iPsPNS_8internal3dec9BitWriterE:
  517|  4.02M|                              BitWriter* bw) {
  518|  4.02M|  coeff_t temp2;
  519|  4.02M|  coeff_t temp;
  520|       |  // Assumption: absolute Quantized DC Range: -16384 to +16383.
  521|       |  // Consequence: delta DC Range: -32767 to +32767.
  522|       |  // Thus negation of a negative number will not overflow.
  523|  4.02M|  temp2 = coeffs[0];
  524|  4.02M|  if (!CheckDcRange(temp2)) return false;
  ------------------
  |  Branch (524:7): [True: 0, False: 4.02M]
  ------------------
  525|  4.02M|  temp = temp2 - *last_dc_coeff;
  526|  4.02M|  *last_dc_coeff = temp2;
  527|  4.02M|  temp2 = temp;
  528|  4.02M|  if (temp < 0) {
  ------------------
  |  Branch (528:7): [True: 1.08M, False: 2.93M]
  ------------------
  529|  1.08M|    temp = -temp;
  530|  1.08M|    temp2--;
  531|  1.08M|  }
  532|  4.02M|  int dc_nbits = (temp == 0) ? 0 : (Log2FloorNonZero(temp) + 1);
  ------------------
  |  Branch (532:18): [True: 2.05M, False: 1.97M]
  ------------------
  533|  4.02M|  WriteBits(bw, dc_huff.depth[dc_nbits], dc_huff.code[dc_nbits]);
  534|  4.02M|  if (dc_nbits > 0) {
  ------------------
  |  Branch (534:7): [True: 1.97M, False: 2.05M]
  ------------------
  535|  1.97M|    WriteBits(bw, dc_nbits, temp2 & ((1u << dc_nbits) - 1));
  536|  1.97M|  }
  537|  4.02M|  int r = 0;
  538|   257M|  for (int k = 1; k < 64; ++k) {
  ------------------
  |  Branch (538:19): [True: 253M, False: 4.02M]
  ------------------
  539|   253M|    temp = coeffs[kJPEGNaturalOrder[k]];
  540|   253M|    if (temp == 0) {
  ------------------
  |  Branch (540:9): [True: 253M, False: 48.1k]
  ------------------
  541|   253M|      r++;
  542|   253M|      continue;
  543|   253M|    }
  544|  48.1k|    BRUNSLI_DCHECK(std::abs(static_cast<int>(temp)) <= kBrunsliMaxCoeffAbsVal);
  545|  48.1k|    if (temp < 0) {
  ------------------
  |  Branch (545:9): [True: 29.2k, False: 18.8k]
  ------------------
  546|  29.2k|      temp = -temp;
  547|  29.2k|      temp2 = ~temp;
  548|  29.2k|    } else {
  549|  18.8k|      temp2 = temp;
  550|  18.8k|    }
  551|  82.0k|    while (r > 15) {
  ------------------
  |  Branch (551:12): [True: 33.9k, False: 48.1k]
  ------------------
  552|  33.9k|      WriteBits(bw, ac_huff.depth[0xf0], ac_huff.code[0xf0]);
  553|  33.9k|      r -= 16;
  554|  33.9k|    }
  555|  48.1k|    int ac_nbits = Log2FloorNonZero(temp) + 1;
  556|  48.1k|    int symbol = (r << 4u) + ac_nbits;
  557|  48.1k|    WriteBits(bw, ac_huff.depth[symbol], ac_huff.code[symbol]);
  558|  48.1k|    WriteBits(bw, ac_nbits, temp2 & ((1 << ac_nbits) - 1));
  559|  48.1k|    r = 0;
  560|  48.1k|  }
  561|  4.02M|  for (int i = 0; i < num_zero_runs; ++i) {
  ------------------
  |  Branch (561:19): [True: 3.34k, False: 4.02M]
  ------------------
  562|  3.34k|    WriteBits(bw, ac_huff.depth[0xf0], ac_huff.code[0xf0]);
  563|  3.34k|    r -= 16;
  564|  3.34k|  }
  565|  4.02M|  if (r > 0) {
  ------------------
  |  Branch (565:7): [True: 4.02M, False: 646]
  ------------------
  566|  4.02M|    WriteBits(bw, ac_huff.depth[0], ac_huff.code[0]);
  567|  4.02M|  }
  568|  4.02M|  return true;
  569|  4.02M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_112CheckDcRangeEs:
  508|  7.78M|bool CheckDcRange(coeff_t x) {
  509|       |  // Modern compilers are smart enough to make it a single branch.
  510|  7.78M|  return x >= -16384 && x <= 16383;
  ------------------
  |  Branch (510:10): [True: 7.78M, False: 0]
  |  Branch (510:25): [True: 7.78M, False: 0]
  ------------------
  511|  7.78M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_115BitWriterFinishEPNS_8internal3dec9BitWriterE:
  178|  5.17k|void BitWriterFinish(BitWriter* bw) {
  179|  5.17k|  if (bw->pos == 0) return;
  ------------------
  |  Branch (179:7): [True: 270, False: 4.90k]
  ------------------
  180|  4.90k|  bw->chunk.len = bw->pos;
  181|  4.90k|  bw->output->emplace_back(std::move(bw->chunk));
  182|  4.90k|  bw->chunk = OutputChunk(nullptr, 0);
  183|  4.90k|  bw->data = nullptr;
  184|  4.90k|  bw->pos = 0;
  185|  4.90k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_112DoEncodeScanILi1EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateE:
  715|  1.64k|                                                  SerializationState* state) {
  716|  1.64k|  const JPEGScanInfo& scan_info = jpg.scan_info[state->scan_index];
  717|  1.64k|  EncodeScanState& ss = state->scan_state;
  718|       |
  719|  1.64k|  const int restart_interval =
  720|  1.64k|      state->seen_dri_marker ? jpg.restart_interval : 0;
  ------------------
  |  Branch (720:7): [True: 383, False: 1.26k]
  ------------------
  721|       |
  722|  1.64k|  const auto get_next_extra_zero_run_index = [&ss, &scan_info]() -> int {
  723|  1.64k|    if (ss.extra_zero_runs_pos < scan_info.extra_zero_runs.size()) {
  724|  1.64k|      return scan_info.extra_zero_runs[ss.extra_zero_runs_pos].block_idx;
  725|  1.64k|    } else {
  726|  1.64k|      return -1;
  727|  1.64k|    }
  728|  1.64k|  };
  729|       |
  730|  1.64k|  const auto get_next_reset_point = [&ss, &scan_info]() -> int {
  731|  1.64k|    if (ss.next_reset_point_pos < scan_info.reset_points.size()) {
  732|  1.64k|      return scan_info.reset_points[ss.next_reset_point_pos++];
  733|  1.64k|    } else {
  734|  1.64k|      return -1;
  735|  1.64k|    }
  736|  1.64k|  };
  737|       |
  738|  1.64k|  if (ss.stage == EncodeScanState::HEAD) {
  ------------------
  |  Branch (738:7): [True: 1.64k, False: 0]
  ------------------
  739|  1.64k|    if (!EncodeSOS(jpg, scan_info, state)) return SerializationStatus::ERROR;
  ------------------
  |  Branch (739:9): [True: 22, False: 1.62k]
  ------------------
  740|  1.62k|    BitWriterInit(&ss.bw, &state->output_queue);
  741|  1.62k|    DCTCodingStateInit(&ss.coding_state);
  742|  1.62k|    ss.restarts_to_go = restart_interval;
  743|  1.62k|    ss.next_restart_marker = 0;
  744|  1.62k|    ss.block_scan_index = 0;
  745|  1.62k|    ss.extra_zero_runs_pos = 0;
  746|  1.62k|    ss.next_extra_zero_run_index = get_next_extra_zero_run_index();
  747|  1.62k|    ss.next_reset_point_pos = 0;
  748|  1.62k|    ss.next_reset_point = get_next_reset_point();
  749|  1.62k|    ss.mcu_y = 0;
  750|  1.62k|    memset(ss.last_dc_coeff, 0, sizeof(ss.last_dc_coeff));
  751|  1.62k|    ss.stage = EncodeScanState::BODY;
  752|  1.62k|  }
  753|  1.62k|  BitWriter* bw = &ss.bw;
  754|  1.62k|  DCTCodingState* coding_state = &ss.coding_state;
  755|       |
  756|  1.62k|  BRUNSLI_DCHECK(ss.stage == EncodeScanState::BODY);
  757|       |
  758|       |  // "Non-interleaved" means color data comes in separate scans, in other words
  759|       |  // each scan can contain only one color component.
  760|  1.62k|  const bool is_interleaved = (scan_info.num_components > 1);
  761|  1.62k|  const JPEGComponent& base_component =
  762|  1.62k|      jpg.components[scan_info.components[0].comp_idx];
  763|       |  // h_group / v_group act as numerators for converting number of blocks to
  764|       |  // number of MCU. In interleaved mode it is 1, so MCU is represented with
  765|       |  // max_*_samp_factor blocks. In non-interleaved mode we choose numerator to
  766|       |  // be the samping factor, consequently MCU is always represented with single
  767|       |  // block.
  768|  1.62k|  const int h_group = is_interleaved ? 1 : base_component.h_samp_factor;
  ------------------
  |  Branch (768:23): [True: 939, False: 684]
  ------------------
  769|  1.62k|  const int v_group = is_interleaved ? 1 : base_component.v_samp_factor;
  ------------------
  |  Branch (769:23): [True: 939, False: 684]
  ------------------
  770|  1.62k|  const int MCUs_per_row =
  771|  1.62k|      DivCeil(jpg.width * h_group, 8 * jpg.max_h_samp_factor);
  772|  1.62k|  const int MCU_rows = DivCeil(jpg.height * v_group, 8 * jpg.max_v_samp_factor);
  773|  1.62k|  const bool is_progressive = state->is_progressive;
  774|  1.62k|  const int Al = is_progressive ? scan_info.Al : 0;
  ------------------
  |  Branch (774:18): [True: 1.62k, False: 0]
  ------------------
  775|  1.62k|  const int Ss = is_progressive ? scan_info.Ss : 0;
  ------------------
  |  Branch (775:18): [True: 1.62k, False: 0]
  ------------------
  776|  1.62k|  const int Se = is_progressive ? scan_info.Se : 63;
  ------------------
  |  Branch (776:18): [True: 1.62k, False: 0]
  ------------------
  777|       |
  778|       |  // DC-only is defined by [0..0] spectral range.
  779|  1.62k|  const bool want_ac = ((Ss != 0) || (Se != 0));
  ------------------
  |  Branch (779:25): [True: 1.12k, False: 495]
  |  Branch (779:38): [True: 408, False: 87]
  ------------------
  780|  1.62k|  const bool complete_ac = (parsing_state.stage == Stage::DONE);
  781|  1.62k|  const bool has_ac =
  782|  1.62k|      complete_ac || HasSection(&parsing_state, kBrunsliACDataTag);
  ------------------
  |  Branch (782:7): [True: 1.62k, False: 0]
  |  Branch (782:22): [True: 0, False: 0]
  ------------------
  783|  1.62k|  if (want_ac && !has_ac) return SerializationStatus::NEEDS_MORE_INPUT;
  ------------------
  |  Branch (783:7): [True: 1.53k, False: 87]
  |  Branch (783:18): [True: 0, False: 1.53k]
  ------------------
  784|       |
  785|       |  // |has_ac| implies |complete_dc| but not vice versa; for the sake of
  786|       |  // simplicity we pretend they are equal, because they are separated by just a
  787|       |  // few bytes of input.
  788|  1.62k|  const bool complete_dc = has_ac;
  789|  1.62k|  const bool complete = want_ac ? complete_ac : complete_dc;
  ------------------
  |  Branch (789:25): [True: 1.53k, False: 87]
  ------------------
  790|       |  // When "incomplete" |ac_dc| tracks information about current ("incomplete")
  791|       |  // band parsing progress.
  792|  1.62k|  const int last_mcu_y =
  793|  1.62k|      complete ? MCU_rows : parsing_state.internal->ac_dc.next_mcu_y * v_group;
  ------------------
  |  Branch (793:7): [True: 1.62k, False: 0]
  ------------------
  794|       |
  795|  85.3k|  for (; ss.mcu_y < last_mcu_y; ++ss.mcu_y) {
  ------------------
  |  Branch (795:10): [True: 83.7k, False: 1.61k]
  ------------------
  796|   706k|    for (int mcu_x = 0; mcu_x < MCUs_per_row; ++mcu_x) {
  ------------------
  |  Branch (796:25): [True: 622k, False: 83.7k]
  ------------------
  797|       |      // Possibly emit a restart marker.
  798|   622k|      if (restart_interval > 0 && ss.restarts_to_go == 0) {
  ------------------
  |  Branch (798:11): [True: 505k, False: 116k]
  |  Branch (798:35): [True: 181k, False: 324k]
  ------------------
  799|   181k|        Flush(coding_state, bw);
  800|   181k|        if (!JumpToByteBoundary(bw, &state->pad_bits, state->pad_bits_end)) {
  ------------------
  |  Branch (800:13): [True: 5, False: 181k]
  ------------------
  801|      5|          return SerializationStatus::ERROR;
  802|      5|        }
  803|   181k|        EmitMarker(bw, 0xD0 + ss.next_restart_marker);
  804|   181k|        ss.next_restart_marker += 1;
  805|   181k|        ss.next_restart_marker &= 0x7;
  806|   181k|        ss.restarts_to_go = restart_interval;
  807|   181k|        memset(ss.last_dc_coeff, 0, sizeof(ss.last_dc_coeff));
  808|   181k|      }
  809|       |      // Encode one MCU
  810|  2.01M|      for (size_t i = 0; i < scan_info.num_components; ++i) {
  ------------------
  |  Branch (810:26): [True: 1.38M, False: 622k]
  ------------------
  811|  1.38M|        const JPEGComponentScanInfo& si = scan_info.components[i];
  812|  1.38M|        const JPEGComponent& c = jpg.components[si.comp_idx];
  813|  1.38M|        const HuffmanCodeTable& dc_huff = state->dc_huff_table[si.dc_tbl_idx];
  814|  1.38M|        const HuffmanCodeTable& ac_huff = state->ac_huff_table[si.ac_tbl_idx];
  815|  1.38M|        int n_blocks_y = is_interleaved ? c.v_samp_factor : 1;
  ------------------
  |  Branch (815:26): [True: 1.03M, False: 358k]
  ------------------
  816|  1.38M|        int n_blocks_x = is_interleaved ? c.h_samp_factor : 1;
  ------------------
  |  Branch (816:26): [True: 1.03M, False: 358k]
  ------------------
  817|  5.56M|        for (int iy = 0; iy < n_blocks_y; ++iy) {
  ------------------
  |  Branch (817:26): [True: 4.17M, False: 1.38M]
  ------------------
  818|  14.8M|          for (int ix = 0; ix < n_blocks_x; ++ix) {
  ------------------
  |  Branch (818:28): [True: 10.7M, False: 4.17M]
  ------------------
  819|  10.7M|            int block_y = ss.mcu_y * n_blocks_y + iy;
  820|  10.7M|            int block_x = mcu_x * n_blocks_x + ix;
  821|  10.7M|            int block_idx = block_y * c.width_in_blocks + block_x;
  822|  10.7M|            if (ss.block_scan_index == ss.next_reset_point) {
  ------------------
  |  Branch (822:17): [True: 5.54k, False: 10.7M]
  ------------------
  823|  5.54k|              Flush(coding_state, bw);
  824|  5.54k|              ss.next_reset_point = get_next_reset_point();
  825|  5.54k|            }
  826|  10.7M|            int num_zero_runs = 0;
  827|  10.7M|            if (ss.block_scan_index == ss.next_extra_zero_run_index) {
  ------------------
  |  Branch (827:17): [True: 4.67k, False: 10.7M]
  ------------------
  828|  4.67k|              num_zero_runs = scan_info.extra_zero_runs[ss.extra_zero_runs_pos]
  829|  4.67k|                                  .num_extra_zero_runs;
  830|  4.67k|              ++ss.extra_zero_runs_pos;
  831|  4.67k|              ss.next_extra_zero_run_index = get_next_extra_zero_run_index();
  832|  4.67k|            }
  833|  10.7M|            const coeff_t* coeffs = &c.coeffs[block_idx << 6];
  834|  10.7M|            bool ok;
  835|  10.7M|            if (kMode == 0) {
  ------------------
  |  Branch (835:17): [Folded, False: 10.7M]
  ------------------
  836|      0|              ok = EncodeDCTBlockSequential(coeffs, dc_huff, ac_huff,
  837|      0|                                            num_zero_runs,
  838|      0|                                            ss.last_dc_coeff + si.comp_idx, bw);
  839|  10.7M|            } else if (kMode == 1) {
  ------------------
  |  Branch (839:24): [True: 10.7M, Folded]
  ------------------
  840|  10.7M|              ok = EncodeDCTBlockProgressive(
  841|  10.7M|                  coeffs, dc_huff, ac_huff, Ss, Se, Al, num_zero_runs,
  842|  10.7M|                  coding_state, ss.last_dc_coeff + si.comp_idx, bw);
  843|  10.7M|            } else {
  844|      0|              ok = EncodeRefinementBits(coeffs, ac_huff, Ss, Se, Al,
  845|      0|                                        coding_state, bw);
  846|      0|            }
  847|  10.7M|            if (!ok) return SerializationStatus::ERROR;
  ------------------
  |  Branch (847:17): [True: 0, False: 10.7M]
  ------------------
  848|  10.7M|            ++ss.block_scan_index;
  849|  10.7M|          }
  850|  4.17M|        }
  851|  1.38M|      }
  852|   622k|      --ss.restarts_to_go;
  853|   622k|    }
  854|  83.7k|  }
  855|  1.61k|  if (ss.mcu_y < MCU_rows) {
  ------------------
  |  Branch (855:7): [True: 0, False: 1.61k]
  ------------------
  856|      0|    if (!bw->healthy) return SerializationStatus::ERROR;
  ------------------
  |  Branch (856:9): [True: 0, False: 0]
  ------------------
  857|      0|    return SerializationStatus::NEEDS_MORE_INPUT;
  858|      0|  }
  859|  1.61k|  Flush(coding_state, bw);
  860|  1.61k|  if (!JumpToByteBoundary(bw, &state->pad_bits, state->pad_bits_end)) {
  ------------------
  |  Branch (860:7): [True: 13, False: 1.60k]
  ------------------
  861|     13|    return SerializationStatus::ERROR;
  862|     13|  }
  863|  1.60k|  BitWriterFinish(bw);
  864|  1.60k|  ss.stage = EncodeScanState::HEAD;
  865|  1.60k|  state->scan_index++;
  866|  1.60k|  if (!bw->healthy) return SerializationStatus::ERROR;
  ------------------
  |  Branch (866:7): [True: 1.17k, False: 432]
  ------------------
  867|       |
  868|    432|  return SerializationStatus::DONE;
  869|  1.60k|}
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_112DoEncodeScanILi1EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateEENKUlvE_clEv:
  722|  6.29k|  const auto get_next_extra_zero_run_index = [&ss, &scan_info]() -> int {
  723|  6.29k|    if (ss.extra_zero_runs_pos < scan_info.extra_zero_runs.size()) {
  ------------------
  |  Branch (723:9): [True: 4.68k, False: 1.60k]
  ------------------
  724|  4.68k|      return scan_info.extra_zero_runs[ss.extra_zero_runs_pos].block_idx;
  725|  4.68k|    } else {
  726|  1.60k|      return -1;
  727|  1.60k|    }
  728|  6.29k|  };
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_112DoEncodeScanILi1EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateEENKUlvE0_clEv:
  730|  7.16k|  const auto get_next_reset_point = [&ss, &scan_info]() -> int {
  731|  7.16k|    if (ss.next_reset_point_pos < scan_info.reset_points.size()) {
  ------------------
  |  Branch (731:9): [True: 5.57k, False: 1.59k]
  ------------------
  732|  5.57k|      return scan_info.reset_points[ss.next_reset_point_pos++];
  733|  5.57k|    } else {
  734|  1.59k|      return -1;
  735|  1.59k|    }
  736|  7.16k|  };
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_125EncodeDCTBlockProgressiveEPKsRKNS_16HuffmanCodeTableES5_iiiiPNS_8internal3dec14DCTCodingStateEPsPNS7_9BitWriterE:
  576|  10.7M|                               coeff_t* last_dc_coeff, BitWriter* bw) {
  577|  10.7M|  bool eob_run_allowed = Ss > 0;
  578|  10.7M|  coeff_t temp2;
  579|  10.7M|  coeff_t temp;
  580|  10.7M|  if (Ss == 0) {
  ------------------
  |  Branch (580:7): [True: 3.76M, False: 6.95M]
  ------------------
  581|  3.76M|    temp2 = coeffs[0] >> Al;
  582|  3.76M|    if (!CheckDcRange(temp2)) return false;
  ------------------
  |  Branch (582:9): [True: 0, False: 3.76M]
  ------------------
  583|  3.76M|    temp = temp2 - *last_dc_coeff;
  584|  3.76M|    *last_dc_coeff = temp2;
  585|  3.76M|    temp2 = temp;
  586|  3.76M|    if (temp < 0) {
  ------------------
  |  Branch (586:9): [True: 1.03M, False: 2.73M]
  ------------------
  587|  1.03M|      temp = -temp;
  588|  1.03M|      temp2--;
  589|  1.03M|    }
  590|  3.76M|    int nbits = (temp == 0) ? 0 : (Log2FloorNonZero(temp) + 1);
  ------------------
  |  Branch (590:17): [True: 1.85M, False: 1.90M]
  ------------------
  591|  3.76M|    WriteBits(bw, dc_huff.depth[nbits], dc_huff.code[nbits]);
  592|  3.76M|    if (nbits > 0) {
  ------------------
  |  Branch (592:9): [True: 1.90M, False: 1.85M]
  ------------------
  593|  1.90M|      WriteBits(bw, nbits, temp2 & ((1 << nbits) - 1));
  594|  1.90M|    }
  595|  3.76M|    ++Ss;
  596|  3.76M|  }
  597|  10.7M|  if (Ss > Se) {
  ------------------
  |  Branch (597:7): [True: 595k, False: 10.1M]
  ------------------
  598|   595k|    return true;
  599|   595k|  }
  600|  10.1M|  int r = 0;
  601|   289M|  for (int k = Ss; k <= Se; ++k) {
  ------------------
  |  Branch (601:20): [True: 279M, False: 10.1M]
  ------------------
  602|   279M|    temp = coeffs[kJPEGNaturalOrder[k]];
  603|   279M|    if (temp == 0) {
  ------------------
  |  Branch (603:9): [True: 279M, False: 52.2k]
  ------------------
  604|   279M|      r++;
  605|   279M|      continue;
  606|   279M|    }
  607|  52.2k|    if (temp < 0) {
  ------------------
  |  Branch (607:9): [True: 33.3k, False: 18.8k]
  ------------------
  608|  33.3k|      temp = -temp;
  609|  33.3k|      temp >>= Al;
  610|  33.3k|      temp2 = ~temp;
  611|  33.3k|    } else {
  612|  18.8k|      temp >>= Al;
  613|  18.8k|      temp2 = temp;
  614|  18.8k|    }
  615|  52.2k|    if (temp == 0) {
  ------------------
  |  Branch (615:9): [True: 1.95k, False: 50.2k]
  ------------------
  616|  1.95k|      r++;
  617|  1.95k|      continue;
  618|  1.95k|    }
  619|  50.2k|    Flush(coding_state, bw);
  620|  73.9k|    while (r > 15) {
  ------------------
  |  Branch (620:12): [True: 23.6k, False: 50.2k]
  ------------------
  621|  23.6k|      WriteBits(bw, ac_huff.depth[0xf0], ac_huff.code[0xf0]);
  622|  23.6k|      r -= 16;
  623|  23.6k|    }
  624|  50.2k|    int nbits = Log2FloorNonZero(temp) + 1;
  625|  50.2k|    int symbol = (r << 4u) + nbits;
  626|  50.2k|    WriteBits(bw, ac_huff.depth[symbol], ac_huff.code[symbol]);
  627|  50.2k|    WriteBits(bw, nbits, temp2 & ((1 << nbits) - 1));
  628|  50.2k|    r = 0;
  629|  50.2k|  }
  630|  10.1M|  if (num_zero_runs > 0) {
  ------------------
  |  Branch (630:7): [True: 4.62k, False: 10.1M]
  ------------------
  631|  4.62k|    Flush(coding_state, bw);
  632|  12.6k|    for (int i = 0; i < num_zero_runs; ++i) {
  ------------------
  |  Branch (632:21): [True: 7.98k, False: 4.62k]
  ------------------
  633|  7.98k|      WriteBits(bw, ac_huff.depth[0xf0], ac_huff.code[0xf0]);
  634|  7.98k|      r -= 16;
  635|  7.98k|    }
  636|  4.62k|  }
  637|  10.1M|  if (r > 0) {
  ------------------
  |  Branch (637:7): [True: 10.1M, False: 2.97k]
  ------------------
  638|       |    // Ignore result: since we do not buffer bits - it can not fail.
  639|  10.1M|    BufferEndOfBand(coding_state, &ac_huff, nullptr, 0, bw);
  640|  10.1M|    if (!eob_run_allowed) {
  ------------------
  |  Branch (640:9): [True: 3.51M, False: 6.60M]
  ------------------
  641|  3.51M|      Flush(coding_state, bw);
  642|  3.51M|    }
  643|  10.1M|  }
  644|  10.1M|  return true;
  645|  10.7M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_115BufferEndOfBandEPNS_8internal3dec14DCTCodingStateEPKNS_16HuffmanCodeTableEPKimPNS2_9BitWriterE:
  226|  39.0M|                                           BitWriter* bw) {
  227|  39.0M|  if (s->eob_run_ == 0) {
  ------------------
  |  Branch (227:7): [True: 8.28M, False: 30.8M]
  ------------------
  228|  8.28M|    s->cur_ac_huff_ = ac_huff;
  229|  8.28M|  }
  230|  39.0M|  ++s->eob_run_;
  231|  39.0M|  if (new_bits_count) {
  ------------------
  |  Branch (231:7): [True: 150k, False: 38.9M]
  ------------------
  232|   150k|    uint64_t new_bits = 0;
  233|   940k|    for (size_t i = 0; i < new_bits_count; ++i) {
  ------------------
  |  Branch (233:24): [True: 789k, False: 150k]
  ------------------
  234|   789k|      new_bits = (new_bits << 1) | new_bits_array[i];
  235|   789k|    }
  236|   150k|    size_t tail = s->refinement_bits_count_ & 0xF;
  237|   150k|    if (tail) {  // First stuff the tail item
  ------------------
  |  Branch (237:9): [True: 98.9k, False: 51.4k]
  ------------------
  238|  98.9k|      size_t stuff_bits_count = std::min(16 - tail, new_bits_count);
  239|  98.9k|      uint16_t stuff_bits = new_bits >> (new_bits_count - stuff_bits_count);
  240|  98.9k|      stuff_bits &= ((1u << stuff_bits_count) - 1);
  241|  98.9k|      s->refinement_bits_.back() =
  242|  98.9k|          (s->refinement_bits_.back() << stuff_bits_count) | stuff_bits;
  243|  98.9k|      new_bits_count -= stuff_bits_count;
  244|  98.9k|      s->refinement_bits_count_ += stuff_bits_count;
  245|  98.9k|    }
  246|   167k|    while (new_bits_count >= 16) {
  ------------------
  |  Branch (246:12): [True: 17.2k, False: 150k]
  ------------------
  247|  17.2k|      s->refinement_bits_.push_back(new_bits >> (new_bits_count - 16));
  248|  17.2k|      new_bits_count -= 16;
  249|  17.2k|      s->refinement_bits_count_ += 16;
  250|  17.2k|    }
  251|   150k|    if (new_bits_count) {
  ------------------
  |  Branch (251:9): [True: 62.8k, False: 87.4k]
  ------------------
  252|  62.8k|      s->refinement_bits_.push_back(new_bits & ((1u << new_bits_count) - 1));
  253|  62.8k|      s->refinement_bits_count_ += new_bits_count;
  254|  62.8k|    }
  255|   150k|  }
  256|       |  // At most we buffer at most ~258041 bytes; that is less than we have reserved
  257|       |  // before; still, let's make sure we don't use more memory ever.
  258|  39.0M|  if (s->refinement_bits_count_ > 0x7FFF * (kDCTBlockSize - 1)) {
  ------------------
  |  Branch (258:7): [True: 0, False: 39.0M]
  ------------------
  259|      0|    return false;
  260|      0|  }
  261|  39.0M|  if (s->eob_run_ == 0x7FFF) {
  ------------------
  |  Branch (261:7): [True: 797, False: 39.0M]
  ------------------
  262|    797|    Flush(s, bw);
  263|    797|  }
  264|  39.0M|  return true;
  265|  39.0M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_112DoEncodeScanILi2EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateE:
  715|  2.92k|                                                  SerializationState* state) {
  716|  2.92k|  const JPEGScanInfo& scan_info = jpg.scan_info[state->scan_index];
  717|  2.92k|  EncodeScanState& ss = state->scan_state;
  718|       |
  719|  2.92k|  const int restart_interval =
  720|  2.92k|      state->seen_dri_marker ? jpg.restart_interval : 0;
  ------------------
  |  Branch (720:7): [True: 1.00k, False: 1.91k]
  ------------------
  721|       |
  722|  2.92k|  const auto get_next_extra_zero_run_index = [&ss, &scan_info]() -> int {
  723|  2.92k|    if (ss.extra_zero_runs_pos < scan_info.extra_zero_runs.size()) {
  724|  2.92k|      return scan_info.extra_zero_runs[ss.extra_zero_runs_pos].block_idx;
  725|  2.92k|    } else {
  726|  2.92k|      return -1;
  727|  2.92k|    }
  728|  2.92k|  };
  729|       |
  730|  2.92k|  const auto get_next_reset_point = [&ss, &scan_info]() -> int {
  731|  2.92k|    if (ss.next_reset_point_pos < scan_info.reset_points.size()) {
  732|  2.92k|      return scan_info.reset_points[ss.next_reset_point_pos++];
  733|  2.92k|    } else {
  734|  2.92k|      return -1;
  735|  2.92k|    }
  736|  2.92k|  };
  737|       |
  738|  2.92k|  if (ss.stage == EncodeScanState::HEAD) {
  ------------------
  |  Branch (738:7): [True: 2.92k, False: 0]
  ------------------
  739|  2.92k|    if (!EncodeSOS(jpg, scan_info, state)) return SerializationStatus::ERROR;
  ------------------
  |  Branch (739:9): [True: 85, False: 2.83k]
  ------------------
  740|  2.83k|    BitWriterInit(&ss.bw, &state->output_queue);
  741|  2.83k|    DCTCodingStateInit(&ss.coding_state);
  742|  2.83k|    ss.restarts_to_go = restart_interval;
  743|  2.83k|    ss.next_restart_marker = 0;
  744|  2.83k|    ss.block_scan_index = 0;
  745|  2.83k|    ss.extra_zero_runs_pos = 0;
  746|  2.83k|    ss.next_extra_zero_run_index = get_next_extra_zero_run_index();
  747|  2.83k|    ss.next_reset_point_pos = 0;
  748|  2.83k|    ss.next_reset_point = get_next_reset_point();
  749|  2.83k|    ss.mcu_y = 0;
  750|  2.83k|    memset(ss.last_dc_coeff, 0, sizeof(ss.last_dc_coeff));
  751|  2.83k|    ss.stage = EncodeScanState::BODY;
  752|  2.83k|  }
  753|  2.83k|  BitWriter* bw = &ss.bw;
  754|  2.83k|  DCTCodingState* coding_state = &ss.coding_state;
  755|       |
  756|  2.83k|  BRUNSLI_DCHECK(ss.stage == EncodeScanState::BODY);
  757|       |
  758|       |  // "Non-interleaved" means color data comes in separate scans, in other words
  759|       |  // each scan can contain only one color component.
  760|  2.83k|  const bool is_interleaved = (scan_info.num_components > 1);
  761|  2.83k|  const JPEGComponent& base_component =
  762|  2.83k|      jpg.components[scan_info.components[0].comp_idx];
  763|       |  // h_group / v_group act as numerators for converting number of blocks to
  764|       |  // number of MCU. In interleaved mode it is 1, so MCU is represented with
  765|       |  // max_*_samp_factor blocks. In non-interleaved mode we choose numerator to
  766|       |  // be the samping factor, consequently MCU is always represented with single
  767|       |  // block.
  768|  2.83k|  const int h_group = is_interleaved ? 1 : base_component.h_samp_factor;
  ------------------
  |  Branch (768:23): [True: 2.21k, False: 624]
  ------------------
  769|  2.83k|  const int v_group = is_interleaved ? 1 : base_component.v_samp_factor;
  ------------------
  |  Branch (769:23): [True: 2.21k, False: 624]
  ------------------
  770|  2.83k|  const int MCUs_per_row =
  771|  2.83k|      DivCeil(jpg.width * h_group, 8 * jpg.max_h_samp_factor);
  772|  2.83k|  const int MCU_rows = DivCeil(jpg.height * v_group, 8 * jpg.max_v_samp_factor);
  773|  2.83k|  const bool is_progressive = state->is_progressive;
  774|  2.83k|  const int Al = is_progressive ? scan_info.Al : 0;
  ------------------
  |  Branch (774:18): [True: 2.83k, False: 0]
  ------------------
  775|  2.83k|  const int Ss = is_progressive ? scan_info.Ss : 0;
  ------------------
  |  Branch (775:18): [True: 2.83k, False: 0]
  ------------------
  776|  2.83k|  const int Se = is_progressive ? scan_info.Se : 63;
  ------------------
  |  Branch (776:18): [True: 2.83k, False: 0]
  ------------------
  777|       |
  778|       |  // DC-only is defined by [0..0] spectral range.
  779|  2.83k|  const bool want_ac = ((Ss != 0) || (Se != 0));
  ------------------
  |  Branch (779:25): [True: 2.16k, False: 667]
  |  Branch (779:38): [True: 618, False: 49]
  ------------------
  780|  2.83k|  const bool complete_ac = (parsing_state.stage == Stage::DONE);
  781|  2.83k|  const bool has_ac =
  782|  2.83k|      complete_ac || HasSection(&parsing_state, kBrunsliACDataTag);
  ------------------
  |  Branch (782:7): [True: 2.83k, False: 0]
  |  Branch (782:22): [True: 0, False: 0]
  ------------------
  783|  2.83k|  if (want_ac && !has_ac) return SerializationStatus::NEEDS_MORE_INPUT;
  ------------------
  |  Branch (783:7): [True: 2.78k, False: 49]
  |  Branch (783:18): [True: 0, False: 2.78k]
  ------------------
  784|       |
  785|       |  // |has_ac| implies |complete_dc| but not vice versa; for the sake of
  786|       |  // simplicity we pretend they are equal, because they are separated by just a
  787|       |  // few bytes of input.
  788|  2.83k|  const bool complete_dc = has_ac;
  789|  2.83k|  const bool complete = want_ac ? complete_ac : complete_dc;
  ------------------
  |  Branch (789:25): [True: 2.78k, False: 49]
  ------------------
  790|       |  // When "incomplete" |ac_dc| tracks information about current ("incomplete")
  791|       |  // band parsing progress.
  792|  2.83k|  const int last_mcu_y =
  793|  2.83k|      complete ? MCU_rows : parsing_state.internal->ac_dc.next_mcu_y * v_group;
  ------------------
  |  Branch (793:7): [True: 2.83k, False: 0]
  ------------------
  794|       |
  795|   115k|  for (; ss.mcu_y < last_mcu_y; ++ss.mcu_y) {
  ------------------
  |  Branch (795:10): [True: 112k, False: 2.82k]
  ------------------
  796|  1.29M|    for (int mcu_x = 0; mcu_x < MCUs_per_row; ++mcu_x) {
  ------------------
  |  Branch (796:25): [True: 1.18M, False: 112k]
  ------------------
  797|       |      // Possibly emit a restart marker.
  798|  1.18M|      if (restart_interval > 0 && ss.restarts_to_go == 0) {
  ------------------
  |  Branch (798:11): [True: 973k, False: 212k]
  |  Branch (798:35): [True: 164k, False: 809k]
  ------------------
  799|   164k|        Flush(coding_state, bw);
  800|   164k|        if (!JumpToByteBoundary(bw, &state->pad_bits, state->pad_bits_end)) {
  ------------------
  |  Branch (800:13): [True: 6, False: 164k]
  ------------------
  801|      6|          return SerializationStatus::ERROR;
  802|      6|        }
  803|   164k|        EmitMarker(bw, 0xD0 + ss.next_restart_marker);
  804|   164k|        ss.next_restart_marker += 1;
  805|   164k|        ss.next_restart_marker &= 0x7;
  806|   164k|        ss.restarts_to_go = restart_interval;
  807|   164k|        memset(ss.last_dc_coeff, 0, sizeof(ss.last_dc_coeff));
  808|   164k|      }
  809|       |      // Encode one MCU
  810|  3.61M|      for (size_t i = 0; i < scan_info.num_components; ++i) {
  ------------------
  |  Branch (810:26): [True: 2.42M, False: 1.18M]
  ------------------
  811|  2.42M|        const JPEGComponentScanInfo& si = scan_info.components[i];
  812|  2.42M|        const JPEGComponent& c = jpg.components[si.comp_idx];
  813|  2.42M|        const HuffmanCodeTable& dc_huff = state->dc_huff_table[si.dc_tbl_idx];
  814|  2.42M|        const HuffmanCodeTable& ac_huff = state->ac_huff_table[si.ac_tbl_idx];
  815|  2.42M|        int n_blocks_y = is_interleaved ? c.v_samp_factor : 1;
  ------------------
  |  Branch (815:26): [True: 1.66M, False: 762k]
  ------------------
  816|  2.42M|        int n_blocks_x = is_interleaved ? c.h_samp_factor : 1;
  ------------------
  |  Branch (816:26): [True: 1.66M, False: 762k]
  ------------------
  817|  11.0M|        for (int iy = 0; iy < n_blocks_y; ++iy) {
  ------------------
  |  Branch (817:26): [True: 8.61M, False: 2.42M]
  ------------------
  818|  37.8M|          for (int ix = 0; ix < n_blocks_x; ++ix) {
  ------------------
  |  Branch (818:28): [True: 29.2M, False: 8.61M]
  ------------------
  819|  29.2M|            int block_y = ss.mcu_y * n_blocks_y + iy;
  820|  29.2M|            int block_x = mcu_x * n_blocks_x + ix;
  821|  29.2M|            int block_idx = block_y * c.width_in_blocks + block_x;
  822|  29.2M|            if (ss.block_scan_index == ss.next_reset_point) {
  ------------------
  |  Branch (822:17): [True: 9.77k, False: 29.1M]
  ------------------
  823|  9.77k|              Flush(coding_state, bw);
  824|  9.77k|              ss.next_reset_point = get_next_reset_point();
  825|  9.77k|            }
  826|  29.2M|            int num_zero_runs = 0;
  827|  29.2M|            if (ss.block_scan_index == ss.next_extra_zero_run_index) {
  ------------------
  |  Branch (827:17): [True: 1.11k, False: 29.2M]
  ------------------
  828|  1.11k|              num_zero_runs = scan_info.extra_zero_runs[ss.extra_zero_runs_pos]
  829|  1.11k|                                  .num_extra_zero_runs;
  830|  1.11k|              ++ss.extra_zero_runs_pos;
  831|  1.11k|              ss.next_extra_zero_run_index = get_next_extra_zero_run_index();
  832|  1.11k|            }
  833|  29.2M|            const coeff_t* coeffs = &c.coeffs[block_idx << 6];
  834|  29.2M|            bool ok;
  835|  29.2M|            if (kMode == 0) {
  ------------------
  |  Branch (835:17): [Folded, False: 29.2M]
  ------------------
  836|      0|              ok = EncodeDCTBlockSequential(coeffs, dc_huff, ac_huff,
  837|      0|                                            num_zero_runs,
  838|      0|                                            ss.last_dc_coeff + si.comp_idx, bw);
  839|  29.2M|            } else if (kMode == 1) {
  ------------------
  |  Branch (839:24): [Folded, False: 29.2M]
  ------------------
  840|      0|              ok = EncodeDCTBlockProgressive(
  841|      0|                  coeffs, dc_huff, ac_huff, Ss, Se, Al, num_zero_runs,
  842|      0|                  coding_state, ss.last_dc_coeff + si.comp_idx, bw);
  843|  29.2M|            } else {
  844|  29.2M|              ok = EncodeRefinementBits(coeffs, ac_huff, Ss, Se, Al,
  845|  29.2M|                                        coding_state, bw);
  846|  29.2M|            }
  847|  29.2M|            if (!ok) return SerializationStatus::ERROR;
  ------------------
  |  Branch (847:17): [True: 0, False: 29.2M]
  ------------------
  848|  29.2M|            ++ss.block_scan_index;
  849|  29.2M|          }
  850|  8.61M|        }
  851|  2.42M|      }
  852|  1.18M|      --ss.restarts_to_go;
  853|  1.18M|    }
  854|   112k|  }
  855|  2.82k|  if (ss.mcu_y < MCU_rows) {
  ------------------
  |  Branch (855:7): [True: 0, False: 2.82k]
  ------------------
  856|      0|    if (!bw->healthy) return SerializationStatus::ERROR;
  ------------------
  |  Branch (856:9): [True: 0, False: 0]
  ------------------
  857|      0|    return SerializationStatus::NEEDS_MORE_INPUT;
  858|      0|  }
  859|  2.82k|  Flush(coding_state, bw);
  860|  2.82k|  if (!JumpToByteBoundary(bw, &state->pad_bits, state->pad_bits_end)) {
  ------------------
  |  Branch (860:7): [True: 14, False: 2.81k]
  ------------------
  861|     14|    return SerializationStatus::ERROR;
  862|     14|  }
  863|  2.81k|  BitWriterFinish(bw);
  864|  2.81k|  ss.stage = EncodeScanState::HEAD;
  865|  2.81k|  state->scan_index++;
  866|  2.81k|  if (!bw->healthy) return SerializationStatus::ERROR;
  ------------------
  |  Branch (866:7): [True: 2.18k, False: 633]
  ------------------
  867|       |
  868|    633|  return SerializationStatus::DONE;
  869|  2.81k|}
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_112DoEncodeScanILi2EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateEENKUlvE_clEv:
  722|  3.95k|  const auto get_next_extra_zero_run_index = [&ss, &scan_info]() -> int {
  723|  3.95k|    if (ss.extra_zero_runs_pos < scan_info.extra_zero_runs.size()) {
  ------------------
  |  Branch (723:9): [True: 1.13k, False: 2.81k]
  ------------------
  724|  1.13k|      return scan_info.extra_zero_runs[ss.extra_zero_runs_pos].block_idx;
  725|  2.81k|    } else {
  726|  2.81k|      return -1;
  727|  2.81k|    }
  728|  3.95k|  };
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_112DoEncodeScanILi2EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateEENKUlvE0_clEv:
  730|  12.6k|  const auto get_next_reset_point = [&ss, &scan_info]() -> int {
  731|  12.6k|    if (ss.next_reset_point_pos < scan_info.reset_points.size()) {
  ------------------
  |  Branch (731:9): [True: 9.82k, False: 2.78k]
  ------------------
  732|  9.82k|      return scan_info.reset_points[ss.next_reset_point_pos++];
  733|  9.82k|    } else {
  734|  2.78k|      return -1;
  735|  2.78k|    }
  736|  12.6k|  };
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_120EncodeRefinementBitsEPKsRKNS_16HuffmanCodeTableEiiiPNS_8internal3dec14DCTCodingStateEPNS7_9BitWriterE:
  649|  29.2M|                          int Al, DCTCodingState* coding_state, BitWriter* bw) {
  650|  29.2M|  bool eob_run_allowed = Ss > 0;
  651|  29.2M|  if (Ss == 0) {
  ------------------
  |  Branch (651:7): [True: 4.66M, False: 24.5M]
  ------------------
  652|       |    // Emit next bit of DC component.
  653|  4.66M|    WriteBits(bw, 1, (coeffs[0] >> Al) & 1);
  654|  4.66M|    ++Ss;
  655|  4.66M|  }
  656|  29.2M|  if (Ss > Se) {
  ------------------
  |  Branch (656:7): [True: 231k, False: 28.9M]
  ------------------
  657|   231k|    return true;
  658|   231k|  }
  659|  28.9M|  int abs_values[kDCTBlockSize];
  660|  28.9M|  int eob = 0;
  661|   795M|  for (int k = Ss; k <= Se; k++) {
  ------------------
  |  Branch (661:20): [True: 766M, False: 28.9M]
  ------------------
  662|   766M|    const coeff_t abs_val = std::abs(coeffs[kJPEGNaturalOrder[k]]);
  663|   766M|    abs_values[k] = abs_val >> Al;
  664|   766M|    if (abs_values[k] == 1) {
  ------------------
  |  Branch (664:9): [True: 93.0k, False: 766M]
  ------------------
  665|  93.0k|      eob = k;
  666|  93.0k|    }
  667|   766M|  }
  668|  28.9M|  int r = 0;
  669|  28.9M|  int refinement_bits[kDCTBlockSize];
  670|  28.9M|  size_t refinement_bits_count = 0;
  671|   795M|  for (int k = Ss; k <= Se; k++) {
  ------------------
  |  Branch (671:20): [True: 766M, False: 28.9M]
  ------------------
  672|   766M|    if (abs_values[k] == 0) {
  ------------------
  |  Branch (672:9): [True: 765M, False: 920k]
  ------------------
  673|   765M|      r++;
  674|   765M|      continue;
  675|   765M|    }
  676|   968k|    while (r > 15 && k <= eob) {
  ------------------
  |  Branch (676:12): [True: 123k, False: 844k]
  |  Branch (676:22): [True: 48.2k, False: 75.3k]
  ------------------
  677|  48.2k|      Flush(coding_state, bw);
  678|  48.2k|      WriteBits(bw, ac_huff.depth[0xf0], ac_huff.code[0xf0]);
  679|  48.2k|      r -= 16;
  680|  59.7k|      for (size_t i = 0; i < refinement_bits_count; ++i) {
  ------------------
  |  Branch (680:26): [True: 11.5k, False: 48.2k]
  ------------------
  681|  11.5k|        WriteBits(bw, 1, refinement_bits[i]);
  682|  11.5k|      }
  683|  48.2k|      refinement_bits_count = 0;
  684|  48.2k|    }
  685|   920k|    if (abs_values[k] > 1) {
  ------------------
  |  Branch (685:9): [True: 827k, False: 93.0k]
  ------------------
  686|   827k|      refinement_bits[refinement_bits_count++] = abs_values[k] & 1u;
  687|   827k|      continue;
  688|   827k|    }
  689|  93.0k|    Flush(coding_state, bw);
  690|  93.0k|    int symbol = (r << 4u) + 1;
  691|  93.0k|    int new_non_zero_bit = (coeffs[kJPEGNaturalOrder[k]] < 0) ? 0 : 1;
  ------------------
  |  Branch (691:28): [True: 60.3k, False: 32.7k]
  ------------------
  692|  93.0k|    WriteBits(bw, ac_huff.depth[symbol], ac_huff.code[symbol]);
  693|  93.0k|    WriteBits(bw, 1, new_non_zero_bit);
  694|   118k|    for (size_t i = 0; i < refinement_bits_count; ++i) {
  ------------------
  |  Branch (694:24): [True: 25.7k, False: 93.0k]
  ------------------
  695|  25.7k|      WriteBits(bw, 1, refinement_bits[i]);
  696|  25.7k|    }
  697|  93.0k|    refinement_bits_count = 0;
  698|  93.0k|    r = 0;
  699|  93.0k|  }
  700|  28.9M|  if (r > 0 || refinement_bits_count) {
  ------------------
  |  Branch (700:7): [True: 28.9M, False: 15.1k]
  |  Branch (700:16): [True: 8.23k, False: 6.93k]
  ------------------
  701|  28.9M|    if (!BufferEndOfBand(coding_state, &ac_huff, refinement_bits,
  ------------------
  |  Branch (701:9): [True: 0, False: 28.9M]
  ------------------
  702|  28.9M|                         refinement_bits_count, bw)) {
  703|      0|      return false;
  704|      0|    }
  705|  28.9M|    if (!eob_run_allowed) {
  ------------------
  |  Branch (705:9): [True: 4.61M, False: 24.3M]
  ------------------
  706|  4.61M|      Flush(coding_state, bw);
  707|  4.61M|    }
  708|  28.9M|  }
  709|  28.9M|  return true;
  710|  28.9M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeDQTERKNS_8JPEGDataEPNS_8internal3dec18SerializationStateE:
  431|    175|bool EncodeDQT(const JPEGData& jpg, SerializationState* state) {
  432|    175|  int marker_len = 2;
  433|    175|  for (size_t i = state->dqt_index; i < jpg.quant.size(); ++i) {
  ------------------
  |  Branch (433:37): [True: 166, False: 9]
  ------------------
  434|    166|    const JPEGQuantTable& table = jpg.quant[i];
  435|    166|    marker_len += 1 + (table.precision ? 2 : 1) * kDCTBlockSize;
  ------------------
  |  Branch (435:24): [True: 46, False: 120]
  ------------------
  436|    166|    if (table.is_last) break;
  ------------------
  |  Branch (436:9): [True: 166, False: 0]
  ------------------
  437|    166|  }
  438|    175|  state->output_queue.emplace_back(marker_len + 2);
  439|    175|  uint8_t* data = state->output_queue.back().buffer->data();
  440|    175|  size_t pos = 0;
  441|    175|  data[pos++] = 0xFF;
  442|    175|  data[pos++] = 0xDB;
  443|    175|  data[pos++] = marker_len >> 8u;
  444|    175|  data[pos++] = marker_len & 0xFFu;
  445|    175|  while (true) {
  ------------------
  |  Branch (445:10): [True: 175, Folded]
  ------------------
  446|    175|    const size_t idx = state->dqt_index++;
  447|    175|    if (idx >= jpg.quant.size()) {
  ------------------
  |  Branch (447:9): [True: 9, False: 166]
  ------------------
  448|      9|      return false;  // corrupt input
  449|      9|    }
  450|    166|    const JPEGQuantTable& table = jpg.quant[idx];
  451|    166|    data[pos++] = (table.precision << 4u) + table.index;
  452|  10.7k|    for (size_t i = 0; i < kDCTBlockSize; ++i) {
  ------------------
  |  Branch (452:24): [True: 10.6k, False: 166]
  ------------------
  453|  10.6k|      int val_idx = kJPEGNaturalOrder[i];
  454|  10.6k|      int val = table.values[val_idx];
  455|  10.6k|      if (table.precision) {
  ------------------
  |  Branch (455:11): [True: 2.94k, False: 7.68k]
  ------------------
  456|  2.94k|        data[pos++] = val >> 8u;
  457|  2.94k|      }
  458|  10.6k|      data[pos++] = val & 0xFFu;
  459|  10.6k|    }
  460|    166|    if (table.is_last) break;
  ------------------
  |  Branch (460:9): [True: 166, False: 0]
  ------------------
  461|    166|  }
  462|    166|  return true;
  463|    175|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeDRIERKNS_8JPEGDataEPNS_8internal3dec18SerializationStateE:
  465|  1.94k|bool EncodeDRI(const JPEGData& jpg, SerializationState* state) {
  466|  1.94k|  state->seen_dri_marker = true;
  467|  1.94k|  OutputChunk dri_marker = {0xFF,
  468|  1.94k|                            0xDD,
  469|  1.94k|                            0,
  470|  1.94k|                            4,
  471|  1.94k|                            static_cast<uint8_t>(jpg.restart_interval >> 8),
  472|  1.94k|                            static_cast<uint8_t>(jpg.restart_interval & 0xFF)};
  473|  1.94k|  state->output_queue.push_back(std::move(dri_marker));
  474|  1.94k|  return true;
  475|  1.94k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeAPPERKNS_8JPEGDataEhPNS_8internal3dec18SerializationStateE:
  482|    226|bool EncodeAPP(const JPEGData& jpg, uint8_t marker, SerializationState* state) {
  483|       |  // TODO(eustas): check that marker corresponds to payload?
  484|    226|  (void)marker;
  485|       |
  486|    226|  size_t app_index = state->app_index++;
  487|    226|  if (app_index >= jpg.app_data.size()) return false;
  ------------------
  |  Branch (487:7): [True: 209, False: 17]
  ------------------
  488|     17|  state->output_queue.push_back(OutputChunk({0xFF}));
  489|     17|  state->output_queue.emplace_back(jpg.app_data[app_index]);
  490|     17|  return true;
  491|    226|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeCOMERKNS_8JPEGDataEPNS_8internal3dec18SerializationStateE:
  493|      5|bool EncodeCOM(const JPEGData& jpg, SerializationState* state) {
  494|      5|  size_t com_index = state->com_index++;
  495|      5|  if (com_index >= jpg.com_data.size()) return false;
  ------------------
  |  Branch (495:7): [True: 5, False: 0]
  ------------------
  496|      0|  state->output_queue.push_back(OutputChunk({0xFF}));
  497|      0|  state->output_queue.emplace_back(jpg.com_data[com_index]);
  498|      0|  return true;
  499|      5|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_121EncodeInterMarkerDataERKNS_8JPEGDataEPNS_8internal3dec18SerializationStateE:
  501|     23|bool EncodeInterMarkerData(const JPEGData& jpg, SerializationState* state) {
  502|     23|  size_t index = state->data_index++;
  503|     23|  if (index >= jpg.inter_marker_data.size()) return false;
  ------------------
  |  Branch (503:7): [True: 0, False: 23]
  ------------------
  504|     23|  state->output_queue.emplace_back(jpg.inter_marker_data[index]);
  505|     23|  return true;
  506|     23|}

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

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

_ZN7brunsli8internal3dec13MetadataState9CanFinishEv:
  181|     35|  bool CanFinish() { return (stage == READ_MARKER) || (stage == READ_TAIL); }
  ------------------
  |  Branch (181:29): [True: 26, False: 9]
  |  Branch (181:55): [True: 2, False: 7]
  ------------------

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

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

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

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

