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

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

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

BrotliGetTransforms:
  173|  3.16k|const BrotliTransforms* BrotliGetTransforms(void) {
  174|  3.16k|  return &kBrotliTransforms;
  175|  3.16k|}
BrotliTransformDictionaryWord:
  237|  56.7k|    const BrotliTransforms* transforms, int transform_idx) {
  238|  56.7k|  int idx = 0;
  239|  56.7k|  const uint8_t* prefix = BROTLI_TRANSFORM_PREFIX(transforms, transform_idx);
  ------------------
  |  |   70|  56.7k|#define BROTLI_TRANSFORM_PREFIX(T, I) (&(T)->prefix_suffix[ \
  |  |   71|  56.7k|    (T)->prefix_suffix_map[BROTLI_TRANSFORM_PREFIX_ID(T, I)]])
  |  |  ------------------
  |  |  |  |   65|  56.7k|#define BROTLI_TRANSFORM_PREFIX_ID(T, I) ((T)->transforms[((I) * 3) + 0])
  |  |  ------------------
  ------------------
  240|  56.7k|  uint8_t type = BROTLI_TRANSFORM_TYPE(transforms, transform_idx);
  ------------------
  |  |   66|  56.7k|#define BROTLI_TRANSFORM_TYPE(T, I)      ((T)->transforms[((I) * 3) + 1])
  ------------------
  241|  56.7k|  const uint8_t* suffix = BROTLI_TRANSFORM_SUFFIX(transforms, transform_idx);
  ------------------
  |  |   72|  56.7k|#define BROTLI_TRANSFORM_SUFFIX(T, I) (&(T)->prefix_suffix[ \
  |  |   73|  56.7k|    (T)->prefix_suffix_map[BROTLI_TRANSFORM_SUFFIX_ID(T, I)]])
  |  |  ------------------
  |  |  |  |   67|  56.7k|#define BROTLI_TRANSFORM_SUFFIX_ID(T, I) ((T)->transforms[((I) * 3) + 2])
  |  |  ------------------
  ------------------
  242|  56.7k|  {
  243|  56.7k|    int prefix_len = *prefix++;
  244|  81.7k|    while (prefix_len--) { dst[idx++] = *prefix++; }
  ------------------
  |  Branch (244:12): [True: 25.0k, False: 56.7k]
  ------------------
  245|  56.7k|  }
  246|  56.7k|  {
  247|  56.7k|    const int t = type;
  248|  56.7k|    int i = 0;
  249|  56.7k|    if (t <= BROTLI_TRANSFORM_OMIT_LAST_9) {
  ------------------
  |  Branch (249:9): [True: 42.7k, False: 14.0k]
  ------------------
  250|  42.7k|      len -= t;
  251|  42.7k|    } else if (t >= BROTLI_TRANSFORM_OMIT_FIRST_1
  ------------------
  |  Branch (251:16): [True: 3.92k, False: 10.1k]
  ------------------
  252|  3.92k|        && t <= BROTLI_TRANSFORM_OMIT_FIRST_9) {
  ------------------
  |  Branch (252:12): [True: 3.92k, False: 0]
  ------------------
  253|  3.92k|      int skip = t - (BROTLI_TRANSFORM_OMIT_FIRST_1 - 1);
  254|  3.92k|      word += skip;
  255|  3.92k|      len -= skip;
  256|  3.92k|    }
  257|   397k|    while (i < len) { dst[idx++] = word[i++]; }
  ------------------
  |  Branch (257:12): [True: 341k, False: 56.7k]
  ------------------
  258|  56.7k|    if (t == BROTLI_TRANSFORM_UPPERCASE_FIRST) {
  ------------------
  |  Branch (258:9): [True: 7.53k, False: 49.2k]
  ------------------
  259|  7.53k|      ToUpperCase(&dst[idx - len]);
  260|  49.2k|    } else if (t == BROTLI_TRANSFORM_UPPERCASE_ALL) {
  ------------------
  |  Branch (260:16): [True: 2.57k, False: 46.6k]
  ------------------
  261|  2.57k|      uint8_t* uppercase = &dst[idx - len];
  262|  20.4k|      while (len > 0) {
  ------------------
  |  Branch (262:14): [True: 17.8k, False: 2.57k]
  ------------------
  263|  17.8k|        int step = ToUpperCase(uppercase);
  264|  17.8k|        uppercase += step;
  265|  17.8k|        len -= step;
  266|  17.8k|      }
  267|  46.6k|    } else if (t == BROTLI_TRANSFORM_SHIFT_FIRST) {
  ------------------
  |  Branch (267:16): [True: 0, False: 46.6k]
  ------------------
  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|  46.6k|    } else if (t == BROTLI_TRANSFORM_SHIFT_ALL) {
  ------------------
  |  Branch (271:16): [True: 0, False: 46.6k]
  ------------------
  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|  56.7k|  }
  282|  56.7k|  {
  283|  56.7k|    int suffix_len = *suffix++;
  284|   182k|    while (suffix_len--) { dst[idx++] = *suffix++; }
  ------------------
  |  Branch (284:12): [True: 125k, False: 56.7k]
  ------------------
  285|  56.7k|    return idx;
  286|  56.7k|  }
  287|  56.7k|}
transform.c:ToUpperCase:
  177|  25.3k|static int ToUpperCase(uint8_t* p) {
  178|  25.3k|  if (p[0] < 0xC0) {
  ------------------
  |  Branch (178:7): [True: 20.4k, False: 4.90k]
  ------------------
  179|  20.4k|    if (p[0] >= 'a' && p[0] <= 'z') {
  ------------------
  |  Branch (179:9): [True: 17.6k, False: 2.83k]
  |  Branch (179:24): [True: 16.8k, False: 792]
  ------------------
  180|  16.8k|      p[0] ^= 32;
  181|  16.8k|    }
  182|  20.4k|    return 1;
  183|  20.4k|  }
  184|       |  /* An overly simplified uppercasing model for UTF-8. */
  185|  4.90k|  if (p[0] < 0xE0) {
  ------------------
  |  Branch (185:7): [True: 1.47k, False: 3.42k]
  ------------------
  186|  1.47k|    p[1] ^= 32;
  187|  1.47k|    return 2;
  188|  1.47k|  }
  189|       |  /* An arbitrary transform for three byte characters. */
  190|  3.42k|  p[2] ^= 5;
  191|  3.42k|  return 3;
  192|  4.90k|}

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

decode.c:BrotliBitReaderUnload:
  223|  87.1k|static BROTLI_INLINE void BrotliBitReaderUnload(BrotliBitReader* br) {
  224|  87.1k|  uint32_t unused_bytes = BrotliGetAvailableBits(br) >> 3;
  225|  87.1k|  uint32_t unused_bits = unused_bytes << 3;
  226|  87.1k|  br->avail_in += unused_bytes;
  227|  87.1k|  br->next_in -= unused_bytes;
  228|  87.1k|  if (unused_bits == sizeof(br->val_) << 3) {
  ------------------
  |  Branch (228:7): [True: 1.91k, False: 85.2k]
  ------------------
  229|  1.91k|    br->val_ = 0;
  230|  85.2k|  } else {
  231|  85.2k|    br->val_ <<= unused_bits;
  232|  85.2k|  }
  233|  87.1k|  br->bit_pos_ += unused_bits;
  234|  87.1k|}
decode.c:BrotliTakeBits:
  239|  94.0M|  BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
  240|  94.0M|  *val = (uint32_t)BrotliGetBitsUnmasked(br) & BitMask(n_bits);
  241|  94.0M|  BROTLI_LOG(("[BrotliTakeBits]  %d %d %d val: %6x\n",
  242|  94.0M|      (int)br->avail_in, (int)br->bit_pos_, (int)n_bits, (int)*val));
  243|  94.0M|  BrotliDropBits(br, n_bits);
  244|  94.0M|}
decode.c:BrotliGetBitsUnmasked:
  184|  1.63G|    BrotliBitReader* const br) {
  185|  1.63G|  return br->val_ >> br->bit_pos_;
  186|  1.63G|}
decode.c:BrotliDropBits:
  219|  1.55G|    BrotliBitReader* const br, uint32_t n_bits) {
  220|  1.55G|  br->bit_pos_ += n_bits;
  221|  1.55G|}
decode.c:BrotliSafeReadBits:
  292|   935k|    BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
  293|   935k|  BROTLI_DCHECK(n_bits <= 24);
  294|  1.67M|  while (BrotliGetAvailableBits(br) < n_bits) {
  ------------------
  |  Branch (294:10): [True: 743k, False: 934k]
  ------------------
  295|   743k|    if (!BrotliPullByte(br)) {
  ------------------
  |  Branch (295:9): [True: 932, False: 742k]
  ------------------
  296|    932|      return BROTLI_FALSE;
  ------------------
  |  |   53|    932|#define BROTLI_FALSE 0
  ------------------
  297|    932|    }
  298|   743k|  }
  299|   934k|  BrotliTakeBits(br, n_bits, val);
  300|   934k|  return BROTLI_TRUE;
  ------------------
  |  |   51|   934k|#define BROTLI_TRUE 1
  ------------------
  301|   935k|}
decode.c:BrotliPullByte:
  165|   276M|static BROTLI_INLINE BROTLI_BOOL BrotliPullByte(BrotliBitReader* const br) {
  166|   276M|  if (br->avail_in == 0) {
  ------------------
  |  Branch (166:7): [True: 275M, False: 871k]
  ------------------
  167|   275M|    return BROTLI_FALSE;
  ------------------
  |  |   53|   275M|#define BROTLI_FALSE 0
  ------------------
  168|   275M|  }
  169|   871k|  br->val_ >>= 8;
  170|   871k|#if (BROTLI_64_BITS)
  171|   871k|  br->val_ |= ((uint64_t)*br->next_in) << 56;
  172|       |#else
  173|       |  br->val_ |= ((uint32_t)*br->next_in) << 24;
  174|       |#endif
  175|   871k|  br->bit_pos_ -= 8;
  176|   871k|  --br->avail_in;
  177|   871k|  ++br->next_in;
  178|   871k|  return BROTLI_TRUE;
  ------------------
  |  |   51|   871k|#define BROTLI_TRUE 1
  ------------------
  179|   276M|}
decode.c:BrotliJumpToByteBoundary:
  322|  8.42k|static BROTLI_INLINE BROTLI_BOOL BrotliJumpToByteBoundary(BrotliBitReader* br) {
  323|  8.42k|  uint32_t pad_bits_count = BrotliGetAvailableBits(br) & 0x7;
  324|  8.42k|  uint32_t pad_bits = 0;
  325|  8.42k|  if (pad_bits_count != 0) {
  ------------------
  |  Branch (325:7): [True: 7.96k, False: 464]
  ------------------
  326|  7.96k|    BrotliTakeBits(br, pad_bits_count, &pad_bits);
  327|  7.96k|  }
  328|  8.42k|  return TO_BROTLI_BOOL(pad_bits == 0);
  ------------------
  |  |   55|  8.42k|#define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE)
  |  |  ------------------
  |  |  |  |   51|  8.38k|#define BROTLI_TRUE 1
  |  |  ------------------
  |  |               #define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE)
  |  |  ------------------
  |  |  |  |   53|     40|#define BROTLI_FALSE 0
  |  |  ------------------
  |  |  |  Branch (55:28): [True: 8.38k, False: 40]
  |  |  ------------------
  ------------------
  329|  8.42k|}
decode.c:BrotliSafeGetBits:
  207|  1.00G|    BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
  208|  1.00G|  while (BrotliGetAvailableBits(br) < n_bits) {
  ------------------
  |  Branch (208:10): [True: 275M, False: 730M]
  ------------------
  209|   275M|    if (!BrotliPullByte(br)) {
  ------------------
  |  Branch (209:9): [True: 275M, False: 129k]
  ------------------
  210|   275M|      return BROTLI_FALSE;
  ------------------
  |  |   53|   275M|#define BROTLI_FALSE 0
  ------------------
  211|   275M|    }
  212|   275M|  }
  213|   730M|  *val = (uint32_t)BrotliGetBitsUnmasked(br) & BitMask(n_bits);
  214|   730M|  return BROTLI_TRUE;
  ------------------
  |  |   51|   730M|#define BROTLI_TRUE 1
  ------------------
  215|  1.00G|}
