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

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

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

BrotliGetTransforms:
  173|  3.98k|const BrotliTransforms* BrotliGetTransforms(void) {
  174|  3.98k|  return &kBrotliTransforms;
  175|  3.98k|}
BrotliTransformDictionaryWord:
  237|  36.7k|    const BrotliTransforms* transforms, int transform_idx) {
  238|  36.7k|  int idx = 0;
  239|  36.7k|  const uint8_t* prefix = BROTLI_TRANSFORM_PREFIX(transforms, transform_idx);
  ------------------
  |  |   70|  36.7k|#define BROTLI_TRANSFORM_PREFIX(T, I) (&(T)->prefix_suffix[ \
  |  |   71|  36.7k|    (T)->prefix_suffix_map[BROTLI_TRANSFORM_PREFIX_ID(T, I)]])
  |  |  ------------------
  |  |  |  |   65|  36.7k|#define BROTLI_TRANSFORM_PREFIX_ID(T, I) ((T)->transforms[((I) * 3) + 0])
  |  |  ------------------
  ------------------
  240|  36.7k|  uint8_t type = BROTLI_TRANSFORM_TYPE(transforms, transform_idx);
  ------------------
  |  |   66|  36.7k|#define BROTLI_TRANSFORM_TYPE(T, I)      ((T)->transforms[((I) * 3) + 1])
  ------------------
  241|  36.7k|  const uint8_t* suffix = BROTLI_TRANSFORM_SUFFIX(transforms, transform_idx);
  ------------------
  |  |   72|  36.7k|#define BROTLI_TRANSFORM_SUFFIX(T, I) (&(T)->prefix_suffix[ \
  |  |   73|  36.7k|    (T)->prefix_suffix_map[BROTLI_TRANSFORM_SUFFIX_ID(T, I)]])
  |  |  ------------------
  |  |  |  |   67|  36.7k|#define BROTLI_TRANSFORM_SUFFIX_ID(T, I) ((T)->transforms[((I) * 3) + 2])
  |  |  ------------------
  ------------------
  242|  36.7k|  {
  243|  36.7k|    int prefix_len = *prefix++;
  244|  71.9k|    while (prefix_len--) { dst[idx++] = *prefix++; }
  ------------------
  |  Branch (244:12): [True: 35.1k, False: 36.7k]
  ------------------
  245|  36.7k|  }
  246|  36.7k|  {
  247|  36.7k|    const int t = type;
  248|  36.7k|    int i = 0;
  249|  36.7k|    if (t <= BROTLI_TRANSFORM_OMIT_LAST_9) {
  ------------------
  |  Branch (249:9): [True: 26.4k, False: 10.2k]
  ------------------
  250|  26.4k|      len -= t;
  251|  26.4k|    } else if (t >= BROTLI_TRANSFORM_OMIT_FIRST_1
  ------------------
  |  Branch (251:16): [True: 1.70k, False: 8.54k]
  ------------------
  252|  1.70k|        && t <= BROTLI_TRANSFORM_OMIT_FIRST_9) {
  ------------------
  |  Branch (252:12): [True: 1.70k, False: 0]
  ------------------
  253|  1.70k|      int skip = t - (BROTLI_TRANSFORM_OMIT_FIRST_1 - 1);
  254|  1.70k|      word += skip;
  255|  1.70k|      len -= skip;
  256|  1.70k|    }
  257|   256k|    while (i < len) { dst[idx++] = word[i++]; }
  ------------------
  |  Branch (257:12): [True: 220k, False: 36.7k]
  ------------------
  258|  36.7k|    if (t == BROTLI_TRANSFORM_UPPERCASE_FIRST) {
  ------------------
  |  Branch (258:9): [True: 5.28k, False: 31.4k]
  ------------------
  259|  5.28k|      ToUpperCase(&dst[idx - len]);
  260|  31.4k|    } else if (t == BROTLI_TRANSFORM_UPPERCASE_ALL) {
  ------------------
  |  Branch (260:16): [True: 3.26k, False: 28.1k]
  ------------------
  261|  3.26k|      uint8_t* uppercase = &dst[idx - len];
  262|  18.7k|      while (len > 0) {
  ------------------
  |  Branch (262:14): [True: 15.4k, False: 3.26k]
  ------------------
  263|  15.4k|        int step = ToUpperCase(uppercase);
  264|  15.4k|        uppercase += step;
  265|  15.4k|        len -= step;
  266|  15.4k|      }
  267|  28.1k|    } else if (t == BROTLI_TRANSFORM_SHIFT_FIRST) {
  ------------------
  |  Branch (267:16): [True: 0, False: 28.1k]
  ------------------
  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|  28.1k|    } else if (t == BROTLI_TRANSFORM_SHIFT_ALL) {
  ------------------
  |  Branch (271:16): [True: 0, False: 28.1k]
  ------------------
  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|  36.7k|  }
  282|  36.7k|  {
  283|  36.7k|    int suffix_len = *suffix++;
  284|   112k|    while (suffix_len--) { dst[idx++] = *suffix++; }
  ------------------
  |  Branch (284:12): [True: 75.3k, False: 36.7k]
  ------------------
  285|  36.7k|    return idx;
  286|  36.7k|  }
  287|  36.7k|}
transform.c:ToUpperCase:
  177|  20.7k|static int ToUpperCase(uint8_t* p) {
  178|  20.7k|  if (p[0] < 0xC0) {
  ------------------
  |  Branch (178:7): [True: 15.9k, False: 4.73k]
  ------------------
  179|  15.9k|    if (p[0] >= 'a' && p[0] <= 'z') {
  ------------------
  |  Branch (179:9): [True: 12.0k, False: 3.90k]
  |  Branch (179:24): [True: 11.6k, False: 445]
  ------------------
  180|  11.6k|      p[0] ^= 32;
  181|  11.6k|    }
  182|  15.9k|    return 1;
  183|  15.9k|  }
  184|       |  /* An overly simplified uppercasing model for UTF-8. */
  185|  4.73k|  if (p[0] < 0xE0) {
  ------------------
  |  Branch (185:7): [True: 4.07k, False: 659]
  ------------------
  186|  4.07k|    p[1] ^= 32;
  187|  4.07k|    return 2;
  188|  4.07k|  }
  189|       |  /* An arbitrary transform for three byte characters. */
  190|    659|  p[2] ^= 5;
  191|    659|  return 3;
  192|  4.73k|}

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

decode.c:BrotliBitReaderUnload:
  223|   122k|static BROTLI_INLINE void BrotliBitReaderUnload(BrotliBitReader* br) {
  224|   122k|  uint32_t unused_bytes = BrotliGetAvailableBits(br) >> 3;
  225|   122k|  uint32_t unused_bits = unused_bytes << 3;
  226|   122k|  br->avail_in += unused_bytes;
  227|   122k|  br->next_in -= unused_bytes;
  228|   122k|  if (unused_bits == sizeof(br->val_) << 3) {
  ------------------
  |  Branch (228:7): [True: 3.84k, False: 118k]
  ------------------
  229|  3.84k|    br->val_ = 0;
  230|   118k|  } else {
  231|   118k|    br->val_ <<= unused_bits;
  232|   118k|  }
  233|   122k|  br->bit_pos_ += unused_bits;
  234|   122k|}
decode.c:BrotliTakeBits:
  239|  75.3M|  BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
  240|  75.3M|  *val = (uint32_t)BrotliGetBitsUnmasked(br) & BitMask(n_bits);
  241|  75.3M|  BROTLI_LOG(("[BrotliTakeBits]  %d %d %d val: %6x\n",
  242|  75.3M|      (int)br->avail_in, (int)br->bit_pos_, (int)n_bits, (int)*val));
  243|  75.3M|  BrotliDropBits(br, n_bits);
  244|  75.3M|}
decode.c:BrotliGetBitsUnmasked:
  184|  2.15G|    BrotliBitReader* const br) {
  185|  2.15G|  return br->val_ >> br->bit_pos_;
  186|  2.15G|}
decode.c:BrotliDropBits:
  219|  2.08G|    BrotliBitReader* const br, uint32_t n_bits) {
  220|  2.08G|  br->bit_pos_ += n_bits;
  221|  2.08G|}
decode.c:BrotliSafeReadBits:
  292|   611k|    BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
  293|   611k|  BROTLI_DCHECK(n_bits <= 24);
  294|   952k|  while (BrotliGetAvailableBits(br) < n_bits) {
  ------------------
  |  Branch (294:10): [True: 342k, False: 609k]
  ------------------
  295|   342k|    if (!BrotliPullByte(br)) {
  ------------------
  |  Branch (295:9): [True: 1.22k, False: 341k]
  ------------------
  296|  1.22k|      return BROTLI_FALSE;
  ------------------
  |  |   53|  1.22k|#define BROTLI_FALSE 0
  ------------------
  297|  1.22k|    }
  298|   342k|  }
  299|   609k|  BrotliTakeBits(br, n_bits, val);
  300|   609k|  return BROTLI_TRUE;
  ------------------
  |  |   51|   609k|#define BROTLI_TRUE 1
  ------------------
  301|   611k|}
decode.c:BrotliPullByte:
  165|   522M|static BROTLI_INLINE BROTLI_BOOL BrotliPullByte(BrotliBitReader* const br) {
  166|   522M|  if (br->avail_in == 0) {
  ------------------
  |  Branch (166:7): [True: 522M, False: 456k]
  ------------------
  167|   522M|    return BROTLI_FALSE;
  ------------------
  |  |   53|   522M|#define BROTLI_FALSE 0
  ------------------
  168|   522M|  }
  169|   456k|  br->val_ >>= 8;
  170|   456k|#if (BROTLI_64_BITS)
  171|   456k|  br->val_ |= ((uint64_t)*br->next_in) << 56;
  172|       |#else
  173|       |  br->val_ |= ((uint32_t)*br->next_in) << 24;
  174|       |#endif
  175|   456k|  br->bit_pos_ -= 8;
  176|   456k|  --br->avail_in;
  177|   456k|  ++br->next_in;
  178|   456k|  return BROTLI_TRUE;
  ------------------
  |  |   51|   456k|#define BROTLI_TRUE 1
  ------------------
  179|   522M|}
decode.c:BrotliJumpToByteBoundary:
  322|  4.05k|static BROTLI_INLINE BROTLI_BOOL BrotliJumpToByteBoundary(BrotliBitReader* br) {
  323|  4.05k|  uint32_t pad_bits_count = BrotliGetAvailableBits(br) & 0x7;
  324|  4.05k|  uint32_t pad_bits = 0;
  325|  4.05k|  if (pad_bits_count != 0) {
  ------------------
  |  Branch (325:7): [True: 3.38k, False: 662]
  ------------------
  326|  3.38k|    BrotliTakeBits(br, pad_bits_count, &pad_bits);
  327|  3.38k|  }
  328|  4.05k|  return TO_BROTLI_BOOL(pad_bits == 0);
  ------------------
  |  |   55|  4.05k|#define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE)
  |  |  ------------------
  |  |  |  |   51|  3.98k|#define BROTLI_TRUE 1
  |  |  ------------------
  |  |               #define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE)
  |  |  ------------------
  |  |  |  |   53|     62|#define BROTLI_FALSE 0
  |  |  ------------------
  |  |  |  Branch (55:28): [True: 3.98k, False: 62]
  |  |  ------------------
  ------------------
  329|  4.05k|}
decode.c:BrotliSafeGetBits:
  207|  1.51G|    BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
  208|  1.51G|  while (BrotliGetAvailableBits(br) < n_bits) {
  ------------------
  |  Branch (208:10): [True: 522M, False: 996M]
  ------------------
  209|   522M|    if (!BrotliPullByte(br)) {
  ------------------
  |  Branch (209:9): [True: 522M, False: 114k]
  ------------------
  210|   522M|      return BROTLI_FALSE;
  ------------------
  |  |   53|   522M|#define BROTLI_FALSE 0
  ------------------
  211|   522M|    }
  212|   522M|  }
  213|   996M|  *val = (uint32_t)BrotliGetBitsUnmasked(br) & BitMask(n_bits);
  214|   996M|  return BROTLI_TRUE;
  ------------------
  |  |   51|   996M|#define BROTLI_TRUE 1
  ------------------
  215|  1.51G|}
decode.c:BrotliCheckInputAmount:
   99|   504M|    BrotliBitReader* const br, size_t num) {
  100|   504M|  return TO_BROTLI_BOOL(br->avail_in >= num);
  ------------------
  |  |   55|   504M|#define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE)
  |  |  ------------------
  |  |  |  |   51|   504M|#define BROTLI_TRUE 1
  |  |  ------------------
  |  |               #define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE)
  |  |  ------------------
  |  |  |  |   53|  88.1k|#define BROTLI_FALSE 0
  |  |  ------------------
  |  |  |  Branch (55:28): [True: 504M, False: 88.1k]
  |  |  ------------------
  ------------------
  101|   504M|}
decode.c:BrotliFillBitWindow16:
  159|   142k|static BROTLI_INLINE void BrotliFillBitWindow16(BrotliBitReader* const br) {
  160|   142k|  BrotliFillBitWindow(br, 17);
  161|   142k|}
decode.c:BrotliFillBitWindow:
  108|   654M|    BrotliBitReader* const br, uint32_t n_bits) {
  109|   654M|#if (BROTLI_64_BITS)
  110|   654M|  if (!BROTLI_ALIGNED_READ && BROTLI_IS_CONSTANT(n_bits) && (n_bits <= 8)) {
  ------------------
  |  |  287|  1.30G|#define BROTLI_ALIGNED_READ (!!0)
  ------------------
                if (!BROTLI_ALIGNED_READ && BROTLI_IS_CONSTANT(n_bits) && (n_bits <= 8)) {
  ------------------
  |  |  459|  1.30G|#define BROTLI_IS_CONSTANT(x) (!!__builtin_constant_p(x))
  |  |  ------------------
  |  |  |  Branch (459:31): [True: 579M, False: 74.7M]
  |  |  ------------------
  ------------------
  |  Branch (110:7): [True: 654M, Folded]
  |  Branch (110:61): [True: 459M, False: 120M]
  ------------------
  111|   459M|    if (br->bit_pos_ >= 56) {
  ------------------
  |  Branch (111:9): [True: 7.05k, False: 459M]
  ------------------
  112|  7.05k|      br->val_ >>= 56;
  113|  7.05k|      br->bit_pos_ ^= 56;  /* here same as -= 56 because of the if condition */
  114|  7.05k|      br->val_ |= BROTLI_UNALIGNED_LOAD64LE(br->next_in) << 8;
  ------------------
  |  |  386|  7.05k|#define BROTLI_UNALIGNED_LOAD64LE BrotliUnalignedRead64
  ------------------
  115|  7.05k|      br->avail_in -= 7;
  116|  7.05k|      br->next_in += 7;
  117|  7.05k|    }
  118|   459M|  } else if (
  119|   195M|      !BROTLI_ALIGNED_READ && BROTLI_IS_CONSTANT(n_bits) && (n_bits <= 16)) {
  ------------------
  |  |  287|   390M|#define BROTLI_ALIGNED_READ (!!0)
  ------------------
                    !BROTLI_ALIGNED_READ && BROTLI_IS_CONSTANT(n_bits) && (n_bits <= 16)) {
  ------------------
  |  |  459|   390M|#define BROTLI_IS_CONSTANT(x) (!!__builtin_constant_p(x))
  |  |  ------------------
  |  |  |  Branch (459:31): [True: 120M, False: 74.7M]
  |  |  ------------------
  ------------------
  |  Branch (119:7): [True: 195M, Folded]
  |  Branch (119:61): [True: 120M, False: 142k]
  ------------------
  120|   120M|    if (br->bit_pos_ >= 48) {
  ------------------
  |  Branch (120:9): [True: 62.8k, False: 120M]
  ------------------
  121|  62.8k|      br->val_ >>= 48;
  122|  62.8k|      br->bit_pos_ ^= 48;  /* here same as -= 48 because of the if condition */
  123|  62.8k|      br->val_ |= BROTLI_UNALIGNED_LOAD64LE(br->next_in) << 16;
  ------------------
  |  |  386|  62.8k|#define BROTLI_UNALIGNED_LOAD64LE BrotliUnalignedRead64
  ------------------
  124|  62.8k|      br->avail_in -= 6;
  125|  62.8k|      br->next_in += 6;
  126|  62.8k|    }
  127|   120M|  } else {
  128|  74.9M|    if (br->bit_pos_ >= 32) {
  ------------------
  |  Branch (128:9): [True: 74.1k, False: 74.8M]
  ------------------
  129|  74.1k|      br->val_ >>= 32;
  130|  74.1k|      br->bit_pos_ ^= 32;  /* here same as -= 32 because of the if condition */
  131|  74.1k|      br->val_ |= ((uint64_t)BROTLI_UNALIGNED_LOAD32LE(br->next_in)) << 32;
  ------------------
  |  |  385|  74.1k|#define BROTLI_UNALIGNED_LOAD32LE BrotliUnalignedRead32
  ------------------
  132|  74.1k|      br->avail_in -= BROTLI_SHORT_FILL_BIT_WINDOW_READ;
  ------------------
  |  |   22|  74.1k|#define BROTLI_SHORT_FILL_BIT_WINDOW_READ (sizeof(brotli_reg_t) >> 1)
  ------------------
  133|  74.1k|      br->next_in += BROTLI_SHORT_FILL_BIT_WINDOW_READ;
  ------------------
  |  |   22|  74.1k|#define BROTLI_SHORT_FILL_BIT_WINDOW_READ (sizeof(brotli_reg_t) >> 1)
  ------------------
  134|  74.1k|    }
  135|  74.9M|  }
  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|   654M|}
decode.c:BrotliGetRemainingBytes:
   90|  2.96k|static BROTLI_INLINE size_t BrotliGetRemainingBytes(BrotliBitReader* br) {
   91|  2.96k|  static const size_t kCap = (size_t)1 << BROTLI_LARGE_MAX_WBITS;
  ------------------
  |  |   57|  2.96k|#define BROTLI_LARGE_MAX_WBITS 30
  ------------------
   92|  2.96k|  if (br->avail_in > kCap) return kCap;
  ------------------
  |  Branch (92:7): [True: 0, False: 2.96k]
  ------------------
   93|  2.96k|  return br->avail_in + (BrotliGetAvailableBits(br) >> 3);
   94|  2.96k|}
decode.c:BrotliCopyBytes:
  335|  2.96k|                                          BrotliBitReader* br, size_t num) {
  336|  3.82k|  while (BrotliGetAvailableBits(br) >= 8 && num > 0) {
  ------------------
  |  Branch (336:10): [True: 1.31k, False: 2.50k]
  |  Branch (336:45): [True: 863, False: 454]
  ------------------
  337|    863|    *dest = (uint8_t)BrotliGetBitsUnmasked(br);
  338|    863|    BrotliDropBits(br, 8);
  339|    863|    ++dest;
  340|    863|    --num;
  341|    863|  }
  342|  2.96k|  memcpy(dest, br->next_in, num);
  343|  2.96k|  br->avail_in -= num;
  344|  2.96k|  br->next_in += num;
  345|  2.96k|}