decode.c:BrotliCheckInputAmount:
   99|   476M|    BrotliBitReader* const br, size_t num) {
  100|   476M|  return TO_BROTLI_BOOL(br->avail_in >= num);
  ------------------
  |  |   55|   476M|#define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE)
  |  |  ------------------
  |  |  |  |   51|   476M|#define BROTLI_TRUE 1
  |  |  ------------------
  |  |               #define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE)
  |  |  ------------------
  |  |  |  |   53|  57.0k|#define BROTLI_FALSE 0
  |  |  ------------------
  |  |  |  Branch (55:28): [True: 476M, False: 57.0k]
  |  |  ------------------
  ------------------
  101|   476M|}
decode.c:BrotliFillBitWindow16:
  159|  84.2k|static BROTLI_INLINE void BrotliFillBitWindow16(BrotliBitReader* const br) {
  160|  84.2k|  BrotliFillBitWindow(br, 17);
  161|  84.2k|}
decode.c:BrotliFillBitWindow:
  108|   664M|    BrotliBitReader* const br, uint32_t n_bits) {
  109|   664M|#if (BROTLI_64_BITS)
  110|   664M|  if (!BROTLI_ALIGNED_READ && BROTLI_IS_CONSTANT(n_bits) && (n_bits <= 8)) {
  ------------------
  |  |  287|  1.32G|#define BROTLI_ALIGNED_READ (!!0)
  ------------------
                if (!BROTLI_ALIGNED_READ && BROTLI_IS_CONSTANT(n_bits) && (n_bits <= 8)) {
  ------------------
  |  |  459|  1.32G|#define BROTLI_IS_CONSTANT(x) (!!__builtin_constant_p(x))
  |  |  ------------------
  |  |  |  Branch (459:31): [True: 571M, False: 93.1M]
  |  |  ------------------
  ------------------
  |  Branch (110:7): [True: 664M, Folded]
  |  Branch (110:61): [True: 452M, False: 118M]
  ------------------
  111|   452M|    if (br->bit_pos_ >= 56) {
  ------------------
  |  Branch (111:9): [True: 6.38k, False: 452M]
  ------------------
  112|  6.38k|      br->val_ >>= 56;
  113|  6.38k|      br->bit_pos_ ^= 56;  /* here same as -= 56 because of the if condition */
  114|  6.38k|      br->val_ |= BROTLI_UNALIGNED_LOAD64LE(br->next_in) << 8;
  ------------------
  |  |  386|  6.38k|#define BROTLI_UNALIGNED_LOAD64LE BrotliUnalignedRead64
  ------------------
  115|  6.38k|      br->avail_in -= 7;
  116|  6.38k|      br->next_in += 7;
  117|  6.38k|    }
  118|   452M|  } else if (
  119|   212M|      !BROTLI_ALIGNED_READ && BROTLI_IS_CONSTANT(n_bits) && (n_bits <= 16)) {
  ------------------
  |  |  287|   424M|#define BROTLI_ALIGNED_READ (!!0)
  ------------------
                    !BROTLI_ALIGNED_READ && BROTLI_IS_CONSTANT(n_bits) && (n_bits <= 16)) {
  ------------------
  |  |  459|   424M|#define BROTLI_IS_CONSTANT(x) (!!__builtin_constant_p(x))
  |  |  ------------------
  |  |  |  Branch (459:31): [True: 118M, False: 93.1M]
  |  |  ------------------
  ------------------
  |  Branch (119:7): [True: 212M, Folded]
  |  Branch (119:61): [True: 118M, False: 84.2k]
  ------------------
  120|   118M|    if (br->bit_pos_ >= 48) {
  ------------------
  |  Branch (120:9): [True: 32.7k, False: 118M]
  ------------------
  121|  32.7k|      br->val_ >>= 48;
  122|  32.7k|      br->bit_pos_ ^= 48;  /* here same as -= 48 because of the if condition */
  123|  32.7k|      br->val_ |= BROTLI_UNALIGNED_LOAD64LE(br->next_in) << 16;
  ------------------
  |  |  386|  32.7k|#define BROTLI_UNALIGNED_LOAD64LE BrotliUnalignedRead64
  ------------------
  124|  32.7k|      br->avail_in -= 6;
  125|  32.7k|      br->next_in += 6;
  126|  32.7k|    }
  127|   118M|  } else {
  128|  93.2M|    if (br->bit_pos_ >= 32) {
  ------------------
  |  Branch (128:9): [True: 112k, False: 93.0M]
  ------------------
  129|   112k|      br->val_ >>= 32;
  130|   112k|      br->bit_pos_ ^= 32;  /* here same as -= 32 because of the if condition */
  131|   112k|      br->val_ |= ((uint64_t)BROTLI_UNALIGNED_LOAD32LE(br->next_in)) << 32;
  ------------------
  |  |  385|   112k|#define BROTLI_UNALIGNED_LOAD32LE BrotliUnalignedRead32
  ------------------
  132|   112k|      br->avail_in -= BROTLI_SHORT_FILL_BIT_WINDOW_READ;
  ------------------
  |  |   22|   112k|#define BROTLI_SHORT_FILL_BIT_WINDOW_READ (sizeof(brotli_reg_t) >> 1)
  ------------------
  133|   112k|      br->next_in += BROTLI_SHORT_FILL_BIT_WINDOW_READ;
  ------------------
  |  |   22|   112k|#define BROTLI_SHORT_FILL_BIT_WINDOW_READ (sizeof(brotli_reg_t) >> 1)
  ------------------
  134|   112k|    }
  135|  93.2M|  }
  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|   664M|}
decode.c:BrotliGetRemainingBytes:
   90|  1.73k|static BROTLI_INLINE size_t BrotliGetRemainingBytes(BrotliBitReader* br) {
   91|  1.73k|  static const size_t kCap = (size_t)1 << BROTLI_LARGE_MAX_WBITS;
  ------------------
  |  |   57|  1.73k|#define BROTLI_LARGE_MAX_WBITS 30
  ------------------
   92|  1.73k|  if (br->avail_in > kCap) return kCap;
  ------------------
  |  Branch (92:7): [True: 0, False: 1.73k]
  ------------------
   93|  1.73k|  return br->avail_in + (BrotliGetAvailableBits(br) >> 3);
   94|  1.73k|}
decode.c:BrotliCopyBytes:
  335|  1.73k|                                          BrotliBitReader* br, size_t num) {
  336|  2.46k|  while (BrotliGetAvailableBits(br) >= 8 && num > 0) {
  ------------------
  |  Branch (336:10): [True: 1.06k, False: 1.39k]
  |  Branch (336:45): [True: 722, False: 347]
  ------------------
  337|    722|    *dest = (uint8_t)BrotliGetBitsUnmasked(br);
  338|    722|    BrotliDropBits(br, 8);
  339|    722|    ++dest;
  340|    722|    --num;
  341|    722|  }
  342|  1.73k|  memcpy(dest, br->next_in, num);
  343|  1.73k|  br->avail_in -= num;
  344|  1.73k|  br->next_in += num;
  345|  1.73k|}
decode.c:BitMask:
   26|  1.28G|static BROTLI_INLINE uint32_t BitMask(uint32_t n) {
   27|  1.28G|  if (BROTLI_IS_CONSTANT(n) || BROTLI_HAS_UBFX) {
  ------------------
  |  |  459|  2.57G|#define BROTLI_IS_CONSTANT(x) (!!__builtin_constant_p(x))
  |  |  ------------------
  |  |  |  Branch (459:31): [True: 1.18G, False: 104M]
  |  |  ------------------
  ------------------
                if (BROTLI_IS_CONSTANT(n) || BROTLI_HAS_UBFX) {
  ------------------
  |  |  467|   104M|#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.18G|    return ~((0xFFFFFFFFu) << n);
   31|  1.18G|  } else {
   32|   104M|    return kBrotliBitMask[n];
   33|   104M|  }
   34|  1.28G|}
decode.c:BrotliReadBits24:
  250|  91.1M|    BrotliBitReader* const br, uint32_t n_bits) {
  251|  91.1M|  BROTLI_DCHECK(n_bits <= 24);
  252|  91.1M|  if (BROTLI_64_BITS || (n_bits <= 16)) {
  ------------------
  |  |  235|   182M|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 91.1M, Folded]
  |  |  ------------------
  ------------------
  |  Branch (252:25): [True: 0, False: 0]
  ------------------
  253|  91.1M|    uint32_t val;
  254|  91.1M|    BrotliFillBitWindow(br, n_bits);
  255|  91.1M|    BrotliTakeBits(br, n_bits, &val);
  256|  91.1M|    return val;
  257|  91.1M|  } else {
  258|      0|    uint32_t low_val;
  259|      0|    uint32_t high_val;
  260|      0|    BrotliFillBitWindow(br, 16);
  261|      0|    BrotliTakeBits(br, 16, &low_val);
  262|      0|    BrotliFillBitWindow(br, 8);
  263|      0|    BrotliTakeBits(br, n_bits - 16, &high_val);
  264|      0|    return low_val | (high_val << 16);
  265|      0|  }
  266|  91.1M|}
decode.c:BrotliBitReaderSaveState:
   67|   182M|    BrotliBitReader* const from, BrotliBitReaderState* to) {
   68|   182M|  to->val_ = from->val_;
   69|   182M|  to->bit_pos_ = from->bit_pos_;
   70|   182M|  to->next_in = from->next_in;
   71|   182M|  to->avail_in = from->avail_in;
   72|   182M|}
decode.c:BrotliBitReaderRestoreState:
   75|    634|    BrotliBitReader* const to, BrotliBitReaderState* from) {
   76|    634|  to->val_ = from->val_;
   77|    634|  to->bit_pos_ = from->bit_pos_;
   78|    634|  to->next_in = from->next_in;
   79|    634|  to->avail_in = from->avail_in;
   80|    634|}
decode.c:BrotliGetBits:
  199|   452M|    BrotliBitReader* const br, uint32_t n_bits) {
  200|   452M|  BrotliFillBitWindow(br, n_bits);
  201|   452M|  return (uint32_t)BrotliGetBitsUnmasked(br) & BitMask(n_bits);
  202|   452M|}
decode.c:BrotliGet16BitsUnmasked:
  191|   118M|    BrotliBitReader* const br) {
  192|   118M|  BrotliFillBitWindow(br, 16);
  193|   118M|  return (uint32_t)BrotliGetBitsUnmasked(br);
  194|   118M|}
decode.c:BrotliReadBits32:
  270|  1.92M|    BrotliBitReader* const br, uint32_t n_bits) {
  271|  1.92M|  BROTLI_DCHECK(n_bits <= 32);
  272|  1.92M|  if (BROTLI_64_BITS || (n_bits <= 16)) {
  ------------------
  |  |  235|  3.84M|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 1.92M, Folded]
  |  |  ------------------
  ------------------
  |  Branch (272:25): [True: 0, False: 0]
  ------------------
  273|  1.92M|    uint32_t val;
  274|  1.92M|    BrotliFillBitWindow(br, n_bits);
  275|  1.92M|    BrotliTakeBits(br, n_bits, &val);
  276|  1.92M|    return val;
  277|  1.92M|  } 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.92M|}
decode.c:BrotliSafeReadBits32:
  305|  3.40k|    BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
  306|  3.40k|  BROTLI_DCHECK(n_bits <= 32);
  307|  3.40k|  if (BROTLI_64_BITS || (n_bits <= 24)) {
  ------------------
  |  |  235|  6.80k|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 3.40k, Folded]
  |  |  ------------------
  ------------------
  |  Branch (307:25): [True: 0, False: 0]
  ------------------
  308|  3.53k|    while (BrotliGetAvailableBits(br) < n_bits) {
  ------------------
  |  Branch (308:12): [True: 317, False: 3.21k]
  ------------------
  309|    317|      if (!BrotliPullByte(br)) {
  ------------------
  |  Branch (309:11): [True: 188, False: 129]
  ------------------
  310|    188|        return BROTLI_FALSE;
  ------------------
  |  |   53|    188|#define BROTLI_FALSE 0
  ------------------
  311|    188|      }
  312|    317|    }
  313|  3.21k|    BrotliTakeBits(br, n_bits, val);
  314|  3.21k|    return BROTLI_TRUE;
  ------------------
  |  |   51|  3.21k|#define BROTLI_TRUE 1
  ------------------
  315|  3.40k|  } else {
  316|      0|    return BrotliSafeReadBits32Slow(br, n_bits, val);
  317|      0|  }
  318|  3.40k|}
decode.c:BrotliGetAvailableBits:
   83|  1.28G|    const BrotliBitReader* br) {
   84|  1.28G|  return (BROTLI_64_BITS ? 64 : 32) - br->bit_pos_;
  ------------------
  |  |  235|  1.28G|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 1.28G, Folded]
  |  |  ------------------
  ------------------
   85|  1.28G|}
bit_reader.c:BrotliGetAvailableBits:
   83|  43.9k|    const BrotliBitReader* br) {
   84|  43.9k|  return (BROTLI_64_BITS ? 64 : 32) - br->bit_pos_;
  ------------------
  |  |  235|  43.9k|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 43.9k, Folded]
  |  |  ------------------
  ------------------
   85|  43.9k|}
bit_reader.c:BrotliPullByte:
  165|  18.7k|static BROTLI_INLINE BROTLI_BOOL BrotliPullByte(BrotliBitReader* const br) {
  166|  18.7k|  if (br->avail_in == 0) {
  ------------------
  |  Branch (166:7): [True: 198, False: 18.5k]
  ------------------
  167|    198|    return BROTLI_FALSE;
  ------------------
  |  |   53|    198|#define BROTLI_FALSE 0
  ------------------
  168|    198|  }
  169|  18.5k|  br->val_ >>= 8;
  170|  18.5k|#if (BROTLI_64_BITS)
  171|  18.5k|  br->val_ |= ((uint64_t)*br->next_in) << 56;
  172|       |#else
  173|       |  br->val_ |= ((uint32_t)*br->next_in) << 24;
  174|       |#endif
  175|  18.5k|  br->bit_pos_ -= 8;
  176|  18.5k|  --br->avail_in;
  177|  18.5k|  ++br->next_in;
  178|  18.5k|  return BROTLI_TRUE;
  ------------------
  |  |   51|  18.5k|#define BROTLI_TRUE 1
  ------------------
  179|  18.7k|}

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

BrotliBuildCodeLengthsHuffmanTable:
  106|  4.25k|                                        uint16_t* count) {
  107|  4.25k|  HuffmanCode code;       /* current table entry */
  108|  4.25k|  int symbol;             /* symbol index in original or sorted table */
  109|  4.25k|  brotli_reg_t key;       /* prefix code */
  ------------------
  |  |  241|  4.25k|#define brotli_reg_t uint64_t
  ------------------
  110|  4.25k|  brotli_reg_t key_step;  /* prefix code addend */
  ------------------
  |  |  241|  4.25k|#define brotli_reg_t uint64_t
  ------------------
  111|  4.25k|  int step;               /* step size to replicate values in current table */
  112|  4.25k|  int table_size;         /* size of current table */
  113|  4.25k|  int sorted[BROTLI_CODE_LENGTH_CODES];  /* symbols sorted by code length */
  114|       |  /* offsets in sorted table for each length */
  115|  4.25k|  int offset[BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH + 1];
  116|  4.25k|  int bits;
  117|  4.25k|  int bits_count;
  118|  4.25k|  BROTLI_DCHECK(BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH <=
  119|  4.25k|                BROTLI_REVERSE_BITS_MAX);
  120|       |
  121|       |  /* Generate offsets into sorted symbol table by code length. */
  122|  4.25k|  symbol = -1;
  123|  4.25k|  bits = 1;
  124|  4.25k|  BROTLI_REPEAT(BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH, {
  ------------------
  |  |  505|  4.25k|#define BROTLI_REPEAT(N, X) {     \
  |  |  506|  4.25k|  if ((N & 1) != 0) {X;}          \
  |  |  ------------------
  |  |  |  Branch (506:7): [True: 4.25k, Folded]
  |  |  ------------------
  |  |  507|  4.25k|  if ((N & 2) != 0) {X; X;}       \
  |  |  ------------------
  |  |  |  Branch (507:7): [Folded, False: 4.25k]
  |  |  ------------------
  |  |  508|  4.25k|  if ((N & 4) != 0) {X; X; X; X;} \
  |  |  ------------------
  |  |  |  Branch (508:7): [True: 4.25k, Folded]
  |  |  ------------------
  |  |  509|  4.25k|}
  ------------------
  125|  4.25k|    symbol += count[bits];
  126|  4.25k|    offset[bits] = symbol;
  127|  4.25k|    bits++;
  128|  4.25k|  });
  129|       |  /* Symbols with code length 0 are placed after all other symbols. */
  130|  4.25k|  offset[0] = BROTLI_CODE_LENGTH_CODES - 1;
  ------------------
  |  |   36|  4.25k|#define BROTLI_CODE_LENGTH_CODES (BROTLI_REPEAT_ZERO_CODE_LENGTH + 1)
  |  |  ------------------
  |  |  |  |   35|  4.25k|#define BROTLI_REPEAT_ZERO_CODE_LENGTH 17
  |  |  ------------------
  ------------------
  131|       |
  132|       |  /* Sort symbols by length, by symbol order within each length. */
  133|  4.25k|  symbol = BROTLI_CODE_LENGTH_CODES;
  ------------------
  |  |   36|  4.25k|#define BROTLI_CODE_LENGTH_CODES (BROTLI_REPEAT_ZERO_CODE_LENGTH + 1)
  |  |  ------------------
  |  |  |  |   35|  4.25k|#define BROTLI_REPEAT_ZERO_CODE_LENGTH 17
  |  |  ------------------
  ------------------
  134|  12.7k|  do {
  135|  12.7k|    BROTLI_REPEAT(6, {
  ------------------
  |  |  505|  12.7k|#define BROTLI_REPEAT(N, X) {     \
  |  |  506|  12.7k|  if ((N & 1) != 0) {X;}          \
  |  |  ------------------
  |  |  |  Branch (506:7): [Folded, False: 12.7k]
  |  |  ------------------
  |  |  507|  12.7k|  if ((N & 2) != 0) {X; X;}       \
  |  |  ------------------
  |  |  |  Branch (507:7): [True: 12.7k, Folded]
  |  |  ------------------
  |  |  508|  12.7k|  if ((N & 4) != 0) {X; X; X; X;} \
  |  |  ------------------
  |  |  |  Branch (508:7): [True: 12.7k, Folded]
  |  |  ------------------
  |  |  509|  12.7k|}
  ------------------
  136|  12.7k|      symbol--;
  137|  12.7k|      sorted[offset[code_lengths[symbol]]--] = symbol;
  138|  12.7k|    });
  139|  12.7k|  } while (symbol != 0);
  ------------------
  |  Branch (139:12): [True: 8.51k, False: 4.25k]
  ------------------
  140|       |
  141|  4.25k|  table_size = 1 << BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH;
  ------------------
  |  |   28|  4.25k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH 5
  ------------------
  142|       |
  143|       |  /* Special case: all symbols but one have 0 code length. */
  144|  4.25k|  if (offset[0] == 0) {
  ------------------
  |  Branch (144:7): [True: 267, False: 3.99k]
  ------------------
  145|    267|    code = ConstructHuffmanCode(0, (uint16_t)sorted[0]);
  146|  8.81k|    for (key = 0; key < (brotli_reg_t)table_size; ++key) {
  ------------------
  |  Branch (146:19): [True: 8.54k, False: 267]
  ------------------
  147|  8.54k|      table[key] = code;
  148|  8.54k|    }
  149|    267|    return;
  150|    267|  }
  151|       |
  152|       |  /* Fill in table. */
  153|  3.99k|  key = 0;
  154|  3.99k|  key_step = BROTLI_REVERSE_BITS_LOWEST;
  ------------------
  |  |   65|  3.99k|  ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   21|  3.99k|#define BROTLI_REVERSE_BITS_MAX 8
  |  |  ------------------
  |  |                 ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   27|  3.99k|#define BROTLI_REVERSE_BITS_BASE 0
  |  |  ------------------
  ------------------
  155|  3.99k|  symbol = 0;
  156|  3.99k|  bits = 1;
  157|  3.99k|  step = 2;
  158|  19.9k|  do {
  159|  42.3k|    for (bits_count = count[bits]; bits_count != 0; --bits_count) {
  ------------------
  |  Branch (159:36): [True: 22.3k, False: 19.9k]
  ------------------
  160|  22.3k|      code = ConstructHuffmanCode((uint8_t)bits, (uint16_t)sorted[symbol++]);
  161|  22.3k|      ReplicateValue(&table[BrotliReverseBits(key)], step, table_size, code);
  162|  22.3k|      key += key_step;
  163|  22.3k|    }
  164|  19.9k|    step <<= 1;
  165|  19.9k|    key_step >>= 1;
  166|  19.9k|  } while (++bits <= BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH);
  ------------------
  |  |   28|  19.9k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH 5
  ------------------
  |  Branch (166:12): [True: 15.9k, False: 3.99k]
  ------------------
  167|  3.99k|}