decode.c:BitMask:
   26|  1.54G|static BROTLI_INLINE uint32_t BitMask(uint32_t n) {
   27|  1.54G|  if (BROTLI_IS_CONSTANT(n) || BROTLI_HAS_UBFX) {
  ------------------
  |  |  459|  3.08G|#define BROTLI_IS_CONSTANT(x) (!!__builtin_constant_p(x))
  |  |  ------------------
  |  |  |  Branch (459:31): [True: 1.45G, False: 85.8M]
  |  |  ------------------
  ------------------
                if (BROTLI_IS_CONSTANT(n) || BROTLI_HAS_UBFX) {
  ------------------
  |  |  467|  85.8M|#define BROTLI_HAS_UBFX (!!0)
  |  |  ------------------
  |  |  |  Branch (467:25): [Folded, False: 0]
  |  |  ------------------
  ------------------
   28|       |    /* Masking with this expression turns to a single
   29|       |       "Unsigned Bit Field Extract" UBFX instruction on ARM. */
   30|  1.45G|    return ~((0xFFFFFFFFu) << n);
   31|  1.45G|  } else {
   32|  85.8M|    return kBrotliBitMask[n];
   33|  85.8M|  }
   34|  1.54G|}
decode.c:BrotliReadBits24:
  250|  73.2M|    BrotliBitReader* const br, uint32_t n_bits) {
  251|  73.2M|  BROTLI_DCHECK(n_bits <= 24);
  252|  73.2M|  if (BROTLI_64_BITS || (n_bits <= 16)) {
  ------------------
  |  |  235|   146M|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 73.2M, Folded]
  |  |  ------------------
  ------------------
  |  Branch (252:25): [True: 0, False: 0]
  ------------------
  253|  73.2M|    uint32_t val;
  254|  73.2M|    BrotliFillBitWindow(br, n_bits);
  255|  73.2M|    BrotliTakeBits(br, n_bits, &val);
  256|  73.2M|    return val;
  257|  73.2M|  } else {
  258|      0|    uint32_t low_val;
  259|      0|    uint32_t high_val;
  260|      0|    BrotliFillBitWindow(br, 16);
  261|      0|    BrotliTakeBits(br, 16, &low_val);
  262|      0|    BrotliFillBitWindow(br, 8);
  263|      0|    BrotliTakeBits(br, n_bits - 16, &high_val);
  264|      0|    return low_val | (high_val << 16);
  265|      0|  }
  266|  73.2M|}
decode.c:BrotliBitReaderSaveState:
   67|   262M|    BrotliBitReader* const from, BrotliBitReaderState* to) {
   68|   262M|  to->val_ = from->val_;
   69|   262M|  to->bit_pos_ = from->bit_pos_;
   70|   262M|  to->next_in = from->next_in;
   71|   262M|  to->avail_in = from->avail_in;
   72|   262M|}
decode.c:BrotliBitReaderRestoreState:
   75|    786|    BrotliBitReader* const to, BrotliBitReaderState* from) {
   76|    786|  to->val_ = from->val_;
   77|    786|  to->bit_pos_ = from->bit_pos_;
   78|    786|  to->next_in = from->next_in;
   79|    786|  to->avail_in = from->avail_in;
   80|    786|}
decode.c:BrotliGetBits:
  199|   459M|    BrotliBitReader* const br, uint32_t n_bits) {
  200|   459M|  BrotliFillBitWindow(br, n_bits);
  201|   459M|  return (uint32_t)BrotliGetBitsUnmasked(br) & BitMask(n_bits);
  202|   459M|}
decode.c:BrotliGet16BitsUnmasked:
  191|   120M|    BrotliBitReader* const br) {
  192|   120M|  BrotliFillBitWindow(br, 16);
  193|   120M|  return (uint32_t)BrotliGetBitsUnmasked(br);
  194|   120M|}
decode.c:BrotliReadBits32:
  270|  1.53M|    BrotliBitReader* const br, uint32_t n_bits) {
  271|  1.53M|  BROTLI_DCHECK(n_bits <= 32);
  272|  1.53M|  if (BROTLI_64_BITS || (n_bits <= 16)) {
  ------------------
  |  |  235|  3.06M|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 1.53M, Folded]
  |  |  ------------------
  ------------------
  |  Branch (272:25): [True: 0, False: 0]
  ------------------
  273|  1.53M|    uint32_t val;
  274|  1.53M|    BrotliFillBitWindow(br, n_bits);
  275|  1.53M|    BrotliTakeBits(br, n_bits, &val);
  276|  1.53M|    return val;
  277|  1.53M|  } 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.53M|}
decode.c:BrotliSafeReadBits32:
  305|  4.68k|    BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
  306|  4.68k|  BROTLI_DCHECK(n_bits <= 32);
  307|  4.68k|  if (BROTLI_64_BITS || (n_bits <= 24)) {
  ------------------
  |  |  235|  9.37k|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 4.68k, Folded]
  |  |  ------------------
  ------------------
  |  Branch (307:25): [True: 0, False: 0]
  ------------------
  308|  4.79k|    while (BrotliGetAvailableBits(br) < n_bits) {
  ------------------
  |  Branch (308:12): [True: 338, False: 4.45k]
  ------------------
  309|    338|      if (!BrotliPullByte(br)) {
  ------------------
  |  Branch (309:11): [True: 229, False: 109]
  ------------------
  310|    229|        return BROTLI_FALSE;
  ------------------
  |  |   53|    229|#define BROTLI_FALSE 0
  ------------------
  311|    229|      }
  312|    338|    }
  313|  4.45k|    BrotliTakeBits(br, n_bits, val);
  314|  4.45k|    return BROTLI_TRUE;
  ------------------
  |  |   51|  4.45k|#define BROTLI_TRUE 1
  ------------------
  315|  4.68k|  } else {
  316|      0|    return BrotliSafeReadBits32Slow(br, n_bits, val);
  317|      0|  }
  318|  4.68k|}
decode.c:BrotliGetAvailableBits:
   83|  2.04G|    const BrotliBitReader* br) {
   84|  2.04G|  return (BROTLI_64_BITS ? 64 : 32) - br->bit_pos_;
  ------------------
  |  |  235|  2.04G|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 2.04G, Folded]
  |  |  ------------------
  ------------------
   85|  2.04G|}
bit_reader.c:BrotliGetAvailableBits:
   83|  74.2k|    const BrotliBitReader* br) {
   84|  74.2k|  return (BROTLI_64_BITS ? 64 : 32) - br->bit_pos_;
  ------------------
  |  |  235|  74.2k|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 74.2k, Folded]
  |  |  ------------------
  ------------------
   85|  74.2k|}
bit_reader.c:BrotliPullByte:
  165|  25.1k|static BROTLI_INLINE BROTLI_BOOL BrotliPullByte(BrotliBitReader* const br) {
  166|  25.1k|  if (br->avail_in == 0) {
  ------------------
  |  Branch (166:7): [True: 229, False: 24.9k]
  ------------------
  167|    229|    return BROTLI_FALSE;
  ------------------
  |  |   53|    229|#define BROTLI_FALSE 0
  ------------------
  168|    229|  }
  169|  24.9k|  br->val_ >>= 8;
  170|  24.9k|#if (BROTLI_64_BITS)
  171|  24.9k|  br->val_ |= ((uint64_t)*br->next_in) << 56;
  172|       |#else
  173|       |  br->val_ |= ((uint32_t)*br->next_in) << 24;
  174|       |#endif
  175|  24.9k|  br->bit_pos_ -= 8;
  176|  24.9k|  --br->avail_in;
  177|  24.9k|  ++br->next_in;
  178|  24.9k|  return BROTLI_TRUE;
  ------------------
  |  |   51|  24.9k|#define BROTLI_TRUE 1
  ------------------
  179|  25.1k|}

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

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

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

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

_ZN7brunsli27ComputeACPredictMultipliersEPKiPiS2_:
   20|  5.85k|                                 int* mult_col) {
   21|  52.7k|  for (size_t y = 0; y < 8; ++y) {
  ------------------
  |  Branch (21:22): [True: 46.8k, False: 5.85k]
  ------------------
   22|   421k|    for (size_t x = 0; x < 8; ++x) {
  ------------------
  |  Branch (22:24): [True: 374k, False: 46.8k]
  ------------------
   23|   374k|      mult_row[x + 8 * y] =
   24|   374k|          (quant[x + 8 * y] * kSqrt2FixedPoint) / quant[y * 8];
   25|       |      // mult_col is transposed i.e. destination rows and columns are swapped.
   26|   374k|      mult_col[x * 8 + y] = (quant[x + 8 * y] * kSqrt2FixedPoint) / quant[x];
   27|   374k|    }
   28|  46.8k|  }
   29|  5.85k|}
_ZN7brunsli16ComponentStateDC7InitAllEv:
   33|  6.40k|void ComponentStateDC::InitAll() {
   34|  6.40k|  is_zero_prob.Init(135);
   35|  64.0k|  for (size_t i = 0; i < sign_prob.size(); ++i) {
  ------------------
  |  Branch (35:22): [True: 57.6k, False: 6.40k]
  ------------------
   36|  57.6k|    sign_prob[i].Init(128);
   37|  57.6k|  }
   38|  25.6k|  for (size_t i = 0; i < is_empty_block_prob.size(); ++i) {
  ------------------
  |  Branch (38:22): [True: 19.2k, False: 6.40k]
  ------------------
   39|  19.2k|    is_empty_block_prob[i].Init(74);
   40|  19.2k|  }
   41|  70.4k|  for (size_t i = 0; i < first_extra_bit_prob.size(); ++i) {
  ------------------
  |  Branch (41:22): [True: 64.0k, False: 6.40k]
  ------------------
   42|  64.0k|    first_extra_bit_prob[i].Init(150);
   43|  64.0k|  }
   44|  6.40k|}
_ZN7brunsli14ComponentState7InitAllEv:
  223|  5.85k|void ComponentState::InitAll() {
  224|  70.2k|  for (int i = 0; i < kNumNonzeroBuckets; ++i) {
  ------------------
  |  Branch (224:19): [True: 64.4k, False: 5.85k]
  ------------------
  225|  4.18M|    for (int k = 0; k < kDCTBlockSize; ++k) {
  ------------------
  |  Branch (225:21): [True: 4.12M, False: 64.4k]
  ------------------
  226|  4.12M|      const int v = kInitProb[k] + 9 * (i - 7);
  227|  4.12M|      BRUNSLI_DCHECK(v <= 255);
  228|  4.12M|      is_zero_prob[i * kDCTBlockSize + k].Init(v);
  229|  4.12M|    }
  230|  64.4k|  }
  231|  6.37M|  for (size_t i = 0; i < sign_prob.size(); ++i) {
  ------------------
  |  Branch (231:22): [True: 6.37M, False: 5.85k]
  ------------------
  232|  6.37M|    if (i < kMaxAverageContext * kDCTBlockSize) {
  ------------------
  |  Branch (232:9): [True: 2.99M, False: 3.37M]
  ------------------
  233|  2.99M|      sign_prob[i].Init(108);
  234|  3.37M|    } else if (i < (kMaxAverageContext + 1) * kDCTBlockSize) {
  ------------------
  |  Branch (234:16): [True: 374k, False: 2.99M]
  ------------------
  235|   374k|      sign_prob[i].Init(128);
  236|  2.99M|    } else {
  237|  2.99M|      sign_prob[i].Init(148);
  238|  2.99M|    }
  239|  6.37M|  }
  240|  3.75M|  for (size_t i = 0; i < first_extra_bit_prob.size(); ++i) {
  ------------------
  |  Branch (240:22): [True: 3.74M, False: 5.85k]
  ------------------
  241|  3.74M|    first_extra_bit_prob[i].Init(158);
  242|  3.74M|  }
  243|       |
  244|   193k|  for (size_t i = 0; i < kNumNonZeroContextCount; ++i) {
  ------------------
  |  Branch (244:22): [True: 187k, False: 5.85k]
  ------------------
  245|   187k|    Prob* non_zero_probs = num_nonzero_prob + i * kNumNonZeroTreeSize;
  246|  11.9M|    for (size_t j = 0; j < kNumNonZeroTreeSize; ++j) {
  ------------------
  |  Branch (246:24): [True: 11.8M, False: 187k]
  ------------------
  247|  11.8M|      non_zero_probs[j].Init(kInitProbNonzero[i][j]);
  248|  11.8M|    }
  249|   187k|  }
  250|  5.85k|}

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

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

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

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

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

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

_ZN7brunsli25PredictWithAdaptiveMedianEPKsiii:
   29|  41.9M|int PredictWithAdaptiveMedian(const coeff_t* coeffs, int x, int y, int stride) {
   30|  41.9M|  const int offset1 = -kDCTBlockSize;
   31|  41.9M|  const int offset2 = -stride;
   32|  41.9M|  const int offset3 = offset2 + offset1;
   33|  41.9M|  if (y != 0) {
  ------------------
  |  Branch (33:7): [True: 41.0M, False: 941k]
  ------------------
   34|  41.0M|    if (x != 0) {
  ------------------
  |  Branch (34:9): [True: 40.6M, False: 330k]
  ------------------
   35|  40.6M|      return AdaptiveMedian(coeffs[offset1], coeffs[offset2], coeffs[offset3]);
   36|  40.6M|    } else {
   37|   330k|      return coeffs[offset2];
   38|   330k|    }
   39|  41.0M|  } else {
   40|   941k|    return x ? coeffs[offset1] : 0;
  ------------------
  |  Branch (40:12): [True: 934k, False: 6.28k]
  ------------------
   41|   941k|  }
   42|  41.9M|}
predict.cc:_ZN7brunsli12_GLOBAL__N_114AdaptiveMedianEiii:
   15|  40.6M|int AdaptiveMedian(int w, int n, int nw) {
   16|  40.6M|  const int mx = (w > n) ? w : n;
  ------------------
  |  Branch (16:18): [True: 6.25M, False: 34.4M]
  ------------------
   17|  40.6M|  const int mn = w + n - mx;
   18|  40.6M|  if (nw > mx) {
  ------------------
  |  Branch (18:7): [True: 927k, False: 39.7M]
  ------------------
   19|   927k|    return mn;
   20|  39.7M|  } else if (nw < mn) {
  ------------------
  |  Branch (20:14): [True: 778k, False: 38.9M]
  ------------------
   21|   778k|    return mx;
   22|  38.9M|  } else {
   23|  38.9M|    return n + w - nw;
   24|  38.9M|  }
   25|  40.6M|}

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

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

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

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

_ZN7brunsli20BrunsliBitReaderInitEPNS_16BrunsliBitReaderE:
   13|  26.2k|void BrunsliBitReaderInit(BrunsliBitReader* br) {
   14|  26.2k|  br->num_bits_ = 0;
   15|  26.2k|  br->bits_ = 0;
   16|  26.2k|  br->num_debt_bytes_ = 0;
   17|  26.2k|  br->is_healthy_ = true;
   18|  26.2k|  br->is_optimistic_ = false;
   19|  26.2k|}
_ZN7brunsli22BrunsliBitReaderResumeEPNS_16BrunsliBitReaderEPKhm:
   22|  26.2k|                              size_t length) {
   23|  26.2k|  br->next_ = buffer;
   24|  26.2k|  br->end_ = buffer + length;
   25|  26.2k|  br->is_optimistic_ = false;
   26|  26.2k|}
_ZN7brunsli23BrunsliBitReaderSuspendEPNS_16BrunsliBitReaderE:
   49|  26.2k|size_t BrunsliBitReaderSuspend(BrunsliBitReader* br) {
   50|  26.2k|  BrunsliBitReaderUnload(br);
   51|  26.2k|  size_t unused_bytes = br->end_ - br->next_;
   52|  26.2k|  br->next_ = nullptr;
   53|  26.2k|  br->end_ = nullptr;
   54|  26.2k|  return unused_bytes;
   55|  26.2k|}
_ZN7brunsli22BrunsliBitReaderFinishEPNS_16BrunsliBitReaderE:
   57|  21.5k|void BrunsliBitReaderFinish(BrunsliBitReader* br) {
   58|  21.5k|  uint32_t n_bits = br->num_bits_;
   59|       |  // Likely, did not invoke Suspend before.
   60|  21.5k|  if (n_bits >= 8) {
  ------------------
  |  Branch (60:7): [True: 0, False: 21.5k]
  ------------------
   61|      0|    br->is_healthy_ = false;
   62|      0|    return;
   63|      0|  }
   64|  21.5k|  if (n_bits > 0) {
  ------------------
  |  Branch (64:7): [True: 15.2k, False: 6.25k]
  ------------------
   65|  15.2k|    uint32_t padding_bits = BrunsliBitReaderRead(br, n_bits);
   66|  15.2k|    if (padding_bits != 0) br->is_healthy_ = false;
  ------------------
  |  Branch (66:9): [True: 24, False: 15.2k]
  ------------------
   67|  15.2k|  }
   68|  21.5k|}
_ZN7brunsli25BrunsliBitReaderIsHealthyEPNS_16BrunsliBitReaderE:
   70|  48.2k|bool BrunsliBitReaderIsHealthy(BrunsliBitReader* br) {
   71|  48.2k|  BrunsliBitReaderUnload(br);
   72|  48.2k|  return (br->num_debt_bytes_ == 0) && (br->is_healthy_);
  ------------------
  |  Branch (72:10): [True: 47.8k, False: 338]
  |  Branch (72:40): [True: 47.8k, False: 24]
  ------------------
   73|  48.2k|}
_ZN7brunsli29BrunsliBitReaderSetOptimisticEPNS_16BrunsliBitReaderE:
   75|  6.51k|void BrunsliBitReaderSetOptimistic(BrunsliBitReader* br) {
   76|  6.51k|  br->is_optimistic_ = true;
   77|  6.51k|}
_ZN7brunsli23BrunsliBitReaderCanReadEPNS_16BrunsliBitReaderEm:
   79|  9.61M|bool BrunsliBitReaderCanRead(BrunsliBitReader* br, size_t n_bits) {
   80|  9.61M|  if (br->is_optimistic_) return true;
  ------------------
  |  Branch (80:7): [True: 773k, False: 8.84M]
  ------------------
   81|  8.84M|  if (br->num_debt_bytes_ != 0) return false;
  ------------------
  |  Branch (81:7): [True: 0, False: 8.84M]
  ------------------
   82|  8.84M|  if (br->num_bits_ >= n_bits) return true;
  ------------------
  |  Branch (82:7): [True: 2.56M, False: 6.28M]
  ------------------
   83|  6.28M|  size_t num_extra_bytes = (n_bits - br->num_bits_ + 7) >> 3;
   84|  6.28M|  return (br->next_ + num_extra_bytes <= br->end_);
   85|  8.84M|}
bit_reader.cc:_ZN7brunsliL22BrunsliBitReaderUnloadEPNS_16BrunsliBitReaderE:
   35|  74.4k|static BRUNSLI_INLINE void BrunsliBitReaderUnload(BrunsliBitReader* br) {
   36|       |  // Cancel the overdraft.
   37|  74.6k|  while ((br->num_debt_bytes_ > 0) && (br->num_bits_ >= 8)) {
  ------------------
  |  Branch (37:10): [True: 1.01k, False: 73.6k]
  |  Branch (37:39): [True: 171, False: 847]
  ------------------
   38|    171|    br->num_debt_bytes_--;
   39|    171|    br->num_bits_ -= 8;
   40|    171|  }
   41|       |  // Return unused bytes.
   42|  74.9k|  while (br->num_bits_ >= 8) {
  ------------------
  |  Branch (42:10): [True: 428, False: 74.4k]
  ------------------
   43|    428|    br->next_--;
   44|    428|    br->num_bits_ -= 8;
   45|    428|  }
   46|  74.4k|  br->bits_ &= BrunsliBitReaderBitMask(br->num_bits_);
   47|  74.4k|}

_ZN7brunsli20BrunsliBitReaderReadEPNS_16BrunsliBitReaderEj:
  127|  9.10M|                                                    uint32_t n_bits) {
  128|  9.10M|  uint32_t result = BrunsliBitReaderGet(br, n_bits);
  129|  9.10M|  BrunsliBitReaderDrop(br, n_bits);
  130|  9.10M|  return result;
  131|  9.10M|}
brunsli_decode.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|  8.96M|                                                   uint32_t n_bits) {
  110|  8.96M|  BRUNSLI_DCHECK(n_bits <= 24);
  111|  8.96M|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|  8.96M|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 2.46k, False: 8.96M]
  ------------------
  113|  2.46k|    BrunsliBitReaderMaybeFetchByte(br, n_bits);
  114|  2.46k|    if (n_bits > 16) BrunsliBitReaderMaybeFetchByte(br, n_bits);
  ------------------
  |  Branch (114:9): [True: 0, False: 2.46k]
  ------------------
  115|  2.46k|  }
  116|  8.96M|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|  8.96M|}