BrotliBuildHuffmanTable:
  172|  4.00k|                                 uint16_t* count) {
  173|  4.00k|  HuffmanCode code;       /* current table entry */
  174|  4.00k|  HuffmanCode* table;     /* next available space in table */
  175|  4.00k|  int len;                /* current code length */
  176|  4.00k|  int symbol;             /* symbol index in original or sorted table */
  177|  4.00k|  brotli_reg_t key;       /* prefix code */
  ------------------
  |  |  241|  4.00k|#define brotli_reg_t uint64_t
  ------------------
  178|  4.00k|  brotli_reg_t key_step;  /* prefix code addend */
  ------------------
  |  |  241|  4.00k|#define brotli_reg_t uint64_t
  ------------------
  179|  4.00k|  brotli_reg_t sub_key;   /* 2nd level table prefix code */
  ------------------
  |  |  241|  4.00k|#define brotli_reg_t uint64_t
  ------------------
  180|  4.00k|  brotli_reg_t sub_key_step;  /* 2nd level table prefix code addend */
  ------------------
  |  |  241|  4.00k|#define brotli_reg_t uint64_t
  ------------------
  181|  4.00k|  int step;               /* step size to replicate values in current table */
  182|  4.00k|  int table_bits;         /* key length of current table */
  183|  4.00k|  int table_size;         /* size of current table */
  184|  4.00k|  int total_size;         /* sum of root table size and 2nd level table sizes */
  185|  4.00k|  int max_length = -1;
  186|  4.00k|  int bits;
  187|  4.00k|  int bits_count;
  188|       |
  189|  4.00k|  BROTLI_DCHECK(root_bits <= BROTLI_REVERSE_BITS_MAX);
  190|  4.00k|  BROTLI_DCHECK(BROTLI_HUFFMAN_MAX_CODE_LENGTH - root_bits <=
  191|  4.00k|                BROTLI_REVERSE_BITS_MAX);
  192|       |
  193|  53.3k|  while (symbol_lists[max_length] == 0xFFFF) max_length--;
  ------------------
  |  Branch (193:10): [True: 49.3k, False: 4.00k]
  ------------------
  194|  4.00k|  max_length += BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1;
  ------------------
  |  |   19|  4.00k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH 15
  ------------------
  195|       |
  196|  4.00k|  table = root_table;
  197|  4.00k|  table_bits = root_bits;
  198|  4.00k|  table_size = 1 << table_bits;
  199|  4.00k|  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|  4.00k|  if (table_bits > max_length) {
  ------------------
  |  Branch (203:7): [True: 3.48k, False: 514]
  ------------------
  204|  3.48k|    table_bits = max_length;
  205|  3.48k|    table_size = 1 << table_bits;
  206|  3.48k|  }
  207|  4.00k|  key = 0;
  208|  4.00k|  key_step = BROTLI_REVERSE_BITS_LOWEST;
  ------------------
  |  |   65|  4.00k|  ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   21|  4.00k|#define BROTLI_REVERSE_BITS_MAX 8
  |  |  ------------------
  |  |                 ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   27|  4.00k|#define BROTLI_REVERSE_BITS_BASE 0
  |  |  ------------------
  ------------------
  209|  4.00k|  bits = 1;
  210|  4.00k|  step = 2;
  211|  9.41k|  do {
  212|  9.41k|    symbol = bits - (BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1);
  ------------------
  |  |   19|  9.41k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH 15
  ------------------
  213|  64.5k|    for (bits_count = count[bits]; bits_count != 0; --bits_count) {
  ------------------
  |  Branch (213:36): [True: 55.1k, False: 9.41k]
  ------------------
  214|  55.1k|      symbol = symbol_lists[symbol];
  215|  55.1k|      code = ConstructHuffmanCode((uint8_t)bits, (uint16_t)symbol);
  216|  55.1k|      ReplicateValue(&table[BrotliReverseBits(key)], step, table_size, code);
  217|  55.1k|      key += key_step;
  218|  55.1k|    }
  219|  9.41k|    step <<= 1;
  220|  9.41k|    key_step >>= 1;
  221|  9.41k|  } while (++bits <= table_bits);
  ------------------
  |  Branch (221:12): [True: 5.41k, False: 4.00k]
  ------------------
  222|       |
  223|       |  /* If root_bits != table_bits then replicate to fill the remaining slots. */
  224|  26.5k|  while (total_size != table_size) {
  ------------------
  |  Branch (224:10): [True: 22.5k, False: 4.00k]
  ------------------
  225|  22.5k|    memcpy(&table[table_size], &table[0],
  226|  22.5k|           (size_t)table_size * sizeof(table[0]));
  227|  22.5k|    table_size <<= 1;
  228|  22.5k|  }
  229|       |
  230|       |  /* Fill in 2nd level tables and add pointers to root table. */
  231|  4.00k|  key_step = BROTLI_REVERSE_BITS_LOWEST >> (root_bits - 1);
  ------------------
  |  |   65|  4.00k|  ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   21|  4.00k|#define BROTLI_REVERSE_BITS_MAX 8
  |  |  ------------------
  |  |                 ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   27|  4.00k|#define BROTLI_REVERSE_BITS_BASE 0
  |  |  ------------------
  ------------------
  232|  4.00k|  sub_key = (BROTLI_REVERSE_BITS_LOWEST << 1);
  ------------------
  |  |   65|  4.00k|  ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   21|  4.00k|#define BROTLI_REVERSE_BITS_MAX 8
  |  |  ------------------
  |  |                 ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   27|  4.00k|#define BROTLI_REVERSE_BITS_BASE 0
  |  |  ------------------
  ------------------
  233|  4.00k|  sub_key_step = BROTLI_REVERSE_BITS_LOWEST;
  ------------------
  |  |   65|  4.00k|  ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   21|  4.00k|#define BROTLI_REVERSE_BITS_MAX 8
  |  |  ------------------
  |  |                 ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   27|  4.00k|#define BROTLI_REVERSE_BITS_BASE 0
  |  |  ------------------
  ------------------
  234|  5.22k|  for (len = root_bits + 1, step = 2; len <= max_length; ++len) {
  ------------------
  |  Branch (234:39): [True: 1.22k, False: 4.00k]
  ------------------
  235|  1.22k|    symbol = len - (BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1);
  ------------------
  |  |   19|  1.22k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH 15
  ------------------
  236|  37.9k|    for (; count[len] != 0; --count[len]) {
  ------------------
  |  Branch (236:12): [True: 36.6k, False: 1.22k]
  ------------------
  237|  36.6k|      if (sub_key == (BROTLI_REVERSE_BITS_LOWEST << 1U)) {
  ------------------
  |  |   65|  36.6k|  ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   21|  36.6k|#define BROTLI_REVERSE_BITS_MAX 8
  |  |  ------------------
  |  |                 ((brotli_reg_t)1 << (BROTLI_REVERSE_BITS_MAX - 1 + BROTLI_REVERSE_BITS_BASE))
  |  |  ------------------
  |  |  |  |   27|  36.6k|#define BROTLI_REVERSE_BITS_BASE 0
  |  |  ------------------
  ------------------
  |  Branch (237:11): [True: 15.1k, False: 21.5k]
  ------------------
  238|  15.1k|        table += table_size;
  239|  15.1k|        table_bits = NextTableBitSize(count, len, root_bits);
  240|  15.1k|        table_size = 1 << table_bits;
  241|  15.1k|        total_size += table_size;
  242|  15.1k|        sub_key = BrotliReverseBits(key);
  243|  15.1k|        key += key_step;
  244|  15.1k|        root_table[sub_key] = ConstructHuffmanCode(
  245|  15.1k|            (uint8_t)(table_bits + root_bits),
  246|  15.1k|            (uint16_t)(((size_t)(table - root_table)) - sub_key));
  247|  15.1k|        sub_key = 0;
  248|  15.1k|      }
  249|  36.6k|      symbol = symbol_lists[symbol];
  250|  36.6k|      code = ConstructHuffmanCode((uint8_t)(len - root_bits), (uint16_t)symbol);
  251|  36.6k|      ReplicateValue(
  252|  36.6k|          &table[BrotliReverseBits(sub_key)], step, table_size, code);
  253|  36.6k|      sub_key += sub_key_step;
  254|  36.6k|    }
  255|  1.22k|    step <<= 1;
  256|  1.22k|    sub_key_step >>= 1;
  257|  1.22k|  }
  258|  4.00k|  return (uint32_t)total_size;
  259|  4.00k|}
BrotliBuildSimpleHuffmanTable:
  264|  21.5k|                                       uint32_t num_symbols) {
  265|  21.5k|  uint32_t table_size = 1;
  266|  21.5k|  const uint32_t goal_size = 1U << root_bits;
  267|  21.5k|  switch (num_symbols) {
  ------------------
  |  Branch (267:11): [True: 21.5k, False: 0]
  ------------------
  268|  15.4k|    case 0:
  ------------------
  |  Branch (268:5): [True: 15.4k, False: 6.18k]
  ------------------
  269|  15.4k|      table[0] = ConstructHuffmanCode(0, val[0]);
  270|  15.4k|      break;
  271|  2.83k|    case 1:
  ------------------
  |  Branch (271:5): [True: 2.83k, False: 18.7k]
  ------------------
  272|  2.83k|      if (val[1] > val[0]) {
  ------------------
  |  Branch (272:11): [True: 1.79k, False: 1.04k]
  ------------------
  273|  1.79k|        table[0] = ConstructHuffmanCode(1, val[0]);
  274|  1.79k|        table[1] = ConstructHuffmanCode(1, val[1]);
  275|  1.79k|      } else {
  276|  1.04k|        table[0] = ConstructHuffmanCode(1, val[1]);
  277|  1.04k|        table[1] = ConstructHuffmanCode(1, val[0]);
  278|  1.04k|      }
  279|  2.83k|      table_size = 2;
  280|  2.83k|      break;
  281|  1.41k|    case 2:
  ------------------
  |  Branch (281:5): [True: 1.41k, False: 20.1k]
  ------------------
  282|  1.41k|      table[0] = ConstructHuffmanCode(1, val[0]);
  283|  1.41k|      table[2] = ConstructHuffmanCode(1, val[0]);
  284|  1.41k|      if (val[2] > val[1]) {
  ------------------
  |  Branch (284:11): [True: 1.02k, False: 384]
  ------------------
  285|  1.02k|        table[1] = ConstructHuffmanCode(2, val[1]);
  286|  1.02k|        table[3] = ConstructHuffmanCode(2, val[2]);
  287|  1.02k|      } else {
  288|    384|        table[1] = ConstructHuffmanCode(2, val[2]);
  289|    384|        table[3] = ConstructHuffmanCode(2, val[1]);
  290|    384|      }
  291|  1.41k|      table_size = 4;
  292|  1.41k|      break;
  293|  1.43k|    case 3: {
  ------------------
  |  Branch (293:5): [True: 1.43k, False: 20.1k]
  ------------------
  294|  1.43k|      int i, k;
  295|  5.75k|      for (i = 0; i < 3; ++i) {
  ------------------
  |  Branch (295:19): [True: 4.31k, False: 1.43k]
  ------------------
  296|  12.9k|        for (k = i + 1; k < 4; ++k) {
  ------------------
  |  Branch (296:25): [True: 8.62k, False: 4.31k]
  ------------------
  297|  8.62k|          if (val[k] < val[i]) {
  ------------------
  |  Branch (297:15): [True: 4.33k, False: 4.29k]
  ------------------
  298|  4.33k|            uint16_t t = val[k];
  299|  4.33k|            val[k] = val[i];
  300|  4.33k|            val[i] = t;
  301|  4.33k|          }
  302|  8.62k|        }
  303|  4.31k|      }
  304|  1.43k|      table[0] = ConstructHuffmanCode(2, val[0]);
  305|  1.43k|      table[2] = ConstructHuffmanCode(2, val[1]);
  306|  1.43k|      table[1] = ConstructHuffmanCode(2, val[2]);
  307|  1.43k|      table[3] = ConstructHuffmanCode(2, val[3]);
  308|  1.43k|      table_size = 4;
  309|  1.43k|      break;
  310|      0|    }
  311|    497|    case 4: {
  ------------------
  |  Branch (311:5): [True: 497, False: 21.0k]
  ------------------
  312|    497|      if (val[3] < val[2]) {
  ------------------
  |  Branch (312:11): [True: 145, False: 352]
  ------------------
  313|    145|        uint16_t t = val[3];
  314|    145|        val[3] = val[2];
  315|    145|        val[2] = t;
  316|    145|      }
  317|    497|      table[0] = ConstructHuffmanCode(1, val[0]);
  318|    497|      table[1] = ConstructHuffmanCode(2, val[1]);
  319|    497|      table[2] = ConstructHuffmanCode(1, val[0]);
  320|    497|      table[3] = ConstructHuffmanCode(3, val[2]);
  321|    497|      table[4] = ConstructHuffmanCode(1, val[0]);
  322|    497|      table[5] = ConstructHuffmanCode(2, val[1]);
  323|    497|      table[6] = ConstructHuffmanCode(1, val[0]);
  324|    497|      table[7] = ConstructHuffmanCode(3, val[3]);
  325|    497|      table_size = 8;
  326|    497|      break;
  327|      0|    }
  328|  21.5k|  }
  329|   184k|  while (table_size != goal_size) {
  ------------------
  |  Branch (329:10): [True: 162k, False: 21.5k]
  ------------------
  330|   162k|    memcpy(&table[table_size], &table[0],
  331|   162k|           (size_t)table_size * sizeof(table[0]));
  332|   162k|    table_size <<= 1;
  333|   162k|  }
  334|  21.5k|  return goal_size;
  335|  21.5k|}
huffman.c:ReplicateValue:
   82|   114k|                                         HuffmanCode code) {
   83|   310k|  do {
   84|   310k|    end -= step;
   85|   310k|    table[end] = code;
   86|   310k|  } while (end > 0);
  ------------------
  |  Branch (86:12): [True: 195k, False: 114k]
  ------------------
   87|   114k|}
huffman.c:BrotliReverseBits:
   70|   129k|static BROTLI_INLINE brotli_reg_t BrotliReverseBits(brotli_reg_t num) {
   71|       |#if defined(BROTLI_RBIT)
   72|       |  return BROTLI_RBIT(num);
   73|       |#else
   74|   129k|  return kReverseBits[num];
   75|   129k|#endif
   76|   129k|}
huffman.c:NextTableBitSize:
   93|  15.1k|                                          int len, int root_bits) {
   94|  15.1k|  int left = 1 << (len - root_bits);
   95|  15.8k|  while (len < BROTLI_HUFFMAN_MAX_CODE_LENGTH) {
  ------------------
  |  |   19|  15.8k|#define BROTLI_HUFFMAN_MAX_CODE_LENGTH 15
  ------------------
  |  Branch (95:10): [True: 15.7k, False: 137]
  ------------------
   96|  15.7k|    left -= count[len];
   97|  15.7k|    if (left <= 0) break;
  ------------------
  |  Branch (97:9): [True: 15.0k, False: 680]
  ------------------
   98|    680|    ++len;
   99|    680|    left <<= 1;
  100|    680|  }
  101|  15.1k|  return len - root_bits;
  102|  15.1k|}

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

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

_ZN7brunsli27ComputeACPredictMultipliersEPKiPiS2_:
   20|  4.70k|                                 int* mult_col) {
   21|  42.3k|  for (size_t y = 0; y < 8; ++y) {
  ------------------
  |  Branch (21:22): [True: 37.6k, False: 4.70k]
  ------------------
   22|   338k|    for (size_t x = 0; x < 8; ++x) {
  ------------------
  |  Branch (22:24): [True: 301k, False: 37.6k]
  ------------------
   23|   301k|      mult_row[x + 8 * y] =
   24|   301k|          (quant[x + 8 * y] * kSqrt2FixedPoint) / quant[y * 8];
   25|       |      // mult_col is transposed i.e. destination rows and columns are swapped.
   26|   301k|      mult_col[x * 8 + y] = (quant[x + 8 * y] * kSqrt2FixedPoint) / quant[x];
   27|   301k|    }
   28|  37.6k|  }
   29|  4.70k|}
_ZN7brunsli16ComponentStateDC7InitAllEv:
   33|  5.18k|void ComponentStateDC::InitAll() {
   34|  5.18k|  is_zero_prob.Init(135);
   35|  51.8k|  for (size_t i = 0; i < sign_prob.size(); ++i) {
  ------------------
  |  Branch (35:22): [True: 46.6k, False: 5.18k]
  ------------------
   36|  46.6k|    sign_prob[i].Init(128);
   37|  46.6k|  }
   38|  20.7k|  for (size_t i = 0; i < is_empty_block_prob.size(); ++i) {
  ------------------
  |  Branch (38:22): [True: 15.5k, False: 5.18k]
  ------------------
   39|  15.5k|    is_empty_block_prob[i].Init(74);
   40|  15.5k|  }
   41|  57.0k|  for (size_t i = 0; i < first_extra_bit_prob.size(); ++i) {
  ------------------
  |  Branch (41:22): [True: 51.8k, False: 5.18k]
  ------------------
   42|  51.8k|    first_extra_bit_prob[i].Init(150);
   43|  51.8k|  }
   44|  5.18k|}
_ZN7brunsli14ComponentState7InitAllEv:
  223|  4.70k|void ComponentState::InitAll() {
  224|  56.4k|  for (int i = 0; i < kNumNonzeroBuckets; ++i) {
  ------------------
  |  Branch (224:19): [True: 51.7k, False: 4.70k]
  ------------------
  225|  3.36M|    for (int k = 0; k < kDCTBlockSize; ++k) {
  ------------------
  |  Branch (225:21): [True: 3.31M, False: 51.7k]
  ------------------
  226|  3.31M|      const int v = kInitProb[k] + 9 * (i - 7);
  227|  3.31M|      BRUNSLI_DCHECK(v <= 255);
  228|  3.31M|      is_zero_prob[i * kDCTBlockSize + k].Init(v);
  229|  3.31M|    }
  230|  51.7k|  }
  231|  5.12M|  for (size_t i = 0; i < sign_prob.size(); ++i) {
  ------------------
  |  Branch (231:22): [True: 5.12M, False: 4.70k]
  ------------------
  232|  5.12M|    if (i < kMaxAverageContext * kDCTBlockSize) {
  ------------------
  |  Branch (232:9): [True: 2.41M, False: 2.71M]
  ------------------
  233|  2.41M|      sign_prob[i].Init(108);
  234|  2.71M|    } else if (i < (kMaxAverageContext + 1) * kDCTBlockSize) {
  ------------------
  |  Branch (234:16): [True: 301k, False: 2.41M]
  ------------------
  235|   301k|      sign_prob[i].Init(128);
  236|  2.41M|    } else {
  237|  2.41M|      sign_prob[i].Init(148);
  238|  2.41M|    }
  239|  5.12M|  }
  240|  3.01M|  for (size_t i = 0; i < first_extra_bit_prob.size(); ++i) {
  ------------------
  |  Branch (240:22): [True: 3.01M, False: 4.70k]
  ------------------
  241|  3.01M|    first_extra_bit_prob[i].Init(158);
  242|  3.01M|  }
  243|       |
  244|   155k|  for (size_t i = 0; i < kNumNonZeroContextCount; ++i) {
  ------------------
  |  Branch (244:22): [True: 150k, False: 4.70k]
  ------------------
  245|   150k|    Prob* non_zero_probs = num_nonzero_prob + i * kNumNonZeroTreeSize;
  246|  9.64M|    for (size_t j = 0; j < kNumNonZeroTreeSize; ++j) {
  ------------------
  |  Branch (246:24): [True: 9.49M, False: 150k]
  ------------------
  247|  9.49M|      non_zero_probs[j].Init(kInitProbNonzero[i][j]);
  248|  9.49M|    }
  249|   150k|  }
  250|  4.70k|}

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

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

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

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

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

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

_ZN7brunsli25PredictWithAdaptiveMedianEPKsiii:
   29|  37.1M|int PredictWithAdaptiveMedian(const coeff_t* coeffs, int x, int y, int stride) {
   30|  37.1M|  const int offset1 = -kDCTBlockSize;
   31|  37.1M|  const int offset2 = -stride;
   32|  37.1M|  const int offset3 = offset2 + offset1;
   33|  37.1M|  if (y != 0) {
  ------------------
  |  Branch (33:7): [True: 36.3M, False: 823k]
  ------------------
   34|  36.3M|    if (x != 0) {
  ------------------
  |  Branch (34:9): [True: 36.0M, False: 278k]
  ------------------
   35|  36.0M|      return AdaptiveMedian(coeffs[offset1], coeffs[offset2], coeffs[offset3]);
   36|  36.0M|    } else {
   37|   278k|      return coeffs[offset2];
   38|   278k|    }
   39|  36.3M|  } else {
   40|   823k|    return x ? coeffs[offset1] : 0;
  ------------------
  |  Branch (40:12): [True: 818k, False: 5.07k]
  ------------------
   41|   823k|  }
   42|  37.1M|}
predict.cc:_ZN7brunsli12_GLOBAL__N_114AdaptiveMedianEiii:
   15|  36.0M|int AdaptiveMedian(int w, int n, int nw) {
   16|  36.0M|  const int mx = (w > n) ? w : n;
  ------------------
  |  Branch (16:18): [True: 7.21M, False: 28.8M]
  ------------------
   17|  36.0M|  const int mn = w + n - mx;
   18|  36.0M|  if (nw > mx) {
  ------------------
  |  Branch (18:7): [True: 1.28M, False: 34.7M]
  ------------------
   19|  1.28M|    return mn;
   20|  34.7M|  } else if (nw < mn) {
  ------------------
  |  Branch (20:14): [True: 984k, False: 33.8M]
  ------------------
   21|   984k|    return mx;
   22|  33.8M|  } else {
   23|  33.8M|    return n + w - nw;
   24|  33.8M|  }
   25|  36.0M|}

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

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

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

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

_ZN7brunsli20BrunsliBitReaderInitEPNS_16BrunsliBitReaderE:
   13|  20.9k|void BrunsliBitReaderInit(BrunsliBitReader* br) {
   14|  20.9k|  br->num_bits_ = 0;
   15|  20.9k|  br->bits_ = 0;
   16|  20.9k|  br->num_debt_bytes_ = 0;
   17|  20.9k|  br->is_healthy_ = true;
   18|  20.9k|  br->is_optimistic_ = false;
   19|  20.9k|}
_ZN7brunsli22BrunsliBitReaderResumeEPNS_16BrunsliBitReaderEPKhm:
   22|  20.9k|                              size_t length) {
   23|  20.9k|  br->next_ = buffer;
   24|  20.9k|  br->end_ = buffer + length;
   25|  20.9k|  br->is_optimistic_ = false;
   26|  20.9k|}
_ZN7brunsli23BrunsliBitReaderSuspendEPNS_16BrunsliBitReaderE:
   49|  20.9k|size_t BrunsliBitReaderSuspend(BrunsliBitReader* br) {
   50|  20.9k|  BrunsliBitReaderUnload(br);
   51|  20.9k|  size_t unused_bytes = br->end_ - br->next_;
   52|  20.9k|  br->next_ = nullptr;
   53|  20.9k|  br->end_ = nullptr;
   54|  20.9k|  return unused_bytes;
   55|  20.9k|}
_ZN7brunsli22BrunsliBitReaderFinishEPNS_16BrunsliBitReaderE:
   57|  17.1k|void BrunsliBitReaderFinish(BrunsliBitReader* br) {
   58|  17.1k|  uint32_t n_bits = br->num_bits_;
   59|       |  // Likely, did not invoke Suspend before.
   60|  17.1k|  if (n_bits >= 8) {
  ------------------
  |  Branch (60:7): [True: 0, False: 17.1k]
  ------------------
   61|      0|    br->is_healthy_ = false;
   62|      0|    return;
   63|      0|  }
   64|  17.1k|  if (n_bits > 0) {
  ------------------
  |  Branch (64:7): [True: 12.1k, False: 5.05k]
  ------------------
   65|  12.1k|    uint32_t padding_bits = BrunsliBitReaderRead(br, n_bits);
   66|  12.1k|    if (padding_bits != 0) br->is_healthy_ = false;
  ------------------
  |  Branch (66:9): [True: 22, False: 12.1k]
  ------------------
   67|  12.1k|  }
   68|  17.1k|}
_ZN7brunsli25BrunsliBitReaderIsHealthyEPNS_16BrunsliBitReaderE:
   70|  39.1k|bool BrunsliBitReaderIsHealthy(BrunsliBitReader* br) {
   71|  39.1k|  BrunsliBitReaderUnload(br);
   72|  39.1k|  return (br->num_debt_bytes_ == 0) && (br->is_healthy_);
  ------------------
  |  Branch (72:10): [True: 38.9k, False: 208]
  |  Branch (72:40): [True: 38.8k, False: 22]
  ------------------
   73|  39.1k|}
_ZN7brunsli29BrunsliBitReaderSetOptimisticEPNS_16BrunsliBitReaderE:
   75|  5.07k|void BrunsliBitReaderSetOptimistic(BrunsliBitReader* br) {
   76|  5.07k|  br->is_optimistic_ = true;
   77|  5.07k|}
_ZN7brunsli23BrunsliBitReaderCanReadEPNS_16BrunsliBitReaderEm:
   79|  3.14M|bool BrunsliBitReaderCanRead(BrunsliBitReader* br, size_t n_bits) {
   80|  3.14M|  if (br->is_optimistic_) return true;
  ------------------
  |  Branch (80:7): [True: 729k, False: 2.41M]
  ------------------
   81|  2.41M|  if (br->num_debt_bytes_ != 0) return false;
  ------------------
  |  Branch (81:7): [True: 0, False: 2.41M]
  ------------------
   82|  2.41M|  if (br->num_bits_ >= n_bits) return true;
  ------------------
  |  Branch (82:7): [True: 870k, False: 1.54M]
  ------------------
   83|  1.54M|  size_t num_extra_bytes = (n_bits - br->num_bits_ + 7) >> 3;
   84|  1.54M|  return (br->next_ + num_extra_bytes <= br->end_);
   85|  2.41M|}
bit_reader.cc:_ZN7brunsliL22BrunsliBitReaderUnloadEPNS_16BrunsliBitReaderE:
   35|  60.0k|static BRUNSLI_INLINE void BrunsliBitReaderUnload(BrunsliBitReader* br) {
   36|       |  // Cancel the overdraft.
   37|  60.2k|  while ((br->num_debt_bytes_ > 0) && (br->num_bits_ >= 8)) {
  ------------------
  |  Branch (37:10): [True: 661, False: 59.5k]
  |  Branch (37:39): [True: 121, False: 540]
  ------------------
   38|    121|    br->num_debt_bytes_--;
   39|    121|    br->num_bits_ -= 8;
   40|    121|  }
   41|       |  // Return unused bytes.
   42|  60.4k|  while (br->num_bits_ >= 8) {
  ------------------
  |  Branch (42:10): [True: 375, False: 60.0k]
  ------------------
   43|    375|    br->next_--;
   44|    375|    br->num_bits_ -= 8;
   45|    375|  }
   46|  60.0k|  br->bits_ &= BrunsliBitReaderBitMask(br->num_bits_);
   47|  60.0k|}

_ZN7brunsli20BrunsliBitReaderReadEPNS_16BrunsliBitReaderEj:
  127|  2.62M|                                                    uint32_t n_bits) {
  128|  2.62M|  uint32_t result = BrunsliBitReaderGet(br, n_bits);
  129|  2.62M|  BrunsliBitReaderDrop(br, n_bits);
  130|  2.62M|  return result;
  131|  2.62M|}
brunsli_decode.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|  2.47M|                                                   uint32_t n_bits) {
  110|  2.47M|  BRUNSLI_DCHECK(n_bits <= 24);
  111|  2.47M|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|  2.47M|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 1.42k, False: 2.47M]
  ------------------
  113|  1.42k|    BrunsliBitReaderMaybeFetchByte(br, n_bits);
  114|  1.42k|    if (n_bits > 16) BrunsliBitReaderMaybeFetchByte(br, n_bits);
  ------------------
  |  Branch (114:9): [True: 0, False: 1.42k]
  ------------------
  115|  1.42k|  }
  116|  2.47M|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|  2.47M|}