brunsli_decode.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|  8.96M|                                                          uint32_t n_bits) {
   81|  8.96M|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 6.22M, False: 2.74M]
  ------------------
   82|  6.22M|    if (BRUNSLI_PREDICT_FALSE(br->next_ >= br->end_)) {
  ------------------
  |  |   85|  6.22M|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 38, False: 6.22M]
  |  |  ------------------
  ------------------
   83|     38|      BrunsliBitReaderOweByte(br);
   84|  6.22M|    } else {
   85|  6.22M|      br->bits_ |= static_cast<uint32_t>(*br->next_) << br->num_bits_;
   86|  6.22M|      br->num_bits_ += 8;
   87|  6.22M|      br->next_++;
   88|  6.22M|    }
   89|  6.22M|  }
   90|  8.96M|}
brunsli_decode.cc:_ZN7brunsliL23BrunsliBitReaderOweByteEPNS_16BrunsliBitReaderE:
   73|     38|static BRUNSLI_INLINE void BrunsliBitReaderOweByte(BrunsliBitReader* br) {
   74|     38|  br->num_bits_ += 8;
   75|     38|  br->num_debt_bytes_++;
   76|     38|}
brunsli_decode.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|  8.96M|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|  8.96M|  return ~((0xFFFFFFFFu) << n);
   70|  8.96M|}
brunsli_decode.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|  8.96M|                                                uint32_t n_bits) {
  121|  8.96M|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|  8.96M|  br->bits_ >>= n_bits;
  123|  8.96M|  br->num_bits_ -= n_bits;
  124|  8.96M|}
context_map_decode.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|  4.66k|                                                   uint32_t n_bits) {
  110|  4.66k|  BRUNSLI_DCHECK(n_bits <= 24);
  111|  4.66k|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|  4.66k|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 127, False: 4.53k]
  ------------------
  113|    127|    BrunsliBitReaderMaybeFetchByte(br, n_bits);
  114|    127|    if (n_bits > 16) BrunsliBitReaderMaybeFetchByte(br, n_bits);
  ------------------
  |  Branch (114:9): [True: 0, False: 127]
  ------------------
  115|    127|  }
  116|  4.66k|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|  4.66k|}
context_map_decode.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|  4.79k|                                                          uint32_t n_bits) {
   81|  4.79k|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 774, False: 4.01k]
  ------------------
   82|    774|    if (BRUNSLI_PREDICT_FALSE(br->next_ >= br->end_)) {
  ------------------
  |  |   85|    774|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 478, False: 296]
  |  |  ------------------
  ------------------
   83|    478|      BrunsliBitReaderOweByte(br);
   84|    478|    } else {
   85|    296|      br->bits_ |= static_cast<uint32_t>(*br->next_) << br->num_bits_;
   86|    296|      br->num_bits_ += 8;
   87|    296|      br->next_++;
   88|    296|    }
   89|    774|  }
   90|  4.79k|}
context_map_decode.cc:_ZN7brunsliL23BrunsliBitReaderOweByteEPNS_16BrunsliBitReaderE:
   73|    478|static BRUNSLI_INLINE void BrunsliBitReaderOweByte(BrunsliBitReader* br) {
   74|    478|  br->num_bits_ += 8;
   75|    478|  br->num_debt_bytes_++;
   76|    478|}
context_map_decode.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|  4.66k|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|  4.66k|  return ~((0xFFFFFFFFu) << n);
   70|  4.66k|}
context_map_decode.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|  4.66k|                                                uint32_t n_bits) {
  121|  4.66k|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|  4.66k|  br->bits_ >>= n_bits;
  123|  4.66k|  br->num_bits_ -= n_bits;
  124|  4.66k|}
histogram_decode.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|   120k|                                                   uint32_t n_bits) {
  110|   120k|  BRUNSLI_DCHECK(n_bits <= 24);
  111|   120k|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|   120k|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 2.04k, False: 118k]
  ------------------
  113|  2.04k|    BrunsliBitReaderMaybeFetchByte(br, n_bits);
  114|  2.04k|    if (n_bits > 16) BrunsliBitReaderMaybeFetchByte(br, n_bits);
  ------------------
  |  Branch (114:9): [True: 0, False: 2.04k]
  ------------------
  115|  2.04k|  }
  116|   120k|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|   120k|}
histogram_decode.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|   122k|                                                          uint32_t n_bits) {
   81|   122k|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 26.9k, False: 95.1k]
  ------------------
   82|  26.9k|    if (BRUNSLI_PREDICT_FALSE(br->next_ >= br->end_)) {
  ------------------
  |  |   85|  26.9k|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 804, False: 26.1k]
  |  |  ------------------
  ------------------
   83|    804|      BrunsliBitReaderOweByte(br);
   84|  26.1k|    } else {
   85|  26.1k|      br->bits_ |= static_cast<uint32_t>(*br->next_) << br->num_bits_;
   86|  26.1k|      br->num_bits_ += 8;
   87|  26.1k|      br->next_++;
   88|  26.1k|    }
   89|  26.9k|  }
   90|   122k|}
histogram_decode.cc:_ZN7brunsliL23BrunsliBitReaderOweByteEPNS_16BrunsliBitReaderE:
   73|    804|static BRUNSLI_INLINE void BrunsliBitReaderOweByte(BrunsliBitReader* br) {
   74|    804|  br->num_bits_ += 8;
   75|    804|  br->num_debt_bytes_++;
   76|    804|}
histogram_decode.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|   120k|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|   120k|  return ~((0xFFFFFFFFu) << n);
   70|   120k|}
histogram_decode.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|   120k|                                                uint32_t n_bits) {
  121|   120k|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|   120k|  br->bits_ >>= n_bits;
  123|   120k|  br->num_bits_ -= n_bits;
  124|   120k|}
huffman_decode.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|   843k|                                                   uint32_t n_bits) {
  110|   843k|  BRUNSLI_DCHECK(n_bits <= 24);
  111|   843k|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|   843k|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 119, False: 843k]
  ------------------
  113|    119|    BrunsliBitReaderMaybeFetchByte(br, n_bits);
  114|    119|    if (n_bits > 16) BrunsliBitReaderMaybeFetchByte(br, n_bits);
  ------------------
  |  Branch (114:9): [True: 0, False: 119]
  ------------------
  115|    119|  }
  116|   843k|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|   843k|}
huffman_decode.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|   843k|                                                          uint32_t n_bits) {
   81|   843k|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 67.2k, False: 776k]
  ------------------
   82|  67.2k|    if (BRUNSLI_PREDICT_FALSE(br->next_ >= br->end_)) {
  ------------------
  |  |   85|  67.2k|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 57.1k, False: 10.1k]
  |  |  ------------------
  ------------------
   83|  57.1k|      BrunsliBitReaderOweByte(br);
   84|  57.1k|    } else {
   85|  10.1k|      br->bits_ |= static_cast<uint32_t>(*br->next_) << br->num_bits_;
   86|  10.1k|      br->num_bits_ += 8;
   87|  10.1k|      br->next_++;
   88|  10.1k|    }
   89|  67.2k|  }
   90|   843k|}
huffman_decode.cc:_ZN7brunsliL23BrunsliBitReaderOweByteEPNS_16BrunsliBitReaderE:
   73|  57.1k|static BRUNSLI_INLINE void BrunsliBitReaderOweByte(BrunsliBitReader* br) {
   74|  57.1k|  br->num_bits_ += 8;
   75|  57.1k|  br->num_debt_bytes_++;
   76|  57.1k|}
huffman_decode.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|   843k|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|   843k|  return ~((0xFFFFFFFFu) << n);
   70|   843k|}
huffman_decode.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|   843k|                                                uint32_t n_bits) {
  121|   843k|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|   843k|  br->bits_ >>= n_bits;
  123|   843k|  br->num_bits_ -= n_bits;
  124|   843k|}
bit_reader.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|  89.7k|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|  89.7k|  return ~((0xFFFFFFFFu) << n);
   70|  89.7k|}
bit_reader.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|  15.2k|                                                   uint32_t n_bits) {
  110|  15.2k|  BRUNSLI_DCHECK(n_bits <= 24);
  111|  15.2k|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|  15.2k|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 0, False: 15.2k]
  ------------------
  113|      0|    BrunsliBitReaderMaybeFetchByte(br, n_bits);
  114|      0|    if (n_bits > 16) BrunsliBitReaderMaybeFetchByte(br, n_bits);
  ------------------
  |  Branch (114:9): [True: 0, False: 0]
  ------------------
  115|      0|  }
  116|  15.2k|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|  15.2k|}
bit_reader.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|  15.2k|                                                          uint32_t n_bits) {
   81|  15.2k|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 0, False: 15.2k]
  ------------------
   82|      0|    if (BRUNSLI_PREDICT_FALSE(br->next_ >= br->end_)) {
  ------------------
  |  |   85|      0|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 0, False: 0]
  |  |  ------------------
  ------------------
   83|      0|      BrunsliBitReaderOweByte(br);
   84|      0|    } else {
   85|      0|      br->bits_ |= static_cast<uint32_t>(*br->next_) << br->num_bits_;
   86|      0|      br->num_bits_ += 8;
   87|      0|      br->next_++;
   88|      0|    }
   89|      0|  }
   90|  15.2k|}
bit_reader.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|  15.2k|                                                uint32_t n_bits) {
  121|  15.2k|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|  15.2k|  br->bits_ >>= n_bits;
  123|  15.2k|  br->num_bits_ -= n_bits;
  124|  15.2k|}

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

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

_ZN7brunsli16DecodeContextMapERKNS_19HuffmanDecodingDataEmPmPNSt3__16vectorIhNS4_9allocatorIhEEEEPNS_16BrunsliBitReaderE:
   44|    748|                               BrunsliBitReader* br) {
   45|    748|  size_t& i = *index;
   46|    748|  uint8_t* map = context_map->data();
   47|    748|  const size_t length = context_map->size();
   48|   826k|  while (i < length) {
  ------------------
  |  Branch (48:10): [True: 826k, False: 539]
  ------------------
   49|       |    // Check there is enough deta for Huffman code, RLE and IMTF bit.
   50|   826k|    if (!BrunsliBitReaderCanRead(br, 15 + max_run_length_prefix + 1)) {
  ------------------
  |  Branch (50:9): [True: 137, False: 826k]
  ------------------
   51|    137|      return BRUNSLI_NOT_ENOUGH_DATA;
   52|    137|    }
   53|   826k|    uint32_t code = entropy.ReadSymbol(br);
   54|   826k|    if (code == 0) {
  ------------------
  |  Branch (54:9): [True: 126k, False: 699k]
  ------------------
   55|   126k|      map[i] = 0;
   56|   126k|      ++i;
   57|   699k|    } else if (code <= max_run_length_prefix) {
  ------------------
  |  Branch (57:16): [True: 4.12k, False: 695k]
  ------------------
   58|  4.12k|      size_t reps = 1u + (1u << code) + (int)BrunsliBitReaderRead(br, code);
   59|   227k|      while (--reps) {
  ------------------
  |  Branch (59:14): [True: 223k, False: 4.05k]
  ------------------
   60|   223k|        if (i >= length) return BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (60:13): [True: 72, False: 223k]
  ------------------
   61|   223k|        map[i] = 0;
   62|   223k|        ++i;
   63|   223k|      }
   64|   695k|    } else {
   65|   695k|      map[i] = (uint8_t)(code - max_run_length_prefix);
   66|   695k|      ++i;
   67|   695k|    }
   68|   826k|  }
   69|    539|  if (BrunsliBitReaderRead(br, 1)) {
  ------------------
  |  Branch (69:7): [True: 383, False: 156]
  ------------------
   70|    383|    InverseMoveToFrontTransform(map, length);
   71|    383|  }
   72|    539|  return BrunsliBitReaderIsHealthy(br) ? BRUNSLI_OK : BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (72:10): [True: 454, False: 85]
  ------------------
   73|    748|}
context_map_decode.cc:_ZN7brunsli12_GLOBAL__N_127InverseMoveToFrontTransformEPhm:
   27|    383|void InverseMoveToFrontTransform(uint8_t* v, size_t v_len) {
   28|    383|  uint8_t mtf[256];
   29|  98.4k|  for (size_t i = 0; i < 256; ++i) {
  ------------------
  |  Branch (29:22): [True: 98.0k, False: 383]
  ------------------
   30|  98.0k|    mtf[i] = static_cast<uint8_t>(i);
   31|  98.0k|  }
   32|   610k|  for (size_t i = 0; i < v_len; ++i) {
  ------------------
  |  Branch (32:22): [True: 610k, False: 383]
  ------------------
   33|   610k|    uint8_t index = v[i];
   34|   610k|    v[i] = mtf[index];
   35|   610k|    if (index) MoveToFront(mtf, index);
  ------------------
  |  Branch (35:9): [True: 589k, False: 20.3k]
  ------------------
   36|   610k|  }
   37|    383|}
context_map_decode.cc:_ZN7brunsli12_GLOBAL__N_111MoveToFrontEPhh:
   20|   589k|void MoveToFront(uint8_t* v, uint8_t index) {
   21|   589k|  uint8_t value = v[index];
   22|   589k|  uint8_t i = index;
   23|  19.9M|  for (; i; --i) v[i] = v[i - 1];
  ------------------
  |  Branch (23:10): [True: 19.3M, False: 589k]
  ------------------
   24|   589k|  v[0] = value;
   25|   589k|}

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

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

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

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

_ZN7brunsli9WriteJpegERKNS_8JPEGDataENS_10JPEGOutputE:
  967|  4.58k|bool WriteJpeg(const JPEGData& jpg, JPEGOutput out) {
  968|  4.58k|  State state;
  969|  4.58k|  state.stage = Stage::DONE;
  970|  4.58k|  std::vector<uint8_t> buffer(16384);
  971|  4.84k|  while (true) {
  ------------------
  |  Branch (971:10): [True: 4.84k, Folded]
  ------------------
  972|  4.84k|    uint8_t* next_out = buffer.data();
  973|  4.84k|    size_t available_out = buffer.size();
  974|  4.84k|    SerializationStatus status =
  975|  4.84k|        SerializeJpeg(&state, jpg, &available_out, &next_out);
  976|  4.84k|    if (status != SerializationStatus::DONE &&
  ------------------
  |  Branch (976:9): [True: 4.54k, False: 299]
  ------------------
  977|  4.54k|        status != SerializationStatus::NEEDS_MORE_OUTPUT) {
  ------------------
  |  Branch (977:9): [True: 4.28k, False: 263]
  ------------------
  978|  4.28k|      return false;
  979|  4.28k|    }
  980|    562|    size_t to_write = buffer.size() - available_out;
  981|    562|    if (!out.Write(buffer.data(), to_write)) return false;
  ------------------
  |  Branch (981:9): [True: 0, False: 562]
  ------------------
  982|    562|    if (status == SerializationStatus::DONE) return true;
  ------------------
  |  Branch (982:9): [True: 299, False: 263]
  ------------------
  983|    562|  }
  984|  4.58k|}