brunsli_decode.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|  2.48M|                                                          uint32_t n_bits) {
   81|  2.48M|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 1.47M, False: 1.00M]
  ------------------
   82|  1.47M|    if (BRUNSLI_PREDICT_FALSE(br->next_ >= br->end_)) {
  ------------------
  |  |   85|  1.47M|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 29, False: 1.47M]
  |  |  ------------------
  ------------------
   83|     29|      BrunsliBitReaderOweByte(br);
   84|  1.47M|    } else {
   85|  1.47M|      br->bits_ |= static_cast<uint32_t>(*br->next_) << br->num_bits_;
   86|  1.47M|      br->num_bits_ += 8;
   87|  1.47M|      br->next_++;
   88|  1.47M|    }
   89|  1.47M|  }
   90|  2.48M|}
brunsli_decode.cc:_ZN7brunsliL23BrunsliBitReaderOweByteEPNS_16BrunsliBitReaderE:
   73|     29|static BRUNSLI_INLINE void BrunsliBitReaderOweByte(BrunsliBitReader* br) {
   74|     29|  br->num_bits_ += 8;
   75|     29|  br->num_debt_bytes_++;
   76|     29|}
brunsli_decode.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|  2.47M|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|  2.47M|  return ~((0xFFFFFFFFu) << n);
   70|  2.47M|}
brunsli_decode.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|  2.47M|                                                uint32_t n_bits) {
  121|  2.47M|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|  2.47M|  br->bits_ >>= n_bits;
  123|  2.47M|  br->num_bits_ -= n_bits;
  124|  2.47M|}
context_map_decode.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|  9.05k|                                                   uint32_t n_bits) {
  110|  9.05k|  BRUNSLI_DCHECK(n_bits <= 24);
  111|  9.05k|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|  9.05k|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 93, False: 8.96k]
  ------------------
  113|     93|    BrunsliBitReaderMaybeFetchByte(br, n_bits);
  114|     93|    if (n_bits > 16) BrunsliBitReaderMaybeFetchByte(br, n_bits);
  ------------------
  |  Branch (114:9): [True: 0, False: 93]
  ------------------
  115|     93|  }
  116|  9.05k|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|  9.05k|}
context_map_decode.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|  9.14k|                                                          uint32_t n_bits) {
   81|  9.14k|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 272, False: 8.87k]
  ------------------
   82|    272|    if (BRUNSLI_PREDICT_FALSE(br->next_ >= br->end_)) {
  ------------------
  |  |   85|    272|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 223, False: 49]
  |  |  ------------------
  ------------------
   83|    223|      BrunsliBitReaderOweByte(br);
   84|    223|    } else {
   85|     49|      br->bits_ |= static_cast<uint32_t>(*br->next_) << br->num_bits_;
   86|     49|      br->num_bits_ += 8;
   87|     49|      br->next_++;
   88|     49|    }
   89|    272|  }
   90|  9.14k|}
context_map_decode.cc:_ZN7brunsliL23BrunsliBitReaderOweByteEPNS_16BrunsliBitReaderE:
   73|    223|static BRUNSLI_INLINE void BrunsliBitReaderOweByte(BrunsliBitReader* br) {
   74|    223|  br->num_bits_ += 8;
   75|    223|  br->num_debt_bytes_++;
   76|    223|}
context_map_decode.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|  9.05k|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|  9.05k|  return ~((0xFFFFFFFFu) << n);
   70|  9.05k|}
context_map_decode.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|  9.05k|                                                uint32_t n_bits) {
  121|  9.05k|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|  9.05k|  br->bits_ >>= n_bits;
  123|  9.05k|  br->num_bits_ -= n_bits;
  124|  9.05k|}
histogram_decode.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|   126k|                                                   uint32_t n_bits) {
  110|   126k|  BRUNSLI_DCHECK(n_bits <= 24);
  111|   126k|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|   126k|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 2.02k, False: 124k]
  ------------------
  113|  2.02k|    BrunsliBitReaderMaybeFetchByte(br, n_bits);
  114|  2.02k|    if (n_bits > 16) BrunsliBitReaderMaybeFetchByte(br, n_bits);
  ------------------
  |  Branch (114:9): [True: 0, False: 2.02k]
  ------------------
  115|  2.02k|  }
  116|   126k|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|   126k|}
histogram_decode.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|   128k|                                                          uint32_t n_bits) {
   81|   128k|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 26.8k, False: 101k]
  ------------------
   82|  26.8k|    if (BRUNSLI_PREDICT_FALSE(br->next_ >= br->end_)) {
  ------------------
  |  |   85|  26.8k|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 579, False: 26.2k]
  |  |  ------------------
  ------------------
   83|    579|      BrunsliBitReaderOweByte(br);
   84|  26.2k|    } else {
   85|  26.2k|      br->bits_ |= static_cast<uint32_t>(*br->next_) << br->num_bits_;
   86|  26.2k|      br->num_bits_ += 8;
   87|  26.2k|      br->next_++;
   88|  26.2k|    }
   89|  26.8k|  }
   90|   128k|}
histogram_decode.cc:_ZN7brunsliL23BrunsliBitReaderOweByteEPNS_16BrunsliBitReaderE:
   73|    579|static BRUNSLI_INLINE void BrunsliBitReaderOweByte(BrunsliBitReader* br) {
   74|    579|  br->num_bits_ += 8;
   75|    579|  br->num_debt_bytes_++;
   76|    579|}
histogram_decode.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|   126k|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|   126k|  return ~((0xFFFFFFFFu) << n);
   70|   126k|}
histogram_decode.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|   126k|                                                uint32_t n_bits) {
  121|   126k|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|   126k|  br->bits_ >>= n_bits;
  123|   126k|  br->num_bits_ -= n_bits;
  124|   126k|}
huffman_decode.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|   803k|                                                   uint32_t n_bits) {
  110|   803k|  BRUNSLI_DCHECK(n_bits <= 24);
  111|   803k|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|   803k|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 54, False: 803k]
  ------------------
  113|     54|    BrunsliBitReaderMaybeFetchByte(br, n_bits);
  114|     54|    if (n_bits > 16) BrunsliBitReaderMaybeFetchByte(br, n_bits);
  ------------------
  |  Branch (114:9): [True: 0, False: 54]
  ------------------
  115|     54|  }
  116|   803k|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|   803k|}
huffman_decode.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|   803k|                                                          uint32_t n_bits) {
   81|   803k|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 41.5k, False: 761k]
  ------------------
   82|  41.5k|    if (BRUNSLI_PREDICT_FALSE(br->next_ >= br->end_)) {
  ------------------
  |  |   85|  41.5k|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 30.0k, False: 11.4k]
  |  |  ------------------
  ------------------
   83|  30.0k|      BrunsliBitReaderOweByte(br);
   84|  30.0k|    } else {
   85|  11.4k|      br->bits_ |= static_cast<uint32_t>(*br->next_) << br->num_bits_;
   86|  11.4k|      br->num_bits_ += 8;
   87|  11.4k|      br->next_++;
   88|  11.4k|    }
   89|  41.5k|  }
   90|   803k|}
huffman_decode.cc:_ZN7brunsliL23BrunsliBitReaderOweByteEPNS_16BrunsliBitReaderE:
   73|  30.0k|static BRUNSLI_INLINE void BrunsliBitReaderOweByte(BrunsliBitReader* br) {
   74|  30.0k|  br->num_bits_ += 8;
   75|  30.0k|  br->num_debt_bytes_++;
   76|  30.0k|}
huffman_decode.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|   803k|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|   803k|  return ~((0xFFFFFFFFu) << n);
   70|   803k|}
huffman_decode.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|   803k|                                                uint32_t n_bits) {
  121|   803k|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|   803k|  br->bits_ >>= n_bits;
  123|   803k|  br->num_bits_ -= n_bits;
  124|   803k|}
bit_reader.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|  72.2k|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|  72.2k|  return ~((0xFFFFFFFFu) << n);
   70|  72.2k|}
bit_reader.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|  12.1k|                                                   uint32_t n_bits) {
  110|  12.1k|  BRUNSLI_DCHECK(n_bits <= 24);
  111|  12.1k|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|  12.1k|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 0, False: 12.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|  12.1k|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|  12.1k|}
bit_reader.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|  12.1k|                                                          uint32_t n_bits) {
   81|  12.1k|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 0, False: 12.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|  12.1k|}
bit_reader.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|  12.1k|                                                uint32_t n_bits) {
  121|  12.1k|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|  12.1k|  br->bits_ >>= n_bits;
  123|  12.1k|  br->num_bits_ -= n_bits;
  124|  12.1k|}

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

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

_ZN7brunsli16DecodeContextMapERKNS_19HuffmanDecodingDataEmPmPNSt3__16vectorIhNS4_9allocatorIhEEEEPNS_16BrunsliBitReaderE:
   44|    599|                               BrunsliBitReader* br) {
   45|    599|  size_t& i = *index;
   46|    599|  uint8_t* map = context_map->data();
   47|    599|  const size_t length = context_map->size();
   48|   790k|  while (i < length) {
  ------------------
  |  Branch (48:10): [True: 789k, False: 448]
  ------------------
   49|       |    // Check there is enough deta for Huffman code, RLE and IMTF bit.
   50|   789k|    if (!BrunsliBitReaderCanRead(br, 15 + max_run_length_prefix + 1)) {
  ------------------
  |  Branch (50:9): [True: 104, False: 789k]
  ------------------
   51|    104|      return BRUNSLI_NOT_ENOUGH_DATA;
   52|    104|    }
   53|   789k|    uint32_t code = entropy.ReadSymbol(br);
   54|   789k|    if (code == 0) {
  ------------------
  |  Branch (54:9): [True: 84.7k, False: 704k]
  ------------------
   55|  84.7k|      map[i] = 0;
   56|  84.7k|      ++i;
   57|   704k|    } else if (code <= max_run_length_prefix) {
  ------------------
  |  Branch (57:16): [True: 8.60k, False: 696k]
  ------------------
   58|  8.60k|      size_t reps = 1u + (1u << code) + (int)BrunsliBitReaderRead(br, code);
   59|   140k|      while (--reps) {
  ------------------
  |  Branch (59:14): [True: 131k, False: 8.55k]
  ------------------
   60|   131k|        if (i >= length) return BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (60:13): [True: 47, False: 131k]
  ------------------
   61|   131k|        map[i] = 0;
   62|   131k|        ++i;
   63|   131k|      }
   64|   696k|    } else {
   65|   696k|      map[i] = (uint8_t)(code - max_run_length_prefix);
   66|   696k|      ++i;
   67|   696k|    }
   68|   789k|  }
   69|    448|  if (BrunsliBitReaderRead(br, 1)) {
  ------------------
  |  Branch (69:7): [True: 343, False: 105]
  ------------------
   70|    343|    InverseMoveToFrontTransform(map, length);
   71|    343|  }
   72|    448|  return BrunsliBitReaderIsHealthy(br) ? BRUNSLI_OK : BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (72:10): [True: 403, False: 45]
  ------------------
   73|    599|}
context_map_decode.cc:_ZN7brunsli12_GLOBAL__N_127InverseMoveToFrontTransformEPhm:
   27|    343|void InverseMoveToFrontTransform(uint8_t* v, size_t v_len) {
   28|    343|  uint8_t mtf[256];
   29|  88.1k|  for (size_t i = 0; i < 256; ++i) {
  ------------------
  |  Branch (29:22): [True: 87.8k, False: 343]
  ------------------
   30|  87.8k|    mtf[i] = static_cast<uint8_t>(i);
   31|  87.8k|  }
   32|   637k|  for (size_t i = 0; i < v_len; ++i) {
  ------------------
  |  Branch (32:22): [True: 636k, False: 343]
  ------------------
   33|   636k|    uint8_t index = v[i];
   34|   636k|    v[i] = mtf[index];
   35|   636k|    if (index) MoveToFront(mtf, index);
  ------------------
  |  Branch (35:9): [True: 620k, False: 16.3k]
  ------------------
   36|   636k|  }
   37|    343|}
context_map_decode.cc:_ZN7brunsli12_GLOBAL__N_111MoveToFrontEPhh:
   20|   620k|void MoveToFront(uint8_t* v, uint8_t index) {
   21|   620k|  uint8_t value = v[index];
   22|   620k|  uint8_t i = index;
   23|  12.9M|  for (; i; --i) v[i] = v[i - 1];
  ------------------
  |  Branch (23:10): [True: 12.3M, False: 620k]
  ------------------
   24|   620k|  v[0] = value;
   25|   620k|}

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