_ZN7brunsli8internal3dec13SerializeJpegEPNS1_5StateERKNS_8JPEGDataEPmPPh:
  989|  4.84k|                                  size_t* available_out, uint8_t** next_out) {
  990|  4.84k|  SerializationState& ss = state->internal->serialization;
  991|       |
  992|  4.84k|  const auto maybe_push_output = [&]() {
  993|  4.84k|    if (ss.stage != SerializationState::ERROR) {
  994|  4.84k|      PushOutput(&ss.output_queue, available_out, next_out);
  995|  4.84k|    }
  996|  4.84k|  };
  997|       |
  998|       |  // Push remaining output from prevoius session.
  999|  4.84k|  maybe_push_output();
 1000|       |
 1001|  44.0k|  while (true) {
  ------------------
  |  Branch (1001:10): [True: 44.0k, Folded]
  ------------------
 1002|  44.0k|    switch (ss.stage) {
 1003|  4.58k|      case SerializationState::INIT: {
  ------------------
  |  Branch (1003:7): [True: 4.58k, False: 39.4k]
  ------------------
 1004|       |        // If parsing is complete, serialization is possible.
 1005|  4.58k|        bool can_start_serialization = (state->stage == Stage::DONE);
 1006|       |        // Parsing of AC/DC has started; i.e. quant/huffman/metadata is ready
 1007|       |        // to be used.
 1008|  4.58k|        if (HasSection(state, kBrunsliDCDataTag) ||
  ------------------
  |  Branch (1008:13): [True: 0, False: 4.58k]
  ------------------
 1009|  4.58k|            HasSection(state, kBrunsliACDataTag)) {
  ------------------
  |  Branch (1009:13): [True: 0, False: 4.58k]
  ------------------
 1010|      0|          can_start_serialization = true;
 1011|      0|        }
 1012|  4.58k|        if (!can_start_serialization) {
  ------------------
  |  Branch (1012:13): [True: 0, False: 4.58k]
  ------------------
 1013|      0|          return SerializationStatus::NEEDS_MORE_INPUT;
 1014|      0|        }
 1015|       |        // JpegBypass is a very simple / special case.
 1016|  4.58k|        if (jpg.version == kFallbackVersion) {
  ------------------
  |  Branch (1016:13): [True: 8, False: 4.57k]
  ------------------
 1017|      8|          if (jpg.original_jpg == nullptr) {
  ------------------
  |  Branch (1017:15): [True: 1, False: 7]
  ------------------
 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|      7|          ss.output_queue.emplace_back(jpg.original_jpg, jpg.original_jpg_size);
 1025|      7|          ss.stage = SerializationState::DONE;
 1026|      7|          break;
 1027|      8|        }
 1028|       |
 1029|       |        // Invalid mode - fallback + something else.
 1030|  4.57k|        if ((jpg.version & 1) == kFallbackVersion) {
  ------------------
  |  Branch (1030:13): [True: 0, False: 4.57k]
  ------------------
 1031|      0|          ss.stage = SerializationState::ERROR;
 1032|      0|          break;
 1033|      0|        }
 1034|       |
 1035|       |        // Valid Brunsli requires, at least, 0xD9 marker.
 1036|       |        // This might happen on corrupted stream, or on unconditioned JPEGData.
 1037|       |        // TODO(eustas): check D9 in the only one and is the last one.
 1038|  4.57k|        if (jpg.marker_order.empty()) {
  ------------------
  |  Branch (1038:13): [True: 0, False: 4.57k]
  ------------------
 1039|      0|          ss.stage = SerializationState::ERROR;
 1040|      0|          break;
 1041|      0|        }
 1042|       |
 1043|  4.57k|        ss.dc_huff_table.resize(kMaxHuffmanTables);
 1044|  4.57k|        ss.ac_huff_table.resize(kMaxHuffmanTables);
 1045|  4.57k|        if (jpg.has_zero_padding_bit) {
  ------------------
  |  Branch (1045:13): [True: 223, False: 4.34k]
  ------------------
 1046|    223|          ss.pad_bits = jpg.padding_bits.data();
 1047|    223|          ss.pad_bits_end = ss.pad_bits + jpg.padding_bits.size();
 1048|    223|        }
 1049|       |
 1050|  4.57k|        EncodeSOI(&ss);
 1051|  4.57k|        maybe_push_output();
 1052|  4.57k|        ss.stage = SerializationState::SERIALIZE_SECTION;
 1053|  4.57k|        break;
 1054|  4.57k|      }
 1055|       |
 1056|  34.5k|      case SerializationState::SERIALIZE_SECTION: {
  ------------------
  |  Branch (1056:7): [True: 34.5k, False: 9.42k]
  ------------------
 1057|  34.5k|        if (ss.section_index >= jpg.marker_order.size()) {
  ------------------
  |  Branch (1057:13): [True: 292, False: 34.2k]
  ------------------
 1058|    292|          ss.stage = SerializationState::DONE;
 1059|    292|          break;
 1060|    292|        }
 1061|  34.2k|        uint8_t marker = jpg.marker_order[ss.section_index];
 1062|  34.2k|        SerializationStatus status = SerializeSection(marker, *state, &ss, jpg);
 1063|  34.2k|        if (status == SerializationStatus::ERROR) {
  ------------------
  |  Branch (1063:13): [True: 4.28k, False: 30.0k]
  ------------------
 1064|  4.28k|          BRUNSLI_LOG_DEBUG() << "Failed to encode marker " << std::hex
  ------------------
  |  |  427|  4.28k|#define BRUNSLI_LOG_DEBUG() BRUNSLI_VOID_LOG()
  |  |  ------------------
  |  |  |  |  406|  4.28k|#define BRUNSLI_VOID_LOG() if (true) {} else std::cerr
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (406:32): [True: 4.28k, Folded]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1065|      0|                              << marker << BRUNSLI_ENDL();
  ------------------
  |  |  414|      0|#define BRUNSLI_ENDL() std::endl
  ------------------
 1066|  4.28k|          ss.stage = SerializationState::ERROR;
 1067|  4.28k|          break;
 1068|  4.28k|        }
 1069|  30.0k|        maybe_push_output();
 1070|  30.0k|        if (status == SerializationStatus::NEEDS_MORE_INPUT) {
  ------------------
  |  Branch (1070:13): [True: 0, False: 30.0k]
  ------------------
 1071|      0|          return SerializationStatus::NEEDS_MORE_INPUT;
 1072|  30.0k|        } else if (status != SerializationStatus::DONE) {
  ------------------
  |  Branch (1072:20): [True: 0, False: 30.0k]
  ------------------
 1073|      0|          BRUNSLI_DCHECK(false);
 1074|      0|          ss.stage = SerializationState::ERROR;
 1075|      0|          break;
 1076|      0|        }
 1077|  30.0k|        ++ss.section_index;
 1078|  30.0k|        break;
 1079|  30.0k|      }
 1080|       |
 1081|    562|      case SerializationState::DONE: {
  ------------------
  |  Branch (1081:7): [True: 562, False: 43.4k]
  ------------------
 1082|    562|        if (!ss.output_queue.empty()) {
  ------------------
  |  Branch (1082:13): [True: 263, False: 299]
  ------------------
 1083|    263|          return SerializationStatus::NEEDS_MORE_OUTPUT;
 1084|    299|        } else {
 1085|    299|          return SerializationStatus::DONE;
 1086|    299|        }
 1087|    562|      }
 1088|       |
 1089|  4.28k|      default:
  ------------------
  |  Branch (1089:7): [True: 4.28k, False: 39.7k]
  ------------------
 1090|  4.28k|        return SerializationStatus::ERROR;
 1091|  44.0k|    }
 1092|  44.0k|  }
 1093|  4.84k|}
jpeg_data_writer.cc:_ZZN7brunsli8internal3dec13SerializeJpegEPNS1_5StateERKNS_8JPEGDataEPmPPhENK3$_0clEv:
  992|  39.4k|  const auto maybe_push_output = [&]() {
  993|  39.4k|    if (ss.stage != SerializationState::ERROR) {
  ------------------
  |  Branch (993:9): [True: 39.4k, False: 0]
  ------------------
  994|  39.4k|      PushOutput(&ss.output_queue, available_out, next_out);
  995|  39.4k|    }
  996|  39.4k|  };
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_110PushOutputEPNSt3__15dequeINS_8internal3dec11OutputChunkENS1_9allocatorIS5_EEEEPmPPh:
  946|  39.4k|                uint8_t** next_out) {
  947|  75.5k|  while (*available_out > 0) {
  ------------------
  |  Branch (947:10): [True: 74.8k, False: 703]
  ------------------
  948|       |    // No more data.
  949|  74.8k|    if (in->empty()) return;
  ------------------
  |  Branch (949:9): [True: 38.7k, False: 36.0k]
  ------------------
  950|  36.0k|    OutputChunk& chunk = in->front();
  951|  36.0k|    size_t to_copy = std::min(*available_out, chunk.len);
  952|  36.0k|    if (to_copy > 0) {
  ------------------
  |  Branch (952:9): [True: 35.7k, False: 305]
  ------------------
  953|  35.7k|      memcpy(*next_out, chunk.next, to_copy);
  954|  35.7k|      *next_out += to_copy;
  955|  35.7k|      *available_out -= to_copy;
  956|  35.7k|      chunk.next += to_copy;
  957|  35.7k|      chunk.len -= to_copy;
  958|  35.7k|    }
  959|  36.0k|    if (chunk.len == 0) in->pop_front();
  ------------------
  |  Branch (959:9): [True: 35.7k, False: 314]
  ------------------
  960|  36.0k|  }
  961|  39.4k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeSOIEPNS_8internal3dec18SerializationStateE:
  306|  4.57k|bool EncodeSOI(SerializationState* state) {
  307|  4.57k|  state->output_queue.push_back(OutputChunk({0xFF, 0xD8}));
  308|  4.57k|  return true;
  309|  4.57k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_116SerializeSectionEhRKNS_8internal3dec5StateEPNS2_18SerializationStateERKNS_8JPEGDataE:
  878|  34.2k|                                     const JPEGData& jpg) {
  879|  34.2k|  const auto to_status = [](bool result) {
  880|  34.2k|    return result ? SerializationStatus::DONE : SerializationStatus::ERROR;
  881|  34.2k|  };
  882|       |  // TODO(eustas): add and use marker enum
  883|  34.2k|  switch (marker) {
  884|  3.66k|    case 0xC0:
  ------------------
  |  Branch (884:5): [True: 3.66k, False: 30.6k]
  ------------------
  885|  4.84k|    case 0xC1:
  ------------------
  |  Branch (885:5): [True: 1.18k, False: 33.1k]
  ------------------
  886|  9.63k|    case 0xC2:
  ------------------
  |  Branch (886:5): [True: 4.79k, False: 29.4k]
  ------------------
  887|  11.0k|    case 0xC9:
  ------------------
  |  Branch (887:5): [True: 1.41k, False: 32.8k]
  ------------------
  888|  12.1k|    case 0xCA:
  ------------------
  |  Branch (888:5): [True: 1.13k, False: 33.1k]
  ------------------
  889|  12.1k|      return to_status(EncodeSOF(jpg, marker, state));
  890|       |
  891|  4.76k|    case 0xC4:
  ------------------
  |  Branch (891:5): [True: 4.76k, False: 29.5k]
  ------------------
  892|  4.76k|      return to_status(EncodeDHT(jpg, state));
  893|       |
  894|  2.00k|    case 0xD0:
  ------------------
  |  Branch (894:5): [True: 2.00k, False: 32.2k]
  ------------------
  895|  3.06k|    case 0xD1:
  ------------------
  |  Branch (895:5): [True: 1.05k, False: 33.2k]
  ------------------
  896|  3.86k|    case 0xD2:
  ------------------
  |  Branch (896:5): [True: 796, False: 33.5k]
  ------------------
  897|  4.87k|    case 0xD3:
  ------------------
  |  Branch (897:5): [True: 1.01k, False: 33.2k]
  ------------------
  898|  5.98k|    case 0xD4:
  ------------------
  |  Branch (898:5): [True: 1.11k, False: 33.1k]
  ------------------
  899|  7.21k|    case 0xD5:
  ------------------
  |  Branch (899:5): [True: 1.23k, False: 33.0k]
  ------------------
  900|  8.63k|    case 0xD6:
  ------------------
  |  Branch (900:5): [True: 1.41k, False: 32.8k]
  ------------------
  901|  9.61k|    case 0xD7:
  ------------------
  |  Branch (901:5): [True: 985, False: 33.3k]
  ------------------
  902|  9.61k|      return to_status(EncodeRestart(marker, state));
  903|       |
  904|    292|    case 0xD9:
  ------------------
  |  Branch (904:5): [True: 292, False: 34.0k]
  ------------------
  905|    292|      return to_status(EncodeEOI(jpg, state));
  906|       |
  907|  5.01k|    case 0xDA:
  ------------------
  |  Branch (907:5): [True: 5.01k, False: 29.2k]
  ------------------
  908|  5.01k|      return EncodeScan(jpg, parsing_state, state);
  909|       |
  910|    179|    case 0xDB:
  ------------------
  |  Branch (910:5): [True: 179, False: 34.1k]
  ------------------
  911|    179|      return to_status(EncodeDQT(jpg, state));
  912|       |
  913|  1.83k|    case 0xDD:
  ------------------
  |  Branch (913:5): [True: 1.83k, False: 32.4k]
  ------------------
  914|  1.83k|      return to_status(EncodeDRI(jpg, state));
  915|       |
  916|     26|    case 0xE0:
  ------------------
  |  Branch (916:5): [True: 26, False: 34.2k]
  ------------------
  917|     34|    case 0xE1:
  ------------------
  |  Branch (917:5): [True: 8, False: 34.2k]
  ------------------
  918|     44|    case 0xE2:
  ------------------
  |  Branch (918:5): [True: 10, False: 34.2k]
  ------------------
  919|     53|    case 0xE3:
  ------------------
  |  Branch (919:5): [True: 9, False: 34.2k]
  ------------------
  920|     60|    case 0xE4:
  ------------------
  |  Branch (920:5): [True: 7, False: 34.2k]
  ------------------
  921|     72|    case 0xE5:
  ------------------
  |  Branch (921:5): [True: 12, False: 34.2k]
  ------------------
  922|     95|    case 0xE6:
  ------------------
  |  Branch (922:5): [True: 23, False: 34.2k]
  ------------------
  923|    118|    case 0xE7:
  ------------------
  |  Branch (923:5): [True: 23, False: 34.2k]
  ------------------
  924|    135|    case 0xE8:
  ------------------
  |  Branch (924:5): [True: 17, False: 34.2k]
  ------------------
  925|    148|    case 0xE9:
  ------------------
  |  Branch (925:5): [True: 13, False: 34.2k]
  ------------------
  926|    158|    case 0xEA:
  ------------------
  |  Branch (926:5): [True: 10, False: 34.2k]
  ------------------
  927|    172|    case 0xEB:
  ------------------
  |  Branch (927:5): [True: 14, False: 34.2k]
  ------------------
  928|    184|    case 0xEC:
  ------------------
  |  Branch (928:5): [True: 12, False: 34.2k]
  ------------------
  929|    209|    case 0xED:
  ------------------
  |  Branch (929:5): [True: 25, False: 34.2k]
  ------------------
  930|    234|    case 0xEE:
  ------------------
  |  Branch (930:5): [True: 25, False: 34.2k]
  ------------------
  931|    247|    case 0xEF:
  ------------------
  |  Branch (931:5): [True: 13, False: 34.2k]
  ------------------
  932|    247|      return to_status(EncodeAPP(jpg, marker, state));
  933|       |
  934|      4|    case 0xFE:
  ------------------
  |  Branch (934:5): [True: 4, False: 34.2k]
  ------------------
  935|      4|      return to_status(EncodeCOM(jpg, state));
  936|       |
  937|     23|    case 0xFF:
  ------------------
  |  Branch (937:5): [True: 23, False: 34.2k]
  ------------------
  938|     23|      return to_status(EncodeInterMarkerData(jpg, state));
  939|       |
  940|    126|    default:
  ------------------
  |  Branch (940:5): [True: 126, False: 34.1k]
  ------------------
  941|    126|      return SerializationStatus::ERROR;
  942|  34.2k|  }
  943|  34.2k|}
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_116SerializeSectionEhRKNS_8internal3dec5StateEPNS2_18SerializationStateERKNS_8JPEGDataEENK3$_0clEb:
  879|  29.1k|  const auto to_status = [](bool result) {
  880|  29.1k|    return result ? SerializationStatus::DONE : SerializationStatus::ERROR;
  ------------------
  |  Branch (880:12): [True: 28.9k, False: 244]
  ------------------
  881|  29.1k|  };
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeSOFERKNS_8JPEGDataEhPNS_8internal3dec18SerializationStateE:
  317|  12.1k|bool EncodeSOF(const JPEGData& jpg, uint8_t marker, SerializationState* state) {
  318|  12.1k|  if (marker <= 0xC2) state->is_progressive = (marker == 0xC2);
  ------------------
  |  Branch (318:7): [True: 9.63k, False: 2.55k]
  ------------------
  319|       |
  320|  12.1k|  const size_t n_comps = jpg.components.size();
  321|  12.1k|  const size_t marker_len = 8 + 3 * n_comps;
  322|  12.1k|  state->output_queue.emplace_back(marker_len + 2);
  323|  12.1k|  uint8_t* data = state->output_queue.back().buffer->data();
  324|  12.1k|  size_t pos = 0;
  325|  12.1k|  data[pos++] = 0xFFu;
  326|  12.1k|  data[pos++] = marker;
  327|  12.1k|  data[pos++] = static_cast<uint8_t>(marker_len >> 8u);
  328|  12.1k|  data[pos++] = static_cast<uint8_t>(marker_len);
  329|  12.1k|  data[pos++] = kJpegPrecision;
  330|  12.1k|  data[pos++] = jpg.height >> 8u;
  331|  12.1k|  data[pos++] = jpg.height & 0xFFu;
  332|  12.1k|  data[pos++] = jpg.width >> 8u;
  333|  12.1k|  data[pos++] = jpg.width & 0xFFu;
  334|  12.1k|  data[pos++] = static_cast<uint8_t>(n_comps);
  335|  24.4k|  for (size_t i = 0; i < n_comps; ++i) {
  ------------------
  |  Branch (335:22): [True: 12.2k, False: 12.1k]
  ------------------
  336|  12.2k|    data[pos++] = jpg.components[i].id;
  337|  12.2k|    data[pos++] = ((jpg.components[i].h_samp_factor << 4u) |
  338|  12.2k|                   (jpg.components[i].v_samp_factor));
  339|  12.2k|    const size_t quant_idx = jpg.components[i].quant_idx;
  340|  12.2k|    if (quant_idx >= jpg.quant.size()) return false;
  ------------------
  |  Branch (340:9): [True: 0, False: 12.2k]
  ------------------
  341|  12.2k|    data[pos++] = jpg.quant[quant_idx].index;
  342|  12.2k|  }
  343|  12.1k|  return true;
  344|  12.1k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeDHTERKNS_8JPEGDataEPNS_8internal3dec18SerializationStateE:
  370|  4.76k|bool EncodeDHT(const JPEGData& jpg, SerializationState* state) {
  371|  4.76k|  const std::vector<JPEGHuffmanCode>& huffman_code = jpg.huffman_code;
  372|       |
  373|  4.76k|  size_t marker_len = 2;
  374|  12.4k|  for (size_t i = state->dht_index; i < huffman_code.size(); ++i) {
  ------------------
  |  Branch (374:37): [True: 12.4k, False: 0]
  ------------------
  375|  12.4k|    const JPEGHuffmanCode& huff = huffman_code[i];
  376|  12.4k|    marker_len += kJpegHuffmanMaxBitLength;
  377|   223k|    for (size_t j = 0; j < huff.counts.size(); ++j) {
  ------------------
  |  Branch (377:24): [True: 211k, False: 12.4k]
  ------------------
  378|   211k|      marker_len += huff.counts[j];
  379|   211k|    }
  380|  12.4k|    if (huff.is_last) break;
  ------------------
  |  Branch (380:9): [True: 4.76k, False: 7.65k]
  ------------------
  381|  12.4k|  }
  382|  4.76k|  state->output_queue.emplace_back(marker_len + 2);
  383|  4.76k|  uint8_t* data = state->output_queue.back().buffer->data();
  384|  4.76k|  size_t pos = 0;
  385|  4.76k|  data[pos++] = 0xFFu;
  386|  4.76k|  data[pos++] = 0xC4u;
  387|  4.76k|  data[pos++] = static_cast<uint8_t>(marker_len >> 8u);
  388|  4.76k|  data[pos++] = static_cast<uint8_t>(marker_len);
  389|  12.4k|  while (true) {
  ------------------
  |  Branch (389:10): [True: 12.4k, Folded]
  ------------------
  390|  12.4k|    const size_t huffman_code_index = state->dht_index++;
  391|  12.4k|    if (huffman_code_index >= huffman_code.size()) {
  ------------------
  |  Branch (391:9): [True: 0, False: 12.4k]
  ------------------
  392|      0|      return false;
  393|      0|    }
  394|  12.4k|    const JPEGHuffmanCode& huff = huffman_code[huffman_code_index];
  395|  12.4k|    size_t index = huff.slot_id;
  396|  12.4k|    HuffmanCodeTable* huff_table;
  397|  12.4k|    if (index & 0x10) {
  ------------------
  |  Branch (397:9): [True: 7.14k, False: 5.28k]
  ------------------
  398|  7.14k|      index -= 0x10;
  399|  7.14k|      huff_table = &state->ac_huff_table[index];
  400|  7.14k|    } else {
  401|  5.28k|      huff_table = &state->dc_huff_table[index];
  402|  5.28k|    }
  403|       |    // TODO(eustas): cache
  404|       |    // TODO(eustas): set up non-existing symbols
  405|  12.4k|    if (!BuildHuffmanCodeTable(huff, huff_table)) {
  ------------------
  |  Branch (405:9): [True: 0, False: 12.4k]
  ------------------
  406|      0|      return false;
  407|      0|    }
  408|  12.4k|    size_t total_count = 0;
  409|  12.4k|    size_t max_length = 0;
  410|   223k|    for (size_t i = 0; i < huff.counts.size(); ++i) {
  ------------------
  |  Branch (410:24): [True: 211k, False: 12.4k]
  ------------------
  411|   211k|      if (huff.counts[i] != 0) {
  ------------------
  |  Branch (411:11): [True: 107k, False: 103k]
  ------------------
  412|   107k|        max_length = i;
  413|   107k|      }
  414|   211k|      total_count += huff.counts[i];
  415|   211k|    }
  416|  12.4k|    --total_count;
  417|  12.4k|    data[pos++] = huff.slot_id;
  418|   211k|    for (size_t i = 1; i <= kJpegHuffmanMaxBitLength; ++i) {
  ------------------
  |  Branch (418:24): [True: 198k, False: 12.4k]
  ------------------
  419|   198k|      data[pos++] = (i == max_length ? huff.counts[i] - 1 : huff.counts[i]);
  ------------------
  |  Branch (419:22): [True: 12.4k, False: 186k]
  ------------------
  420|   198k|    }
  421|   947k|    for (size_t i = 0; i < total_count; ++i) {
  ------------------
  |  Branch (421:24): [True: 935k, False: 12.4k]
  ------------------
  422|   935k|      data[pos++] = huff.values[i];
  423|   935k|    }
  424|  12.4k|    if (huff.is_last) break;
  ------------------
  |  Branch (424:9): [True: 4.76k, False: 7.65k]
  ------------------
  425|  12.4k|  }
  426|  4.76k|  return true;
  427|  4.76k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_121BuildHuffmanCodeTableERKNS_15JPEGHuffmanCodeEPNS_16HuffmanCodeTableE:
  266|  12.4k|                           HuffmanCodeTable* table) {
  267|  12.4k|  int huff_code[kJpegHuffmanAlphabetSize];
  268|       |  // +1 for a sentinel element.
  269|  12.4k|  uint32_t huff_size[kJpegHuffmanAlphabetSize + 1];
  270|  12.4k|  int p = 0;
  271|   211k|  for (size_t l = 1; l <= kJpegHuffmanMaxBitLength; ++l) {
  ------------------
  |  Branch (271:22): [True: 198k, False: 12.4k]
  ------------------
  272|   198k|    int i = huff.counts[l];
  273|   198k|    if (p + i > kJpegHuffmanAlphabetSize + 1) {
  ------------------
  |  Branch (273:9): [True: 0, False: 198k]
  ------------------
  274|      0|      return false;
  275|      0|    }
  276|  1.14M|    while (i--) huff_size[p++] = static_cast<uint32_t>(l);
  ------------------
  |  Branch (276:12): [True: 947k, False: 198k]
  ------------------
  277|   198k|  }
  278|       |
  279|  12.4k|  if (p == 0) {
  ------------------
  |  Branch (279:7): [True: 0, False: 12.4k]
  ------------------
  280|      0|    return true;
  281|      0|  }
  282|       |
  283|       |  // Reuse sentinel element.
  284|  12.4k|  int last_p = p - 1;
  285|  12.4k|  huff_size[last_p] = 0;
  286|       |
  287|  12.4k|  int code = 0;
  288|  12.4k|  uint32_t si = huff_size[0];
  289|  12.4k|  p = 0;
  290|   129k|  while (huff_size[p]) {
  ------------------
  |  Branch (290:10): [True: 117k, False: 12.4k]
  ------------------
  291|  1.05M|    while ((huff_size[p]) == si) {
  ------------------
  |  Branch (291:12): [True: 935k, False: 117k]
  ------------------
  292|   935k|      huff_code[p++] = code;
  293|   935k|      code++;
  294|   935k|    }
  295|   117k|    code <<= 1;
  296|   117k|    si++;
  297|   117k|  }
  298|   947k|  for (p = 0; p < last_p; p++) {
  ------------------
  |  Branch (298:15): [True: 935k, False: 12.4k]
  ------------------
  299|   935k|    int i = huff.values[p];
  300|   935k|    table->depth[i] = huff_size[p];
  301|   935k|    table->code[i] = huff_code[p];
  302|   935k|  }
  303|  12.4k|  return true;
  304|  12.4k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_113EncodeRestartEhPNS_8internal3dec18SerializationStateE:
  475|  9.61k|bool EncodeRestart(uint8_t marker, SerializationState* state) {
  476|  9.61k|  state->output_queue.push_back(OutputChunk({0xFF, marker}));
  477|  9.61k|  return true;
  478|  9.61k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeEOIERKNS_8JPEGDataEPNS_8internal3dec18SerializationStateE:
  311|    292|bool EncodeEOI(const JPEGData& jpg, SerializationState* state) {
  312|    292|  state->output_queue.push_back(OutputChunk({0xFF, 0xD9}));
  313|    292|  state->output_queue.emplace_back(jpg.tail_data);
  314|    292|  return true;
  315|    292|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_110EncodeScanERKNS_8JPEGDataERKNS_8internal3dec5StateEPNS5_18SerializationStateE:
  858|  5.01k|           SerializationState* state) {
  859|  5.01k|  const JPEGScanInfo& scan_info = jpg.scan_info[state->scan_index];
  860|  5.01k|  const bool is_progressive = state->is_progressive;
  861|  5.01k|  const int Al = is_progressive ? scan_info.Al : 0;
  ------------------
  |  Branch (861:18): [True: 4.27k, False: 733]
  ------------------
  862|  5.01k|  const int Ah = is_progressive ? scan_info.Ah : 0;
  ------------------
  |  Branch (862:18): [True: 4.27k, False: 733]
  ------------------
  863|  5.01k|  const int Ss = is_progressive ? scan_info.Ss : 0;
  ------------------
  |  Branch (863:18): [True: 4.27k, False: 733]
  ------------------
  864|  5.01k|  const int Se = is_progressive ? scan_info.Se : 63;
  ------------------
  |  Branch (864:18): [True: 4.27k, False: 733]
  ------------------
  865|  5.01k|  const bool need_sequential =
  866|  5.01k|      !is_progressive || (Ah == 0 && Al == 0 && Ss == 0 && Se == 63);
  ------------------
  |  Branch (866:7): [True: 733, False: 4.27k]
  |  Branch (866:27): [True: 1.56k, False: 2.71k]
  |  Branch (866:38): [True: 817, False: 744]
  |  Branch (866:49): [True: 342, False: 475]
  |  Branch (866:60): [True: 18, False: 324]
  ------------------
  867|  5.01k|  if (need_sequential) {
  ------------------
  |  Branch (867:7): [True: 751, False: 4.25k]
  ------------------
  868|    751|    return DoEncodeScan<0>(jpg, parsing_state, state);
  869|  4.25k|  } else if (Ah == 0) {
  ------------------
  |  Branch (869:14): [True: 1.54k, False: 2.71k]
  ------------------
  870|  1.54k|    return DoEncodeScan<1>(jpg, parsing_state, state);
  871|  2.71k|  } else {
  872|  2.71k|    return DoEncodeScan<2>(jpg, parsing_state, state);
  873|  2.71k|  }
  874|  5.01k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_112DoEncodeScanILi0EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateE:
  700|    751|                                                  SerializationState* state) {
  701|    751|  const JPEGScanInfo& scan_info = jpg.scan_info[state->scan_index];
  702|    751|  EncodeScanState& ss = state->scan_state;
  703|       |
  704|    751|  const int restart_interval =
  705|    751|      state->seen_dri_marker ? jpg.restart_interval : 0;
  ------------------
  |  Branch (705:7): [True: 169, False: 582]
  ------------------
  706|       |
  707|    751|  const auto get_next_extra_zero_run_index = [&ss, &scan_info]() -> int {
  708|    751|    if (ss.extra_zero_runs_pos < scan_info.extra_zero_runs.size()) {
  709|    751|      return scan_info.extra_zero_runs[ss.extra_zero_runs_pos].block_idx;
  710|    751|    } else {
  711|    751|      return -1;
  712|    751|    }
  713|    751|  };
  714|       |
  715|    751|  const auto get_next_reset_point = [&ss, &scan_info]() -> int {
  716|    751|    if (ss.next_reset_point_pos < scan_info.reset_points.size()) {
  717|    751|      return scan_info.reset_points[ss.next_reset_point_pos++];
  718|    751|    } else {
  719|    751|      return -1;
  720|    751|    }
  721|    751|  };
  722|       |
  723|    751|  if (ss.stage == EncodeScanState::HEAD) {
  ------------------
  |  Branch (723:7): [True: 751, False: 0]
  ------------------
  724|    751|    if (!EncodeSOS(jpg, scan_info, state)) return SerializationStatus::ERROR;
  ------------------
  |  Branch (724:9): [True: 24, False: 727]
  ------------------
  725|    727|    BitWriterInit(&ss.bw, &state->output_queue);
  726|    727|    DCTCodingStateInit(&ss.coding_state);
  727|    727|    ss.restarts_to_go = restart_interval;
  728|    727|    ss.next_restart_marker = 0;
  729|    727|    ss.block_scan_index = 0;
  730|    727|    ss.extra_zero_runs_pos = 0;
  731|    727|    ss.next_extra_zero_run_index = get_next_extra_zero_run_index();
  732|    727|    ss.next_reset_point_pos = 0;
  733|    727|    ss.next_reset_point = get_next_reset_point();
  734|    727|    ss.mcu_y = 0;
  735|    727|    memset(ss.last_dc_coeff, 0, sizeof(ss.last_dc_coeff));
  736|    727|    ss.stage = EncodeScanState::BODY;
  737|    727|  }
  738|    727|  BitWriter* bw = &ss.bw;
  739|    727|  DCTCodingState* coding_state = &ss.coding_state;
  740|       |
  741|    727|  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|    727|  const bool is_interleaved = (scan_info.num_components > 1);
  746|    727|  const JPEGComponent& base_component =
  747|    727|      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|    727|  const int h_group = is_interleaved ? 1 : base_component.h_samp_factor;
  ------------------
  |  Branch (753:23): [True: 421, False: 306]
  ------------------
  754|    727|  const int v_group = is_interleaved ? 1 : base_component.v_samp_factor;
  ------------------
  |  Branch (754:23): [True: 421, False: 306]
  ------------------
  755|    727|  const int MCUs_per_row =
  756|    727|      DivCeil(jpg.width * h_group, 8 * jpg.max_h_samp_factor);
  757|    727|  const int MCU_rows = DivCeil(jpg.height * v_group, 8 * jpg.max_v_samp_factor);
  758|    727|  const bool is_progressive = state->is_progressive;
  759|    727|  const int Al = is_progressive ? scan_info.Al : 0;
  ------------------
  |  Branch (759:18): [True: 18, False: 709]
  ------------------
  760|    727|  const int Ss = is_progressive ? scan_info.Ss : 0;
  ------------------
  |  Branch (760:18): [True: 18, False: 709]
  ------------------
  761|    727|  const int Se = is_progressive ? scan_info.Se : 63;
  ------------------
  |  Branch (761:18): [True: 18, False: 709]
  ------------------
  762|       |
  763|       |  // DC-only is defined by [0..0] spectral range.
  764|    727|  const bool want_ac = ((Ss != 0) || (Se != 0));
  ------------------
  |  Branch (764:25): [True: 0, False: 727]
  |  Branch (764:38): [True: 727, False: 0]
  ------------------
  765|    727|  const bool complete_ac = (parsing_state.stage == Stage::DONE);
  766|    727|  const bool has_ac =
  767|    727|      complete_ac || HasSection(&parsing_state, kBrunsliACDataTag);
  ------------------
  |  Branch (767:7): [True: 727, False: 0]
  |  Branch (767:22): [True: 0, False: 0]
  ------------------
  768|    727|  if (want_ac && !has_ac) return SerializationStatus::NEEDS_MORE_INPUT;
  ------------------
  |  Branch (768:7): [True: 727, False: 0]
  |  Branch (768:18): [True: 0, False: 727]
  ------------------
  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|    727|  const bool complete_dc = has_ac;
  774|    727|  const bool complete = want_ac ? complete_ac : complete_dc;
  ------------------
  |  Branch (774:25): [True: 727, False: 0]
  ------------------
  775|       |  // When "incomplete" |ac_dc| tracks information about current ("incomplete")
  776|       |  // band parsing progress.
  777|    727|  const int last_mcu_y =
  778|    727|      complete ? MCU_rows : parsing_state.internal->ac_dc.next_mcu_y * v_group;
  ------------------
  |  Branch (778:7): [True: 727, False: 0]
  ------------------
  779|       |
  780|  71.2k|  for (; ss.mcu_y < last_mcu_y; ++ss.mcu_y) {
  ------------------
  |  Branch (780:10): [True: 70.5k, False: 716]
  ------------------
  781|   578k|    for (int mcu_x = 0; mcu_x < MCUs_per_row; ++mcu_x) {
  ------------------
  |  Branch (781:25): [True: 507k, False: 70.5k]
  ------------------
  782|       |      // Possibly emit a restart marker.
  783|   507k|      if (restart_interval > 0 && ss.restarts_to_go == 0) {
  ------------------
  |  Branch (783:11): [True: 479k, False: 28.1k]
  |  Branch (783:35): [True: 150k, False: 329k]
  ------------------
  784|   150k|        Flush(coding_state, bw);
  785|   150k|        if (!JumpToByteBoundary(bw, &state->pad_bits, state->pad_bits_end)) {
  ------------------
  |  Branch (785:13): [True: 11, False: 150k]
  ------------------
  786|     11|          return SerializationStatus::ERROR;
  787|     11|        }
  788|   150k|        EmitMarker(bw, 0xD0 + ss.next_restart_marker);
  789|   150k|        ss.next_restart_marker += 1;
  790|   150k|        ss.next_restart_marker &= 0x7;
  791|   150k|        ss.restarts_to_go = restart_interval;
  792|   150k|        memset(ss.last_dc_coeff, 0, sizeof(ss.last_dc_coeff));
  793|   150k|      }
  794|       |      // Encode one MCU
  795|  1.45M|      for (size_t i = 0; i < scan_info.num_components; ++i) {
  ------------------
  |  Branch (795:26): [True: 949k, False: 507k]
  ------------------
  796|   949k|        const JPEGComponentScanInfo& si = scan_info.components[i];
  797|   949k|        const JPEGComponent& c = jpg.components[si.comp_idx];
  798|   949k|        const HuffmanCodeTable& dc_huff = state->dc_huff_table[si.dc_tbl_idx];
  799|   949k|        const HuffmanCodeTable& ac_huff = state->ac_huff_table[si.ac_tbl_idx];
  800|   949k|        int n_blocks_y = is_interleaved ? c.v_samp_factor : 1;
  ------------------
  |  Branch (800:26): [True: 590k, False: 358k]
  ------------------
  801|   949k|        int n_blocks_x = is_interleaved ? c.h_samp_factor : 1;
  ------------------
  |  Branch (801:26): [True: 590k, False: 358k]
  ------------------
  802|  2.89M|        for (int iy = 0; iy < n_blocks_y; ++iy) {
  ------------------
  |  Branch (802:26): [True: 1.94M, False: 949k]
  ------------------
  803|  6.28M|          for (int ix = 0; ix < n_blocks_x; ++ix) {
  ------------------
  |  Branch (803:28): [True: 4.34M, False: 1.94M]
  ------------------
  804|  4.34M|            int block_y = ss.mcu_y * n_blocks_y + iy;
  805|  4.34M|            int block_x = mcu_x * n_blocks_x + ix;
  806|  4.34M|            int block_idx = block_y * c.width_in_blocks + block_x;
  807|  4.34M|            if (ss.block_scan_index == ss.next_reset_point) {
  ------------------
  |  Branch (807:17): [True: 652, False: 4.34M]
  ------------------
  808|    652|              Flush(coding_state, bw);
  809|    652|              ss.next_reset_point = get_next_reset_point();
  810|    652|            }
  811|  4.34M|            int num_zero_runs = 0;
  812|  4.34M|            if (ss.block_scan_index == ss.next_extra_zero_run_index) {
  ------------------
  |  Branch (812:17): [True: 1.23k, False: 4.34M]
  ------------------
  813|  1.23k|              num_zero_runs = scan_info.extra_zero_runs[ss.extra_zero_runs_pos]
  814|  1.23k|                                  .num_extra_zero_runs;
  815|  1.23k|              ++ss.extra_zero_runs_pos;
  816|  1.23k|              ss.next_extra_zero_run_index = get_next_extra_zero_run_index();
  817|  1.23k|            }
  818|  4.34M|            const coeff_t* coeffs = &c.coeffs[block_idx << 6];
  819|  4.34M|            bool ok;
  820|  4.34M|            if (kMode == 0) {
  ------------------
  |  Branch (820:17): [True: 4.34M, Folded]
  ------------------
  821|  4.34M|              ok = EncodeDCTBlockSequential(coeffs, dc_huff, ac_huff,
  822|  4.34M|                                            num_zero_runs,
  823|  4.34M|                                            ss.last_dc_coeff + si.comp_idx, bw);
  824|  4.34M|            } else if (kMode == 1) {
  ------------------
  |  Branch (824:24): [Folded, False: 0]
  ------------------
  825|      0|              ok = EncodeDCTBlockProgressive(
  826|      0|                  coeffs, dc_huff, ac_huff, Ss, Se, Al, num_zero_runs,
  827|      0|                  coding_state, ss.last_dc_coeff + si.comp_idx, bw);
  828|      0|            } else {
  829|      0|              ok = EncodeRefinementBits(coeffs, ac_huff, Ss, Se, Al,
  830|      0|                                        coding_state, bw);
  831|      0|            }
  832|  4.34M|            if (!ok) return SerializationStatus::ERROR;
  ------------------
  |  Branch (832:17): [True: 0, False: 4.34M]
  ------------------
  833|  4.34M|            ++ss.block_scan_index;
  834|  4.34M|          }
  835|  1.94M|        }
  836|   949k|      }
  837|   507k|      --ss.restarts_to_go;
  838|   507k|    }
  839|  70.5k|  }
  840|    716|  if (ss.mcu_y < MCU_rows) {
  ------------------
  |  Branch (840:7): [True: 0, False: 716]
  ------------------
  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|    716|  Flush(coding_state, bw);
  845|    716|  if (!JumpToByteBoundary(bw, &state->pad_bits, state->pad_bits_end)) {
  ------------------
  |  Branch (845:7): [True: 12, False: 704]
  ------------------
  846|     12|    return SerializationStatus::ERROR;
  847|     12|  }
  848|    704|  BitWriterFinish(bw);
  849|    704|  ss.stage = EncodeScanState::HEAD;
  850|    704|  state->scan_index++;
  851|    704|  if (!bw->healthy) return SerializationStatus::ERROR;
  ------------------
  |  Branch (851:7): [True: 557, False: 147]
  ------------------
  852|       |
  853|    147|  return SerializationStatus::DONE;
  854|    704|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeSOSERKNS_8JPEGDataERKNS_12JPEGScanInfoEPNS_8internal3dec18SerializationStateE:
  347|  5.01k|               SerializationState* state) {
  348|  5.01k|  const size_t n_scans = scan_info.num_components;
  349|  5.01k|  const size_t marker_len = 6 + 2 * n_scans;
  350|  5.01k|  state->output_queue.emplace_back(marker_len + 2);
  351|  5.01k|  uint8_t* data = state->output_queue.back().buffer->data();
  352|  5.01k|  size_t pos = 0;
  353|  5.01k|  data[pos++] = 0xFFu;
  354|  5.01k|  data[pos++] = 0xDAu;
  355|  5.01k|  data[pos++] = static_cast<uint8_t>(marker_len >> 8u);
  356|  5.01k|  data[pos++] = static_cast<uint8_t>(marker_len);
  357|  5.01k|  data[pos++] = static_cast<uint8_t>(n_scans);
  358|  18.1k|  for (size_t i = 0; i < n_scans; ++i) {
  ------------------
  |  Branch (358:22): [True: 13.2k, False: 4.90k]
  ------------------
  359|  13.2k|    const JPEGComponentScanInfo& si = scan_info.components[i];
  360|  13.2k|    if (si.comp_idx >= jpg.components.size()) return false;
  ------------------
  |  Branch (360:9): [True: 107, False: 13.0k]
  ------------------
  361|  13.0k|    data[pos++] = jpg.components[si.comp_idx].id;
  362|  13.0k|    data[pos++] = (si.dc_tbl_idx << 4u) + si.ac_tbl_idx;
  363|  13.0k|  }
  364|  4.90k|  data[pos++] = scan_info.Ss;
  365|  4.90k|  data[pos++] = scan_info.Se;
  366|  4.90k|  data[pos++] = ((scan_info.Ah << 4u) | (scan_info.Al));
  367|  4.90k|  return true;
  368|  5.01k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_113BitWriterInitEPNS_8internal3dec9BitWriterEPNSt3__15dequeINS2_11OutputChunkENS5_9allocatorIS7_EEEE:
   52|  4.90k|void BitWriterInit(BitWriter* bw, std::deque<OutputChunk>* output_queue) {
   53|  4.90k|  bw->output = output_queue;
   54|  4.90k|  bw->chunk = OutputChunk(kBitWriterChunkSize);
   55|  4.90k|  bw->pos = 0;
   56|  4.90k|  bw->put_buffer = 0;
   57|  4.90k|  bw->put_bits = 64;
   58|  4.90k|  bw->healthy = true;
   59|  4.90k|  bw->data = bw->chunk.buffer->data();
   60|  4.90k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_118DCTCodingStateInitEPNS_8internal3dec14DCTCodingStateE:
  185|  4.90k|void DCTCodingStateInit(DCTCodingState* s) {
  186|  4.90k|  s->eob_run_ = 0;
  187|  4.90k|  s->cur_ac_huff_ = nullptr;
  188|  4.90k|  s->refinement_bits_.clear();
  189|  4.90k|  s->refinement_bits_.reserve(64);  // 1024 bits most often is more than enough.
  190|  4.90k|  s->refinement_bits_count_ = 0;
  191|  4.90k|}
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_112DoEncodeScanILi0EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateEENKUlvE_clEv:
  707|  1.95k|  const auto get_next_extra_zero_run_index = [&ss, &scan_info]() -> int {
  708|  1.95k|    if (ss.extra_zero_runs_pos < scan_info.extra_zero_runs.size()) {
  ------------------
  |  Branch (708:9): [True: 1.23k, False: 724]
  ------------------
  709|  1.23k|      return scan_info.extra_zero_runs[ss.extra_zero_runs_pos].block_idx;
  710|  1.23k|    } else {
  711|    724|      return -1;
  712|    724|    }
  713|  1.95k|  };
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_112DoEncodeScanILi0EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateEENKUlvE0_clEv:
  715|  1.37k|  const auto get_next_reset_point = [&ss, &scan_info]() -> int {
  716|  1.37k|    if (ss.next_reset_point_pos < scan_info.reset_points.size()) {
  ------------------
  |  Branch (716:9): [True: 654, False: 725]
  ------------------
  717|    654|      return scan_info.reset_points[ss.next_reset_point_pos++];
  718|    725|    } else {
  719|    725|      return -1;
  720|    725|    }
  721|  1.37k|  };
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_17DivCeilEii:
   44|  9.80k|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|  7.69M|static BRUNSLI_INLINE void Flush(DCTCodingState* s, BitWriter* bw) {
  196|  7.69M|  if (s->eob_run_ > 0) {
  ------------------
  |  Branch (196:7): [True: 7.28M, False: 406k]
  ------------------
  197|  7.28M|    int nbits = Log2FloorNonZero(s->eob_run_);
  198|  7.28M|    int symbol = nbits << 4u;
  199|  7.28M|    WriteBits(bw, s->cur_ac_huff_->depth[symbol],
  200|  7.28M|              s->cur_ac_huff_->code[symbol]);
  201|  7.28M|    if (nbits > 0) {
  ------------------
  |  Branch (201:9): [True: 34.2k, False: 7.25M]
  ------------------
  202|  34.2k|      WriteBits(bw, nbits, s->eob_run_ & ((1 << nbits) - 1));
  203|  34.2k|    }
  204|  7.28M|    s->eob_run_ = 0;
  205|  7.28M|  }
  206|  7.69M|  size_t num_words = s->refinement_bits_count_ >> 4;
  207|  7.72M|  for (size_t i = 0; i < num_words; ++i) {
  ------------------
  |  Branch (207:22): [True: 31.9k, False: 7.69M]
  ------------------
  208|  31.9k|    WriteBits(bw, 16, s->refinement_bits_[i]);
  209|  31.9k|  }
  210|  7.69M|  size_t tail = s->refinement_bits_count_ & 0xF;
  211|  7.69M|  if (tail) {
  ------------------
  |  Branch (211:7): [True: 37.5k, False: 7.65M]
  ------------------
  212|  37.5k|    WriteBits(bw, tail, s->refinement_bits_.back());
  213|  37.5k|  }
  214|  7.69M|  s->refinement_bits_.clear();
  215|  7.69M|  s->refinement_bits_count_ = 0;
  216|  7.69M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19WriteBitsEPNS_8internal3dec9BitWriterEim:
  117|  27.9M|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|  27.9M|  if (nbits == 0) {
  ------------------
  |  Branch (122:7): [True: 3.58M, False: 24.3M]
  ------------------
  123|  3.58M|    bw->healthy = false;
  124|  3.58M|    return;
  125|  3.58M|  }
  126|  24.3M|  bw->put_bits -= nbits;
  127|  24.3M|  bw->put_buffer |= (bits << bw->put_bits);
  128|  24.3M|  if (bw->put_bits <= 16) DischargeBitBuffer(bw);
  ------------------
  |  Branch (128:7): [True: 2.36M, False: 21.9M]
  ------------------
  129|  24.3M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_118DischargeBitBufferEPNS_8internal3dec9BitWriterE:
   87|  2.36M|static BRUNSLI_INLINE void DischargeBitBuffer(BitWriter* bw) {
   88|       |  // At this point we are ready to emit the most significant 6 bytes of
   89|       |  // put_buffer_ to the output.
   90|       |  // The JPEG format requires that after every 0xff byte in the entropy
   91|       |  // coded section, there is a zero byte, therefore we first check if any of
   92|       |  // the 6 most significant bytes of put_buffer_ is 0xFF.
   93|  2.36M|  Reserve(bw, 12);
   94|  2.36M|  if (HasZeroByte(~bw->put_buffer | 0xFFFF)) {
  ------------------
  |  Branch (94:7): [True: 762k, False: 1.59M]
  ------------------
   95|       |    // We have a 0xFF byte somewhere, examine each byte and append a zero
   96|       |    // byte if necessary.
   97|   762k|    EmitByte(bw, (bw->put_buffer >> 56) & 0xFF);
   98|   762k|    EmitByte(bw, (bw->put_buffer >> 48) & 0xFF);
   99|   762k|    EmitByte(bw, (bw->put_buffer >> 40) & 0xFF);
  100|   762k|    EmitByte(bw, (bw->put_buffer >> 32) & 0xFF);
  101|   762k|    EmitByte(bw, (bw->put_buffer >> 24) & 0xFF);
  102|   762k|    EmitByte(bw, (bw->put_buffer >> 16) & 0xFF);
  103|  1.59M|  } else {
  104|       |    // We don't have any 0xFF bytes, output all 6 bytes without checking.
  105|  1.59M|    bw->data[bw->pos] = (bw->put_buffer >> 56) & 0xFF;
  106|  1.59M|    bw->data[bw->pos + 1] = (bw->put_buffer >> 48) & 0xFF;
  107|  1.59M|    bw->data[bw->pos + 2] = (bw->put_buffer >> 40) & 0xFF;
  108|  1.59M|    bw->data[bw->pos + 3] = (bw->put_buffer >> 32) & 0xFF;
  109|  1.59M|    bw->data[bw->pos + 4] = (bw->put_buffer >> 24) & 0xFF;
  110|  1.59M|    bw->data[bw->pos + 5] = (bw->put_buffer >> 16) & 0xFF;
  111|  1.59M|    bw->pos += 6;
  112|  1.59M|  }
  113|  2.36M|  bw->put_buffer <<= 48;
  114|  2.36M|  bw->put_bits += 48;
  115|  2.36M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_17ReserveEPNS_8internal3dec9BitWriterEm:
   70|  3.05M|static BRUNSLI_INLINE void Reserve(BitWriter* bw, size_t n_bytes) {
   71|  3.05M|  if (BRUNSLI_PREDICT_FALSE((bw->pos + n_bytes) > kBitWriterChunkSize)) {
  ------------------
  |  |   85|  3.05M|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 870, False: 3.05M]
  |  |  ------------------
  ------------------
   72|    870|    SwapBuffer(bw);
   73|    870|  }
   74|  3.05M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_110SwapBufferEPNS_8internal3dec9BitWriterE:
   62|    870|static BRUNSLI_NOINLINE void SwapBuffer(BitWriter* bw) {
   63|    870|  bw->chunk.len = bw->pos;
   64|    870|  bw->output->emplace_back(std::move(bw->chunk));
   65|    870|  bw->chunk = OutputChunk(kBitWriterChunkSize);
   66|    870|  bw->data = bw->chunk.buffer->data();
   67|    870|  bw->pos = 0;
   68|    870|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_111HasZeroByteEm:
   48|  2.36M|static BRUNSLI_INLINE uint64_t HasZeroByte(uint64_t x) {
   49|  2.36M|  return (x - 0x0101010101010101ULL) & ~x & 0x8080808080808080ULL;
   50|  2.36M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_18EmitByteEPNS_8internal3dec9BitWriterEi:
   82|  5.26M|static BRUNSLI_INLINE void EmitByte(BitWriter* bw, int byte) {
   83|  5.26M|  bw->data[bw->pos++] = byte;
   84|  5.26M|  if (byte == 0xFF) bw->data[bw->pos++] = 0;
  ------------------
  |  Branch (84:7): [True: 1.10M, False: 4.15M]
  ------------------
   85|  5.26M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_118JumpToByteBoundaryEPNS_8internal3dec9BitWriterEPPKiS6_:
  139|   350k|                        const int* pad_bits_end) {
  140|   350k|  size_t n_bits = bw->put_bits & 7u;
  141|   350k|  uint8_t pad_pattern;
  142|   350k|  if (*pad_bits == nullptr) {
  ------------------
  |  Branch (142:7): [True: 349k, False: 1.51k]
  ------------------
  143|   349k|    pad_pattern = (1u << n_bits) - 1;
  144|   349k|  } else {
  145|  1.51k|    pad_pattern = 0;
  146|  1.51k|    const int* src = *pad_bits;
  147|       |    // TODO(eustas): bitwise reading looks insanely ineffective...
  148|  5.00k|    while (n_bits--) {
  ------------------
  |  Branch (148:12): [True: 3.53k, False: 1.46k]
  ------------------
  149|  3.53k|      pad_pattern <<= 1;
  150|  3.53k|      if (src >= pad_bits_end) return false;
  ------------------
  |  Branch (150:11): [True: 56, False: 3.48k]
  ------------------
  151|       |      // TODO(eustas): DCHECK *src == {0, 1}
  152|  3.48k|      pad_pattern |= !!*(src++);
  153|  3.48k|    }
  154|  1.46k|    *pad_bits = src;
  155|  1.46k|  }
  156|       |
  157|   350k|  Reserve(bw, 16);
  158|       |
  159|   786k|  while (bw->put_bits <= 56) {
  ------------------
  |  Branch (159:10): [True: 436k, False: 350k]
  ------------------
  160|   436k|    int c = (bw->put_buffer >> 56) & 0xFF;
  161|   436k|    EmitByte(bw, c);
  162|   436k|    bw->put_buffer <<= 8;
  163|   436k|    bw->put_bits += 8;
  164|   436k|  }
  165|   350k|  if (bw->put_bits < 64) {
  ------------------
  |  Branch (165:7): [True: 252k, False: 98.1k]
  ------------------
  166|   252k|    int pad_mask = 0xFFu >> (64 - bw->put_bits);
  167|   252k|    int c = ((bw->put_buffer >> 56) & ~pad_mask) | pad_pattern;
  168|   252k|    EmitByte(bw, c);
  169|   252k|  }
  170|   350k|  bw->put_buffer = 0;
  171|   350k|  bw->put_bits = 64;
  172|       |
  173|   350k|  return true;
  174|   350k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_110EmitMarkerEPNS_8internal3dec9BitWriterEi:
  131|   345k|void EmitMarker(BitWriter* bw, int marker) {
  132|   345k|  Reserve(bw, 2);
  133|   345k|  BRUNSLI_DCHECK(marker != 0xFF);
  134|   345k|  bw->data[bw->pos++] = 0xFF;
  135|   345k|  bw->data[bw->pos++] = marker;
  136|   345k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_124EncodeDCTBlockSequentialEPKsRKNS_16HuffmanCodeTableES5_iPsPNS_8internal3dec9BitWriterE:
  510|  4.34M|                              BitWriter* bw) {
  511|  4.34M|  coeff_t temp2;
  512|  4.34M|  coeff_t temp;
  513|  4.34M|  temp2 = coeffs[0];
  514|  4.34M|  temp = temp2 - *last_dc_coeff;
  515|  4.34M|  *last_dc_coeff = temp2;
  516|  4.34M|  temp2 = temp;
  517|  4.34M|  if (temp < 0) {
  ------------------
  |  Branch (517:7): [True: 1.12M, False: 3.22M]
  ------------------
  518|  1.12M|    temp = -temp;
  519|  1.12M|    temp2--;
  520|  1.12M|  }
  521|  4.34M|  int dc_nbits = (temp == 0) ? 0 : (Log2FloorNonZero(temp) + 1);
  ------------------
  |  Branch (521:18): [True: 2.22M, False: 2.11M]
  ------------------
  522|  4.34M|  WriteBits(bw, dc_huff.depth[dc_nbits], dc_huff.code[dc_nbits]);
  523|  4.34M|  if (dc_nbits > 0) {
  ------------------
  |  Branch (523:7): [True: 2.11M, False: 2.22M]
  ------------------
  524|  2.11M|    WriteBits(bw, dc_nbits, temp2 & ((1u << dc_nbits) - 1));
  525|  2.11M|  }
  526|  4.34M|  int r = 0;
  527|   277M|  for (int k = 1; k < 64; ++k) {
  ------------------
  |  Branch (527:19): [True: 273M, False: 4.34M]
  ------------------
  528|   273M|    if ((temp = coeffs[kJPEGNaturalOrder[k]]) == 0) {
  ------------------
  |  Branch (528:9): [True: 273M, False: 46.1k]
  ------------------
  529|   273M|      r++;
  530|   273M|      continue;
  531|   273M|    }
  532|  46.1k|    if (temp < 0) {
  ------------------
  |  Branch (532:9): [True: 28.0k, False: 18.1k]
  ------------------
  533|  28.0k|      temp = -temp;
  534|  28.0k|      temp2 = ~temp;
  535|  28.0k|    } else {
  536|  18.1k|      temp2 = temp;
  537|  18.1k|    }
  538|  73.6k|    while (r > 15) {
  ------------------
  |  Branch (538:12): [True: 27.4k, False: 46.1k]
  ------------------
  539|  27.4k|      WriteBits(bw, ac_huff.depth[0xf0], ac_huff.code[0xf0]);
  540|  27.4k|      r -= 16;
  541|  27.4k|    }
  542|  46.1k|    int ac_nbits = Log2FloorNonZero(temp) + 1;
  543|  46.1k|    int symbol = (r << 4u) + ac_nbits;
  544|  46.1k|    WriteBits(bw, ac_huff.depth[symbol], ac_huff.code[symbol]);
  545|  46.1k|    WriteBits(bw, ac_nbits, temp2 & ((1 << ac_nbits) - 1));
  546|  46.1k|    r = 0;
  547|  46.1k|  }
  548|  4.34M|  for (int i = 0; i < num_zero_runs; ++i) {
  ------------------
  |  Branch (548:19): [True: 3.13k, False: 4.34M]
  ------------------
  549|  3.13k|    WriteBits(bw, ac_huff.depth[0xf0], ac_huff.code[0xf0]);
  550|  3.13k|    r -= 16;
  551|  3.13k|  }
  552|  4.34M|  if (r > 0) {
  ------------------
  |  Branch (552:7): [True: 4.34M, False: 625]
  ------------------
  553|  4.34M|    WriteBits(bw, ac_huff.depth[0], ac_huff.code[0]);
  554|  4.34M|  }
  555|  4.34M|  return true;
  556|  4.34M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_115BitWriterFinishEPNS_8internal3dec9BitWriterE:
  176|  4.84k|void BitWriterFinish(BitWriter* bw) {
  177|  4.84k|  if (bw->pos == 0) return;
  ------------------
  |  Branch (177:7): [True: 236, False: 4.61k]
  ------------------
  178|  4.61k|  bw->chunk.len = bw->pos;
  179|  4.61k|  bw->output->emplace_back(std::move(bw->chunk));
  180|  4.61k|  bw->chunk = OutputChunk(nullptr, 0);
  181|  4.61k|  bw->data = nullptr;
  182|  4.61k|  bw->pos = 0;
  183|  4.61k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_112DoEncodeScanILi1EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateE:
  700|  1.54k|                                                  SerializationState* state) {
  701|  1.54k|  const JPEGScanInfo& scan_info = jpg.scan_info[state->scan_index];
  702|  1.54k|  EncodeScanState& ss = state->scan_state;
  703|       |
  704|  1.54k|  const int restart_interval =
  705|  1.54k|      state->seen_dri_marker ? jpg.restart_interval : 0;
  ------------------
  |  Branch (705:7): [True: 331, False: 1.21k]
  ------------------
  706|       |
  707|  1.54k|  const auto get_next_extra_zero_run_index = [&ss, &scan_info]() -> int {
  708|  1.54k|    if (ss.extra_zero_runs_pos < scan_info.extra_zero_runs.size()) {
  709|  1.54k|      return scan_info.extra_zero_runs[ss.extra_zero_runs_pos].block_idx;
  710|  1.54k|    } else {
  711|  1.54k|      return -1;
  712|  1.54k|    }
  713|  1.54k|  };
  714|       |
  715|  1.54k|  const auto get_next_reset_point = [&ss, &scan_info]() -> int {
  716|  1.54k|    if (ss.next_reset_point_pos < scan_info.reset_points.size()) {
  717|  1.54k|      return scan_info.reset_points[ss.next_reset_point_pos++];
  718|  1.54k|    } else {
  719|  1.54k|      return -1;
  720|  1.54k|    }
  721|  1.54k|  };
  722|       |
  723|  1.54k|  if (ss.stage == EncodeScanState::HEAD) {
  ------------------
  |  Branch (723:7): [True: 1.54k, False: 0]
  ------------------
  724|  1.54k|    if (!EncodeSOS(jpg, scan_info, state)) return SerializationStatus::ERROR;
  ------------------
  |  Branch (724:9): [True: 17, False: 1.52k]
  ------------------
  725|  1.52k|    BitWriterInit(&ss.bw, &state->output_queue);
  726|  1.52k|    DCTCodingStateInit(&ss.coding_state);
  727|  1.52k|    ss.restarts_to_go = restart_interval;
  728|  1.52k|    ss.next_restart_marker = 0;
  729|  1.52k|    ss.block_scan_index = 0;
  730|  1.52k|    ss.extra_zero_runs_pos = 0;
  731|  1.52k|    ss.next_extra_zero_run_index = get_next_extra_zero_run_index();
  732|  1.52k|    ss.next_reset_point_pos = 0;
  733|  1.52k|    ss.next_reset_point = get_next_reset_point();
  734|  1.52k|    ss.mcu_y = 0;
  735|  1.52k|    memset(ss.last_dc_coeff, 0, sizeof(ss.last_dc_coeff));
  736|  1.52k|    ss.stage = EncodeScanState::BODY;
  737|  1.52k|  }
  738|  1.52k|  BitWriter* bw = &ss.bw;
  739|  1.52k|  DCTCodingState* coding_state = &ss.coding_state;
  740|       |
  741|  1.52k|  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.52k|  const bool is_interleaved = (scan_info.num_components > 1);
  746|  1.52k|  const JPEGComponent& base_component =
  747|  1.52k|      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.52k|  const int h_group = is_interleaved ? 1 : base_component.h_samp_factor;
  ------------------
  |  Branch (753:23): [True: 907, False: 619]
  ------------------
  754|  1.52k|  const int v_group = is_interleaved ? 1 : base_component.v_samp_factor;
  ------------------
  |  Branch (754:23): [True: 907, False: 619]
  ------------------
  755|  1.52k|  const int MCUs_per_row =
  756|  1.52k|      DivCeil(jpg.width * h_group, 8 * jpg.max_h_samp_factor);
  757|  1.52k|  const int MCU_rows = DivCeil(jpg.height * v_group, 8 * jpg.max_v_samp_factor);
  758|  1.52k|  const bool is_progressive = state->is_progressive;
  759|  1.52k|  const int Al = is_progressive ? scan_info.Al : 0;
  ------------------
  |  Branch (759:18): [True: 1.52k, False: 0]
  ------------------
  760|  1.52k|  const int Ss = is_progressive ? scan_info.Ss : 0;
  ------------------
  |  Branch (760:18): [True: 1.52k, False: 0]
  ------------------
  761|  1.52k|  const int Se = is_progressive ? scan_info.Se : 63;
  ------------------
  |  Branch (761:18): [True: 1.52k, False: 0]
  ------------------
  762|       |
  763|       |  // DC-only is defined by [0..0] spectral range.
  764|  1.52k|  const bool want_ac = ((Ss != 0) || (Se != 0));
  ------------------
  |  Branch (764:25): [True: 1.07k, False: 454]
  |  Branch (764:38): [True: 378, False: 76]
  ------------------
  765|  1.52k|  const bool complete_ac = (parsing_state.stage == Stage::DONE);
  766|  1.52k|  const bool has_ac =
  767|  1.52k|      complete_ac || HasSection(&parsing_state, kBrunsliACDataTag);
  ------------------
  |  Branch (767:7): [True: 1.52k, False: 0]
  |  Branch (767:22): [True: 0, False: 0]
  ------------------
  768|  1.52k|  if (want_ac && !has_ac) return SerializationStatus::NEEDS_MORE_INPUT;
  ------------------
  |  Branch (768:7): [True: 1.45k, False: 76]
  |  Branch (768:18): [True: 0, False: 1.45k]
  ------------------
  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.52k|  const bool complete_dc = has_ac;
  774|  1.52k|  const bool complete = want_ac ? complete_ac : complete_dc;
  ------------------
  |  Branch (774:25): [True: 1.45k, False: 76]
  ------------------
  775|       |  // When "incomplete" |ac_dc| tracks information about current ("incomplete")
  776|       |  // band parsing progress.
  777|  1.52k|  const int last_mcu_y =
  778|  1.52k|      complete ? MCU_rows : parsing_state.internal->ac_dc.next_mcu_y * v_group;
  ------------------
  |  Branch (778:7): [True: 1.52k, False: 0]
  ------------------
  779|       |
  780|  71.6k|  for (; ss.mcu_y < last_mcu_y; ++ss.mcu_y) {
  ------------------
  |  Branch (780:10): [True: 70.0k, False: 1.52k]
  ------------------
  781|   548k|    for (int mcu_x = 0; mcu_x < MCUs_per_row; ++mcu_x) {
  ------------------
  |  Branch (781:25): [True: 478k, False: 70.0k]
  ------------------
  782|       |      // Possibly emit a restart marker.
  783|   478k|      if (restart_interval > 0 && ss.restarts_to_go == 0) {
  ------------------
  |  Branch (783:11): [True: 352k, False: 125k]
  |  Branch (783:35): [True: 59.2k, False: 293k]
  ------------------
  784|  59.2k|        Flush(coding_state, bw);
  785|  59.2k|        if (!JumpToByteBoundary(bw, &state->pad_bits, state->pad_bits_end)) {
  ------------------
  |  Branch (785:13): [True: 4, False: 59.2k]
  ------------------
  786|      4|          return SerializationStatus::ERROR;
  787|      4|        }
  788|  59.2k|        EmitMarker(bw, 0xD0 + ss.next_restart_marker);
  789|  59.2k|        ss.next_restart_marker += 1;
  790|  59.2k|        ss.next_restart_marker &= 0x7;
  791|  59.2k|        ss.restarts_to_go = restart_interval;
  792|  59.2k|        memset(ss.last_dc_coeff, 0, sizeof(ss.last_dc_coeff));
  793|  59.2k|      }
  794|       |      // Encode one MCU
  795|  1.55M|      for (size_t i = 0; i < scan_info.num_components; ++i) {
  ------------------
  |  Branch (795:26): [True: 1.07M, False: 478k]
  ------------------
  796|  1.07M|        const JPEGComponentScanInfo& si = scan_info.components[i];
  797|  1.07M|        const JPEGComponent& c = jpg.components[si.comp_idx];
  798|  1.07M|        const HuffmanCodeTable& dc_huff = state->dc_huff_table[si.dc_tbl_idx];
  799|  1.07M|        const HuffmanCodeTable& ac_huff = state->ac_huff_table[si.ac_tbl_idx];
  800|  1.07M|        int n_blocks_y = is_interleaved ? c.v_samp_factor : 1;
  ------------------
  |  Branch (800:26): [True: 799k, False: 275k]
  ------------------
  801|  1.07M|        int n_blocks_x = is_interleaved ? c.h_samp_factor : 1;
  ------------------
  |  Branch (801:26): [True: 799k, False: 275k]
  ------------------
  802|  4.79M|        for (int iy = 0; iy < n_blocks_y; ++iy) {
  ------------------
  |  Branch (802:26): [True: 3.72M, False: 1.07M]
  ------------------
  803|  13.7M|          for (int ix = 0; ix < n_blocks_x; ++ix) {
  ------------------
  |  Branch (803:28): [True: 10.0M, False: 3.72M]
  ------------------
  804|  10.0M|            int block_y = ss.mcu_y * n_blocks_y + iy;
  805|  10.0M|            int block_x = mcu_x * n_blocks_x + ix;
  806|  10.0M|            int block_idx = block_y * c.width_in_blocks + block_x;
  807|  10.0M|            if (ss.block_scan_index == ss.next_reset_point) {
  ------------------
  |  Branch (807:17): [True: 5.72k, False: 10.0M]
  ------------------
  808|  5.72k|              Flush(coding_state, bw);
  809|  5.72k|              ss.next_reset_point = get_next_reset_point();
  810|  5.72k|            }
  811|  10.0M|            int num_zero_runs = 0;
  812|  10.0M|            if (ss.block_scan_index == ss.next_extra_zero_run_index) {
  ------------------
  |  Branch (812:17): [True: 4.31k, False: 10.0M]
  ------------------
  813|  4.31k|              num_zero_runs = scan_info.extra_zero_runs[ss.extra_zero_runs_pos]
  814|  4.31k|                                  .num_extra_zero_runs;
  815|  4.31k|              ++ss.extra_zero_runs_pos;
  816|  4.31k|              ss.next_extra_zero_run_index = get_next_extra_zero_run_index();
  817|  4.31k|            }
  818|  10.0M|            const coeff_t* coeffs = &c.coeffs[block_idx << 6];
  819|  10.0M|            bool ok;
  820|  10.0M|            if (kMode == 0) {
  ------------------
  |  Branch (820:17): [Folded, False: 10.0M]
  ------------------
  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|  10.0M|            } else if (kMode == 1) {
  ------------------
  |  Branch (824:24): [True: 10.0M, Folded]
  ------------------
  825|  10.0M|              ok = EncodeDCTBlockProgressive(
  826|  10.0M|                  coeffs, dc_huff, ac_huff, Ss, Se, Al, num_zero_runs,
  827|  10.0M|                  coding_state, ss.last_dc_coeff + si.comp_idx, bw);
  828|  10.0M|            } else {
  829|      0|              ok = EncodeRefinementBits(coeffs, ac_huff, Ss, Se, Al,
  830|      0|                                        coding_state, bw);
  831|      0|            }
  832|  10.0M|            if (!ok) return SerializationStatus::ERROR;
  ------------------
  |  Branch (832:17): [True: 0, False: 10.0M]
  ------------------
  833|  10.0M|            ++ss.block_scan_index;
  834|  10.0M|          }
  835|  3.72M|        }
  836|  1.07M|      }
  837|   478k|      --ss.restarts_to_go;
  838|   478k|    }
  839|  70.0k|  }
  840|  1.52k|  if (ss.mcu_y < MCU_rows) {
  ------------------
  |  Branch (840:7): [True: 0, False: 1.52k]
  ------------------
  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.52k|  Flush(coding_state, bw);
  845|  1.52k|  if (!JumpToByteBoundary(bw, &state->pad_bits, state->pad_bits_end)) {
  ------------------
  |  Branch (845:7): [True: 10, False: 1.51k]
  ------------------
  846|     10|    return SerializationStatus::ERROR;
  847|     10|  }
  848|  1.51k|  BitWriterFinish(bw);
  849|  1.51k|  ss.stage = EncodeScanState::HEAD;
  850|  1.51k|  state->scan_index++;
  851|  1.51k|  if (!bw->healthy) return SerializationStatus::ERROR;
  ------------------
  |  Branch (851:7): [True: 1.12k, False: 392]
  ------------------
  852|       |
  853|    392|  return SerializationStatus::DONE;
  854|  1.51k|}
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_112DoEncodeScanILi1EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateEENKUlvE_clEv:
  707|  5.84k|  const auto get_next_extra_zero_run_index = [&ss, &scan_info]() -> int {
  708|  5.84k|    if (ss.extra_zero_runs_pos < scan_info.extra_zero_runs.size()) {
  ------------------
  |  Branch (708:9): [True: 4.33k, False: 1.50k]
  ------------------
  709|  4.33k|      return scan_info.extra_zero_runs[ss.extra_zero_runs_pos].block_idx;
  710|  4.33k|    } else {
  711|  1.50k|      return -1;
  712|  1.50k|    }
  713|  5.84k|  };
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_112DoEncodeScanILi1EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateEENKUlvE0_clEv:
  715|  7.25k|  const auto get_next_reset_point = [&ss, &scan_info]() -> int {
  716|  7.25k|    if (ss.next_reset_point_pos < scan_info.reset_points.size()) {
  ------------------
  |  Branch (716:9): [True: 5.74k, False: 1.50k]
  ------------------
  717|  5.74k|      return scan_info.reset_points[ss.next_reset_point_pos++];
  718|  5.74k|    } else {
  719|  1.50k|      return -1;
  720|  1.50k|    }
  721|  7.25k|  };
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_125EncodeDCTBlockProgressiveEPKsRKNS_16HuffmanCodeTableES5_iiiiPNS_8internal3dec14DCTCodingStateEPsPNS7_9BitWriterE:
  563|  10.0M|                               coeff_t* last_dc_coeff, BitWriter* bw) {
  564|  10.0M|  bool eob_run_allowed = Ss > 0;
  565|  10.0M|  coeff_t temp2;
  566|  10.0M|  coeff_t temp;
  567|  10.0M|  if (Ss == 0) {
  ------------------
  |  Branch (567:7): [True: 3.59M, False: 6.48M]
  ------------------
  568|  3.59M|    temp2 = coeffs[0] >> Al;
  569|  3.59M|    temp = temp2 - *last_dc_coeff;
  570|  3.59M|    *last_dc_coeff = temp2;
  571|  3.59M|    temp2 = temp;
  572|  3.59M|    if (temp < 0) {
  ------------------
  |  Branch (572:9): [True: 974k, False: 2.61M]
  ------------------
  573|   974k|      temp = -temp;
  574|   974k|      temp2--;
  575|   974k|    }
  576|  3.59M|    int nbits = (temp == 0) ? 0 : (Log2FloorNonZero(temp) + 1);
  ------------------
  |  Branch (576:17): [True: 1.85M, False: 1.73M]
  ------------------
  577|  3.59M|    WriteBits(bw, dc_huff.depth[nbits], dc_huff.code[nbits]);
  578|  3.59M|    if (nbits > 0) {
  ------------------
  |  Branch (578:9): [True: 1.73M, False: 1.85M]
  ------------------
  579|  1.73M|      WriteBits(bw, nbits, temp2 & ((1 << nbits) - 1));
  580|  1.73M|    }
  581|  3.59M|    ++Ss;
  582|  3.59M|  }
  583|  10.0M|  if (Ss > Se) {
  ------------------
  |  Branch (583:7): [True: 456k, False: 9.62M]
  ------------------
  584|   456k|    return true;
  585|   456k|  }
  586|  9.62M|  int r = 0;
  587|   267M|  for (int k = Ss; k <= Se; ++k) {
  ------------------
  |  Branch (587:20): [True: 258M, False: 9.62M]
  ------------------
  588|   258M|    if ((temp = coeffs[kJPEGNaturalOrder[k]]) == 0) {
  ------------------
  |  Branch (588:9): [True: 257M, False: 41.0k]
  ------------------
  589|   257M|      r++;
  590|   257M|      continue;
  591|   257M|    }
  592|  41.0k|    if (temp < 0) {
  ------------------
  |  Branch (592:9): [True: 27.7k, False: 13.3k]
  ------------------
  593|  27.7k|      temp = -temp;
  594|  27.7k|      temp >>= Al;
  595|  27.7k|      temp2 = ~temp;
  596|  27.7k|    } else {
  597|  13.3k|      temp >>= Al;
  598|  13.3k|      temp2 = temp;
  599|  13.3k|    }
  600|  41.0k|    if (temp == 0) {
  ------------------
  |  Branch (600:9): [True: 1.68k, False: 39.4k]
  ------------------
  601|  1.68k|      r++;
  602|  1.68k|      continue;
  603|  1.68k|    }
  604|  39.4k|    Flush(coding_state, bw);
  605|  65.3k|    while (r > 15) {
  ------------------
  |  Branch (605:12): [True: 25.9k, False: 39.4k]
  ------------------
  606|  25.9k|      WriteBits(bw, ac_huff.depth[0xf0], ac_huff.code[0xf0]);
  607|  25.9k|      r -= 16;
  608|  25.9k|    }
  609|  39.4k|    int nbits = Log2FloorNonZero(temp) + 1;
  610|  39.4k|    int symbol = (r << 4u) + nbits;
  611|  39.4k|    WriteBits(bw, ac_huff.depth[symbol], ac_huff.code[symbol]);
  612|  39.4k|    WriteBits(bw, nbits, temp2 & ((1 << nbits) - 1));
  613|  39.4k|    r = 0;
  614|  39.4k|  }
  615|  9.62M|  if (num_zero_runs > 0) {
  ------------------
  |  Branch (615:7): [True: 4.25k, False: 9.61M]
  ------------------
  616|  4.25k|    Flush(coding_state, bw);
  617|  11.6k|    for (int i = 0; i < num_zero_runs; ++i) {
  ------------------
  |  Branch (617:21): [True: 7.37k, False: 4.25k]
  ------------------
  618|  7.37k|      WriteBits(bw, ac_huff.depth[0xf0], ac_huff.code[0xf0]);
  619|  7.37k|      r -= 16;
  620|  7.37k|    }
  621|  4.25k|  }
  622|  9.62M|  if (r > 0) {
  ------------------
  |  Branch (622:7): [True: 9.61M, False: 2.79k]
  ------------------
  623|       |    // Ignore result: since we do not buffer bits - it can not fail.
  624|  9.61M|    BufferEndOfBand(coding_state, &ac_huff, nullptr, 0, bw);
  625|  9.61M|    if (!eob_run_allowed) {
  ------------------
  |  Branch (625:9): [True: 3.40M, False: 6.21M]
  ------------------
  626|  3.40M|      Flush(coding_state, bw);
  627|  3.40M|    }
  628|  9.61M|  }
  629|  9.62M|  return true;
  630|  10.0M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_115BufferEndOfBandEPNS_8internal3dec14DCTCodingStateEPKNS_16HuffmanCodeTableEPKimPNS2_9BitWriterE:
  224|  35.1M|                                           BitWriter* bw) {
  225|  35.1M|  if (s->eob_run_ == 0) {
  ------------------
  |  Branch (225:7): [True: 7.28M, False: 27.8M]
  ------------------
  226|  7.28M|    s->cur_ac_huff_ = ac_huff;
  227|  7.28M|  }
  228|  35.1M|  ++s->eob_run_;
  229|  35.1M|  if (new_bits_count) {
  ------------------
  |  Branch (229:7): [True: 135k, False: 35.0M]
  ------------------
  230|   135k|    uint64_t new_bits = 0;
  231|   839k|    for (size_t i = 0; i < new_bits_count; ++i) {
  ------------------
  |  Branch (231:24): [True: 703k, False: 135k]
  ------------------
  232|   703k|      new_bits = (new_bits << 1) | new_bits_array[i];
  233|   703k|    }
  234|   135k|    size_t tail = s->refinement_bits_count_ & 0xF;
  235|   135k|    if (tail) {  // First stuff the tail item
  ------------------
  |  Branch (235:9): [True: 92.0k, False: 43.3k]
  ------------------
  236|  92.0k|      size_t stuff_bits_count = std::min(16 - tail, new_bits_count);
  237|  92.0k|      uint16_t stuff_bits = new_bits >> (new_bits_count - stuff_bits_count);
  238|  92.0k|      stuff_bits &= ((1u << stuff_bits_count) - 1);
  239|  92.0k|      s->refinement_bits_.back() =
  240|  92.0k|          (s->refinement_bits_.back() << stuff_bits_count) | stuff_bits;
  241|  92.0k|      new_bits_count -= stuff_bits_count;
  242|  92.0k|      s->refinement_bits_count_ += stuff_bits_count;
  243|  92.0k|    }
  244|   149k|    while (new_bits_count >= 16) {
  ------------------
  |  Branch (244:12): [True: 13.8k, False: 135k]
  ------------------
  245|  13.8k|      s->refinement_bits_.push_back(new_bits >> (new_bits_count - 16));
  246|  13.8k|      new_bits_count -= 16;
  247|  13.8k|      s->refinement_bits_count_ += 16;
  248|  13.8k|    }
  249|   135k|    if (new_bits_count) {
  ------------------
  |  Branch (249:9): [True: 55.5k, False: 79.8k]
  ------------------
  250|  55.5k|      s->refinement_bits_.push_back(new_bits & ((1u << new_bits_count) - 1));
  251|  55.5k|      s->refinement_bits_count_ += new_bits_count;
  252|  55.5k|    }
  253|   135k|  }
  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|  35.1M|  if (s->refinement_bits_count_ > 0x7FFF * (kDCTBlockSize - 1)) {
  ------------------
  |  Branch (256:7): [True: 0, False: 35.1M]
  ------------------
  257|      0|    return false;
  258|      0|  }
  259|  35.1M|  if (s->eob_run_ == 0x7FFF) {
  ------------------
  |  Branch (259:7): [True: 713, False: 35.1M]
  ------------------
  260|    713|    Flush(s, bw);
  261|    713|  }
  262|  35.1M|  return true;
  263|  35.1M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_112DoEncodeScanILi2EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateE:
  700|  2.71k|                                                  SerializationState* state) {
  701|  2.71k|  const JPEGScanInfo& scan_info = jpg.scan_info[state->scan_index];
  702|  2.71k|  EncodeScanState& ss = state->scan_state;
  703|       |
  704|  2.71k|  const int restart_interval =
  705|  2.71k|      state->seen_dri_marker ? jpg.restart_interval : 0;
  ------------------
  |  Branch (705:7): [True: 948, False: 1.76k]
  ------------------
  706|       |
  707|  2.71k|  const auto get_next_extra_zero_run_index = [&ss, &scan_info]() -> int {
  708|  2.71k|    if (ss.extra_zero_runs_pos < scan_info.extra_zero_runs.size()) {
  709|  2.71k|      return scan_info.extra_zero_runs[ss.extra_zero_runs_pos].block_idx;
  710|  2.71k|    } else {
  711|  2.71k|      return -1;
  712|  2.71k|    }
  713|  2.71k|  };
  714|       |
  715|  2.71k|  const auto get_next_reset_point = [&ss, &scan_info]() -> int {
  716|  2.71k|    if (ss.next_reset_point_pos < scan_info.reset_points.size()) {
  717|  2.71k|      return scan_info.reset_points[ss.next_reset_point_pos++];
  718|  2.71k|    } else {
  719|  2.71k|      return -1;
  720|  2.71k|    }
  721|  2.71k|  };
  722|       |
  723|  2.71k|  if (ss.stage == EncodeScanState::HEAD) {
  ------------------
  |  Branch (723:7): [True: 2.71k, False: 0]
  ------------------
  724|  2.71k|    if (!EncodeSOS(jpg, scan_info, state)) return SerializationStatus::ERROR;
  ------------------
  |  Branch (724:9): [True: 66, False: 2.65k]
  ------------------
  725|  2.65k|    BitWriterInit(&ss.bw, &state->output_queue);
  726|  2.65k|    DCTCodingStateInit(&ss.coding_state);
  727|  2.65k|    ss.restarts_to_go = restart_interval;
  728|  2.65k|    ss.next_restart_marker = 0;
  729|  2.65k|    ss.block_scan_index = 0;
  730|  2.65k|    ss.extra_zero_runs_pos = 0;
  731|  2.65k|    ss.next_extra_zero_run_index = get_next_extra_zero_run_index();
  732|  2.65k|    ss.next_reset_point_pos = 0;
  733|  2.65k|    ss.next_reset_point = get_next_reset_point();
  734|  2.65k|    ss.mcu_y = 0;
  735|  2.65k|    memset(ss.last_dc_coeff, 0, sizeof(ss.last_dc_coeff));
  736|  2.65k|    ss.stage = EncodeScanState::BODY;
  737|  2.65k|  }
  738|  2.65k|  BitWriter* bw = &ss.bw;
  739|  2.65k|  DCTCodingState* coding_state = &ss.coding_state;
  740|       |
  741|  2.65k|  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.65k|  const bool is_interleaved = (scan_info.num_components > 1);
  746|  2.65k|  const JPEGComponent& base_component =
  747|  2.65k|      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.65k|  const int h_group = is_interleaved ? 1 : base_component.h_samp_factor;
  ------------------
  |  Branch (753:23): [True: 2.06k, False: 587]
  ------------------
  754|  2.65k|  const int v_group = is_interleaved ? 1 : base_component.v_samp_factor;
  ------------------
  |  Branch (754:23): [True: 2.06k, False: 587]
  ------------------
  755|  2.65k|  const int MCUs_per_row =
  756|  2.65k|      DivCeil(jpg.width * h_group, 8 * jpg.max_h_samp_factor);
  757|  2.65k|  const int MCU_rows = DivCeil(jpg.height * v_group, 8 * jpg.max_v_samp_factor);
  758|  2.65k|  const bool is_progressive = state->is_progressive;
  759|  2.65k|  const int Al = is_progressive ? scan_info.Al : 0;
  ------------------
  |  Branch (759:18): [True: 2.65k, False: 0]
  ------------------
  760|  2.65k|  const int Ss = is_progressive ? scan_info.Ss : 0;
  ------------------
  |  Branch (760:18): [True: 2.65k, False: 0]
  ------------------
  761|  2.65k|  const int Se = is_progressive ? scan_info.Se : 63;
  ------------------
  |  Branch (761:18): [True: 2.65k, False: 0]
  ------------------
  762|       |
  763|       |  // DC-only is defined by [0..0] spectral range.
  764|  2.65k|  const bool want_ac = ((Ss != 0) || (Se != 0));
  ------------------
  |  Branch (764:25): [True: 2.06k, False: 585]
  |  Branch (764:38): [True: 552, False: 33]
  ------------------
  765|  2.65k|  const bool complete_ac = (parsing_state.stage == Stage::DONE);
  766|  2.65k|  const bool has_ac =
  767|  2.65k|      complete_ac || HasSection(&parsing_state, kBrunsliACDataTag);
  ------------------
  |  Branch (767:7): [True: 2.65k, False: 0]
  |  Branch (767:22): [True: 0, False: 0]
  ------------------
  768|  2.65k|  if (want_ac && !has_ac) return SerializationStatus::NEEDS_MORE_INPUT;
  ------------------
  |  Branch (768:7): [True: 2.61k, False: 33]
  |  Branch (768:18): [True: 0, False: 2.61k]
  ------------------
  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.65k|  const bool complete_dc = has_ac;
  774|  2.65k|  const bool complete = want_ac ? complete_ac : complete_dc;
  ------------------
  |  Branch (774:25): [True: 2.61k, False: 33]
  ------------------
  775|       |  // When "incomplete" |ac_dc| tracks information about current ("incomplete")
  776|       |  // band parsing progress.
  777|  2.65k|  const int last_mcu_y =
  778|  2.65k|      complete ? MCU_rows : parsing_state.internal->ac_dc.next_mcu_y * v_group;
  ------------------
  |  Branch (778:7): [True: 2.65k, False: 0]
  ------------------
  779|       |
  780|  89.9k|  for (; ss.mcu_y < last_mcu_y; ++ss.mcu_y) {
  ------------------
  |  Branch (780:10): [True: 87.3k, False: 2.64k]
  ------------------
  781|  1.01M|    for (int mcu_x = 0; mcu_x < MCUs_per_row; ++mcu_x) {
  ------------------
  |  Branch (781:25): [True: 924k, False: 87.3k]
  ------------------
  782|       |      // Possibly emit a restart marker.
  783|   924k|      if (restart_interval > 0 && ss.restarts_to_go == 0) {
  ------------------
  |  Branch (783:11): [True: 771k, False: 153k]
  |  Branch (783:35): [True: 135k, False: 635k]
  ------------------
  784|   135k|        Flush(coding_state, bw);
  785|   135k|        if (!JumpToByteBoundary(bw, &state->pad_bits, state->pad_bits_end)) {
  ------------------
  |  Branch (785:13): [True: 7, False: 135k]
  ------------------
  786|      7|          return SerializationStatus::ERROR;
  787|      7|        }
  788|   135k|        EmitMarker(bw, 0xD0 + ss.next_restart_marker);
  789|   135k|        ss.next_restart_marker += 1;
  790|   135k|        ss.next_restart_marker &= 0x7;
  791|   135k|        ss.restarts_to_go = restart_interval;
  792|   135k|        memset(ss.last_dc_coeff, 0, sizeof(ss.last_dc_coeff));
  793|   135k|      }
  794|       |      // Encode one MCU
  795|  2.72M|      for (size_t i = 0; i < scan_info.num_components; ++i) {
  ------------------
  |  Branch (795:26): [True: 1.80M, False: 924k]
  ------------------
  796|  1.80M|        const JPEGComponentScanInfo& si = scan_info.components[i];
  797|  1.80M|        const JPEGComponent& c = jpg.components[si.comp_idx];
  798|  1.80M|        const HuffmanCodeTable& dc_huff = state->dc_huff_table[si.dc_tbl_idx];
  799|  1.80M|        const HuffmanCodeTable& ac_huff = state->ac_huff_table[si.ac_tbl_idx];
  800|  1.80M|        int n_blocks_y = is_interleaved ? c.v_samp_factor : 1;
  ------------------
  |  Branch (800:26): [True: 1.17M, False: 621k]
  ------------------
  801|  1.80M|        int n_blocks_x = is_interleaved ? c.h_samp_factor : 1;
  ------------------
  |  Branch (801:26): [True: 1.17M, False: 621k]
  ------------------
  802|  9.14M|        for (int iy = 0; iy < n_blocks_y; ++iy) {
  ------------------
  |  Branch (802:26): [True: 7.34M, False: 1.80M]
  ------------------
  803|  33.3M|          for (int ix = 0; ix < n_blocks_x; ++ix) {
  ------------------
  |  Branch (803:28): [True: 26.0M, False: 7.34M]
  ------------------
  804|  26.0M|            int block_y = ss.mcu_y * n_blocks_y + iy;
  805|  26.0M|            int block_x = mcu_x * n_blocks_x + ix;
  806|  26.0M|            int block_idx = block_y * c.width_in_blocks + block_x;
  807|  26.0M|            if (ss.block_scan_index == ss.next_reset_point) {
  ------------------
  |  Branch (807:17): [True: 9.84k, False: 26.0M]
  ------------------
  808|  9.84k|              Flush(coding_state, bw);
  809|  9.84k|              ss.next_reset_point = get_next_reset_point();
  810|  9.84k|            }
  811|  26.0M|            int num_zero_runs = 0;
  812|  26.0M|            if (ss.block_scan_index == ss.next_extra_zero_run_index) {
  ------------------
  |  Branch (812:17): [True: 1.10k, False: 26.0M]
  ------------------
  813|  1.10k|              num_zero_runs = scan_info.extra_zero_runs[ss.extra_zero_runs_pos]
  814|  1.10k|                                  .num_extra_zero_runs;
  815|  1.10k|              ++ss.extra_zero_runs_pos;
  816|  1.10k|              ss.next_extra_zero_run_index = get_next_extra_zero_run_index();
  817|  1.10k|            }
  818|  26.0M|            const coeff_t* coeffs = &c.coeffs[block_idx << 6];
  819|  26.0M|            bool ok;
  820|  26.0M|            if (kMode == 0) {
  ------------------
  |  Branch (820:17): [Folded, False: 26.0M]
  ------------------
  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|  26.0M|            } else if (kMode == 1) {
  ------------------
  |  Branch (824:24): [Folded, False: 26.0M]
  ------------------
  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|  26.0M|            } else {
  829|  26.0M|              ok = EncodeRefinementBits(coeffs, ac_huff, Ss, Se, Al,
  830|  26.0M|                                        coding_state, bw);
  831|  26.0M|            }
  832|  26.0M|            if (!ok) return SerializationStatus::ERROR;
  ------------------
  |  Branch (832:17): [True: 0, False: 26.0M]
  ------------------
  833|  26.0M|            ++ss.block_scan_index;
  834|  26.0M|          }
  835|  7.34M|        }
  836|  1.80M|      }
  837|   924k|      --ss.restarts_to_go;
  838|   924k|    }
  839|  87.3k|  }
  840|  2.64k|  if (ss.mcu_y < MCU_rows) {
  ------------------
  |  Branch (840:7): [True: 0, False: 2.64k]
  ------------------
  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.64k|  Flush(coding_state, bw);
  845|  2.64k|  if (!JumpToByteBoundary(bw, &state->pad_bits, state->pad_bits_end)) {
  ------------------
  |  Branch (845:7): [True: 12, False: 2.63k]
  ------------------
  846|     12|    return SerializationStatus::ERROR;
  847|     12|  }
  848|  2.63k|  BitWriterFinish(bw);
  849|  2.63k|  ss.stage = EncodeScanState::HEAD;
  850|  2.63k|  state->scan_index++;
  851|  2.63k|  if (!bw->healthy) return SerializationStatus::ERROR;
  ------------------
  |  Branch (851:7): [True: 2.07k, False: 561]
  ------------------
  852|       |
  853|    561|  return SerializationStatus::DONE;
  854|  2.63k|}
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_112DoEncodeScanILi2EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateEENKUlvE_clEv:
  707|  3.75k|  const auto get_next_extra_zero_run_index = [&ss, &scan_info]() -> int {
  708|  3.75k|    if (ss.extra_zero_runs_pos < scan_info.extra_zero_runs.size()) {
  ------------------
  |  Branch (708:9): [True: 1.11k, False: 2.63k]
  ------------------
  709|  1.11k|      return scan_info.extra_zero_runs[ss.extra_zero_runs_pos].block_idx;
  710|  2.63k|    } else {
  711|  2.63k|      return -1;
  712|  2.63k|    }
  713|  3.75k|  };
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_112DoEncodeScanILi2EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateEENKUlvE0_clEv:
  715|  12.4k|  const auto get_next_reset_point = [&ss, &scan_info]() -> int {
  716|  12.4k|    if (ss.next_reset_point_pos < scan_info.reset_points.size()) {
  ------------------
  |  Branch (716:9): [True: 9.89k, False: 2.60k]
  ------------------
  717|  9.89k|      return scan_info.reset_points[ss.next_reset_point_pos++];
  718|  9.89k|    } else {
  719|  2.60k|      return -1;
  720|  2.60k|    }
  721|  12.4k|  };
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_120EncodeRefinementBitsEPKsRKNS_16HuffmanCodeTableEiiiPNS_8internal3dec14DCTCodingStateEPNS7_9BitWriterE:
  634|  26.0M|                          int Al, DCTCodingState* coding_state, BitWriter* bw) {
  635|  26.0M|  bool eob_run_allowed = Ss > 0;
  636|  26.0M|  if (Ss == 0) {
  ------------------
  |  Branch (636:7): [True: 3.92M, False: 22.1M]
  ------------------
  637|       |    // Emit next bit of DC component.
  638|  3.92M|    WriteBits(bw, 1, (coeffs[0] >> Al) & 1);
  639|  3.92M|    ++Ss;
  640|  3.92M|  }
  641|  26.0M|  if (Ss > Se) {
  ------------------
  |  Branch (641:7): [True: 508k, False: 25.5M]
  ------------------
  642|   508k|    return true;
  643|   508k|  }
  644|  25.5M|  int abs_values[kDCTBlockSize];
  645|  25.5M|  int eob = 0;
  646|   779M|  for (int k = Ss; k <= Se; k++) {
  ------------------
  |  Branch (646:20): [True: 754M, False: 25.5M]
  ------------------
  647|   754M|    const coeff_t abs_val = std::abs(coeffs[kJPEGNaturalOrder[k]]);
  648|   754M|    abs_values[k] = abs_val >> Al;
  649|   754M|    if (abs_values[k] == 1) {
  ------------------
  |  Branch (649:9): [True: 87.0k, False: 754M]
  ------------------
  650|  87.0k|      eob = k;
  651|  87.0k|    }
  652|   754M|  }
  653|  25.5M|  int r = 0;
  654|  25.5M|  int refinement_bits[kDCTBlockSize];
  655|  25.5M|  size_t refinement_bits_count = 0;
  656|   779M|  for (int k = Ss; k <= Se; k++) {
  ------------------
  |  Branch (656:20): [True: 754M, False: 25.5M]
  ------------------
  657|   754M|    if (abs_values[k] == 0) {
  ------------------
  |  Branch (657:9): [True: 753M, False: 823k]
  ------------------
  658|   753M|      r++;
  659|   753M|      continue;
  660|   753M|    }
  661|   869k|    while (r > 15 && k <= eob) {
  ------------------
  |  Branch (661:12): [True: 108k, False: 761k]
  |  Branch (661:22): [True: 45.8k, False: 62.2k]
  ------------------
  662|  45.8k|      Flush(coding_state, bw);
  663|  45.8k|      WriteBits(bw, ac_huff.depth[0xf0], ac_huff.code[0xf0]);
  664|  45.8k|      r -= 16;
  665|  56.2k|      for (size_t i = 0; i < refinement_bits_count; ++i) {
  ------------------
  |  Branch (665:26): [True: 10.3k, False: 45.8k]
  ------------------
  666|  10.3k|        WriteBits(bw, 1, refinement_bits[i]);
  667|  10.3k|      }
  668|  45.8k|      refinement_bits_count = 0;
  669|  45.8k|    }
  670|   823k|    if (abs_values[k] > 1) {
  ------------------
  |  Branch (670:9): [True: 736k, False: 87.0k]
  ------------------
  671|   736k|      refinement_bits[refinement_bits_count++] = abs_values[k] & 1u;
  672|   736k|      continue;
  673|   736k|    }
  674|  87.0k|    Flush(coding_state, bw);
  675|  87.0k|    int symbol = (r << 4u) + 1;
  676|  87.0k|    int new_non_zero_bit = (coeffs[kJPEGNaturalOrder[k]] < 0) ? 0 : 1;
  ------------------
  |  Branch (676:28): [True: 58.8k, False: 28.1k]
  ------------------
  677|  87.0k|    WriteBits(bw, ac_huff.depth[symbol], ac_huff.code[symbol]);
  678|  87.0k|    WriteBits(bw, 1, new_non_zero_bit);
  679|   109k|    for (size_t i = 0; i < refinement_bits_count; ++i) {
  ------------------
  |  Branch (679:24): [True: 22.1k, False: 87.0k]
  ------------------
  680|  22.1k|      WriteBits(bw, 1, refinement_bits[i]);
  681|  22.1k|    }
  682|  87.0k|    refinement_bits_count = 0;
  683|  87.0k|    r = 0;
  684|  87.0k|  }
  685|  25.5M|  if (r > 0 || refinement_bits_count) {
  ------------------
  |  Branch (685:7): [True: 25.5M, False: 12.2k]
  |  Branch (685:16): [True: 7.35k, False: 4.91k]
  ------------------
  686|  25.5M|    if (!BufferEndOfBand(coding_state, &ac_huff, refinement_bits,
  ------------------
  |  Branch (686:9): [True: 0, False: 25.5M]
  ------------------
  687|  25.5M|                         refinement_bits_count, bw)) {
  688|      0|      return false;
  689|      0|    }
  690|  25.5M|    if (!eob_run_allowed) {
  ------------------
  |  Branch (690:9): [True: 3.74M, False: 21.7M]
  ------------------
  691|  3.74M|      Flush(coding_state, bw);
  692|  3.74M|    }
  693|  25.5M|  }
  694|  25.5M|  return true;
  695|  25.5M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeDQTERKNS_8JPEGDataEPNS_8internal3dec18SerializationStateE:
  429|    179|bool EncodeDQT(const JPEGData& jpg, SerializationState* state) {
  430|    179|  int marker_len = 2;
  431|    179|  for (size_t i = state->dqt_index; i < jpg.quant.size(); ++i) {
  ------------------
  |  Branch (431:37): [True: 171, False: 8]
  ------------------
  432|    171|    const JPEGQuantTable& table = jpg.quant[i];
  433|    171|    marker_len += 1 + (table.precision ? 2 : 1) * kDCTBlockSize;
  ------------------
  |  Branch (433:24): [True: 53, False: 118]
  ------------------
  434|    171|    if (table.is_last) break;
  ------------------
  |  Branch (434:9): [True: 171, False: 0]
  ------------------
  435|    171|  }
  436|    179|  state->output_queue.emplace_back(marker_len + 2);
  437|    179|  uint8_t* data = state->output_queue.back().buffer->data();
  438|    179|  size_t pos = 0;
  439|    179|  data[pos++] = 0xFF;
  440|    179|  data[pos++] = 0xDB;
  441|    179|  data[pos++] = marker_len >> 8u;
  442|    179|  data[pos++] = marker_len & 0xFFu;
  443|    179|  while (true) {
  ------------------
  |  Branch (443:10): [True: 179, Folded]
  ------------------
  444|    179|    const size_t idx = state->dqt_index++;
  445|    179|    if (idx >= jpg.quant.size()) {
  ------------------
  |  Branch (445:9): [True: 8, False: 171]
  ------------------
  446|      8|      return false;  // corrupt input
  447|      8|    }
  448|    171|    const JPEGQuantTable& table = jpg.quant[idx];
  449|    171|    data[pos++] = (table.precision << 4u) + table.index;
  450|  11.1k|    for (size_t i = 0; i < kDCTBlockSize; ++i) {
  ------------------
  |  Branch (450:24): [True: 10.9k, False: 171]
  ------------------
  451|  10.9k|      int val_idx = kJPEGNaturalOrder[i];
  452|  10.9k|      int val = table.values[val_idx];
  453|  10.9k|      if (table.precision) {
  ------------------
  |  Branch (453:11): [True: 3.39k, False: 7.55k]
  ------------------
  454|  3.39k|        data[pos++] = val >> 8u;
  455|  3.39k|      }
  456|  10.9k|      data[pos++] = val & 0xFFu;
  457|  10.9k|    }
  458|    171|    if (table.is_last) break;
  ------------------
  |  Branch (458:9): [True: 171, False: 0]
  ------------------
  459|    171|  }
  460|    171|  return true;
  461|    179|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeDRIERKNS_8JPEGDataEPNS_8internal3dec18SerializationStateE:
  463|  1.83k|bool EncodeDRI(const JPEGData& jpg, SerializationState* state) {
  464|  1.83k|  state->seen_dri_marker = true;
  465|  1.83k|  OutputChunk dri_marker = {0xFF,
  466|  1.83k|                            0xDD,
  467|  1.83k|                            0,
  468|  1.83k|                            4,
  469|  1.83k|                            static_cast<uint8_t>(jpg.restart_interval >> 8),
  470|  1.83k|                            static_cast<uint8_t>(jpg.restart_interval & 0xFF)};
  471|  1.83k|  state->output_queue.push_back(std::move(dri_marker));
  472|  1.83k|  return true;
  473|  1.83k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeAPPERKNS_8JPEGDataEhPNS_8internal3dec18SerializationStateE:
  480|    247|bool EncodeAPP(const JPEGData& jpg, uint8_t marker, SerializationState* state) {
  481|       |  // TODO(eustas): check that marker corresponds to payload?
  482|    247|  (void)marker;
  483|       |
  484|    247|  size_t app_index = state->app_index++;
  485|    247|  if (app_index >= jpg.app_data.size()) return false;
  ------------------
  |  Branch (485:7): [True: 232, False: 15]
  ------------------
  486|     15|  state->output_queue.push_back(OutputChunk({0xFF}));
  487|     15|  state->output_queue.emplace_back(jpg.app_data[app_index]);
  488|     15|  return true;
  489|    247|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeCOMERKNS_8JPEGDataEPNS_8internal3dec18SerializationStateE:
  491|      4|bool EncodeCOM(const JPEGData& jpg, SerializationState* state) {
  492|      4|  size_t com_index = state->com_index++;
  493|      4|  if (com_index >= jpg.com_data.size()) return false;
  ------------------
  |  Branch (493:7): [True: 4, False: 0]
  ------------------
  494|      0|  state->output_queue.push_back(OutputChunk({0xFF}));
  495|      0|  state->output_queue.emplace_back(jpg.com_data[com_index]);
  496|      0|  return true;
  497|      4|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_121EncodeInterMarkerDataERKNS_8JPEGDataEPNS_8internal3dec18SerializationStateE:
  499|     23|bool EncodeInterMarkerData(const JPEGData& jpg, SerializationState* state) {
  500|     23|  size_t index = state->data_index++;
  501|     23|  if (index >= jpg.inter_marker_data.size()) return false;
  ------------------
  |  Branch (501:7): [True: 0, False: 23]
  ------------------
  502|     23|  state->output_queue.emplace_back(jpg.inter_marker_data[index]);
  503|     23|  return true;
  504|     23|}

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

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

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

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

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

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

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