_ZN7brunsli22ReadHuffmanCodeLengthsEPKhmPhPNS_16BrunsliBitReaderE:
   29|    204|                           BrunsliBitReader* br) {
   30|    204|  size_t symbol = 0;
   31|    204|  uint8_t prev_code_len = kDefaultCodeLength;
   32|    204|  size_t repeat = 0;
   33|    204|  uint8_t repeat_code_len = 0;
   34|    204|  const int kFullSpace = 1 << 15;
   35|    204|  int space = kFullSpace;
   36|    204|  HuffmanCode table[32];
   37|       |
   38|    204|  uint16_t counts[16] = {0};
   39|  3.87k|  for (int i = 0; i < kCodeLengthCodes; ++i) {
  ------------------
  |  Branch (39:19): [True: 3.67k, False: 204]
  ------------------
   40|  3.67k|    ++counts[code_length_code_lengths[i]];
   41|  3.67k|  }
   42|    204|  if (!BuildHuffmanTable(table, 5, code_length_code_lengths, kCodeLengthCodes,
  ------------------
  |  Branch (42:7): [True: 0, False: 204]
  ------------------
   43|    204|                         &counts[0])) {
   44|      0|    return false;
   45|      0|  }
   46|       |
   47|  6.69k|  while (symbol < num_symbols && space > 0) {
  ------------------
  |  Branch (47:10): [True: 6.61k, False: 81]
  |  Branch (47:34): [True: 6.51k, False: 100]
  ------------------
   48|  6.51k|    const HuffmanCode* p = table;
   49|  6.51k|    uint8_t code_len;
   50|  6.51k|    p += BrunsliBitReaderGet(br, 5);
   51|  6.51k|    BrunsliBitReaderDrop(br, p->bits);
   52|  6.51k|    code_len = (uint8_t)p->value;
   53|  6.51k|    if (code_len < kCodeLengthRepeatCode) {
  ------------------
  |  Branch (53:9): [True: 5.97k, False: 540]
  ------------------
   54|  5.97k|      repeat = 0;
   55|  5.97k|      code_lengths[symbol++] = code_len;
   56|  5.97k|      if (code_len != 0) {
  ------------------
  |  Branch (56:11): [True: 4.53k, False: 1.43k]
  ------------------
   57|  4.53k|        prev_code_len = code_len;
   58|  4.53k|        space -= kFullSpace >> code_len;
   59|  4.53k|      }
   60|  5.97k|    } else {
   61|    540|      uint32_t extra_bits = code_len - 14;  // >= 2
   62|    540|      size_t old_repeat;
   63|    540|      size_t repeat_delta;
   64|    540|      uint8_t new_len = 0;
   65|    540|      if (code_len == kCodeLengthRepeatCode) {
  ------------------
  |  Branch (65:11): [True: 356, False: 184]
  ------------------
   66|    356|        new_len = prev_code_len;
   67|    356|      }
   68|    540|      if (repeat_code_len != new_len) {
  ------------------
  |  Branch (68:11): [True: 134, False: 406]
  ------------------
   69|    134|        repeat = 0;
   70|    134|        repeat_code_len = new_len;
   71|    134|      }
   72|    540|      old_repeat = repeat;
   73|    540|      if (repeat > 0) {  // >= 3
  ------------------
  |  Branch (73:11): [True: 151, False: 389]
  ------------------
   74|    151|        repeat -= 2;
   75|    151|        repeat <<= extra_bits;
   76|    151|      }
   77|    540|      repeat += BrunsliBitReaderRead(br, extra_bits) + 3u;
   78|    540|      repeat_delta = repeat - old_repeat;
   79|    540|      if (symbol + repeat_delta > num_symbols) {
  ------------------
  |  Branch (79:11): [True: 23, False: 517]
  ------------------
   80|     23|        return false;
   81|     23|      }
   82|    517|      memset(&code_lengths[symbol], repeat_code_len, (size_t)repeat_delta);
   83|    517|      symbol += repeat_delta;
   84|    517|      if (repeat_code_len != 0) {
  ------------------
  |  Branch (84:11): [True: 343, False: 174]
  ------------------
   85|    343|        space -= static_cast<int>(repeat_delta * kFullSpace) >> repeat_code_len;
   86|    343|      }
   87|    517|    }
   88|  6.51k|  }
   89|    181|  if (space != 0) {
  ------------------
  |  Branch (89:7): [True: 68, False: 113]
  ------------------
   90|     68|    return false;
   91|     68|  }
   92|    113|  memset(&code_lengths[symbol], 0, (size_t)(num_symbols - symbol));
   93|    113|  return BrunsliBitReaderIsHealthy(br);
   94|    181|}
_ZN7brunsli19HuffmanDecodingData17ReadFromBitStreamEmPNS_16BrunsliBitReaderEPNS_5ArenaINS_11HuffmanCodeEEE:
  191|    818|    Arena<HuffmanCode>* arena) {
  192|    818|  Arena<HuffmanCode> local_arena;
  193|    818|  if (arena == nullptr) arena = &local_arena;
  ------------------
  |  Branch (193:7): [True: 0, False: 818]
  ------------------
  194|       |
  195|    818|  if (alphabet_size > (1 << kMaxHuffmanBits)) return false;
  ------------------
  |  Branch (195:7): [True: 0, False: 818]
  ------------------
  196|       |
  197|    818|  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|    818|  uint32_t simple_code_or_skip = BrunsliBitReaderRead(br, 2);
  202|    818|  if (simple_code_or_skip == 1u) {
  ------------------
  |  Branch (202:7): [True: 547, False: 271]
  ------------------
  203|    547|    table_.resize(1u << kHuffmanTableBits);
  204|    547|    return ReadSimpleCode(static_cast<uint16_t>(alphabet_size), br,
  205|    547|                          table_.data());
  206|    547|  }
  207|       |
  208|    271|  uint8_t code_length_code_lengths[kCodeLengthCodes] = {0};
  209|    271|  int space = 32;
  210|    271|  int num_codes = 0;
  211|       |  /* Static Huffman code for the code length code lengths */
  212|    271|  static const HuffmanCode huff[16] = {
  213|    271|      {2, 0}, {2, 4}, {2, 3}, {3, 2}, {2, 0}, {2, 4}, {2, 3}, {4, 1},
  214|    271|      {2, 0}, {2, 4}, {2, 3}, {3, 2}, {2, 0}, {2, 4}, {2, 3}, {4, 5},
  215|    271|  };
  216|  3.57k|  for (size_t i = simple_code_or_skip; i < kCodeLengthCodes && space > 0; ++i) {
  ------------------
  |  Branch (216:40): [True: 3.48k, False: 84]
  |  Branch (216:64): [True: 3.30k, False: 187]
  ------------------
  217|  3.30k|    const int code_len_idx = kCodeLengthCodeOrder[i];
  218|  3.30k|    const HuffmanCode* p = huff;
  219|  3.30k|    uint8_t v;
  220|  3.30k|    p += BrunsliBitReaderGet(br, 4);
  221|  3.30k|    BrunsliBitReaderDrop(br, p->bits);
  222|  3.30k|    v = (uint8_t)p->value;
  223|  3.30k|    code_length_code_lengths[code_len_idx] = v;
  224|  3.30k|    if (v != 0) {
  ------------------
  |  Branch (224:9): [True: 1.63k, False: 1.67k]
  ------------------
  225|  1.63k|      space -= (32u >> v);
  226|  1.63k|      ++num_codes;
  227|  1.63k|    }
  228|  3.30k|  }
  229|    271|  bool ok = (num_codes == 1 || space == 0) &&
  ------------------
  |  Branch (229:14): [True: 30, False: 241]
  |  Branch (229:32): [True: 174, False: 67]
  ------------------
  230|    204|       ReadHuffmanCodeLengths(code_length_code_lengths, alphabet_size,
  ------------------
  |  Branch (230:8): [True: 109, False: 95]
  ------------------
  231|    204|                              &code_lengths[0], br);
  232|       |
  233|    271|  if (!ok || !BrunsliBitReaderIsHealthy(br)) return false;
  ------------------
  |  Branch (233:7): [True: 162, False: 109]
  |  Branch (233:14): [True: 0, False: 109]
  ------------------
  234|    109|  uint16_t counts[16] = {0};
  235|  12.4k|  for (size_t i = 0; i < alphabet_size; ++i) {
  ------------------
  |  Branch (235:22): [True: 12.3k, False: 109]
  ------------------
  236|  12.3k|    ++counts[code_lengths[i]];
  237|  12.3k|  }
  238|    109|  arena->reserve(alphabet_size + 376);
  239|    109|  uint32_t table_size =
  240|    109|      BuildHuffmanTable(arena->data(), kHuffmanTableBits, &code_lengths[0],
  241|    109|                        alphabet_size, &counts[0]);
  242|    109|  table_ = std::vector<HuffmanCode>(arena->data(), arena->data() + table_size);
  243|    109|  return (table_size > 0);
  244|    271|}
_ZNK7brunsli19HuffmanDecodingData10ReadSymbolEPNS_16BrunsliBitReaderE:
  247|   789k|uint16_t HuffmanDecodingData::ReadSymbol(BrunsliBitReader* br) const {
  248|   789k|  uint32_t n_bits;
  249|   789k|  const HuffmanCode* table = table_.data();
  250|   789k|  table += BrunsliBitReaderGet(br, kHuffmanTableBits);
  251|   789k|  n_bits = table->bits;
  252|   789k|  if (n_bits > kHuffmanTableBits) {
  ------------------
  |  Branch (252:7): [True: 1.06k, False: 788k]
  ------------------
  253|  1.06k|    BrunsliBitReaderDrop(br, kHuffmanTableBits);
  254|  1.06k|    n_bits -= kHuffmanTableBits;
  255|  1.06k|    table += table->value;
  256|  1.06k|    table += BrunsliBitReaderGet(br, n_bits);
  257|  1.06k|  }
  258|   789k|  BrunsliBitReaderDrop(br, table->bits);
  259|   789k|  return table->value;
  260|   789k|}
huffman_decode.cc:_ZN7brunsliL14ReadSimpleCodeEtPNS_16BrunsliBitReaderEPNS_11HuffmanCodeE:
   98|    547|                                          HuffmanCode* table) {
   99|    547|  uint32_t max_bits =
  100|    547|      (alphabet_size > 1u) ? Log2FloorNonZero(alphabet_size - 1u) + 1 : 0;
  ------------------
  |  Branch (100:7): [True: 547, False: 0]
  ------------------
  101|       |
  102|    547|  size_t num_symbols = BrunsliBitReaderRead(br, 2) + 1;
  103|       |
  104|    547|  uint16_t symbols[4] = {0};
  105|  1.32k|  for (size_t i = 0; i < num_symbols; ++i) {
  ------------------
  |  Branch (105:22): [True: 795, False: 528]
  ------------------
  106|    795|    uint16_t symbol = BrunsliBitReaderRead(br, max_bits);
  107|    795|    if (symbol >= alphabet_size) {
  ------------------
  |  Branch (107:9): [True: 19, False: 776]
  ------------------
  108|     19|      return false;
  109|     19|    }
  110|    776|    symbols[i] = symbol;
  111|    776|  }
  112|       |
  113|    732|  for (size_t i = 0; i < num_symbols - 1; ++i) {
  ------------------
  |  Branch (113:22): [True: 214, False: 518]
  ------------------
  114|    533|    for (size_t j = i + 1; j < num_symbols; ++j) {
  ------------------
  |  Branch (114:28): [True: 329, False: 204]
  ------------------
  115|    329|      if (symbols[i] == symbols[j]) return false;
  ------------------
  |  Branch (115:11): [True: 10, False: 319]
  ------------------
  116|    329|    }
  117|    214|  }
  118|       |
  119|       |  // 4 symbols have to option to encode.
  120|    518|  if (num_symbols == 4) num_symbols += BrunsliBitReaderRead(br, 1);
  ------------------
  |  Branch (120:7): [True: 27, False: 491]
  ------------------
  121|       |
  122|    518|  const auto swap_symbols = [&symbols] (size_t i, size_t j) {
  123|    518|    uint16_t t = symbols[j];
  124|    518|    symbols[j] = symbols[i];
  125|    518|    symbols[i] = t;
  126|    518|  };
  127|       |
  128|    518|  size_t table_size = 1;
  129|    518|  switch (num_symbols) {
  130|    397|    case 1:
  ------------------
  |  Branch (130:5): [True: 397, False: 121]
  ------------------
  131|    397|      table[0] = {0, symbols[0]};
  132|    397|      break;
  133|     74|    case 2:
  ------------------
  |  Branch (133:5): [True: 74, False: 444]
  ------------------
  134|     74|      if (symbols[0] > symbols[1]) swap_symbols(0, 1);
  ------------------
  |  Branch (134:11): [True: 33, False: 41]
  ------------------
  135|     74|      table[0] = {1, symbols[0]};
  136|     74|      table[1] = {1, symbols[1]};
  137|     74|      table_size = 2;
  138|     74|      break;
  139|     20|    case 3:
  ------------------
  |  Branch (139:5): [True: 20, False: 498]
  ------------------
  140|     20|      if (symbols[1] > symbols[2]) swap_symbols(1, 2);
  ------------------
  |  Branch (140:11): [True: 14, False: 6]
  ------------------
  141|     20|      table[0] = {1, symbols[0]};
  142|     20|      table[2] = {1, symbols[0]};
  143|     20|      table[1] = {2, symbols[1]};
  144|     20|      table[3] = {2, symbols[2]};
  145|     20|      table_size = 4;
  146|     20|      break;
  147|     18|    case 4: {
  ------------------
  |  Branch (147:5): [True: 18, False: 500]
  ------------------
  148|     72|      for (size_t i = 0; i < 3; ++i) {
  ------------------
  |  Branch (148:26): [True: 54, False: 18]
  ------------------
  149|    162|        for (size_t j = i + 1; j < 4; ++j) {
  ------------------
  |  Branch (149:32): [True: 108, False: 54]
  ------------------
  150|    108|          if (symbols[i] > symbols[j]) swap_symbols(i, j);
  ------------------
  |  Branch (150:15): [True: 77, False: 31]
  ------------------
  151|    108|        }
  152|     54|      }
  153|     18|      table[0] = {2, symbols[0]};
  154|     18|      table[2] = {2, symbols[1]};
  155|     18|      table[1] = {2, symbols[2]};
  156|     18|      table[3] = {2, symbols[3]};
  157|     18|      table_size = 4;
  158|     18|      break;
  159|      0|    }
  160|      9|    case 5: {
  ------------------
  |  Branch (160:5): [True: 9, False: 509]
  ------------------
  161|      9|      if (symbols[2] > symbols[3]) swap_symbols(2, 3);
  ------------------
  |  Branch (161:11): [True: 6, False: 3]
  ------------------
  162|      9|      table[0] = {1, symbols[0]};
  163|      9|      table[1] = {2, symbols[1]};
  164|      9|      table[2] = {1, symbols[0]};
  165|      9|      table[3] = {3, symbols[2]};
  166|      9|      table[4] = {1, symbols[0]};
  167|      9|      table[5] = {2, symbols[1]};
  168|      9|      table[6] = {1, symbols[0]};
  169|      9|      table[7] = {3, symbols[3]};
  170|      9|      table_size = 8;
  171|      9|      break;
  172|      0|    }
  173|      0|    default: {
  ------------------
  |  Branch (173:5): [True: 0, False: 518]
  ------------------
  174|       |      // Unreachable.
  175|      0|      return false;
  176|      0|    }
  177|    518|  }
  178|       |
  179|    518|  const uint32_t goal_size = 1u << kHuffmanTableBits;
  180|  4.48k|  while (table_size != goal_size) {
  ------------------
  |  Branch (180:10): [True: 3.96k, False: 518]
  ------------------
  181|  3.96k|    memcpy(&table[table_size], &table[0],
  182|  3.96k|           (size_t)table_size * sizeof(table[0]));
  183|  3.96k|    table_size <<= 1;
  184|  3.96k|  }
  185|       |
  186|    518|  return BrunsliBitReaderIsHealthy(br);
  187|    518|}
huffman_decode.cc:_ZZN7brunsliL14ReadSimpleCodeEtPNS_16BrunsliBitReaderEPNS_11HuffmanCodeEENKUlmmE_clEmm:
  122|    130|  const auto swap_symbols = [&symbols] (size_t i, size_t j) {
  123|    130|    uint16_t t = symbols[j];
  124|    130|    symbols[j] = symbols[i];
  125|    130|    symbols[i] = t;
  126|    130|  };

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

_ZN7brunsli17BuildHuffmanTableEPNS_11HuffmanCodeEmPKhmPt:
   55|    313|                           size_t code_lengths_size, uint16_t* count) {
   56|    313|  HuffmanCode code;    /* current table entry */
   57|    313|  HuffmanCode* table;  /* next available space in table */
   58|    313|  size_t len;          /* current code length */
   59|    313|  size_t symbol;       /* symbol index in original or sorted table */
   60|    313|  int key;             /* reversed prefix code */
   61|    313|  int step;            /* step size to replicate values in current table */
   62|    313|  int low;             /* low bits for current root entry */
   63|    313|  int mask;            /* mask for low bits */
   64|    313|  size_t table_bits;   /* key length of current table */
   65|    313|  int table_size;      /* size of current table */
   66|    313|  int total_size;      /* sum of root table size and 2nd level table sizes */
   67|       |  /* offsets in sorted table for each length */
   68|    313|  uint16_t offset[kMaxHuffmanBits + 1];
   69|    313|  size_t max_length = 1;
   70|       |
   71|    313|  if (code_lengths_size > 1u << kMaxHuffmanBits) return 0;
  ------------------
  |  Branch (71:7): [True: 0, False: 313]
  ------------------
   72|       |
   73|       |  /* symbols sorted by code length */
   74|    313|  std::vector<uint16_t> sorted_storage(code_lengths_size);
   75|    313|  uint16_t* sorted = sorted_storage.data();
   76|       |
   77|       |  /* generate offsets into sorted symbol table by code length */
   78|    313|  {
   79|    313|    uint16_t sum = 0;
   80|  5.00k|    for (len = 1; len <= kMaxHuffmanBits; len++) {
  ------------------
  |  Branch (80:19): [True: 4.69k, False: 313]
  ------------------
   81|  4.69k|      offset[len] = sum;
   82|  4.69k|      if (count[len]) {
  ------------------
  |  Branch (82:11): [True: 834, False: 3.86k]
  ------------------
   83|    834|        sum = static_cast<uint16_t>(sum + count[len]);
   84|    834|        max_length = len;
   85|    834|      }
   86|  4.69k|    }
   87|    313|  }
   88|       |
   89|       |  /* sort symbols by length, by symbol order within each length */
   90|  16.3k|  for (symbol = 0; symbol < code_lengths_size; symbol++) {
  ------------------
  |  Branch (90:20): [True: 16.0k, False: 313]
  ------------------
   91|  16.0k|    if (code_lengths[symbol] != 0) {
  ------------------
  |  Branch (91:9): [True: 7.47k, False: 8.58k]
  ------------------
   92|  7.47k|      sorted[offset[code_lengths[symbol]]++] = static_cast<uint16_t>(symbol);
   93|  7.47k|    }
   94|  16.0k|  }
   95|       |
   96|    313|  table = root_table;
   97|    313|  table_bits = root_bits;
   98|    313|  table_size = 1u << table_bits;
   99|    313|  total_size = table_size;
  100|       |
  101|       |  /* special case code with only one value */
  102|    313|  if (offset[kMaxHuffmanBits] == 1) {
  ------------------
  |  Branch (102:7): [True: 30, False: 283]
  ------------------
  103|     30|    code.bits = 0;
  104|     30|    code.value = static_cast<uint16_t>(sorted[0]);
  105|    990|    for (key = 0; key < total_size; ++key) {
  ------------------
  |  Branch (105:19): [True: 960, False: 30]
  ------------------
  106|    960|      table[key] = code;
  107|    960|    }
  108|     30|    return total_size;
  109|     30|  }
  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|    283|  if (table_bits > max_length) {
  ------------------
  |  Branch (114:7): [True: 210, False: 73]
  ------------------
  115|    210|    table_bits = max_length;
  116|    210|    table_size = 1u << table_bits;
  117|    210|  }
  118|    283|  key = 0;
  119|    283|  symbol = 0;
  120|    283|  code.bits = 1;
  121|    283|  step = 2;
  122|  1.13k|  do {
  123|  4.96k|    for (; count[code.bits] != 0; --count[code.bits]) {
  ------------------
  |  Branch (123:12): [True: 3.83k, False: 1.13k]
  ------------------
  124|  3.83k|      code.value = static_cast<uint16_t>(sorted[symbol++]);
  125|  3.83k|      ReplicateValue(&table[key], step, table_size, code);
  126|  3.83k|      key = GetNextKey(key, code.bits);
  127|  3.83k|    }
  128|  1.13k|    step <<= 1;
  129|  1.13k|  } while (++code.bits <= table_bits);
  ------------------
  |  Branch (129:12): [True: 848, False: 283]
  ------------------
  130|       |
  131|       |  /* if root_bits != table_bits we only created one fraction of the */
  132|       |  /* table, and we need to replicate it now. */
  133|    894|  while (total_size != table_size) {
  ------------------
  |  Branch (133:10): [True: 611, False: 283]
  ------------------
  134|    611|    memcpy(&table[table_size], &table[0], table_size * sizeof(table[0]));
  135|    611|    table_size <<= 1;
  136|    611|  }
  137|       |
  138|       |  /* fill in 2nd level tables and add pointers to root table */
  139|    283|  mask = total_size - 1;
  140|    283|  low = -1;
  141|    390|  for (len = root_bits + 1, step = 2; len <= max_length; ++len, step <<= 1) {
  ------------------
  |  Branch (141:39): [True: 107, False: 283]
  ------------------
  142|  3.72k|    for (; count[len] != 0; --count[len]) {
  ------------------
  |  Branch (142:12): [True: 3.61k, False: 107]
  ------------------
  143|  3.61k|      if ((key & mask) != low) {
  ------------------
  |  Branch (143:11): [True: 1.41k, False: 2.19k]
  ------------------
  144|  1.41k|        table += table_size;
  145|  1.41k|        table_bits = NextTableBitSize(count, len, root_bits);
  146|  1.41k|        table_size = 1u << table_bits;
  147|  1.41k|        total_size += table_size;
  148|  1.41k|        low = key & mask;
  149|  1.41k|        root_table[low].bits = static_cast<uint8_t>(table_bits + root_bits);
  150|  1.41k|        root_table[low].value =
  151|  1.41k|            static_cast<uint16_t>((table - root_table) - low);
  152|  1.41k|      }
  153|  3.61k|      code.bits = static_cast<uint8_t>(len - root_bits);
  154|  3.61k|      code.value = static_cast<uint16_t>(sorted[symbol++]);
  155|  3.61k|      ReplicateValue(&table[key >> root_bits], step, table_size, code);
  156|  3.61k|      key = GetNextKey(key, len);
  157|  3.61k|    }
  158|    107|  }
  159|       |
  160|    283|  return total_size;
  161|    313|}
huffman_table.cc:_ZN7brunsliL14ReplicateValueEPNS_11HuffmanCodeEiiS0_:
   31|  7.44k|                                  HuffmanCode code) {
   32|  16.4k|  do {
   33|  16.4k|    end -= step;
   34|  16.4k|    table[end] = code;
   35|  16.4k|  } while (end > 0);
  ------------------
  |  Branch (35:12): [True: 8.99k, False: 7.44k]
  ------------------
   36|  7.44k|}
huffman_table.cc:_ZN7brunsliL10GetNextKeyEim:
   20|  7.44k|static inline int GetNextKey(int key, size_t len) {
   21|  7.44k|  int step = 1u << (len - 1);
   22|  14.6k|  while (key & step) {
  ------------------
  |  Branch (22:10): [True: 7.16k, False: 7.44k]
  ------------------
   23|  7.16k|    step >>= 1;
   24|  7.16k|  }
   25|  7.44k|  return (key & (step - 1)) + step;
   26|  7.44k|}
huffman_table.cc:_ZN7brunsliL16NextTableBitSizeEPKtmm:
   42|  1.41k|                                      size_t root_bits) {
   43|  1.41k|  size_t left = size_t(1) << (len - root_bits);
   44|  1.46k|  while (len < kMaxHuffmanBits) {
  ------------------
  |  Branch (44:10): [True: 1.45k, False: 2]
  ------------------
   45|  1.45k|    if (left <= count[len]) break;
  ------------------
  |  Branch (45:9): [True: 1.41k, False: 45]
  ------------------
   46|     45|    left -= count[len];
   47|     45|    ++len;
   48|     45|    left <<= 1;
   49|     45|  }
   50|  1.41k|  return len - root_bits;
   51|  1.41k|}

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

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

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

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

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

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

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

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

