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

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

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

BrotliGetTransforms:
  173|  3.68k|const BrotliTransforms* BrotliGetTransforms(void) {
  174|  3.68k|  return &kBrotliTransforms;
  175|  3.68k|}
BrotliTransformDictionaryWord:
  237|  31.4k|    const BrotliTransforms* transforms, int transform_idx) {
  238|  31.4k|  int idx = 0;
  239|  31.4k|  const uint8_t* prefix = BROTLI_TRANSFORM_PREFIX(transforms, transform_idx);
  ------------------
  |  |   70|  31.4k|#define BROTLI_TRANSFORM_PREFIX(T, I) (&(T)->prefix_suffix[ \
  |  |   71|  31.4k|    (T)->prefix_suffix_map[BROTLI_TRANSFORM_PREFIX_ID(T, I)]])
  |  |  ------------------
  |  |  |  |   65|  31.4k|#define BROTLI_TRANSFORM_PREFIX_ID(T, I) ((T)->transforms[((I) * 3) + 0])
  |  |  ------------------
  ------------------
  240|  31.4k|  uint8_t type = BROTLI_TRANSFORM_TYPE(transforms, transform_idx);
  ------------------
  |  |   66|  31.4k|#define BROTLI_TRANSFORM_TYPE(T, I)      ((T)->transforms[((I) * 3) + 1])
  ------------------
  241|  31.4k|  const uint8_t* suffix = BROTLI_TRANSFORM_SUFFIX(transforms, transform_idx);
  ------------------
  |  |   72|  31.4k|#define BROTLI_TRANSFORM_SUFFIX(T, I) (&(T)->prefix_suffix[ \
  |  |   73|  31.4k|    (T)->prefix_suffix_map[BROTLI_TRANSFORM_SUFFIX_ID(T, I)]])
  |  |  ------------------
  |  |  |  |   67|  31.4k|#define BROTLI_TRANSFORM_SUFFIX_ID(T, I) ((T)->transforms[((I) * 3) + 2])
  |  |  ------------------
  ------------------
  242|  31.4k|  {
  243|  31.4k|    int prefix_len = *prefix++;
  244|  45.4k|    while (prefix_len--) { dst[idx++] = *prefix++; }
  ------------------
  |  Branch (244:12): [True: 13.9k, False: 31.4k]
  ------------------
  245|  31.4k|  }
  246|  31.4k|  {
  247|  31.4k|    const int t = type;
  248|  31.4k|    int i = 0;
  249|  31.4k|    if (t <= BROTLI_TRANSFORM_OMIT_LAST_9) {
  ------------------
  |  Branch (249:9): [True: 21.8k, False: 9.58k]
  ------------------
  250|  21.8k|      len -= t;
  251|  21.8k|    } else if (t >= BROTLI_TRANSFORM_OMIT_FIRST_1
  ------------------
  |  Branch (251:16): [True: 3.38k, False: 6.19k]
  ------------------
  252|  3.38k|        && t <= BROTLI_TRANSFORM_OMIT_FIRST_9) {
  ------------------
  |  Branch (252:12): [True: 3.38k, False: 0]
  ------------------
  253|  3.38k|      int skip = t - (BROTLI_TRANSFORM_OMIT_FIRST_1 - 1);
  254|  3.38k|      word += skip;
  255|  3.38k|      len -= skip;
  256|  3.38k|    }
  257|   235k|    while (i < len) { dst[idx++] = word[i++]; }
  ------------------
  |  Branch (257:12): [True: 203k, False: 31.4k]
  ------------------
  258|  31.4k|    if (t == BROTLI_TRANSFORM_UPPERCASE_FIRST) {
  ------------------
  |  Branch (258:9): [True: 4.71k, False: 26.7k]
  ------------------
  259|  4.71k|      ToUpperCase(&dst[idx - len]);
  260|  26.7k|    } else if (t == BROTLI_TRANSFORM_UPPERCASE_ALL) {
  ------------------
  |  Branch (260:16): [True: 1.48k, False: 25.2k]
  ------------------
  261|  1.48k|      uint8_t* uppercase = &dst[idx - len];
  262|  13.1k|      while (len > 0) {
  ------------------
  |  Branch (262:14): [True: 11.6k, False: 1.48k]
  ------------------
  263|  11.6k|        int step = ToUpperCase(uppercase);
  264|  11.6k|        uppercase += step;
  265|  11.6k|        len -= step;
  266|  11.6k|      }
  267|  25.2k|    } else if (t == BROTLI_TRANSFORM_SHIFT_FIRST) {
  ------------------
  |  Branch (267:16): [True: 0, False: 25.2k]
  ------------------
  268|      0|      uint16_t param = (uint16_t)(transforms->params[transform_idx * 2]
  269|      0|          + (transforms->params[transform_idx * 2 + 1] << 8u));
  270|      0|      Shift(&dst[idx - len], len, param);
  271|  25.2k|    } else if (t == BROTLI_TRANSFORM_SHIFT_ALL) {
  ------------------
  |  Branch (271:16): [True: 0, False: 25.2k]
  ------------------
  272|      0|      uint16_t param = (uint16_t)(transforms->params[transform_idx * 2]
  273|      0|          + (transforms->params[transform_idx * 2 + 1] << 8u));
  274|      0|      uint8_t* shift = &dst[idx - len];
  275|      0|      while (len > 0) {
  ------------------
  |  Branch (275:14): [True: 0, False: 0]
  ------------------
  276|      0|        int step = Shift(shift, len, param);
  277|      0|        shift += step;
  278|      0|        len -= step;
  279|      0|      }
  280|      0|    }
  281|  31.4k|  }
  282|  31.4k|  {
  283|  31.4k|    int suffix_len = *suffix++;
  284|  84.4k|    while (suffix_len--) { dst[idx++] = *suffix++; }
  ------------------
  |  Branch (284:12): [True: 52.9k, False: 31.4k]
  ------------------
  285|  31.4k|    return idx;
  286|  31.4k|  }
  287|  31.4k|}
transform.c:ToUpperCase:
  177|  16.3k|static int ToUpperCase(uint8_t* p) {
  178|  16.3k|  if (p[0] < 0xC0) {
  ------------------
  |  Branch (178:7): [True: 13.0k, False: 3.27k]
  ------------------
  179|  13.0k|    if (p[0] >= 'a' && p[0] <= 'z') {
  ------------------
  |  Branch (179:9): [True: 11.0k, False: 1.95k]
  |  Branch (179:24): [True: 10.0k, False: 1.03k]
  ------------------
  180|  10.0k|      p[0] ^= 32;
  181|  10.0k|    }
  182|  13.0k|    return 1;
  183|  13.0k|  }
  184|       |  /* An overly simplified uppercasing model for UTF-8. */
  185|  3.27k|  if (p[0] < 0xE0) {
  ------------------
  |  Branch (185:7): [True: 1.45k, False: 1.82k]
  ------------------
  186|  1.45k|    p[1] ^= 32;
  187|  1.45k|    return 2;
  188|  1.45k|  }
  189|       |  /* An arbitrary transform for three byte characters. */
  190|  1.82k|  p[2] ^= 5;
  191|  1.82k|  return 3;
  192|  3.27k|}

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

decode.c:BrotliBitReaderUnload:
  223|   140k|static BROTLI_INLINE void BrotliBitReaderUnload(BrotliBitReader* br) {
  224|   140k|  uint32_t unused_bytes = BrotliGetAvailableBits(br) >> 3;
  225|   140k|  uint32_t unused_bits = unused_bytes << 3;
  226|   140k|  br->avail_in += unused_bytes;
  227|   140k|  br->next_in -= unused_bytes;
  228|   140k|  if (unused_bits == sizeof(br->val_) << 3) {
  ------------------
  |  Branch (228:7): [True: 2.54k, False: 137k]
  ------------------
  229|  2.54k|    br->val_ = 0;
  230|   137k|  } else {
  231|   137k|    br->val_ <<= unused_bits;
  232|   137k|  }
  233|   140k|  br->bit_pos_ += unused_bits;
  234|   140k|}
decode.c:BrotliTakeBits:
  239|  76.7M|  BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
  240|  76.7M|  *val = (uint32_t)BrotliGetBitsUnmasked(br) & BitMask(n_bits);
  241|  76.7M|  BROTLI_LOG(("[BrotliTakeBits]  %d %d %d val: %6x\n",
  242|  76.7M|      (int)br->avail_in, (int)br->bit_pos_, (int)n_bits, (int)*val));
  243|  76.7M|  BrotliDropBits(br, n_bits);
  244|  76.7M|}
decode.c:BrotliGetBitsUnmasked:
  184|  1.91G|    BrotliBitReader* const br) {
  185|  1.91G|  return br->val_ >> br->bit_pos_;
  186|  1.91G|}
decode.c:BrotliDropBits:
  219|  1.83G|    BrotliBitReader* const br, uint32_t n_bits) {
  220|  1.83G|  br->bit_pos_ += n_bits;
  221|  1.83G|}
decode.c:BrotliSafeReadBits:
  292|   509k|    BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
  293|   509k|  BROTLI_DCHECK(n_bits <= 24);
  294|   754k|  while (BrotliGetAvailableBits(br) < n_bits) {
  ------------------
  |  Branch (294:10): [True: 246k, False: 508k]
  ------------------
  295|   246k|    if (!BrotliPullByte(br)) {
  ------------------
  |  Branch (295:9): [True: 1.02k, False: 245k]
  ------------------
  296|  1.02k|      return BROTLI_FALSE;
  ------------------
  |  |   53|  1.02k|#define BROTLI_FALSE 0
  ------------------
  297|  1.02k|    }
  298|   246k|  }
  299|   508k|  BrotliTakeBits(br, n_bits, val);
  300|   508k|  return BROTLI_TRUE;
  ------------------
  |  |   51|   508k|#define BROTLI_TRUE 1
  ------------------
  301|   509k|}
decode.c:BrotliPullByte:
  165|   215M|static BROTLI_INLINE BROTLI_BOOL BrotliPullByte(BrotliBitReader* const br) {
  166|   215M|  if (br->avail_in == 0) {
  ------------------
  |  Branch (166:7): [True: 214M, False: 410k]
  ------------------
  167|   214M|    return BROTLI_FALSE;
  ------------------
  |  |   53|   214M|#define BROTLI_FALSE 0
  ------------------
  168|   214M|  }
  169|   410k|  br->val_ >>= 8;
  170|   410k|#if (BROTLI_64_BITS)
  171|   410k|  br->val_ |= ((uint64_t)*br->next_in) << 56;
  172|       |#else
  173|       |  br->val_ |= ((uint32_t)*br->next_in) << 24;
  174|       |#endif
  175|   410k|  br->bit_pos_ -= 8;
  176|   410k|  --br->avail_in;
  177|   410k|  ++br->next_in;
  178|   410k|  return BROTLI_TRUE;
  ------------------
  |  |   51|   410k|#define BROTLI_TRUE 1
  ------------------
  179|   215M|}
decode.c:BrotliJumpToByteBoundary:
  322|  9.72k|static BROTLI_INLINE BROTLI_BOOL BrotliJumpToByteBoundary(BrotliBitReader* br) {
  323|  9.72k|  uint32_t pad_bits_count = BrotliGetAvailableBits(br) & 0x7;
  324|  9.72k|  uint32_t pad_bits = 0;
  325|  9.72k|  if (pad_bits_count != 0) {
  ------------------
  |  Branch (325:7): [True: 9.03k, False: 692]
  ------------------
  326|  9.03k|    BrotliTakeBits(br, pad_bits_count, &pad_bits);
  327|  9.03k|  }
  328|  9.72k|  return TO_BROTLI_BOOL(pad_bits == 0);
  ------------------
  |  |   55|  9.72k|#define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE)
  |  |  ------------------
  |  |  |  |   51|  9.66k|#define BROTLI_TRUE 1
  |  |  ------------------
  |  |               #define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE)
  |  |  ------------------
  |  |  |  |   53|     58|#define BROTLI_FALSE 0
  |  |  ------------------
  |  |  |  Branch (55:28): [True: 9.66k, False: 58]
  |  |  ------------------
  ------------------
  329|  9.72k|}
decode.c:BrotliSafeGetBits:
  207|  1.18G|    BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
  208|  1.18G|  while (BrotliGetAvailableBits(br) < n_bits) {
  ------------------
  |  Branch (208:10): [True: 215M, False: 973M]
  ------------------
  209|   215M|    if (!BrotliPullByte(br)) {
  ------------------
  |  Branch (209:9): [True: 214M, False: 164k]
  ------------------
  210|   214M|      return BROTLI_FALSE;
  ------------------
  |  |   53|   214M|#define BROTLI_FALSE 0
  ------------------
  211|   214M|    }
  212|   215M|  }
  213|   973M|  *val = (uint32_t)BrotliGetBitsUnmasked(br) & BitMask(n_bits);
  214|   973M|  return BROTLI_TRUE;
  ------------------
  |  |   51|   973M|#define BROTLI_TRUE 1
  ------------------
  215|  1.18G|}
decode.c:BrotliCheckInputAmount:
   99|   587M|    BrotliBitReader* const br, size_t num) {
  100|   587M|  return TO_BROTLI_BOOL(br->avail_in >= num);
  ------------------
  |  |   55|   587M|#define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE)
  |  |  ------------------
  |  |  |  |   51|   587M|#define BROTLI_TRUE 1
  |  |  ------------------
  |  |               #define TO_BROTLI_BOOL(X) (!!(X) ? BROTLI_TRUE : BROTLI_FALSE)
  |  |  ------------------
  |  |  |  |   53|  98.4k|#define BROTLI_FALSE 0
  |  |  ------------------
  |  |  |  Branch (55:28): [True: 587M, False: 98.4k]
  |  |  ------------------
  ------------------
  101|   587M|}
decode.c:BrotliFillBitWindow16:
  159|   131k|static BROTLI_INLINE void BrotliFillBitWindow16(BrotliBitReader* const br) {
  160|   131k|  BrotliFillBitWindow(br, 17);
  161|   131k|}
decode.c:BrotliFillBitWindow:
  108|   740M|    BrotliBitReader* const br, uint32_t n_bits) {
  109|   740M|#if (BROTLI_64_BITS)
  110|   740M|  if (!BROTLI_ALIGNED_READ && BROTLI_IS_CONSTANT(n_bits) && (n_bits <= 8)) {
  ------------------
  |  |  287|  1.48G|#define BROTLI_ALIGNED_READ (!!0)
  ------------------
                if (!BROTLI_ALIGNED_READ && BROTLI_IS_CONSTANT(n_bits) && (n_bits <= 8)) {
  ------------------
  |  |  459|  1.48G|#define BROTLI_IS_CONSTANT(x) (!!__builtin_constant_p(x))
  |  |  ------------------
  |  |  |  Branch (459:31): [True: 664M, False: 76.1M]
  |  |  ------------------
  ------------------
  |  Branch (110:7): [True: 740M, Folded]
  |  Branch (110:61): [True: 534M, False: 129M]
  ------------------
  111|   534M|    if (br->bit_pos_ >= 56) {
  ------------------
  |  Branch (111:9): [True: 13.5k, False: 534M]
  ------------------
  112|  13.5k|      br->val_ >>= 56;
  113|  13.5k|      br->bit_pos_ ^= 56;  /* here same as -= 56 because of the if condition */
  114|  13.5k|      br->val_ |= BROTLI_UNALIGNED_LOAD64LE(br->next_in) << 8;
  ------------------
  |  |  386|  13.5k|#define BROTLI_UNALIGNED_LOAD64LE BrotliUnalignedRead64
  ------------------
  115|  13.5k|      br->avail_in -= 7;
  116|  13.5k|      br->next_in += 7;
  117|  13.5k|    }
  118|   534M|  } else if (
  119|   205M|      !BROTLI_ALIGNED_READ && BROTLI_IS_CONSTANT(n_bits) && (n_bits <= 16)) {
  ------------------
  |  |  287|   411M|#define BROTLI_ALIGNED_READ (!!0)
  ------------------
                    !BROTLI_ALIGNED_READ && BROTLI_IS_CONSTANT(n_bits) && (n_bits <= 16)) {
  ------------------
  |  |  459|   411M|#define BROTLI_IS_CONSTANT(x) (!!__builtin_constant_p(x))
  |  |  ------------------
  |  |  |  Branch (459:31): [True: 129M, False: 76.1M]
  |  |  ------------------
  ------------------
  |  Branch (119:7): [True: 205M, Folded]
  |  Branch (119:61): [True: 129M, False: 131k]
  ------------------
  120|   129M|    if (br->bit_pos_ >= 48) {
  ------------------
  |  Branch (120:9): [True: 55.6k, False: 129M]
  ------------------
  121|  55.6k|      br->val_ >>= 48;
  122|  55.6k|      br->bit_pos_ ^= 48;  /* here same as -= 48 because of the if condition */
  123|  55.6k|      br->val_ |= BROTLI_UNALIGNED_LOAD64LE(br->next_in) << 16;
  ------------------
  |  |  386|  55.6k|#define BROTLI_UNALIGNED_LOAD64LE BrotliUnalignedRead64
  ------------------
  124|  55.6k|      br->avail_in -= 6;
  125|  55.6k|      br->next_in += 6;
  126|  55.6k|    }
  127|   129M|  } else {
  128|  76.3M|    if (br->bit_pos_ >= 32) {
  ------------------
  |  Branch (128:9): [True: 171k, False: 76.1M]
  ------------------
  129|   171k|      br->val_ >>= 32;
  130|   171k|      br->bit_pos_ ^= 32;  /* here same as -= 32 because of the if condition */
  131|   171k|      br->val_ |= ((uint64_t)BROTLI_UNALIGNED_LOAD32LE(br->next_in)) << 32;
  ------------------
  |  |  385|   171k|#define BROTLI_UNALIGNED_LOAD32LE BrotliUnalignedRead32
  ------------------
  132|   171k|      br->avail_in -= BROTLI_SHORT_FILL_BIT_WINDOW_READ;
  ------------------
  |  |   22|   171k|#define BROTLI_SHORT_FILL_BIT_WINDOW_READ (sizeof(brotli_reg_t) >> 1)
  ------------------
  133|   171k|      br->next_in += BROTLI_SHORT_FILL_BIT_WINDOW_READ;
  ------------------
  |  |   22|   171k|#define BROTLI_SHORT_FILL_BIT_WINDOW_READ (sizeof(brotli_reg_t) >> 1)
  ------------------
  134|   171k|    }
  135|  76.3M|  }
  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|   740M|}
decode.c:BrotliGetRemainingBytes:
   90|  2.18k|static BROTLI_INLINE size_t BrotliGetRemainingBytes(BrotliBitReader* br) {
   91|  2.18k|  static const size_t kCap = (size_t)1 << BROTLI_LARGE_MAX_WBITS;
  ------------------
  |  |   57|  2.18k|#define BROTLI_LARGE_MAX_WBITS 30
  ------------------
   92|  2.18k|  if (br->avail_in > kCap) return kCap;
  ------------------
  |  Branch (92:7): [True: 0, False: 2.18k]
  ------------------
   93|  2.18k|  return br->avail_in + (BrotliGetAvailableBits(br) >> 3);
   94|  2.18k|}
decode.c:BrotliCopyBytes:
  335|  2.18k|                                          BrotliBitReader* br, size_t num) {
  336|  3.62k|  while (BrotliGetAvailableBits(br) >= 8 && num > 0) {
  ------------------
  |  Branch (336:10): [True: 2.42k, False: 1.20k]
  |  Branch (336:45): [True: 1.44k, False: 981]
  ------------------
  337|  1.44k|    *dest = (uint8_t)BrotliGetBitsUnmasked(br);
  338|  1.44k|    BrotliDropBits(br, 8);
  339|  1.44k|    ++dest;
  340|  1.44k|    --num;
  341|  1.44k|  }
  342|  2.18k|  memcpy(dest, br->next_in, num);
  343|  2.18k|  br->avail_in -= num;
  344|  2.18k|  br->next_in += num;
  345|  2.18k|}
decode.c:BitMask:
   26|  1.59G|static BROTLI_INLINE uint32_t BitMask(uint32_t n) {
   27|  1.59G|  if (BROTLI_IS_CONSTANT(n) || BROTLI_HAS_UBFX) {
  ------------------
  |  |  459|  3.18G|#define BROTLI_IS_CONSTANT(x) (!!__builtin_constant_p(x))
  |  |  ------------------
  |  |  |  Branch (459:31): [True: 1.50G, False: 85.7M]
  |  |  ------------------
  ------------------
                if (BROTLI_IS_CONSTANT(n) || BROTLI_HAS_UBFX) {
  ------------------
  |  |  467|  85.7M|#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.50G|    return ~((0xFFFFFFFFu) << n);
   31|  1.50G|  } else {
   32|  85.7M|    return kBrotliBitMask[n];
   33|  85.7M|  }
   34|  1.59G|}
decode.c:BrotliReadBits24:
  250|  74.9M|    BrotliBitReader* const br, uint32_t n_bits) {
  251|  74.9M|  BROTLI_DCHECK(n_bits <= 24);
  252|  74.9M|  if (BROTLI_64_BITS || (n_bits <= 16)) {
  ------------------
  |  |  235|   149M|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 74.9M, Folded]
  |  |  ------------------
  ------------------
  |  Branch (252:25): [True: 0, False: 0]
  ------------------
  253|  74.9M|    uint32_t val;
  254|  74.9M|    BrotliFillBitWindow(br, n_bits);
  255|  74.9M|    BrotliTakeBits(br, n_bits, &val);
  256|  74.9M|    return val;
  257|  74.9M|  } 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|  74.9M|}
decode.c:BrotliBitReaderSaveState:
   67|   192M|    BrotliBitReader* const from, BrotliBitReaderState* to) {
   68|   192M|  to->val_ = from->val_;
   69|   192M|  to->bit_pos_ = from->bit_pos_;
   70|   192M|  to->next_in = from->next_in;
   71|   192M|  to->avail_in = from->avail_in;
   72|   192M|}
decode.c:BrotliBitReaderRestoreState:
   75|    721|    BrotliBitReader* const to, BrotliBitReaderState* from) {
   76|    721|  to->val_ = from->val_;
   77|    721|  to->bit_pos_ = from->bit_pos_;
   78|    721|  to->next_in = from->next_in;
   79|    721|  to->avail_in = from->avail_in;
   80|    721|}
decode.c:BrotliGetBits:
  199|   534M|    BrotliBitReader* const br, uint32_t n_bits) {
  200|   534M|  BrotliFillBitWindow(br, n_bits);
  201|   534M|  return (uint32_t)BrotliGetBitsUnmasked(br) & BitMask(n_bits);
  202|   534M|}
decode.c:BrotliGet16BitsUnmasked:
  191|   129M|    BrotliBitReader* const br) {
  192|   129M|  BrotliFillBitWindow(br, 16);
  193|   129M|  return (uint32_t)BrotliGetBitsUnmasked(br);
  194|   129M|}
decode.c:BrotliReadBits32:
  270|  1.23M|    BrotliBitReader* const br, uint32_t n_bits) {
  271|  1.23M|  BROTLI_DCHECK(n_bits <= 32);
  272|  1.23M|  if (BROTLI_64_BITS || (n_bits <= 16)) {
  ------------------
  |  |  235|  2.47M|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 1.23M, Folded]
  |  |  ------------------
  ------------------
  |  Branch (272:25): [True: 0, False: 0]
  ------------------
  273|  1.23M|    uint32_t val;
  274|  1.23M|    BrotliFillBitWindow(br, n_bits);
  275|  1.23M|    BrotliTakeBits(br, n_bits, &val);
  276|  1.23M|    return val;
  277|  1.23M|  } 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.23M|}
decode.c:BrotliSafeReadBits32:
  305|  5.03k|    BrotliBitReader* const br, uint32_t n_bits, uint32_t* val) {
  306|  5.03k|  BROTLI_DCHECK(n_bits <= 32);
  307|  5.03k|  if (BROTLI_64_BITS || (n_bits <= 24)) {
  ------------------
  |  |  235|  10.0k|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 5.03k, Folded]
  |  |  ------------------
  ------------------
  |  Branch (307:25): [True: 0, False: 0]
  ------------------
  308|  5.18k|    while (BrotliGetAvailableBits(br) < n_bits) {
  ------------------
  |  Branch (308:12): [True: 384, False: 4.79k]
  ------------------
  309|    384|      if (!BrotliPullByte(br)) {
  ------------------
  |  Branch (309:11): [True: 238, False: 146]
  ------------------
  310|    238|        return BROTLI_FALSE;
  ------------------
  |  |   53|    238|#define BROTLI_FALSE 0
  ------------------
  311|    238|      }
  312|    384|    }
  313|  4.79k|    BrotliTakeBits(br, n_bits, val);
  314|  4.79k|    return BROTLI_TRUE;
  ------------------
  |  |   51|  4.79k|#define BROTLI_TRUE 1
  ------------------
  315|  5.03k|  } else {
  316|      0|    return BrotliSafeReadBits32Slow(br, n_bits, val);
  317|      0|  }
  318|  5.03k|}
decode.c:BrotliGetAvailableBits:
   83|  1.40G|    const BrotliBitReader* br) {
   84|  1.40G|  return (BROTLI_64_BITS ? 64 : 32) - br->bit_pos_;
  ------------------
  |  |  235|  1.40G|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 1.40G, Folded]
  |  |  ------------------
  ------------------
   85|  1.40G|}
bit_reader.c:BrotliGetAvailableBits:
   83|  68.6k|    const BrotliBitReader* br) {
   84|  68.6k|  return (BROTLI_64_BITS ? 64 : 32) - br->bit_pos_;
  ------------------
  |  |  235|  68.6k|#define BROTLI_64_BITS 1
  |  |  ------------------
  |  |  |  Branch (235:24): [True: 68.6k, Folded]
  |  |  ------------------
  ------------------
   85|  68.6k|}
bit_reader.c:BrotliPullByte:
  165|  24.3k|static BROTLI_INLINE BROTLI_BOOL BrotliPullByte(BrotliBitReader* const br) {
  166|  24.3k|  if (br->avail_in == 0) {
  ------------------
  |  Branch (166:7): [True: 191, False: 24.1k]
  ------------------
  167|    191|    return BROTLI_FALSE;
  ------------------
  |  |   53|    191|#define BROTLI_FALSE 0
  ------------------
  168|    191|  }
  169|  24.1k|  br->val_ >>= 8;
  170|  24.1k|#if (BROTLI_64_BITS)
  171|  24.1k|  br->val_ |= ((uint64_t)*br->next_in) << 56;
  172|       |#else
  173|       |  br->val_ |= ((uint32_t)*br->next_in) << 24;
  174|       |#endif
  175|  24.1k|  br->bit_pos_ -= 8;
  176|  24.1k|  --br->avail_in;
  177|  24.1k|  ++br->next_in;
  178|  24.1k|  return BROTLI_TRUE;
  ------------------
  |  |   51|  24.1k|#define BROTLI_TRUE 1
  ------------------
  179|  24.3k|}

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

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

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

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

_ZN7brunsli27ComputeACPredictMultipliersEPKiPiS2_:
   20|  5.44k|                                 int* mult_col) {
   21|  48.9k|  for (size_t y = 0; y < 8; ++y) {
  ------------------
  |  Branch (21:22): [True: 43.5k, False: 5.44k]
  ------------------
   22|   391k|    for (size_t x = 0; x < 8; ++x) {
  ------------------
  |  Branch (22:24): [True: 348k, False: 43.5k]
  ------------------
   23|   348k|      mult_row[x + 8 * y] =
   24|   348k|          (quant[x + 8 * y] * kSqrt2FixedPoint) / quant[y * 8];
   25|       |      // mult_col is transposed i.e. destination rows and columns are swapped.
   26|   348k|      mult_col[x * 8 + y] = (quant[x + 8 * y] * kSqrt2FixedPoint) / quant[x];
   27|   348k|    }
   28|  43.5k|  }
   29|  5.44k|}
_ZN7brunsli16ComponentStateDC7InitAllEv:
   33|  6.03k|void ComponentStateDC::InitAll() {
   34|  6.03k|  is_zero_prob.Init(135);
   35|  60.3k|  for (size_t i = 0; i < sign_prob.size(); ++i) {
  ------------------
  |  Branch (35:22): [True: 54.3k, False: 6.03k]
  ------------------
   36|  54.3k|    sign_prob[i].Init(128);
   37|  54.3k|  }
   38|  24.1k|  for (size_t i = 0; i < is_empty_block_prob.size(); ++i) {
  ------------------
  |  Branch (38:22): [True: 18.1k, False: 6.03k]
  ------------------
   39|  18.1k|    is_empty_block_prob[i].Init(74);
   40|  18.1k|  }
   41|  66.3k|  for (size_t i = 0; i < first_extra_bit_prob.size(); ++i) {
  ------------------
  |  Branch (41:22): [True: 60.3k, False: 6.03k]
  ------------------
   42|  60.3k|    first_extra_bit_prob[i].Init(150);
   43|  60.3k|  }
   44|  6.03k|}
_ZN7brunsli14ComponentState7InitAllEv:
  223|  5.44k|void ComponentState::InitAll() {
  224|  65.3k|  for (int i = 0; i < kNumNonzeroBuckets; ++i) {
  ------------------
  |  Branch (224:19): [True: 59.8k, False: 5.44k]
  ------------------
  225|  3.89M|    for (int k = 0; k < kDCTBlockSize; ++k) {
  ------------------
  |  Branch (225:21): [True: 3.83M, False: 59.8k]
  ------------------
  226|  3.83M|      const int v = kInitProb[k] + 9 * (i - 7);
  227|  3.83M|      BRUNSLI_DCHECK(v <= 255);
  228|  3.83M|      is_zero_prob[i * kDCTBlockSize + k].Init(v);
  229|  3.83M|    }
  230|  59.8k|  }
  231|  5.92M|  for (size_t i = 0; i < sign_prob.size(); ++i) {
  ------------------
  |  Branch (231:22): [True: 5.92M, False: 5.44k]
  ------------------
  232|  5.92M|    if (i < kMaxAverageContext * kDCTBlockSize) {
  ------------------
  |  Branch (232:9): [True: 2.78M, False: 3.13M]
  ------------------
  233|  2.78M|      sign_prob[i].Init(108);
  234|  3.13M|    } else if (i < (kMaxAverageContext + 1) * kDCTBlockSize) {
  ------------------
  |  Branch (234:16): [True: 348k, False: 2.78M]
  ------------------
  235|   348k|      sign_prob[i].Init(128);
  236|  2.78M|    } else {
  237|  2.78M|      sign_prob[i].Init(148);
  238|  2.78M|    }
  239|  5.92M|  }
  240|  3.48M|  for (size_t i = 0; i < first_extra_bit_prob.size(); ++i) {
  ------------------
  |  Branch (240:22): [True: 3.48M, False: 5.44k]
  ------------------
  241|  3.48M|    first_extra_bit_prob[i].Init(158);
  242|  3.48M|  }
  243|       |
  244|   179k|  for (size_t i = 0; i < kNumNonZeroContextCount; ++i) {
  ------------------
  |  Branch (244:22): [True: 174k, False: 5.44k]
  ------------------
  245|   174k|    Prob* non_zero_probs = num_nonzero_prob + i * kNumNonZeroTreeSize;
  246|  11.1M|    for (size_t j = 0; j < kNumNonZeroTreeSize; ++j) {
  ------------------
  |  Branch (246:24): [True: 10.9M, False: 174k]
  ------------------
  247|  10.9M|      non_zero_probs[j].Init(kInitProbNonzero[i][j]);
  248|  10.9M|    }
  249|   174k|  }
  250|  5.44k|}

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

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

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

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

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

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

_ZN7brunsli25PredictWithAdaptiveMedianEPKsiii:
   29|  40.7M|int PredictWithAdaptiveMedian(const coeff_t* coeffs, int x, int y, int stride) {
   30|  40.7M|  const int offset1 = -kDCTBlockSize;
   31|  40.7M|  const int offset2 = -stride;
   32|  40.7M|  const int offset3 = offset2 + offset1;
   33|  40.7M|  if (y != 0) {
  ------------------
  |  Branch (33:7): [True: 39.8M, False: 905k]
  ------------------
   34|  39.8M|    if (x != 0) {
  ------------------
  |  Branch (34:9): [True: 39.4M, False: 363k]
  ------------------
   35|  39.4M|      return AdaptiveMedian(coeffs[offset1], coeffs[offset2], coeffs[offset3]);
   36|  39.4M|    } else {
   37|   363k|      return coeffs[offset2];
   38|   363k|    }
   39|  39.8M|  } else {
   40|   905k|    return x ? coeffs[offset1] : 0;
  ------------------
  |  Branch (40:12): [True: 899k, False: 5.90k]
  ------------------
   41|   905k|  }
   42|  40.7M|}
predict.cc:_ZN7brunsli12_GLOBAL__N_114AdaptiveMedianEiii:
   15|  39.4M|int AdaptiveMedian(int w, int n, int nw) {
   16|  39.4M|  const int mx = (w > n) ? w : n;
  ------------------
  |  Branch (16:18): [True: 8.63M, False: 30.8M]
  ------------------
   17|  39.4M|  const int mn = w + n - mx;
   18|  39.4M|  if (nw > mx) {
  ------------------
  |  Branch (18:7): [True: 1.14M, False: 38.3M]
  ------------------
   19|  1.14M|    return mn;
   20|  38.3M|  } else if (nw < mn) {
  ------------------
  |  Branch (20:14): [True: 1.48M, False: 36.8M]
  ------------------
   21|  1.48M|    return mx;
   22|  36.8M|  } else {
   23|  36.8M|    return n + w - nw;
   24|  36.8M|  }
   25|  39.4M|}

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

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

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

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

_ZN7brunsli20BrunsliBitReaderInitEPNS_16BrunsliBitReaderE:
   13|  24.6k|void BrunsliBitReaderInit(BrunsliBitReader* br) {
   14|  24.6k|  br->num_bits_ = 0;
   15|  24.6k|  br->bits_ = 0;
   16|  24.6k|  br->num_debt_bytes_ = 0;
   17|  24.6k|  br->is_healthy_ = true;
   18|  24.6k|  br->is_optimistic_ = false;
   19|  24.6k|}
_ZN7brunsli22BrunsliBitReaderResumeEPNS_16BrunsliBitReaderEPKhm:
   22|  24.6k|                              size_t length) {
   23|  24.6k|  br->next_ = buffer;
   24|  24.6k|  br->end_ = buffer + length;
   25|  24.6k|  br->is_optimistic_ = false;
   26|  24.6k|}
_ZN7brunsli23BrunsliBitReaderSuspendEPNS_16BrunsliBitReaderE:
   49|  24.6k|size_t BrunsliBitReaderSuspend(BrunsliBitReader* br) {
   50|  24.6k|  BrunsliBitReaderUnload(br);
   51|  24.6k|  size_t unused_bytes = br->end_ - br->next_;
   52|  24.6k|  br->next_ = nullptr;
   53|  24.6k|  br->end_ = nullptr;
   54|  24.6k|  return unused_bytes;
   55|  24.6k|}
_ZN7brunsli22BrunsliBitReaderFinishEPNS_16BrunsliBitReaderE:
   57|  20.0k|void BrunsliBitReaderFinish(BrunsliBitReader* br) {
   58|  20.0k|  uint32_t n_bits = br->num_bits_;
   59|       |  // Likely, did not invoke Suspend before.
   60|  20.0k|  if (n_bits >= 8) {
  ------------------
  |  Branch (60:7): [True: 0, False: 20.0k]
  ------------------
   61|      0|    br->is_healthy_ = false;
   62|      0|    return;
   63|      0|  }
   64|  20.0k|  if (n_bits > 0) {
  ------------------
  |  Branch (64:7): [True: 14.2k, False: 5.85k]
  ------------------
   65|  14.2k|    uint32_t padding_bits = BrunsliBitReaderRead(br, n_bits);
   66|  14.2k|    if (padding_bits != 0) br->is_healthy_ = false;
  ------------------
  |  Branch (66:9): [True: 32, False: 14.1k]
  ------------------
   67|  14.2k|  }
   68|  20.0k|}
_ZN7brunsli25BrunsliBitReaderIsHealthyEPNS_16BrunsliBitReaderE:
   70|  45.6k|bool BrunsliBitReaderIsHealthy(BrunsliBitReader* br) {
   71|  45.6k|  BrunsliBitReaderUnload(br);
   72|  45.6k|  return (br->num_debt_bytes_ == 0) && (br->is_healthy_);
  ------------------
  |  Branch (72:10): [True: 45.3k, False: 283]
  |  Branch (72:40): [True: 45.3k, False: 32]
  ------------------
   73|  45.6k|}
_ZN7brunsli29BrunsliBitReaderSetOptimisticEPNS_16BrunsliBitReaderE:
   75|  5.92k|void BrunsliBitReaderSetOptimistic(BrunsliBitReader* br) {
   76|  5.92k|  br->is_optimistic_ = true;
   77|  5.92k|}
_ZN7brunsli23BrunsliBitReaderCanReadEPNS_16BrunsliBitReaderEm:
   79|  4.85M|bool BrunsliBitReaderCanRead(BrunsliBitReader* br, size_t n_bits) {
   80|  4.85M|  if (br->is_optimistic_) return true;
  ------------------
  |  Branch (80:7): [True: 1.02M, False: 3.83M]
  ------------------
   81|  3.83M|  if (br->num_debt_bytes_ != 0) return false;
  ------------------
  |  Branch (81:7): [True: 0, False: 3.83M]
  ------------------
   82|  3.83M|  if (br->num_bits_ >= n_bits) return true;
  ------------------
  |  Branch (82:7): [True: 1.57M, False: 2.25M]
  ------------------
   83|  2.25M|  size_t num_extra_bytes = (n_bits - br->num_bits_ + 7) >> 3;
   84|  2.25M|  return (br->next_ + num_extra_bytes <= br->end_);
   85|  3.83M|}
bit_reader.cc:_ZN7brunsliL22BrunsliBitReaderUnloadEPNS_16BrunsliBitReaderE:
   35|  70.3k|static BRUNSLI_INLINE void BrunsliBitReaderUnload(BrunsliBitReader* br) {
   36|       |  // Cancel the overdraft.
   37|  70.4k|  while ((br->num_debt_bytes_ > 0) && (br->num_bits_ >= 8)) {
  ------------------
  |  Branch (37:10): [True: 802, False: 69.6k]
  |  Branch (37:39): [True: 122, False: 680]
  ------------------
   38|    122|    br->num_debt_bytes_--;
   39|    122|    br->num_bits_ -= 8;
   40|    122|  }
   41|       |  // Return unused bytes.
   42|  70.8k|  while (br->num_bits_ >= 8) {
  ------------------
  |  Branch (42:10): [True: 570, False: 70.3k]
  ------------------
   43|    570|    br->next_--;
   44|    570|    br->num_bits_ -= 8;
   45|    570|  }
   46|  70.3k|  br->bits_ &= BrunsliBitReaderBitMask(br->num_bits_);
   47|  70.3k|}

_ZN7brunsli20BrunsliBitReaderReadEPNS_16BrunsliBitReaderEj:
  127|  4.03M|                                                    uint32_t n_bits) {
  128|  4.03M|  uint32_t result = BrunsliBitReaderGet(br, n_bits);
  129|  4.03M|  BrunsliBitReaderDrop(br, n_bits);
  130|  4.03M|  return result;
  131|  4.03M|}
brunsli_decode.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|  3.88M|                                                   uint32_t n_bits) {
  110|  3.88M|  BRUNSLI_DCHECK(n_bits <= 24);
  111|  3.88M|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|  3.88M|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 1.72k, False: 3.88M]
  ------------------
  113|  1.72k|    BrunsliBitReaderMaybeFetchByte(br, n_bits);
  114|  1.72k|    if (n_bits > 16) BrunsliBitReaderMaybeFetchByte(br, n_bits);
  ------------------
  |  Branch (114:9): [True: 0, False: 1.72k]
  ------------------
  115|  1.72k|  }
  116|  3.88M|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|  3.88M|}
brunsli_decode.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|  3.88M|                                                          uint32_t n_bits) {
   81|  3.88M|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 2.13M, False: 1.74M]
  ------------------
   82|  2.13M|    if (BRUNSLI_PREDICT_FALSE(br->next_ >= br->end_)) {
  ------------------
  |  |   85|  2.13M|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 28, False: 2.13M]
  |  |  ------------------
  ------------------
   83|     28|      BrunsliBitReaderOweByte(br);
   84|  2.13M|    } else {
   85|  2.13M|      br->bits_ |= static_cast<uint32_t>(*br->next_) << br->num_bits_;
   86|  2.13M|      br->num_bits_ += 8;
   87|  2.13M|      br->next_++;
   88|  2.13M|    }
   89|  2.13M|  }
   90|  3.88M|}
brunsli_decode.cc:_ZN7brunsliL23BrunsliBitReaderOweByteEPNS_16BrunsliBitReaderE:
   73|     28|static BRUNSLI_INLINE void BrunsliBitReaderOweByte(BrunsliBitReader* br) {
   74|     28|  br->num_bits_ += 8;
   75|     28|  br->num_debt_bytes_++;
   76|     28|}
brunsli_decode.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|  3.88M|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|  3.88M|  return ~((0xFFFFFFFFu) << n);
   70|  3.88M|}
brunsli_decode.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|  3.88M|                                                uint32_t n_bits) {
  121|  3.88M|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|  3.88M|  br->bits_ >>= n_bits;
  123|  3.88M|  br->num_bits_ -= n_bits;
  124|  3.88M|}
context_map_decode.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|  16.5k|                                                   uint32_t n_bits) {
  110|  16.5k|  BRUNSLI_DCHECK(n_bits <= 24);
  111|  16.5k|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|  16.5k|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 121, False: 16.3k]
  ------------------
  113|    121|    BrunsliBitReaderMaybeFetchByte(br, n_bits);
  114|    121|    if (n_bits > 16) BrunsliBitReaderMaybeFetchByte(br, n_bits);
  ------------------
  |  Branch (114:9): [True: 0, False: 121]
  ------------------
  115|    121|  }
  116|  16.5k|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|  16.5k|}
context_map_decode.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|  16.6k|                                                          uint32_t n_bits) {
   81|  16.6k|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 769, False: 15.8k]
  ------------------
   82|    769|    if (BRUNSLI_PREDICT_FALSE(br->next_ >= br->end_)) {
  ------------------
  |  |   85|    769|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 447, False: 322]
  |  |  ------------------
  ------------------
   83|    447|      BrunsliBitReaderOweByte(br);
   84|    447|    } else {
   85|    322|      br->bits_ |= static_cast<uint32_t>(*br->next_) << br->num_bits_;
   86|    322|      br->num_bits_ += 8;
   87|    322|      br->next_++;
   88|    322|    }
   89|    769|  }
   90|  16.6k|}
context_map_decode.cc:_ZN7brunsliL23BrunsliBitReaderOweByteEPNS_16BrunsliBitReaderE:
   73|    447|static BRUNSLI_INLINE void BrunsliBitReaderOweByte(BrunsliBitReader* br) {
   74|    447|  br->num_bits_ += 8;
   75|    447|  br->num_debt_bytes_++;
   76|    447|}
context_map_decode.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|  16.5k|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|  16.5k|  return ~((0xFFFFFFFFu) << n);
   70|  16.5k|}
context_map_decode.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|  16.5k|                                                uint32_t n_bits) {
  121|  16.5k|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|  16.5k|  br->bits_ >>= n_bits;
  123|  16.5k|  br->num_bits_ -= n_bits;
  124|  16.5k|}
histogram_decode.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|   114k|                                                   uint32_t n_bits) {
  110|   114k|  BRUNSLI_DCHECK(n_bits <= 24);
  111|   114k|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|   114k|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 2.57k, False: 112k]
  ------------------
  113|  2.57k|    BrunsliBitReaderMaybeFetchByte(br, n_bits);
  114|  2.57k|    if (n_bits > 16) BrunsliBitReaderMaybeFetchByte(br, n_bits);
  ------------------
  |  Branch (114:9): [True: 0, False: 2.57k]
  ------------------
  115|  2.57k|  }
  116|   114k|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|   114k|}
histogram_decode.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|   117k|                                                          uint32_t n_bits) {
   81|   117k|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 26.8k, False: 90.3k]
  ------------------
   82|  26.8k|    if (BRUNSLI_PREDICT_FALSE(br->next_ >= br->end_)) {
  ------------------
  |  |   85|  26.8k|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 751, False: 26.1k]
  |  |  ------------------
  ------------------
   83|    751|      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.8k|  }
   90|   117k|}
histogram_decode.cc:_ZN7brunsliL23BrunsliBitReaderOweByteEPNS_16BrunsliBitReaderE:
   73|    751|static BRUNSLI_INLINE void BrunsliBitReaderOweByte(BrunsliBitReader* br) {
   74|    751|  br->num_bits_ += 8;
   75|    751|  br->num_debt_bytes_++;
   76|    751|}
histogram_decode.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|   114k|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|   114k|  return ~((0xFFFFFFFFu) << n);
   70|   114k|}
histogram_decode.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|   114k|                                                uint32_t n_bits) {
  121|   114k|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|   114k|  br->bits_ >>= n_bits;
  123|   114k|  br->num_bits_ -= n_bits;
  124|   114k|}
huffman_decode.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|  1.15M|                                                   uint32_t n_bits) {
  110|  1.15M|  BRUNSLI_DCHECK(n_bits <= 24);
  111|  1.15M|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|  1.15M|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 130, False: 1.15M]
  ------------------
  113|    130|    BrunsliBitReaderMaybeFetchByte(br, n_bits);
  114|    130|    if (n_bits > 16) BrunsliBitReaderMaybeFetchByte(br, n_bits);
  ------------------
  |  Branch (114:9): [True: 0, False: 130]
  ------------------
  115|    130|  }
  116|  1.15M|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|  1.15M|}
huffman_decode.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|  1.15M|                                                          uint32_t n_bits) {
   81|  1.15M|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 112k, False: 1.03M]
  ------------------
   82|   112k|    if (BRUNSLI_PREDICT_FALSE(br->next_ >= br->end_)) {
  ------------------
  |  |   85|   112k|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 98.0k, False: 14.1k]
  |  |  ------------------
  ------------------
   83|  98.0k|      BrunsliBitReaderOweByte(br);
   84|  98.0k|    } else {
   85|  14.1k|      br->bits_ |= static_cast<uint32_t>(*br->next_) << br->num_bits_;
   86|  14.1k|      br->num_bits_ += 8;
   87|  14.1k|      br->next_++;
   88|  14.1k|    }
   89|   112k|  }
   90|  1.15M|}
huffman_decode.cc:_ZN7brunsliL23BrunsliBitReaderOweByteEPNS_16BrunsliBitReaderE:
   73|  98.0k|static BRUNSLI_INLINE void BrunsliBitReaderOweByte(BrunsliBitReader* br) {
   74|  98.0k|  br->num_bits_ += 8;
   75|  98.0k|  br->num_debt_bytes_++;
   76|  98.0k|}
huffman_decode.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|  1.15M|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|  1.15M|  return ~((0xFFFFFFFFu) << n);
   70|  1.15M|}
huffman_decode.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|  1.15M|                                                uint32_t n_bits) {
  121|  1.15M|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|  1.15M|  br->bits_ >>= n_bits;
  123|  1.15M|  br->num_bits_ -= n_bits;
  124|  1.15M|}
bit_reader.cc:_ZN7brunsliL23BrunsliBitReaderBitMaskEj:
   68|  84.5k|static BRUNSLI_INLINE uint32_t BrunsliBitReaderBitMask(uint32_t n) {
   69|  84.5k|  return ~((0xFFFFFFFFu) << n);
   70|  84.5k|}
bit_reader.cc:_ZN7brunsliL19BrunsliBitReaderGetEPNS_16BrunsliBitReaderEj:
  109|  14.2k|                                                   uint32_t n_bits) {
  110|  14.2k|  BRUNSLI_DCHECK(n_bits <= 24);
  111|  14.2k|  BrunsliBitReaderMaybeFetchByte(br, n_bits);
  112|  14.2k|  if (n_bits > 8) {
  ------------------
  |  Branch (112:7): [True: 0, False: 14.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|  14.2k|  return br->bits_ & BrunsliBitReaderBitMask(n_bits);
  117|  14.2k|}
bit_reader.cc:_ZN7brunsliL30BrunsliBitReaderMaybeFetchByteEPNS_16BrunsliBitReaderEj:
   80|  14.2k|                                                          uint32_t n_bits) {
   81|  14.2k|  if (br->num_bits_ < n_bits) {
  ------------------
  |  Branch (81:7): [True: 0, False: 14.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|  14.2k|}
bit_reader.cc:_ZN7brunsliL20BrunsliBitReaderDropEPNS_16BrunsliBitReaderEj:
  120|  14.2k|                                                uint32_t n_bits) {
  121|  14.2k|  BRUNSLI_DCHECK(n_bits <= br->num_bits_);
  122|  14.2k|  br->bits_ >>= n_bits;
  123|  14.2k|  br->num_bits_ -= n_bits;
  124|  14.2k|}

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

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

_ZN7brunsli16DecodeContextMapERKNS_19HuffmanDecodingDataEmPmPNSt3__16vectorIhNS4_9allocatorIhEEEEPNS_16BrunsliBitReaderE:
   44|    852|                               BrunsliBitReader* br) {
   45|    852|  size_t& i = *index;
   46|    852|  uint8_t* map = context_map->data();
   47|    852|  const size_t length = context_map->size();
   48|  1.13M|  while (i < length) {
  ------------------
  |  Branch (48:10): [True: 1.13M, False: 648]
  ------------------
   49|       |    // Check there is enough deta for Huffman code, RLE and IMTF bit.
   50|  1.13M|    if (!BrunsliBitReaderCanRead(br, 15 + max_run_length_prefix + 1)) {
  ------------------
  |  Branch (50:9): [True: 145, False: 1.13M]
  ------------------
   51|    145|      return BRUNSLI_NOT_ENOUGH_DATA;
   52|    145|    }
   53|  1.13M|    uint32_t code = entropy.ReadSymbol(br);
   54|  1.13M|    if (code == 0) {
  ------------------
  |  Branch (54:9): [True: 131k, False: 999k]
  ------------------
   55|   131k|      map[i] = 0;
   56|   131k|      ++i;
   57|   999k|    } else if (code <= max_run_length_prefix) {
  ------------------
  |  Branch (57:16): [True: 15.8k, False: 983k]
  ------------------
   58|  15.8k|      size_t reps = 1u + (1u << code) + (int)BrunsliBitReaderRead(br, code);
   59|   245k|      while (--reps) {
  ------------------
  |  Branch (59:14): [True: 229k, False: 15.8k]
  ------------------
   60|   229k|        if (i >= length) return BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (60:13): [True: 59, False: 229k]
  ------------------
   61|   229k|        map[i] = 0;
   62|   229k|        ++i;
   63|   229k|      }
   64|   983k|    } else {
   65|   983k|      map[i] = (uint8_t)(code - max_run_length_prefix);
   66|   983k|      ++i;
   67|   983k|    }
   68|  1.13M|  }
   69|    648|  if (BrunsliBitReaderRead(br, 1)) {
  ------------------
  |  Branch (69:7): [True: 484, False: 164]
  ------------------
   70|    484|    InverseMoveToFrontTransform(map, length);
   71|    484|  }
   72|    648|  return BrunsliBitReaderIsHealthy(br) ? BRUNSLI_OK : BRUNSLI_INVALID_BRN;
  ------------------
  |  Branch (72:10): [True: 564, False: 84]
  ------------------
   73|    852|}
context_map_decode.cc:_ZN7brunsli12_GLOBAL__N_127InverseMoveToFrontTransformEPhm:
   27|    484|void InverseMoveToFrontTransform(uint8_t* v, size_t v_len) {
   28|    484|  uint8_t mtf[256];
   29|   124k|  for (size_t i = 0; i < 256; ++i) {
  ------------------
  |  Branch (29:22): [True: 123k, False: 484]
  ------------------
   30|   123k|    mtf[i] = static_cast<uint8_t>(i);
   31|   123k|  }
   32|   852k|  for (size_t i = 0; i < v_len; ++i) {
  ------------------
  |  Branch (32:22): [True: 851k, False: 484]
  ------------------
   33|   851k|    uint8_t index = v[i];
   34|   851k|    v[i] = mtf[index];
   35|   851k|    if (index) MoveToFront(mtf, index);
  ------------------
  |  Branch (35:9): [True: 840k, False: 11.5k]
  ------------------
   36|   851k|  }
   37|    484|}
context_map_decode.cc:_ZN7brunsli12_GLOBAL__N_111MoveToFrontEPhh:
   20|   840k|void MoveToFront(uint8_t* v, uint8_t index) {
   21|   840k|  uint8_t value = v[index];
   22|   840k|  uint8_t i = index;
   23|  18.9M|  for (; i; --i) v[i] = v[i - 1];
  ------------------
  |  Branch (23:10): [True: 18.0M, False: 840k]
  ------------------
   24|   840k|  v[0] = value;
   25|   840k|}

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

_ZN7brunsli22ReadHuffmanCodeLengthsEPKhmPhPNS_16BrunsliBitReaderE:
   29|    288|                           BrunsliBitReader* br) {
   30|    288|  size_t symbol = 0;
   31|    288|  uint8_t prev_code_len = kDefaultCodeLength;
   32|    288|  size_t repeat = 0;
   33|    288|  uint8_t repeat_code_len = 0;
   34|    288|  const int kFullSpace = 1 << 15;
   35|    288|  int space = kFullSpace;
   36|    288|  HuffmanCode table[32];
   37|       |
   38|    288|  uint16_t counts[16] = {0};
   39|  5.47k|  for (int i = 0; i < kCodeLengthCodes; ++i) {
  ------------------
  |  Branch (39:19): [True: 5.18k, False: 288]
  ------------------
   40|  5.18k|    ++counts[code_length_code_lengths[i]];
   41|  5.18k|  }
   42|    288|  if (!BuildHuffmanTable(table, 5, code_length_code_lengths, kCodeLengthCodes,
  ------------------
  |  Branch (42:7): [True: 0, False: 288]
  ------------------
   43|    288|                         &counts[0])) {
   44|      0|    return false;
   45|      0|  }
   46|       |
   47|  11.9k|  while (symbol < num_symbols && space > 0) {
  ------------------
  |  Branch (47:10): [True: 11.8k, False: 102]
  |  Branch (47:34): [True: 11.6k, False: 163]
  ------------------
   48|  11.6k|    const HuffmanCode* p = table;
   49|  11.6k|    uint8_t code_len;
   50|  11.6k|    p += BrunsliBitReaderGet(br, 5);
   51|  11.6k|    BrunsliBitReaderDrop(br, p->bits);
   52|  11.6k|    code_len = (uint8_t)p->value;
   53|  11.6k|    if (code_len < kCodeLengthRepeatCode) {
  ------------------
  |  Branch (53:9): [True: 10.8k, False: 845]
  ------------------
   54|  10.8k|      repeat = 0;
   55|  10.8k|      code_lengths[symbol++] = code_len;
   56|  10.8k|      if (code_len != 0) {
  ------------------
  |  Branch (56:11): [True: 9.17k, False: 1.66k]
  ------------------
   57|  9.17k|        prev_code_len = code_len;
   58|  9.17k|        space -= kFullSpace >> code_len;
   59|  9.17k|      }
   60|  10.8k|    } else {
   61|    845|      uint32_t extra_bits = code_len - 14;  // >= 2
   62|    845|      size_t old_repeat;
   63|    845|      size_t repeat_delta;
   64|    845|      uint8_t new_len = 0;
   65|    845|      if (code_len == kCodeLengthRepeatCode) {
  ------------------
  |  Branch (65:11): [True: 486, False: 359]
  ------------------
   66|    486|        new_len = prev_code_len;
   67|    486|      }
   68|    845|      if (repeat_code_len != new_len) {
  ------------------
  |  Branch (68:11): [True: 242, False: 603]
  ------------------
   69|    242|        repeat = 0;
   70|    242|        repeat_code_len = new_len;
   71|    242|      }
   72|    845|      old_repeat = repeat;
   73|    845|      if (repeat > 0) {  // >= 3
  ------------------
  |  Branch (73:11): [True: 187, False: 658]
  ------------------
   74|    187|        repeat -= 2;
   75|    187|        repeat <<= extra_bits;
   76|    187|      }
   77|    845|      repeat += BrunsliBitReaderRead(br, extra_bits) + 3u;
   78|    845|      repeat_delta = repeat - old_repeat;
   79|    845|      if (symbol + repeat_delta > num_symbols) {
  ------------------
  |  Branch (79:11): [True: 23, False: 822]
  ------------------
   80|     23|        return false;
   81|     23|      }
   82|    822|      memset(&code_lengths[symbol], repeat_code_len, (size_t)repeat_delta);
   83|    822|      symbol += repeat_delta;
   84|    822|      if (repeat_code_len != 0) {
  ------------------
  |  Branch (84:11): [True: 476, False: 346]
  ------------------
   85|    476|        space -= static_cast<int>(repeat_delta * kFullSpace) >> repeat_code_len;
   86|    476|      }
   87|    822|    }
   88|  11.6k|  }
   89|    265|  if (space != 0) {
  ------------------
  |  Branch (89:7): [True: 83, False: 182]
  ------------------
   90|     83|    return false;
   91|     83|  }
   92|    182|  memset(&code_lengths[symbol], 0, (size_t)(num_symbols - symbol));
   93|    182|  return BrunsliBitReaderIsHealthy(br);
   94|    265|}
_ZN7brunsli19HuffmanDecodingData17ReadFromBitStreamEmPNS_16BrunsliBitReaderEPNS_5ArenaINS_11HuffmanCodeEEE:
  191|  1.10k|    Arena<HuffmanCode>* arena) {
  192|  1.10k|  Arena<HuffmanCode> local_arena;
  193|  1.10k|  if (arena == nullptr) arena = &local_arena;
  ------------------
  |  Branch (193:7): [True: 0, False: 1.10k]
  ------------------
  194|       |
  195|  1.10k|  if (alphabet_size > (1 << kMaxHuffmanBits)) return false;
  ------------------
  |  Branch (195:7): [True: 0, False: 1.10k]
  ------------------
  196|       |
  197|  1.10k|  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.10k|  uint32_t simple_code_or_skip = BrunsliBitReaderRead(br, 2);
  202|  1.10k|  if (simple_code_or_skip == 1u) {
  ------------------
  |  Branch (202:7): [True: 743, False: 357]
  ------------------
  203|    743|    table_.resize(1u << kHuffmanTableBits);
  204|    743|    return ReadSimpleCode(static_cast<uint16_t>(alphabet_size), br,
  205|    743|                          table_.data());
  206|    743|  }
  207|       |
  208|    357|  uint8_t code_length_code_lengths[kCodeLengthCodes] = {0};
  209|    357|  int space = 32;
  210|    357|  int num_codes = 0;
  211|       |  /* Static Huffman code for the code length code lengths */
  212|    357|  static const HuffmanCode huff[16] = {
  213|    357|      {2, 0}, {2, 4}, {2, 3}, {3, 2}, {2, 0}, {2, 4}, {2, 3}, {4, 1},
  214|    357|      {2, 0}, {2, 4}, {2, 3}, {3, 2}, {2, 0}, {2, 4}, {2, 3}, {4, 5},
  215|    357|  };
  216|  4.86k|  for (size_t i = simple_code_or_skip; i < kCodeLengthCodes && space > 0; ++i) {
  ------------------
  |  Branch (216:40): [True: 4.74k, False: 125]
  |  Branch (216:64): [True: 4.51k, False: 232]
  ------------------
  217|  4.51k|    const int code_len_idx = kCodeLengthCodeOrder[i];
  218|  4.51k|    const HuffmanCode* p = huff;
  219|  4.51k|    uint8_t v;
  220|  4.51k|    p += BrunsliBitReaderGet(br, 4);
  221|  4.51k|    BrunsliBitReaderDrop(br, p->bits);
  222|  4.51k|    v = (uint8_t)p->value;
  223|  4.51k|    code_length_code_lengths[code_len_idx] = v;
  224|  4.51k|    if (v != 0) {
  ------------------
  |  Branch (224:9): [True: 2.24k, False: 2.26k]
  ------------------
  225|  2.24k|      space -= (32u >> v);
  226|  2.24k|      ++num_codes;
  227|  2.24k|    }
  228|  4.51k|  }
  229|    357|  bool ok = (num_codes == 1 || space == 0) &&
  ------------------
  |  Branch (229:14): [True: 56, False: 301]
  |  Branch (229:32): [True: 232, False: 69]
  ------------------
  230|    288|       ReadHuffmanCodeLengths(code_length_code_lengths, alphabet_size,
  ------------------
  |  Branch (230:8): [True: 174, False: 114]
  ------------------
  231|    288|                              &code_lengths[0], br);
  232|       |
  233|    357|  if (!ok || !BrunsliBitReaderIsHealthy(br)) return false;
  ------------------
  |  Branch (233:7): [True: 183, False: 174]
  |  Branch (233:14): [True: 0, False: 174]
  ------------------
  234|    174|  uint16_t counts[16] = {0};
  235|  18.8k|  for (size_t i = 0; i < alphabet_size; ++i) {
  ------------------
  |  Branch (235:22): [True: 18.6k, False: 174]
  ------------------
  236|  18.6k|    ++counts[code_lengths[i]];
  237|  18.6k|  }
  238|    174|  arena->reserve(alphabet_size + 376);
  239|    174|  uint32_t table_size =
  240|    174|      BuildHuffmanTable(arena->data(), kHuffmanTableBits, &code_lengths[0],
  241|    174|                        alphabet_size, &counts[0]);
  242|    174|  table_ = std::vector<HuffmanCode>(arena->data(), arena->data() + table_size);
  243|    174|  return (table_size > 0);
  244|    357|}
_ZNK7brunsli19HuffmanDecodingData10ReadSymbolEPNS_16BrunsliBitReaderE:
  247|  1.13M|uint16_t HuffmanDecodingData::ReadSymbol(BrunsliBitReader* br) const {
  248|  1.13M|  uint32_t n_bits;
  249|  1.13M|  const HuffmanCode* table = table_.data();
  250|  1.13M|  table += BrunsliBitReaderGet(br, kHuffmanTableBits);
  251|  1.13M|  n_bits = table->bits;
  252|  1.13M|  if (n_bits > kHuffmanTableBits) {
  ------------------
  |  Branch (252:7): [True: 787, False: 1.13M]
  ------------------
  253|    787|    BrunsliBitReaderDrop(br, kHuffmanTableBits);
  254|    787|    n_bits -= kHuffmanTableBits;
  255|    787|    table += table->value;
  256|    787|    table += BrunsliBitReaderGet(br, n_bits);
  257|    787|  }
  258|  1.13M|  BrunsliBitReaderDrop(br, table->bits);
  259|  1.13M|  return table->value;
  260|  1.13M|}
huffman_decode.cc:_ZN7brunsliL14ReadSimpleCodeEtPNS_16BrunsliBitReaderEPNS_11HuffmanCodeE:
   98|    743|                                          HuffmanCode* table) {
   99|    743|  uint32_t max_bits =
  100|    743|      (alphabet_size > 1u) ? Log2FloorNonZero(alphabet_size - 1u) + 1 : 0;
  ------------------
  |  Branch (100:7): [True: 743, False: 0]
  ------------------
  101|       |
  102|    743|  size_t num_symbols = BrunsliBitReaderRead(br, 2) + 1;
  103|       |
  104|    743|  uint16_t symbols[4] = {0};
  105|  1.87k|  for (size_t i = 0; i < num_symbols; ++i) {
  ------------------
  |  Branch (105:22): [True: 1.16k, False: 716]
  ------------------
  106|  1.16k|    uint16_t symbol = BrunsliBitReaderRead(br, max_bits);
  107|  1.16k|    if (symbol >= alphabet_size) {
  ------------------
  |  Branch (107:9): [True: 27, False: 1.13k]
  ------------------
  108|     27|      return false;
  109|     27|    }
  110|  1.13k|    symbols[i] = symbol;
  111|  1.13k|  }
  112|       |
  113|  1.05k|  for (size_t i = 0; i < num_symbols - 1; ++i) {
  ------------------
  |  Branch (113:22): [True: 359, False: 698]
  ------------------
  114|    905|    for (size_t j = i + 1; j < num_symbols; ++j) {
  ------------------
  |  Branch (114:28): [True: 564, False: 341]
  ------------------
  115|    564|      if (symbols[i] == symbols[j]) return false;
  ------------------
  |  Branch (115:11): [True: 18, False: 546]
  ------------------
  116|    564|    }
  117|    359|  }
  118|       |
  119|       |  // 4 symbols have to option to encode.
  120|    698|  if (num_symbols == 4) num_symbols += BrunsliBitReaderRead(br, 1);
  ------------------
  |  Branch (120:7): [True: 53, False: 645]
  ------------------
  121|       |
  122|    698|  const auto swap_symbols = [&symbols] (size_t i, size_t j) {
  123|    698|    uint16_t t = symbols[j];
  124|    698|    symbols[j] = symbols[i];
  125|    698|    symbols[i] = t;
  126|    698|  };
  127|       |
  128|    698|  size_t table_size = 1;
  129|    698|  switch (num_symbols) {
  130|    503|    case 1:
  ------------------
  |  Branch (130:5): [True: 503, False: 195]
  ------------------
  131|    503|      table[0] = {0, symbols[0]};
  132|    503|      break;
  133|    111|    case 2:
  ------------------
  |  Branch (133:5): [True: 111, False: 587]
  ------------------
  134|    111|      if (symbols[0] > symbols[1]) swap_symbols(0, 1);
  ------------------
  |  Branch (134:11): [True: 77, False: 34]
  ------------------
  135|    111|      table[0] = {1, symbols[0]};
  136|    111|      table[1] = {1, symbols[1]};
  137|    111|      table_size = 2;
  138|    111|      break;
  139|     31|    case 3:
  ------------------
  |  Branch (139:5): [True: 31, False: 667]
  ------------------
  140|     31|      if (symbols[1] > symbols[2]) swap_symbols(1, 2);
  ------------------
  |  Branch (140:11): [True: 17, False: 14]
  ------------------
  141|     31|      table[0] = {1, symbols[0]};
  142|     31|      table[2] = {1, symbols[0]};
  143|     31|      table[1] = {2, symbols[1]};
  144|     31|      table[3] = {2, symbols[2]};
  145|     31|      table_size = 4;
  146|     31|      break;
  147|     29|    case 4: {
  ------------------
  |  Branch (147:5): [True: 29, False: 669]
  ------------------
  148|    116|      for (size_t i = 0; i < 3; ++i) {
  ------------------
  |  Branch (148:26): [True: 87, False: 29]
  ------------------
  149|    261|        for (size_t j = i + 1; j < 4; ++j) {
  ------------------
  |  Branch (149:32): [True: 174, False: 87]
  ------------------
  150|    174|          if (symbols[i] > symbols[j]) swap_symbols(i, j);
  ------------------
  |  Branch (150:15): [True: 112, False: 62]
  ------------------
  151|    174|        }
  152|     87|      }
  153|     29|      table[0] = {2, symbols[0]};
  154|     29|      table[2] = {2, symbols[1]};
  155|     29|      table[1] = {2, symbols[2]};
  156|     29|      table[3] = {2, symbols[3]};
  157|     29|      table_size = 4;
  158|     29|      break;
  159|      0|    }
  160|     24|    case 5: {
  ------------------
  |  Branch (160:5): [True: 24, False: 674]
  ------------------
  161|     24|      if (symbols[2] > symbols[3]) swap_symbols(2, 3);
  ------------------
  |  Branch (161:11): [True: 12, False: 12]
  ------------------
  162|     24|      table[0] = {1, symbols[0]};
  163|     24|      table[1] = {2, symbols[1]};
  164|     24|      table[2] = {1, symbols[0]};
  165|     24|      table[3] = {3, symbols[2]};
  166|     24|      table[4] = {1, symbols[0]};
  167|     24|      table[5] = {2, symbols[1]};
  168|     24|      table[6] = {1, symbols[0]};
  169|     24|      table[7] = {3, symbols[3]};
  170|     24|      table_size = 8;
  171|     24|      break;
  172|      0|    }
  173|      0|    default: {
  ------------------
  |  Branch (173:5): [True: 0, False: 698]
  ------------------
  174|       |      // Unreachable.
  175|      0|      return false;
  176|      0|    }
  177|    698|  }
  178|       |
  179|    698|  const uint32_t goal_size = 1u << kHuffmanTableBits;
  180|  5.97k|  while (table_size != goal_size) {
  ------------------
  |  Branch (180:10): [True: 5.28k, False: 698]
  ------------------
  181|  5.28k|    memcpy(&table[table_size], &table[0],
  182|  5.28k|           (size_t)table_size * sizeof(table[0]));
  183|  5.28k|    table_size <<= 1;
  184|  5.28k|  }
  185|       |
  186|    698|  return BrunsliBitReaderIsHealthy(br);
  187|    698|}
huffman_decode.cc:_ZZN7brunsliL14ReadSimpleCodeEtPNS_16BrunsliBitReaderEPNS_11HuffmanCodeEENKUlmmE_clEmm:
  122|    218|  const auto swap_symbols = [&symbols] (size_t i, size_t j) {
  123|    218|    uint16_t t = symbols[j];
  124|    218|    symbols[j] = symbols[i];
  125|    218|    symbols[i] = t;
  126|    218|  };

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

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

_ZN7brunsli9WriteJpegERKNS_8JPEGDataENS_10JPEGOutputE:
  967|  4.15k|bool WriteJpeg(const JPEGData& jpg, JPEGOutput out) {
  968|  4.15k|  State state;
  969|  4.15k|  state.stage = Stage::DONE;
  970|  4.15k|  std::vector<uint8_t> buffer(16384);
  971|  4.41k|  while (true) {
  ------------------
  |  Branch (971:10): [True: 4.41k, Folded]
  ------------------
  972|  4.41k|    uint8_t* next_out = buffer.data();
  973|  4.41k|    size_t available_out = buffer.size();
  974|  4.41k|    SerializationStatus status =
  975|  4.41k|        SerializeJpeg(&state, jpg, &available_out, &next_out);
  976|  4.41k|    if (status != SerializationStatus::DONE &&
  ------------------
  |  Branch (976:9): [True: 4.17k, False: 239]
  ------------------
  977|  4.17k|        status != SerializationStatus::NEEDS_MORE_OUTPUT) {
  ------------------
  |  Branch (977:9): [True: 3.91k, False: 263]
  ------------------
  978|  3.91k|      return false;
  979|  3.91k|    }
  980|    502|    size_t to_write = buffer.size() - available_out;
  981|    502|    if (!out.Write(buffer.data(), to_write)) return false;
  ------------------
  |  Branch (981:9): [True: 0, False: 502]
  ------------------
  982|    502|    if (status == SerializationStatus::DONE) return true;
  ------------------
  |  Branch (982:9): [True: 239, False: 263]
  ------------------
  983|    502|  }
  984|  4.15k|}
_ZN7brunsli8internal3dec13SerializeJpegEPNS1_5StateERKNS_8JPEGDataEPmPPh:
  989|  4.41k|                                  size_t* available_out, uint8_t** next_out) {
  990|  4.41k|  SerializationState& ss = state->internal->serialization;
  991|       |
  992|  4.41k|  const auto maybe_push_output = [&]() {
  993|  4.41k|    if (ss.stage != SerializationState::ERROR) {
  994|  4.41k|      PushOutput(&ss.output_queue, available_out, next_out);
  995|  4.41k|    }
  996|  4.41k|  };
  997|       |
  998|       |  // Push remaining output from prevoius session.
  999|  4.41k|  maybe_push_output();
 1000|       |
 1001|  39.5k|  while (true) {
  ------------------
  |  Branch (1001:10): [True: 39.5k, Folded]
  ------------------
 1002|  39.5k|    switch (ss.stage) {
 1003|  4.15k|      case SerializationState::INIT: {
  ------------------
  |  Branch (1003:7): [True: 4.15k, False: 35.4k]
  ------------------
 1004|       |        // If parsing is complete, serialization is possible.
 1005|  4.15k|        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.15k|        if (HasSection(state, kBrunsliDCDataTag) ||
  ------------------
  |  Branch (1008:13): [True: 0, False: 4.15k]
  ------------------
 1009|  4.15k|            HasSection(state, kBrunsliACDataTag)) {
  ------------------
  |  Branch (1009:13): [True: 0, False: 4.15k]
  ------------------
 1010|      0|          can_start_serialization = true;
 1011|      0|        }
 1012|  4.15k|        if (!can_start_serialization) {
  ------------------
  |  Branch (1012:13): [True: 0, False: 4.15k]
  ------------------
 1013|      0|          return SerializationStatus::NEEDS_MORE_INPUT;
 1014|      0|        }
 1015|       |        // JpegBypass is a very simple / special case.
 1016|  4.15k|        if (jpg.version == kFallbackVersion) {
  ------------------
  |  Branch (1016:13): [True: 8, False: 4.14k]
  ------------------
 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.14k|        if ((jpg.version & 1) == kFallbackVersion) {
  ------------------
  |  Branch (1030:13): [True: 0, False: 4.14k]
  ------------------
 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.14k|        if (jpg.marker_order.empty()) {
  ------------------
  |  Branch (1038:13): [True: 0, False: 4.14k]
  ------------------
 1039|      0|          ss.stage = SerializationState::ERROR;
 1040|      0|          break;
 1041|      0|        }
 1042|       |
 1043|  4.14k|        ss.dc_huff_table.resize(kMaxHuffmanTables);
 1044|  4.14k|        ss.ac_huff_table.resize(kMaxHuffmanTables);
 1045|  4.14k|        if (jpg.has_zero_padding_bit) {
  ------------------
  |  Branch (1045:13): [True: 257, False: 3.89k]
  ------------------
 1046|    257|          ss.pad_bits = jpg.padding_bits.data();
 1047|    257|          ss.pad_bits_end = ss.pad_bits + jpg.padding_bits.size();
 1048|    257|        }
 1049|       |
 1050|  4.14k|        EncodeSOI(&ss);
 1051|  4.14k|        maybe_push_output();
 1052|  4.14k|        ss.stage = SerializationState::SERIALIZE_SECTION;
 1053|  4.14k|        break;
 1054|  4.14k|      }
 1055|       |
 1056|  31.0k|      case SerializationState::SERIALIZE_SECTION: {
  ------------------
  |  Branch (1056:7): [True: 31.0k, False: 8.57k]
  ------------------
 1057|  31.0k|        if (ss.section_index >= jpg.marker_order.size()) {
  ------------------
  |  Branch (1057:13): [True: 232, False: 30.7k]
  ------------------
 1058|    232|          ss.stage = SerializationState::DONE;
 1059|    232|          break;
 1060|    232|        }
 1061|  30.7k|        uint8_t marker = jpg.marker_order[ss.section_index];
 1062|  30.7k|        SerializationStatus status = SerializeSection(marker, *state, &ss, jpg);
 1063|  30.7k|        if (status == SerializationStatus::ERROR) {
  ------------------
  |  Branch (1063:13): [True: 3.91k, False: 26.8k]
  ------------------
 1064|  3.91k|          BRUNSLI_LOG_DEBUG() << "Failed to encode marker " << std::hex
  ------------------
  |  |  427|  3.91k|#define BRUNSLI_LOG_DEBUG() BRUNSLI_VOID_LOG()
  |  |  ------------------
  |  |  |  |  406|  3.91k|#define BRUNSLI_VOID_LOG() if (true) {} else std::cerr
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (406:32): [True: 3.91k, Folded]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1065|      0|                              << marker << BRUNSLI_ENDL();
  ------------------
  |  |  414|      0|#define BRUNSLI_ENDL() std::endl
  ------------------
 1066|  3.91k|          ss.stage = SerializationState::ERROR;
 1067|  3.91k|          break;
 1068|  3.91k|        }
 1069|  26.8k|        maybe_push_output();
 1070|  26.8k|        if (status == SerializationStatus::NEEDS_MORE_INPUT) {
  ------------------
  |  Branch (1070:13): [True: 0, False: 26.8k]
  ------------------
 1071|      0|          return SerializationStatus::NEEDS_MORE_INPUT;
 1072|  26.8k|        } else if (status != SerializationStatus::DONE) {
  ------------------
  |  Branch (1072:20): [True: 0, False: 26.8k]
  ------------------
 1073|      0|          BRUNSLI_DCHECK(false);
 1074|      0|          ss.stage = SerializationState::ERROR;
 1075|      0|          break;
 1076|      0|        }
 1077|  26.8k|        ++ss.section_index;
 1078|  26.8k|        break;
 1079|  26.8k|      }
 1080|       |
 1081|    502|      case SerializationState::DONE: {
  ------------------
  |  Branch (1081:7): [True: 502, False: 39.0k]
  ------------------
 1082|    502|        if (!ss.output_queue.empty()) {
  ------------------
  |  Branch (1082:13): [True: 263, False: 239]
  ------------------
 1083|    263|          return SerializationStatus::NEEDS_MORE_OUTPUT;
 1084|    263|        } else {
 1085|    239|          return SerializationStatus::DONE;
 1086|    239|        }
 1087|    502|      }
 1088|       |
 1089|  3.91k|      default:
  ------------------
  |  Branch (1089:7): [True: 3.91k, False: 35.6k]
  ------------------
 1090|  3.91k|        return SerializationStatus::ERROR;
 1091|  39.5k|    }
 1092|  39.5k|  }
 1093|  4.41k|}
jpeg_data_writer.cc:_ZZN7brunsli8internal3dec13SerializeJpegEPNS1_5StateERKNS_8JPEGDataEPmPPhENK3$_0clEv:
  992|  35.4k|  const auto maybe_push_output = [&]() {
  993|  35.4k|    if (ss.stage != SerializationState::ERROR) {
  ------------------
  |  Branch (993:9): [True: 35.4k, False: 0]
  ------------------
  994|  35.4k|      PushOutput(&ss.output_queue, available_out, next_out);
  995|  35.4k|    }
  996|  35.4k|  };
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_110PushOutputEPNSt3__15dequeINS_8internal3dec11OutputChunkENS1_9allocatorIS5_EEEEPmPPh:
  946|  35.4k|                uint8_t** next_out) {
  947|  67.8k|  while (*available_out > 0) {
  ------------------
  |  Branch (947:10): [True: 67.1k, False: 740]
  ------------------
  948|       |    // No more data.
  949|  67.1k|    if (in->empty()) return;
  ------------------
  |  Branch (949:9): [True: 34.7k, False: 32.4k]
  ------------------
  950|  32.4k|    OutputChunk& chunk = in->front();
  951|  32.4k|    size_t to_copy = std::min(*available_out, chunk.len);
  952|  32.4k|    if (to_copy > 0) {
  ------------------
  |  Branch (952:9): [True: 32.2k, False: 237]
  ------------------
  953|  32.2k|      memcpy(*next_out, chunk.next, to_copy);
  954|  32.2k|      *next_out += to_copy;
  955|  32.2k|      *available_out -= to_copy;
  956|  32.2k|      chunk.next += to_copy;
  957|  32.2k|      chunk.len -= to_copy;
  958|  32.2k|    }
  959|  32.4k|    if (chunk.len == 0) in->pop_front();
  ------------------
  |  Branch (959:9): [True: 32.1k, False: 327]
  ------------------
  960|  32.4k|  }
  961|  35.4k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeSOIEPNS_8internal3dec18SerializationStateE:
  306|  4.14k|bool EncodeSOI(SerializationState* state) {
  307|  4.14k|  state->output_queue.push_back(OutputChunk({0xFF, 0xD8}));
  308|  4.14k|  return true;
  309|  4.14k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_116SerializeSectionEhRKNS_8internal3dec5StateEPNS2_18SerializationStateERKNS_8JPEGDataE:
  878|  30.7k|                                     const JPEGData& jpg) {
  879|  30.7k|  const auto to_status = [](bool result) {
  880|  30.7k|    return result ? SerializationStatus::DONE : SerializationStatus::ERROR;
  881|  30.7k|  };
  882|       |  // TODO(eustas): add and use marker enum
  883|  30.7k|  switch (marker) {
  884|  3.20k|    case 0xC0:
  ------------------
  |  Branch (884:5): [True: 3.20k, False: 27.5k]
  ------------------
  885|  4.16k|    case 0xC1:
  ------------------
  |  Branch (885:5): [True: 961, False: 29.8k]
  ------------------
  886|  8.53k|    case 0xC2:
  ------------------
  |  Branch (886:5): [True: 4.36k, False: 26.4k]
  ------------------
  887|  9.73k|    case 0xC9:
  ------------------
  |  Branch (887:5): [True: 1.20k, False: 29.5k]
  ------------------
  888|  10.8k|    case 0xCA:
  ------------------
  |  Branch (888:5): [True: 1.12k, False: 29.6k]
  ------------------
  889|  10.8k|      return to_status(EncodeSOF(jpg, marker, state));
  890|       |
  891|  4.35k|    case 0xC4:
  ------------------
  |  Branch (891:5): [True: 4.35k, False: 26.4k]
  ------------------
  892|  4.35k|      return to_status(EncodeDHT(jpg, state));
  893|       |
  894|  1.79k|    case 0xD0:
  ------------------
  |  Branch (894:5): [True: 1.79k, False: 28.9k]
  ------------------
  895|  2.85k|    case 0xD1:
  ------------------
  |  Branch (895:5): [True: 1.05k, False: 29.7k]
  ------------------
  896|  3.60k|    case 0xD2:
  ------------------
  |  Branch (896:5): [True: 754, False: 30.0k]
  ------------------
  897|  4.40k|    case 0xD3:
  ------------------
  |  Branch (897:5): [True: 800, False: 29.9k]
  ------------------
  898|  5.29k|    case 0xD4:
  ------------------
  |  Branch (898:5): [True: 889, False: 29.9k]
  ------------------
  899|  6.43k|    case 0xD5:
  ------------------
  |  Branch (899:5): [True: 1.14k, False: 29.6k]
  ------------------
  900|  7.66k|    case 0xD6:
  ------------------
  |  Branch (900:5): [True: 1.22k, False: 29.5k]
  ------------------
  901|  8.45k|    case 0xD7:
  ------------------
  |  Branch (901:5): [True: 792, False: 30.0k]
  ------------------
  902|  8.45k|      return to_status(EncodeRestart(marker, state));
  903|       |
  904|    232|    case 0xD9:
  ------------------
  |  Branch (904:5): [True: 232, False: 30.5k]
  ------------------
  905|    232|      return to_status(EncodeEOI(jpg, state));
  906|       |
  907|  4.63k|    case 0xDA:
  ------------------
  |  Branch (907:5): [True: 4.63k, False: 26.1k]
  ------------------
  908|  4.63k|      return EncodeScan(jpg, parsing_state, state);
  909|       |
  910|    165|    case 0xDB:
  ------------------
  |  Branch (910:5): [True: 165, False: 30.6k]
  ------------------
  911|    165|      return to_status(EncodeDQT(jpg, state));
  912|       |
  913|  1.74k|    case 0xDD:
  ------------------
  |  Branch (913:5): [True: 1.74k, False: 29.0k]
  ------------------
  914|  1.74k|      return to_status(EncodeDRI(jpg, state));
  915|       |
  916|     20|    case 0xE0:
  ------------------
  |  Branch (916:5): [True: 20, False: 30.7k]
  ------------------
  917|     26|    case 0xE1:
  ------------------
  |  Branch (917:5): [True: 6, False: 30.7k]
  ------------------
  918|     36|    case 0xE2:
  ------------------
  |  Branch (918:5): [True: 10, False: 30.7k]
  ------------------
  919|     39|    case 0xE3:
  ------------------
  |  Branch (919:5): [True: 3, False: 30.7k]
  ------------------
  920|     55|    case 0xE4:
  ------------------
  |  Branch (920:5): [True: 16, False: 30.7k]
  ------------------
  921|     67|    case 0xE5:
  ------------------
  |  Branch (921:5): [True: 12, False: 30.7k]
  ------------------
  922|     86|    case 0xE6:
  ------------------
  |  Branch (922:5): [True: 19, False: 30.7k]
  ------------------
  923|    115|    case 0xE7:
  ------------------
  |  Branch (923:5): [True: 29, False: 30.7k]
  ------------------
  924|    132|    case 0xE8:
  ------------------
  |  Branch (924:5): [True: 17, False: 30.7k]
  ------------------
  925|    142|    case 0xE9:
  ------------------
  |  Branch (925:5): [True: 10, False: 30.7k]
  ------------------
  926|    149|    case 0xEA:
  ------------------
  |  Branch (926:5): [True: 7, False: 30.7k]
  ------------------
  927|    153|    case 0xEB:
  ------------------
  |  Branch (927:5): [True: 4, False: 30.7k]
  ------------------
  928|    164|    case 0xEC:
  ------------------
  |  Branch (928:5): [True: 11, False: 30.7k]
  ------------------
  929|    178|    case 0xED:
  ------------------
  |  Branch (929:5): [True: 14, False: 30.7k]
  ------------------
  930|    183|    case 0xEE:
  ------------------
  |  Branch (930:5): [True: 5, False: 30.7k]
  ------------------
  931|    199|    case 0xEF:
  ------------------
  |  Branch (931:5): [True: 16, False: 30.7k]
  ------------------
  932|    199|      return to_status(EncodeAPP(jpg, marker, state));
  933|       |
  934|      3|    case 0xFE:
  ------------------
  |  Branch (934:5): [True: 3, False: 30.7k]
  ------------------
  935|      3|      return to_status(EncodeCOM(jpg, state));
  936|       |
  937|     10|    case 0xFF:
  ------------------
  |  Branch (937:5): [True: 10, False: 30.7k]
  ------------------
  938|     10|      return to_status(EncodeInterMarkerData(jpg, state));
  939|       |
  940|    132|    default:
  ------------------
  |  Branch (940:5): [True: 132, False: 30.6k]
  ------------------
  941|    132|      return SerializationStatus::ERROR;
  942|  30.7k|  }
  943|  30.7k|}
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_116SerializeSectionEhRKNS_8internal3dec5StateEPNS2_18SerializationStateERKNS_8JPEGDataEENK3$_0clEb:
  879|  26.0k|  const auto to_status = [](bool result) {
  880|  26.0k|    return result ? SerializationStatus::DONE : SerializationStatus::ERROR;
  ------------------
  |  Branch (880:12): [True: 25.8k, False: 201]
  ------------------
  881|  26.0k|  };
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeSOFERKNS_8JPEGDataEhPNS_8internal3dec18SerializationStateE:
  317|  10.8k|bool EncodeSOF(const JPEGData& jpg, uint8_t marker, SerializationState* state) {
  318|  10.8k|  if (marker <= 0xC2) state->is_progressive = (marker == 0xC2);
  ------------------
  |  Branch (318:7): [True: 8.53k, False: 2.32k]
  ------------------
  319|       |
  320|  10.8k|  const size_t n_comps = jpg.components.size();
  321|  10.8k|  const size_t marker_len = 8 + 3 * n_comps;
  322|  10.8k|  state->output_queue.emplace_back(marker_len + 2);
  323|  10.8k|  uint8_t* data = state->output_queue.back().buffer->data();
  324|  10.8k|  size_t pos = 0;
  325|  10.8k|  data[pos++] = 0xFFu;
  326|  10.8k|  data[pos++] = marker;
  327|  10.8k|  data[pos++] = static_cast<uint8_t>(marker_len >> 8u);
  328|  10.8k|  data[pos++] = static_cast<uint8_t>(marker_len);
  329|  10.8k|  data[pos++] = kJpegPrecision;
  330|  10.8k|  data[pos++] = jpg.height >> 8u;
  331|  10.8k|  data[pos++] = jpg.height & 0xFFu;
  332|  10.8k|  data[pos++] = jpg.width >> 8u;
  333|  10.8k|  data[pos++] = jpg.width & 0xFFu;
  334|  10.8k|  data[pos++] = static_cast<uint8_t>(n_comps);
  335|  21.8k|  for (size_t i = 0; i < n_comps; ++i) {
  ------------------
  |  Branch (335:22): [True: 10.9k, False: 10.8k]
  ------------------
  336|  10.9k|    data[pos++] = jpg.components[i].id;
  337|  10.9k|    data[pos++] = ((jpg.components[i].h_samp_factor << 4u) |
  338|  10.9k|                   (jpg.components[i].v_samp_factor));
  339|  10.9k|    const size_t quant_idx = jpg.components[i].quant_idx;
  340|  10.9k|    if (quant_idx >= jpg.quant.size()) return false;
  ------------------
  |  Branch (340:9): [True: 0, False: 10.9k]
  ------------------
  341|  10.9k|    data[pos++] = jpg.quant[quant_idx].index;
  342|  10.9k|  }
  343|  10.8k|  return true;
  344|  10.8k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeDHTERKNS_8JPEGDataEPNS_8internal3dec18SerializationStateE:
  370|  4.35k|bool EncodeDHT(const JPEGData& jpg, SerializationState* state) {
  371|  4.35k|  const std::vector<JPEGHuffmanCode>& huffman_code = jpg.huffman_code;
  372|       |
  373|  4.35k|  size_t marker_len = 2;
  374|  12.0k|  for (size_t i = state->dht_index; i < huffman_code.size(); ++i) {
  ------------------
  |  Branch (374:37): [True: 12.0k, False: 0]
  ------------------
  375|  12.0k|    const JPEGHuffmanCode& huff = huffman_code[i];
  376|  12.0k|    marker_len += kJpegHuffmanMaxBitLength;
  377|   216k|    for (size_t j = 0; j < huff.counts.size(); ++j) {
  ------------------
  |  Branch (377:24): [True: 204k, False: 12.0k]
  ------------------
  378|   204k|      marker_len += huff.counts[j];
  379|   204k|    }
  380|  12.0k|    if (huff.is_last) break;
  ------------------
  |  Branch (380:9): [True: 4.35k, False: 7.69k]
  ------------------
  381|  12.0k|  }
  382|  4.35k|  state->output_queue.emplace_back(marker_len + 2);
  383|  4.35k|  uint8_t* data = state->output_queue.back().buffer->data();
  384|  4.35k|  size_t pos = 0;
  385|  4.35k|  data[pos++] = 0xFFu;
  386|  4.35k|  data[pos++] = 0xC4u;
  387|  4.35k|  data[pos++] = static_cast<uint8_t>(marker_len >> 8u);
  388|  4.35k|  data[pos++] = static_cast<uint8_t>(marker_len);
  389|  12.0k|  while (true) {
  ------------------
  |  Branch (389:10): [True: 12.0k, Folded]
  ------------------
  390|  12.0k|    const size_t huffman_code_index = state->dht_index++;
  391|  12.0k|    if (huffman_code_index >= huffman_code.size()) {
  ------------------
  |  Branch (391:9): [True: 0, False: 12.0k]
  ------------------
  392|      0|      return false;
  393|      0|    }
  394|  12.0k|    const JPEGHuffmanCode& huff = huffman_code[huffman_code_index];
  395|  12.0k|    size_t index = huff.slot_id;
  396|  12.0k|    HuffmanCodeTable* huff_table;
  397|  12.0k|    if (index & 0x10) {
  ------------------
  |  Branch (397:9): [True: 6.82k, False: 5.22k]
  ------------------
  398|  6.82k|      index -= 0x10;
  399|  6.82k|      huff_table = &state->ac_huff_table[index];
  400|  6.82k|    } else {
  401|  5.22k|      huff_table = &state->dc_huff_table[index];
  402|  5.22k|    }
  403|       |    // TODO(eustas): cache
  404|       |    // TODO(eustas): set up non-existing symbols
  405|  12.0k|    if (!BuildHuffmanCodeTable(huff, huff_table)) {
  ------------------
  |  Branch (405:9): [True: 0, False: 12.0k]
  ------------------
  406|      0|      return false;
  407|      0|    }
  408|  12.0k|    size_t total_count = 0;
  409|  12.0k|    size_t max_length = 0;
  410|   216k|    for (size_t i = 0; i < huff.counts.size(); ++i) {
  ------------------
  |  Branch (410:24): [True: 204k, False: 12.0k]
  ------------------
  411|   204k|      if (huff.counts[i] != 0) {
  ------------------
  |  Branch (411:11): [True: 104k, False: 100k]
  ------------------
  412|   104k|        max_length = i;
  413|   104k|      }
  414|   204k|      total_count += huff.counts[i];
  415|   204k|    }
  416|  12.0k|    --total_count;
  417|  12.0k|    data[pos++] = huff.slot_id;
  418|   204k|    for (size_t i = 1; i <= kJpegHuffmanMaxBitLength; ++i) {
  ------------------
  |  Branch (418:24): [True: 192k, False: 12.0k]
  ------------------
  419|   192k|      data[pos++] = (i == max_length ? huff.counts[i] - 1 : huff.counts[i]);
  ------------------
  |  Branch (419:22): [True: 12.0k, False: 180k]
  ------------------
  420|   192k|    }
  421|   888k|    for (size_t i = 0; i < total_count; ++i) {
  ------------------
  |  Branch (421:24): [True: 876k, False: 12.0k]
  ------------------
  422|   876k|      data[pos++] = huff.values[i];
  423|   876k|    }
  424|  12.0k|    if (huff.is_last) break;
  ------------------
  |  Branch (424:9): [True: 4.35k, False: 7.69k]
  ------------------
  425|  12.0k|  }
  426|  4.35k|  return true;
  427|  4.35k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_121BuildHuffmanCodeTableERKNS_15JPEGHuffmanCodeEPNS_16HuffmanCodeTableE:
  266|  12.0k|                           HuffmanCodeTable* table) {
  267|  12.0k|  int huff_code[kJpegHuffmanAlphabetSize];
  268|       |  // +1 for a sentinel element.
  269|  12.0k|  uint32_t huff_size[kJpegHuffmanAlphabetSize + 1];
  270|  12.0k|  int p = 0;
  271|   204k|  for (size_t l = 1; l <= kJpegHuffmanMaxBitLength; ++l) {
  ------------------
  |  Branch (271:22): [True: 192k, False: 12.0k]
  ------------------
  272|   192k|    int i = huff.counts[l];
  273|   192k|    if (p + i > kJpegHuffmanAlphabetSize + 1) {
  ------------------
  |  Branch (273:9): [True: 0, False: 192k]
  ------------------
  274|      0|      return false;
  275|      0|    }
  276|  1.08M|    while (i--) huff_size[p++] = static_cast<uint32_t>(l);
  ------------------
  |  Branch (276:12): [True: 888k, False: 192k]
  ------------------
  277|   192k|  }
  278|       |
  279|  12.0k|  if (p == 0) {
  ------------------
  |  Branch (279:7): [True: 0, False: 12.0k]
  ------------------
  280|      0|    return true;
  281|      0|  }
  282|       |
  283|       |  // Reuse sentinel element.
  284|  12.0k|  int last_p = p - 1;
  285|  12.0k|  huff_size[last_p] = 0;
  286|       |
  287|  12.0k|  int code = 0;
  288|  12.0k|  uint32_t si = huff_size[0];
  289|  12.0k|  p = 0;
  290|   125k|  while (huff_size[p]) {
  ------------------
  |  Branch (290:10): [True: 113k, False: 12.0k]
  ------------------
  291|   989k|    while ((huff_size[p]) == si) {
  ------------------
  |  Branch (291:12): [True: 876k, False: 113k]
  ------------------
  292|   876k|      huff_code[p++] = code;
  293|   876k|      code++;
  294|   876k|    }
  295|   113k|    code <<= 1;
  296|   113k|    si++;
  297|   113k|  }
  298|   888k|  for (p = 0; p < last_p; p++) {
  ------------------
  |  Branch (298:15): [True: 876k, False: 12.0k]
  ------------------
  299|   876k|    int i = huff.values[p];
  300|   876k|    table->depth[i] = huff_size[p];
  301|   876k|    table->code[i] = huff_code[p];
  302|   876k|  }
  303|  12.0k|  return true;
  304|  12.0k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_113EncodeRestartEhPNS_8internal3dec18SerializationStateE:
  475|  8.45k|bool EncodeRestart(uint8_t marker, SerializationState* state) {
  476|  8.45k|  state->output_queue.push_back(OutputChunk({0xFF, marker}));
  477|  8.45k|  return true;
  478|  8.45k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeEOIERKNS_8JPEGDataEPNS_8internal3dec18SerializationStateE:
  311|    232|bool EncodeEOI(const JPEGData& jpg, SerializationState* state) {
  312|    232|  state->output_queue.push_back(OutputChunk({0xFF, 0xD9}));
  313|    232|  state->output_queue.emplace_back(jpg.tail_data);
  314|    232|  return true;
  315|    232|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_110EncodeScanERKNS_8JPEGDataERKNS_8internal3dec5StateEPNS5_18SerializationStateE:
  858|  4.63k|           SerializationState* state) {
  859|  4.63k|  const JPEGScanInfo& scan_info = jpg.scan_info[state->scan_index];
  860|  4.63k|  const bool is_progressive = state->is_progressive;
  861|  4.63k|  const int Al = is_progressive ? scan_info.Al : 0;
  ------------------
  |  Branch (861:18): [True: 3.98k, False: 653]
  ------------------
  862|  4.63k|  const int Ah = is_progressive ? scan_info.Ah : 0;
  ------------------
  |  Branch (862:18): [True: 3.98k, False: 653]
  ------------------
  863|  4.63k|  const int Ss = is_progressive ? scan_info.Ss : 0;
  ------------------
  |  Branch (863:18): [True: 3.98k, False: 653]
  ------------------
  864|  4.63k|  const int Se = is_progressive ? scan_info.Se : 63;
  ------------------
  |  Branch (864:18): [True: 3.98k, False: 653]
  ------------------
  865|  4.63k|  const bool need_sequential =
  866|  4.63k|      !is_progressive || (Ah == 0 && Al == 0 && Ss == 0 && Se == 63);
  ------------------
  |  Branch (866:7): [True: 653, False: 3.98k]
  |  Branch (866:27): [True: 1.42k, False: 2.56k]
  |  Branch (866:38): [True: 697, False: 723]
  |  Branch (866:49): [True: 319, False: 378]
  |  Branch (866:60): [True: 24, False: 295]
  ------------------
  867|  4.63k|  if (need_sequential) {
  ------------------
  |  Branch (867:7): [True: 677, False: 3.96k]
  ------------------
  868|    677|    return DoEncodeScan<0>(jpg, parsing_state, state);
  869|  3.96k|  } else if (Ah == 0) {
  ------------------
  |  Branch (869:14): [True: 1.39k, False: 2.56k]
  ------------------
  870|  1.39k|    return DoEncodeScan<1>(jpg, parsing_state, state);
  871|  2.56k|  } else {
  872|  2.56k|    return DoEncodeScan<2>(jpg, parsing_state, state);
  873|  2.56k|  }
  874|  4.63k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_112DoEncodeScanILi0EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateE:
  700|    677|                                                  SerializationState* state) {
  701|    677|  const JPEGScanInfo& scan_info = jpg.scan_info[state->scan_index];
  702|    677|  EncodeScanState& ss = state->scan_state;
  703|       |
  704|    677|  const int restart_interval =
  705|    677|      state->seen_dri_marker ? jpg.restart_interval : 0;
  ------------------
  |  Branch (705:7): [True: 158, False: 519]
  ------------------
  706|       |
  707|    677|  const auto get_next_extra_zero_run_index = [&ss, &scan_info]() -> int {
  708|    677|    if (ss.extra_zero_runs_pos < scan_info.extra_zero_runs.size()) {
  709|    677|      return scan_info.extra_zero_runs[ss.extra_zero_runs_pos].block_idx;
  710|    677|    } else {
  711|    677|      return -1;
  712|    677|    }
  713|    677|  };
  714|       |
  715|    677|  const auto get_next_reset_point = [&ss, &scan_info]() -> int {
  716|    677|    if (ss.next_reset_point_pos < scan_info.reset_points.size()) {
  717|    677|      return scan_info.reset_points[ss.next_reset_point_pos++];
  718|    677|    } else {
  719|    677|      return -1;
  720|    677|    }
  721|    677|  };
  722|       |
  723|    677|  if (ss.stage == EncodeScanState::HEAD) {
  ------------------
  |  Branch (723:7): [True: 677, False: 0]
  ------------------
  724|    677|    if (!EncodeSOS(jpg, scan_info, state)) return SerializationStatus::ERROR;
  ------------------
  |  Branch (724:9): [True: 30, False: 647]
  ------------------
  725|    647|    BitWriterInit(&ss.bw, &state->output_queue);
  726|    647|    DCTCodingStateInit(&ss.coding_state);
  727|    647|    ss.restarts_to_go = restart_interval;
  728|    647|    ss.next_restart_marker = 0;
  729|    647|    ss.block_scan_index = 0;
  730|    647|    ss.extra_zero_runs_pos = 0;
  731|    647|    ss.next_extra_zero_run_index = get_next_extra_zero_run_index();
  732|    647|    ss.next_reset_point_pos = 0;
  733|    647|    ss.next_reset_point = get_next_reset_point();
  734|    647|    ss.mcu_y = 0;
  735|    647|    memset(ss.last_dc_coeff, 0, sizeof(ss.last_dc_coeff));
  736|    647|    ss.stage = EncodeScanState::BODY;
  737|    647|  }
  738|    647|  BitWriter* bw = &ss.bw;
  739|    647|  DCTCodingState* coding_state = &ss.coding_state;
  740|       |
  741|    647|  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|    647|  const bool is_interleaved = (scan_info.num_components > 1);
  746|    647|  const JPEGComponent& base_component =
  747|    647|      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|    647|  const int h_group = is_interleaved ? 1 : base_component.h_samp_factor;
  ------------------
  |  Branch (753:23): [True: 405, False: 242]
  ------------------
  754|    647|  const int v_group = is_interleaved ? 1 : base_component.v_samp_factor;
  ------------------
  |  Branch (754:23): [True: 405, False: 242]
  ------------------
  755|    647|  const int MCUs_per_row =
  756|    647|      DivCeil(jpg.width * h_group, 8 * jpg.max_h_samp_factor);
  757|    647|  const int MCU_rows = DivCeil(jpg.height * v_group, 8 * jpg.max_v_samp_factor);
  758|    647|  const bool is_progressive = state->is_progressive;
  759|    647|  const int Al = is_progressive ? scan_info.Al : 0;
  ------------------
  |  Branch (759:18): [True: 24, False: 623]
  ------------------
  760|    647|  const int Ss = is_progressive ? scan_info.Ss : 0;
  ------------------
  |  Branch (760:18): [True: 24, False: 623]
  ------------------
  761|    647|  const int Se = is_progressive ? scan_info.Se : 63;
  ------------------
  |  Branch (761:18): [True: 24, False: 623]
  ------------------
  762|       |
  763|       |  // DC-only is defined by [0..0] spectral range.
  764|    647|  const bool want_ac = ((Ss != 0) || (Se != 0));
  ------------------
  |  Branch (764:25): [True: 0, False: 647]
  |  Branch (764:38): [True: 647, False: 0]
  ------------------
  765|    647|  const bool complete_ac = (parsing_state.stage == Stage::DONE);
  766|    647|  const bool has_ac =
  767|    647|      complete_ac || HasSection(&parsing_state, kBrunsliACDataTag);
  ------------------
  |  Branch (767:7): [True: 647, False: 0]
  |  Branch (767:22): [True: 0, False: 0]
  ------------------
  768|    647|  if (want_ac && !has_ac) return SerializationStatus::NEEDS_MORE_INPUT;
  ------------------
  |  Branch (768:7): [True: 647, False: 0]
  |  Branch (768:18): [True: 0, False: 647]
  ------------------
  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|    647|  const bool complete_dc = has_ac;
  774|    647|  const bool complete = want_ac ? complete_ac : complete_dc;
  ------------------
  |  Branch (774:25): [True: 647, False: 0]
  ------------------
  775|       |  // When "incomplete" |ac_dc| tracks information about current ("incomplete")
  776|       |  // band parsing progress.
  777|    647|  const int last_mcu_y =
  778|    647|      complete ? MCU_rows : parsing_state.internal->ac_dc.next_mcu_y * v_group;
  ------------------
  |  Branch (778:7): [True: 647, False: 0]
  ------------------
  779|       |
  780|  73.2k|  for (; ss.mcu_y < last_mcu_y; ++ss.mcu_y) {
  ------------------
  |  Branch (780:10): [True: 72.5k, False: 644]
  ------------------
  781|   597k|    for (int mcu_x = 0; mcu_x < MCUs_per_row; ++mcu_x) {
  ------------------
  |  Branch (781:25): [True: 524k, False: 72.5k]
  ------------------
  782|       |      // Possibly emit a restart marker.
  783|   524k|      if (restart_interval > 0 && ss.restarts_to_go == 0) {
  ------------------
  |  Branch (783:11): [True: 487k, False: 36.9k]
  |  Branch (783:35): [True: 115k, False: 372k]
  ------------------
  784|   115k|        Flush(coding_state, bw);
  785|   115k|        if (!JumpToByteBoundary(bw, &state->pad_bits, state->pad_bits_end)) {
  ------------------
  |  Branch (785:13): [True: 3, False: 115k]
  ------------------
  786|      3|          return SerializationStatus::ERROR;
  787|      3|        }
  788|   115k|        EmitMarker(bw, 0xD0 + ss.next_restart_marker);
  789|   115k|        ss.next_restart_marker += 1;
  790|   115k|        ss.next_restart_marker &= 0x7;
  791|   115k|        ss.restarts_to_go = restart_interval;
  792|   115k|        memset(ss.last_dc_coeff, 0, sizeof(ss.last_dc_coeff));
  793|   115k|      }
  794|       |      // Encode one MCU
  795|  1.54M|      for (size_t i = 0; i < scan_info.num_components; ++i) {
  ------------------
  |  Branch (795:26): [True: 1.01M, False: 524k]
  ------------------
  796|  1.01M|        const JPEGComponentScanInfo& si = scan_info.components[i];
  797|  1.01M|        const JPEGComponent& c = jpg.components[si.comp_idx];
  798|  1.01M|        const HuffmanCodeTable& dc_huff = state->dc_huff_table[si.dc_tbl_idx];
  799|  1.01M|        const HuffmanCodeTable& ac_huff = state->ac_huff_table[si.ac_tbl_idx];
  800|  1.01M|        int n_blocks_y = is_interleaved ? c.v_samp_factor : 1;
  ------------------
  |  Branch (800:26): [True: 658k, False: 356k]
  ------------------
  801|  1.01M|        int n_blocks_x = is_interleaved ? c.h_samp_factor : 1;
  ------------------
  |  Branch (801:26): [True: 658k, False: 356k]
  ------------------
  802|  3.14M|        for (int iy = 0; iy < n_blocks_y; ++iy) {
  ------------------
  |  Branch (802:26): [True: 2.12M, False: 1.01M]
  ------------------
  803|  6.87M|          for (int ix = 0; ix < n_blocks_x; ++ix) {
  ------------------
  |  Branch (803:28): [True: 4.74M, False: 2.12M]
  ------------------
  804|  4.74M|            int block_y = ss.mcu_y * n_blocks_y + iy;
  805|  4.74M|            int block_x = mcu_x * n_blocks_x + ix;
  806|  4.74M|            int block_idx = block_y * c.width_in_blocks + block_x;
  807|  4.74M|            if (ss.block_scan_index == ss.next_reset_point) {
  ------------------
  |  Branch (807:17): [True: 866, False: 4.74M]
  ------------------
  808|    866|              Flush(coding_state, bw);
  809|    866|              ss.next_reset_point = get_next_reset_point();
  810|    866|            }
  811|  4.74M|            int num_zero_runs = 0;
  812|  4.74M|            if (ss.block_scan_index == ss.next_extra_zero_run_index) {
  ------------------
  |  Branch (812:17): [True: 1.11k, False: 4.74M]
  ------------------
  813|  1.11k|              num_zero_runs = scan_info.extra_zero_runs[ss.extra_zero_runs_pos]
  814|  1.11k|                                  .num_extra_zero_runs;
  815|  1.11k|              ++ss.extra_zero_runs_pos;
  816|  1.11k|              ss.next_extra_zero_run_index = get_next_extra_zero_run_index();
  817|  1.11k|            }
  818|  4.74M|            const coeff_t* coeffs = &c.coeffs[block_idx << 6];
  819|  4.74M|            bool ok;
  820|  4.74M|            if (kMode == 0) {
  ------------------
  |  Branch (820:17): [True: 4.74M, Folded]
  ------------------
  821|  4.74M|              ok = EncodeDCTBlockSequential(coeffs, dc_huff, ac_huff,
  822|  4.74M|                                            num_zero_runs,
  823|  4.74M|                                            ss.last_dc_coeff + si.comp_idx, bw);
  824|  4.74M|            } 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.74M|            if (!ok) return SerializationStatus::ERROR;
  ------------------
  |  Branch (832:17): [True: 0, False: 4.74M]
  ------------------
  833|  4.74M|            ++ss.block_scan_index;
  834|  4.74M|          }
  835|  2.12M|        }
  836|  1.01M|      }
  837|   524k|      --ss.restarts_to_go;
  838|   524k|    }
  839|  72.5k|  }
  840|    644|  if (ss.mcu_y < MCU_rows) {
  ------------------
  |  Branch (840:7): [True: 0, False: 644]
  ------------------
  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|    644|  Flush(coding_state, bw);
  845|    644|  if (!JumpToByteBoundary(bw, &state->pad_bits, state->pad_bits_end)) {
  ------------------
  |  Branch (845:7): [True: 6, False: 638]
  ------------------
  846|      6|    return SerializationStatus::ERROR;
  847|      6|  }
  848|    638|  BitWriterFinish(bw);
  849|    638|  ss.stage = EncodeScanState::HEAD;
  850|    638|  state->scan_index++;
  851|    638|  if (!bw->healthy) return SerializationStatus::ERROR;
  ------------------
  |  Branch (851:7): [True: 479, False: 159]
  ------------------
  852|       |
  853|    159|  return SerializationStatus::DONE;
  854|    638|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeSOSERKNS_8JPEGDataERKNS_12JPEGScanInfoEPNS_8internal3dec18SerializationStateE:
  347|  4.63k|               SerializationState* state) {
  348|  4.63k|  const size_t n_scans = scan_info.num_components;
  349|  4.63k|  const size_t marker_len = 6 + 2 * n_scans;
  350|  4.63k|  state->output_queue.emplace_back(marker_len + 2);
  351|  4.63k|  uint8_t* data = state->output_queue.back().buffer->data();
  352|  4.63k|  size_t pos = 0;
  353|  4.63k|  data[pos++] = 0xFFu;
  354|  4.63k|  data[pos++] = 0xDAu;
  355|  4.63k|  data[pos++] = static_cast<uint8_t>(marker_len >> 8u);
  356|  4.63k|  data[pos++] = static_cast<uint8_t>(marker_len);
  357|  4.63k|  data[pos++] = static_cast<uint8_t>(n_scans);
  358|  17.1k|  for (size_t i = 0; i < n_scans; ++i) {
  ------------------
  |  Branch (358:22): [True: 12.6k, False: 4.51k]
  ------------------
  359|  12.6k|    const JPEGComponentScanInfo& si = scan_info.components[i];
  360|  12.6k|    if (si.comp_idx >= jpg.components.size()) return false;
  ------------------
  |  Branch (360:9): [True: 125, False: 12.5k]
  ------------------
  361|  12.5k|    data[pos++] = jpg.components[si.comp_idx].id;
  362|  12.5k|    data[pos++] = (si.dc_tbl_idx << 4u) + si.ac_tbl_idx;
  363|  12.5k|  }
  364|  4.51k|  data[pos++] = scan_info.Ss;
  365|  4.51k|  data[pos++] = scan_info.Se;
  366|  4.51k|  data[pos++] = ((scan_info.Ah << 4u) | (scan_info.Al));
  367|  4.51k|  return true;
  368|  4.63k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_113BitWriterInitEPNS_8internal3dec9BitWriterEPNSt3__15dequeINS2_11OutputChunkENS5_9allocatorIS7_EEEE:
   52|  4.51k|void BitWriterInit(BitWriter* bw, std::deque<OutputChunk>* output_queue) {
   53|  4.51k|  bw->output = output_queue;
   54|  4.51k|  bw->chunk = OutputChunk(kBitWriterChunkSize);
   55|  4.51k|  bw->pos = 0;
   56|  4.51k|  bw->put_buffer = 0;
   57|  4.51k|  bw->put_bits = 64;
   58|  4.51k|  bw->healthy = true;
   59|  4.51k|  bw->data = bw->chunk.buffer->data();
   60|  4.51k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_118DCTCodingStateInitEPNS_8internal3dec14DCTCodingStateE:
  185|  4.51k|void DCTCodingStateInit(DCTCodingState* s) {
  186|  4.51k|  s->eob_run_ = 0;
  187|  4.51k|  s->cur_ac_huff_ = nullptr;
  188|  4.51k|  s->refinement_bits_.clear();
  189|  4.51k|  s->refinement_bits_.reserve(64);  // 1024 bits most often is more than enough.
  190|  4.51k|  s->refinement_bits_count_ = 0;
  191|  4.51k|}
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_112DoEncodeScanILi0EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateEENKUlvE_clEv:
  707|  1.75k|  const auto get_next_extra_zero_run_index = [&ss, &scan_info]() -> int {
  708|  1.75k|    if (ss.extra_zero_runs_pos < scan_info.extra_zero_runs.size()) {
  ------------------
  |  Branch (708:9): [True: 1.11k, False: 643]
  ------------------
  709|  1.11k|      return scan_info.extra_zero_runs[ss.extra_zero_runs_pos].block_idx;
  710|  1.11k|    } else {
  711|    643|      return -1;
  712|    643|    }
  713|  1.75k|  };
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_112DoEncodeScanILi0EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateEENKUlvE0_clEv:
  715|  1.51k|  const auto get_next_reset_point = [&ss, &scan_info]() -> int {
  716|  1.51k|    if (ss.next_reset_point_pos < scan_info.reset_points.size()) {
  ------------------
  |  Branch (716:9): [True: 869, False: 644]
  ------------------
  717|    869|      return scan_info.reset_points[ss.next_reset_point_pos++];
  718|    869|    } else {
  719|    644|      return -1;
  720|    644|    }
  721|  1.51k|  };
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_17DivCeilEii:
   44|  9.02k|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|  9.13M|static BRUNSLI_INLINE void Flush(DCTCodingState* s, BitWriter* bw) {
  196|  9.13M|  if (s->eob_run_ > 0) {
  ------------------
  |  Branch (196:7): [True: 8.83M, False: 296k]
  ------------------
  197|  8.83M|    int nbits = Log2FloorNonZero(s->eob_run_);
  198|  8.83M|    int symbol = nbits << 4u;
  199|  8.83M|    WriteBits(bw, s->cur_ac_huff_->depth[symbol],
  200|  8.83M|              s->cur_ac_huff_->code[symbol]);
  201|  8.83M|    if (nbits > 0) {
  ------------------
  |  Branch (201:9): [True: 37.4k, False: 8.80M]
  ------------------
  202|  37.4k|      WriteBits(bw, nbits, s->eob_run_ & ((1 << nbits) - 1));
  203|  37.4k|    }
  204|  8.83M|    s->eob_run_ = 0;
  205|  8.83M|  }
  206|  9.13M|  size_t num_words = s->refinement_bits_count_ >> 4;
  207|  9.16M|  for (size_t i = 0; i < num_words; ++i) {
  ------------------
  |  Branch (207:22): [True: 30.7k, False: 9.13M]
  ------------------
  208|  30.7k|    WriteBits(bw, 16, s->refinement_bits_[i]);
  209|  30.7k|  }
  210|  9.13M|  size_t tail = s->refinement_bits_count_ & 0xF;
  211|  9.13M|  if (tail) {
  ------------------
  |  Branch (211:7): [True: 45.7k, False: 9.08M]
  ------------------
  212|  45.7k|    WriteBits(bw, tail, s->refinement_bits_.back());
  213|  45.7k|  }
  214|  9.13M|  s->refinement_bits_.clear();
  215|  9.13M|  s->refinement_bits_count_ = 0;
  216|  9.13M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19WriteBitsEPNS_8internal3dec9BitWriterEim:
  117|  32.3M|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|  32.3M|  if (nbits == 0) {
  ------------------
  |  Branch (122:7): [True: 4.00M, False: 28.3M]
  ------------------
  123|  4.00M|    bw->healthy = false;
  124|  4.00M|    return;
  125|  4.00M|  }
  126|  28.3M|  bw->put_bits -= nbits;
  127|  28.3M|  bw->put_buffer |= (bits << bw->put_bits);
  128|  28.3M|  if (bw->put_bits <= 16) DischargeBitBuffer(bw);
  ------------------
  |  Branch (128:7): [True: 2.65M, False: 25.6M]
  ------------------
  129|  28.3M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_118DischargeBitBufferEPNS_8internal3dec9BitWriterE:
   87|  2.65M|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.65M|  Reserve(bw, 12);
   94|  2.65M|  if (HasZeroByte(~bw->put_buffer | 0xFFFF)) {
  ------------------
  |  Branch (94:7): [True: 840k, False: 1.81M]
  ------------------
   95|       |    // We have a 0xFF byte somewhere, examine each byte and append a zero
   96|       |    // byte if necessary.
   97|   840k|    EmitByte(bw, (bw->put_buffer >> 56) & 0xFF);
   98|   840k|    EmitByte(bw, (bw->put_buffer >> 48) & 0xFF);
   99|   840k|    EmitByte(bw, (bw->put_buffer >> 40) & 0xFF);
  100|   840k|    EmitByte(bw, (bw->put_buffer >> 32) & 0xFF);
  101|   840k|    EmitByte(bw, (bw->put_buffer >> 24) & 0xFF);
  102|   840k|    EmitByte(bw, (bw->put_buffer >> 16) & 0xFF);
  103|  1.81M|  } else {
  104|       |    // We don't have any 0xFF bytes, output all 6 bytes without checking.
  105|  1.81M|    bw->data[bw->pos] = (bw->put_buffer >> 56) & 0xFF;
  106|  1.81M|    bw->data[bw->pos + 1] = (bw->put_buffer >> 48) & 0xFF;
  107|  1.81M|    bw->data[bw->pos + 2] = (bw->put_buffer >> 40) & 0xFF;
  108|  1.81M|    bw->data[bw->pos + 3] = (bw->put_buffer >> 32) & 0xFF;
  109|  1.81M|    bw->data[bw->pos + 4] = (bw->put_buffer >> 24) & 0xFF;
  110|  1.81M|    bw->data[bw->pos + 5] = (bw->put_buffer >> 16) & 0xFF;
  111|  1.81M|    bw->pos += 6;
  112|  1.81M|  }
  113|  2.65M|  bw->put_buffer <<= 48;
  114|  2.65M|  bw->put_bits += 48;
  115|  2.65M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_17ReserveEPNS_8internal3dec9BitWriterEm:
   70|  3.13M|static BRUNSLI_INLINE void Reserve(BitWriter* bw, size_t n_bytes) {
   71|  3.13M|  if (BRUNSLI_PREDICT_FALSE((bw->pos + n_bytes) > kBitWriterChunkSize)) {
  ------------------
  |  |   85|  3.13M|#define BRUNSLI_PREDICT_FALSE(x) (__builtin_expect(x, 0))
  |  |  ------------------
  |  |  |  Branch (85:34): [True: 944, False: 3.13M]
  |  |  ------------------
  ------------------
   72|    944|    SwapBuffer(bw);
   73|    944|  }
   74|  3.13M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_110SwapBufferEPNS_8internal3dec9BitWriterE:
   62|    944|static BRUNSLI_NOINLINE void SwapBuffer(BitWriter* bw) {
   63|    944|  bw->chunk.len = bw->pos;
   64|    944|  bw->output->emplace_back(std::move(bw->chunk));
   65|    944|  bw->chunk = OutputChunk(kBitWriterChunkSize);
   66|    944|  bw->data = bw->chunk.buffer->data();
   67|    944|  bw->pos = 0;
   68|    944|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_111HasZeroByteEm:
   48|  2.65M|static BRUNSLI_INLINE uint64_t HasZeroByte(uint64_t x) {
   49|  2.65M|  return (x - 0x0101010101010101ULL) & ~x & 0x8080808080808080ULL;
   50|  2.65M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_18EmitByteEPNS_8internal3dec9BitWriterEi:
   82|  5.59M|static BRUNSLI_INLINE void EmitByte(BitWriter* bw, int byte) {
   83|  5.59M|  bw->data[bw->pos++] = byte;
   84|  5.59M|  if (byte == 0xFF) bw->data[bw->pos++] = 0;
  ------------------
  |  Branch (84:7): [True: 1.18M, False: 4.41M]
  ------------------
   85|  5.59M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_118JumpToByteBoundaryEPNS_8internal3dec9BitWriterEPPKiS6_:
  139|   243k|                        const int* pad_bits_end) {
  140|   243k|  size_t n_bits = bw->put_bits & 7u;
  141|   243k|  uint8_t pad_pattern;
  142|   243k|  if (*pad_bits == nullptr) {
  ------------------
  |  Branch (142:7): [True: 241k, False: 2.08k]
  ------------------
  143|   241k|    pad_pattern = (1u << n_bits) - 1;
  144|   241k|  } else {
  145|  2.08k|    pad_pattern = 0;
  146|  2.08k|    const int* src = *pad_bits;
  147|       |    // TODO(eustas): bitwise reading looks insanely ineffective...
  148|  6.25k|    while (n_bits--) {
  ------------------
  |  Branch (148:12): [True: 4.21k, False: 2.03k]
  ------------------
  149|  4.21k|      pad_pattern <<= 1;
  150|  4.21k|      if (src >= pad_bits_end) return false;
  ------------------
  |  Branch (150:11): [True: 48, False: 4.16k]
  ------------------
  151|       |      // TODO(eustas): DCHECK *src == {0, 1}
  152|  4.16k|      pad_pattern |= !!*(src++);
  153|  4.16k|    }
  154|  2.03k|    *pad_bits = src;
  155|  2.03k|  }
  156|       |
  157|   243k|  Reserve(bw, 16);
  158|       |
  159|   609k|  while (bw->put_bits <= 56) {
  ------------------
  |  Branch (159:10): [True: 366k, False: 243k]
  ------------------
  160|   366k|    int c = (bw->put_buffer >> 56) & 0xFF;
  161|   366k|    EmitByte(bw, c);
  162|   366k|    bw->put_buffer <<= 8;
  163|   366k|    bw->put_bits += 8;
  164|   366k|  }
  165|   243k|  if (bw->put_bits < 64) {
  ------------------
  |  Branch (165:7): [True: 182k, False: 61.0k]
  ------------------
  166|   182k|    int pad_mask = 0xFFu >> (64 - bw->put_bits);
  167|   182k|    int c = ((bw->put_buffer >> 56) & ~pad_mask) | pad_pattern;
  168|   182k|    EmitByte(bw, c);
  169|   182k|  }
  170|   243k|  bw->put_buffer = 0;
  171|   243k|  bw->put_bits = 64;
  172|       |
  173|   243k|  return true;
  174|   243k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_110EmitMarkerEPNS_8internal3dec9BitWriterEi:
  131|   238k|void EmitMarker(BitWriter* bw, int marker) {
  132|   238k|  Reserve(bw, 2);
  133|   238k|  BRUNSLI_DCHECK(marker != 0xFF);
  134|   238k|  bw->data[bw->pos++] = 0xFF;
  135|   238k|  bw->data[bw->pos++] = marker;
  136|   238k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_124EncodeDCTBlockSequentialEPKsRKNS_16HuffmanCodeTableES5_iPsPNS_8internal3dec9BitWriterE:
  510|  4.74M|                              BitWriter* bw) {
  511|  4.74M|  coeff_t temp2;
  512|  4.74M|  coeff_t temp;
  513|  4.74M|  temp2 = coeffs[0];
  514|  4.74M|  temp = temp2 - *last_dc_coeff;
  515|  4.74M|  *last_dc_coeff = temp2;
  516|  4.74M|  temp2 = temp;
  517|  4.74M|  if (temp < 0) {
  ------------------
  |  Branch (517:7): [True: 1.27M, False: 3.47M]
  ------------------
  518|  1.27M|    temp = -temp;
  519|  1.27M|    temp2--;
  520|  1.27M|  }
  521|  4.74M|  int dc_nbits = (temp == 0) ? 0 : (Log2FloorNonZero(temp) + 1);
  ------------------
  |  Branch (521:18): [True: 2.37M, False: 2.37M]
  ------------------
  522|  4.74M|  WriteBits(bw, dc_huff.depth[dc_nbits], dc_huff.code[dc_nbits]);
  523|  4.74M|  if (dc_nbits > 0) {
  ------------------
  |  Branch (523:7): [True: 2.37M, False: 2.37M]
  ------------------
  524|  2.37M|    WriteBits(bw, dc_nbits, temp2 & ((1u << dc_nbits) - 1));
  525|  2.37M|  }
  526|  4.74M|  int r = 0;
  527|   303M|  for (int k = 1; k < 64; ++k) {
  ------------------
  |  Branch (527:19): [True: 299M, False: 4.74M]
  ------------------
  528|   299M|    if ((temp = coeffs[kJPEGNaturalOrder[k]]) == 0) {
  ------------------
  |  Branch (528:9): [True: 299M, False: 31.6k]
  ------------------
  529|   299M|      r++;
  530|   299M|      continue;
  531|   299M|    }
  532|  31.6k|    if (temp < 0) {
  ------------------
  |  Branch (532:9): [True: 24.4k, False: 7.23k]
  ------------------
  533|  24.4k|      temp = -temp;
  534|  24.4k|      temp2 = ~temp;
  535|  24.4k|    } else {
  536|  7.23k|      temp2 = temp;
  537|  7.23k|    }
  538|  70.8k|    while (r > 15) {
  ------------------
  |  Branch (538:12): [True: 39.2k, False: 31.6k]
  ------------------
  539|  39.2k|      WriteBits(bw, ac_huff.depth[0xf0], ac_huff.code[0xf0]);
  540|  39.2k|      r -= 16;
  541|  39.2k|    }
  542|  31.6k|    int ac_nbits = Log2FloorNonZero(temp) + 1;
  543|  31.6k|    int symbol = (r << 4u) + ac_nbits;
  544|  31.6k|    WriteBits(bw, ac_huff.depth[symbol], ac_huff.code[symbol]);
  545|  31.6k|    WriteBits(bw, ac_nbits, temp2 & ((1 << ac_nbits) - 1));
  546|  31.6k|    r = 0;
  547|  31.6k|  }
  548|  4.75M|  for (int i = 0; i < num_zero_runs; ++i) {
  ------------------
  |  Branch (548:19): [True: 3.18k, False: 4.74M]
  ------------------
  549|  3.18k|    WriteBits(bw, ac_huff.depth[0xf0], ac_huff.code[0xf0]);
  550|  3.18k|    r -= 16;
  551|  3.18k|  }
  552|  4.74M|  if (r > 0) {
  ------------------
  |  Branch (552:7): [True: 4.74M, False: 430]
  ------------------
  553|  4.74M|    WriteBits(bw, ac_huff.depth[0], ac_huff.code[0]);
  554|  4.74M|  }
  555|  4.74M|  return true;
  556|  4.74M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_115BitWriterFinishEPNS_8internal3dec9BitWriterE:
  176|  4.46k|void BitWriterFinish(BitWriter* bw) {
  177|  4.46k|  if (bw->pos == 0) return;
  ------------------
  |  Branch (177:7): [True: 190, False: 4.27k]
  ------------------
  178|  4.27k|  bw->chunk.len = bw->pos;
  179|  4.27k|  bw->output->emplace_back(std::move(bw->chunk));
  180|  4.27k|  bw->chunk = OutputChunk(nullptr, 0);
  181|  4.27k|  bw->data = nullptr;
  182|  4.27k|  bw->pos = 0;
  183|  4.27k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_112DoEncodeScanILi1EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateE:
  700|  1.39k|                                                  SerializationState* state) {
  701|  1.39k|  const JPEGScanInfo& scan_info = jpg.scan_info[state->scan_index];
  702|  1.39k|  EncodeScanState& ss = state->scan_state;
  703|       |
  704|  1.39k|  const int restart_interval =
  705|  1.39k|      state->seen_dri_marker ? jpg.restart_interval : 0;
  ------------------
  |  Branch (705:7): [True: 347, False: 1.04k]
  ------------------
  706|       |
  707|  1.39k|  const auto get_next_extra_zero_run_index = [&ss, &scan_info]() -> int {
  708|  1.39k|    if (ss.extra_zero_runs_pos < scan_info.extra_zero_runs.size()) {
  709|  1.39k|      return scan_info.extra_zero_runs[ss.extra_zero_runs_pos].block_idx;
  710|  1.39k|    } else {
  711|  1.39k|      return -1;
  712|  1.39k|    }
  713|  1.39k|  };
  714|       |
  715|  1.39k|  const auto get_next_reset_point = [&ss, &scan_info]() -> int {
  716|  1.39k|    if (ss.next_reset_point_pos < scan_info.reset_points.size()) {
  717|  1.39k|      return scan_info.reset_points[ss.next_reset_point_pos++];
  718|  1.39k|    } else {
  719|  1.39k|      return -1;
  720|  1.39k|    }
  721|  1.39k|  };
  722|       |
  723|  1.39k|  if (ss.stage == EncodeScanState::HEAD) {
  ------------------
  |  Branch (723:7): [True: 1.39k, False: 0]
  ------------------
  724|  1.39k|    if (!EncodeSOS(jpg, scan_info, state)) return SerializationStatus::ERROR;
  ------------------
  |  Branch (724:9): [True: 13, False: 1.38k]
  ------------------
  725|  1.38k|    BitWriterInit(&ss.bw, &state->output_queue);
  726|  1.38k|    DCTCodingStateInit(&ss.coding_state);
  727|  1.38k|    ss.restarts_to_go = restart_interval;
  728|  1.38k|    ss.next_restart_marker = 0;
  729|  1.38k|    ss.block_scan_index = 0;
  730|  1.38k|    ss.extra_zero_runs_pos = 0;
  731|  1.38k|    ss.next_extra_zero_run_index = get_next_extra_zero_run_index();
  732|  1.38k|    ss.next_reset_point_pos = 0;
  733|  1.38k|    ss.next_reset_point = get_next_reset_point();
  734|  1.38k|    ss.mcu_y = 0;
  735|  1.38k|    memset(ss.last_dc_coeff, 0, sizeof(ss.last_dc_coeff));
  736|  1.38k|    ss.stage = EncodeScanState::BODY;
  737|  1.38k|  }
  738|  1.38k|  BitWriter* bw = &ss.bw;
  739|  1.38k|  DCTCodingState* coding_state = &ss.coding_state;
  740|       |
  741|  1.38k|  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.38k|  const bool is_interleaved = (scan_info.num_components > 1);
  746|  1.38k|  const JPEGComponent& base_component =
  747|  1.38k|      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.38k|  const int h_group = is_interleaved ? 1 : base_component.h_samp_factor;
  ------------------
  |  Branch (753:23): [True: 902, False: 481]
  ------------------
  754|  1.38k|  const int v_group = is_interleaved ? 1 : base_component.v_samp_factor;
  ------------------
  |  Branch (754:23): [True: 902, False: 481]
  ------------------
  755|  1.38k|  const int MCUs_per_row =
  756|  1.38k|      DivCeil(jpg.width * h_group, 8 * jpg.max_h_samp_factor);
  757|  1.38k|  const int MCU_rows = DivCeil(jpg.height * v_group, 8 * jpg.max_v_samp_factor);
  758|  1.38k|  const bool is_progressive = state->is_progressive;
  759|  1.38k|  const int Al = is_progressive ? scan_info.Al : 0;
  ------------------
  |  Branch (759:18): [True: 1.38k, False: 0]
  ------------------
  760|  1.38k|  const int Ss = is_progressive ? scan_info.Ss : 0;
  ------------------
  |  Branch (760:18): [True: 1.38k, False: 0]
  ------------------
  761|  1.38k|  const int Se = is_progressive ? scan_info.Se : 63;
  ------------------
  |  Branch (761:18): [True: 1.38k, False: 0]
  ------------------
  762|       |
  763|       |  // DC-only is defined by [0..0] spectral range.
  764|  1.38k|  const bool want_ac = ((Ss != 0) || (Se != 0));
  ------------------
  |  Branch (764:25): [True: 947, False: 436]
  |  Branch (764:38): [True: 374, False: 62]
  ------------------
  765|  1.38k|  const bool complete_ac = (parsing_state.stage == Stage::DONE);
  766|  1.38k|  const bool has_ac =
  767|  1.38k|      complete_ac || HasSection(&parsing_state, kBrunsliACDataTag);
  ------------------
  |  Branch (767:7): [True: 1.38k, False: 0]
  |  Branch (767:22): [True: 0, False: 0]
  ------------------
  768|  1.38k|  if (want_ac && !has_ac) return SerializationStatus::NEEDS_MORE_INPUT;
  ------------------
  |  Branch (768:7): [True: 1.32k, False: 62]
  |  Branch (768:18): [True: 0, False: 1.32k]
  ------------------
  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.38k|  const bool complete_dc = has_ac;
  774|  1.38k|  const bool complete = want_ac ? complete_ac : complete_dc;
  ------------------
  |  Branch (774:25): [True: 1.32k, False: 62]
  ------------------
  775|       |  // When "incomplete" |ac_dc| tracks information about current ("incomplete")
  776|       |  // band parsing progress.
  777|  1.38k|  const int last_mcu_y =
  778|  1.38k|      complete ? MCU_rows : parsing_state.internal->ac_dc.next_mcu_y * v_group;
  ------------------
  |  Branch (778:7): [True: 1.38k, False: 0]
  ------------------
  779|       |
  780|  59.1k|  for (; ss.mcu_y < last_mcu_y; ++ss.mcu_y) {
  ------------------
  |  Branch (780:10): [True: 57.7k, False: 1.36k]
  ------------------
  781|   425k|    for (int mcu_x = 0; mcu_x < MCUs_per_row; ++mcu_x) {
  ------------------
  |  Branch (781:25): [True: 367k, False: 57.7k]
  ------------------
  782|       |      // Possibly emit a restart marker.
  783|   367k|      if (restart_interval > 0 && ss.restarts_to_go == 0) {
  ------------------
  |  Branch (783:11): [True: 284k, False: 83.3k]
  |  Branch (783:35): [True: 33.0k, False: 251k]
  ------------------
  784|  33.0k|        Flush(coding_state, bw);
  785|  33.0k|        if (!JumpToByteBoundary(bw, &state->pad_bits, state->pad_bits_end)) {
  ------------------
  |  Branch (785:13): [True: 15, False: 33.0k]
  ------------------
  786|     15|          return SerializationStatus::ERROR;
  787|     15|        }
  788|  33.0k|        EmitMarker(bw, 0xD0 + ss.next_restart_marker);
  789|  33.0k|        ss.next_restart_marker += 1;
  790|  33.0k|        ss.next_restart_marker &= 0x7;
  791|  33.0k|        ss.restarts_to_go = restart_interval;
  792|  33.0k|        memset(ss.last_dc_coeff, 0, sizeof(ss.last_dc_coeff));
  793|  33.0k|      }
  794|       |      // Encode one MCU
  795|  1.36M|      for (size_t i = 0; i < scan_info.num_components; ++i) {
  ------------------
  |  Branch (795:26): [True: 995k, False: 367k]
  ------------------
  796|   995k|        const JPEGComponentScanInfo& si = scan_info.components[i];
  797|   995k|        const JPEGComponent& c = jpg.components[si.comp_idx];
  798|   995k|        const HuffmanCodeTable& dc_huff = state->dc_huff_table[si.dc_tbl_idx];
  799|   995k|        const HuffmanCodeTable& ac_huff = state->ac_huff_table[si.ac_tbl_idx];
  800|   995k|        int n_blocks_y = is_interleaved ? c.v_samp_factor : 1;
  ------------------
  |  Branch (800:26): [True: 839k, False: 155k]
  ------------------
  801|   995k|        int n_blocks_x = is_interleaved ? c.h_samp_factor : 1;
  ------------------
  |  Branch (801:26): [True: 839k, False: 155k]
  ------------------
  802|  4.36M|        for (int iy = 0; iy < n_blocks_y; ++iy) {
  ------------------
  |  Branch (802:26): [True: 3.37M, False: 995k]
  ------------------
  803|  13.1M|          for (int ix = 0; ix < n_blocks_x; ++ix) {
  ------------------
  |  Branch (803:28): [True: 9.81M, False: 3.37M]
  ------------------
  804|  9.81M|            int block_y = ss.mcu_y * n_blocks_y + iy;
  805|  9.81M|            int block_x = mcu_x * n_blocks_x + ix;
  806|  9.81M|            int block_idx = block_y * c.width_in_blocks + block_x;
  807|  9.81M|            if (ss.block_scan_index == ss.next_reset_point) {
  ------------------
  |  Branch (807:17): [True: 7.58k, False: 9.81M]
  ------------------
  808|  7.58k|              Flush(coding_state, bw);
  809|  7.58k|              ss.next_reset_point = get_next_reset_point();
  810|  7.58k|            }
  811|  9.81M|            int num_zero_runs = 0;
  812|  9.81M|            if (ss.block_scan_index == ss.next_extra_zero_run_index) {
  ------------------
  |  Branch (812:17): [True: 5.05k, False: 9.81M]
  ------------------
  813|  5.05k|              num_zero_runs = scan_info.extra_zero_runs[ss.extra_zero_runs_pos]
  814|  5.05k|                                  .num_extra_zero_runs;
  815|  5.05k|              ++ss.extra_zero_runs_pos;
  816|  5.05k|              ss.next_extra_zero_run_index = get_next_extra_zero_run_index();
  817|  5.05k|            }
  818|  9.81M|            const coeff_t* coeffs = &c.coeffs[block_idx << 6];
  819|  9.81M|            bool ok;
  820|  9.81M|            if (kMode == 0) {
  ------------------
  |  Branch (820:17): [Folded, False: 9.81M]
  ------------------
  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|  9.81M|            } else if (kMode == 1) {
  ------------------
  |  Branch (824:24): [True: 9.81M, Folded]
  ------------------
  825|  9.81M|              ok = EncodeDCTBlockProgressive(
  826|  9.81M|                  coeffs, dc_huff, ac_huff, Ss, Se, Al, num_zero_runs,
  827|  9.81M|                  coding_state, ss.last_dc_coeff + si.comp_idx, bw);
  828|  9.81M|            } else {
  829|      0|              ok = EncodeRefinementBits(coeffs, ac_huff, Ss, Se, Al,
  830|      0|                                        coding_state, bw);
  831|      0|            }
  832|  9.81M|            if (!ok) return SerializationStatus::ERROR;
  ------------------
  |  Branch (832:17): [True: 0, False: 9.81M]
  ------------------
  833|  9.81M|            ++ss.block_scan_index;
  834|  9.81M|          }
  835|  3.37M|        }
  836|   995k|      }
  837|   367k|      --ss.restarts_to_go;
  838|   367k|    }
  839|  57.7k|  }
  840|  1.36k|  if (ss.mcu_y < MCU_rows) {
  ------------------
  |  Branch (840:7): [True: 0, False: 1.36k]
  ------------------
  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.36k|  Flush(coding_state, bw);
  845|  1.36k|  if (!JumpToByteBoundary(bw, &state->pad_bits, state->pad_bits_end)) {
  ------------------
  |  Branch (845:7): [True: 6, False: 1.36k]
  ------------------
  846|      6|    return SerializationStatus::ERROR;
  847|      6|  }
  848|  1.36k|  BitWriterFinish(bw);
  849|  1.36k|  ss.stage = EncodeScanState::HEAD;
  850|  1.36k|  state->scan_index++;
  851|  1.36k|  if (!bw->healthy) return SerializationStatus::ERROR;
  ------------------
  |  Branch (851:7): [True: 1.04k, False: 318]
  ------------------
  852|       |
  853|    318|  return SerializationStatus::DONE;
  854|  1.36k|}
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_112DoEncodeScanILi1EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateEENKUlvE_clEv:
  707|  6.44k|  const auto get_next_extra_zero_run_index = [&ss, &scan_info]() -> int {
  708|  6.44k|    if (ss.extra_zero_runs_pos < scan_info.extra_zero_runs.size()) {
  ------------------
  |  Branch (708:9): [True: 5.08k, False: 1.35k]
  ------------------
  709|  5.08k|      return scan_info.extra_zero_runs[ss.extra_zero_runs_pos].block_idx;
  710|  5.08k|    } else {
  711|  1.35k|      return -1;
  712|  1.35k|    }
  713|  6.44k|  };
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_112DoEncodeScanILi1EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateEENKUlvE0_clEv:
  715|  8.96k|  const auto get_next_reset_point = [&ss, &scan_info]() -> int {
  716|  8.96k|    if (ss.next_reset_point_pos < scan_info.reset_points.size()) {
  ------------------
  |  Branch (716:9): [True: 7.61k, False: 1.34k]
  ------------------
  717|  7.61k|      return scan_info.reset_points[ss.next_reset_point_pos++];
  718|  7.61k|    } else {
  719|  1.34k|      return -1;
  720|  1.34k|    }
  721|  8.96k|  };
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_125EncodeDCTBlockProgressiveEPKsRKNS_16HuffmanCodeTableES5_iiiiPNS_8internal3dec14DCTCodingStateEPsPNS7_9BitWriterE:
  563|  9.81M|                               coeff_t* last_dc_coeff, BitWriter* bw) {
  564|  9.81M|  bool eob_run_allowed = Ss > 0;
  565|  9.81M|  coeff_t temp2;
  566|  9.81M|  coeff_t temp;
  567|  9.81M|  if (Ss == 0) {
  ------------------
  |  Branch (567:7): [True: 4.04M, False: 5.77M]
  ------------------
  568|  4.04M|    temp2 = coeffs[0] >> Al;
  569|  4.04M|    temp = temp2 - *last_dc_coeff;
  570|  4.04M|    *last_dc_coeff = temp2;
  571|  4.04M|    temp2 = temp;
  572|  4.04M|    if (temp < 0) {
  ------------------
  |  Branch (572:9): [True: 1.02M, False: 3.02M]
  ------------------
  573|  1.02M|      temp = -temp;
  574|  1.02M|      temp2--;
  575|  1.02M|    }
  576|  4.04M|    int nbits = (temp == 0) ? 0 : (Log2FloorNonZero(temp) + 1);
  ------------------
  |  Branch (576:17): [True: 2.14M, False: 1.90M]
  ------------------
  577|  4.04M|    WriteBits(bw, dc_huff.depth[nbits], dc_huff.code[nbits]);
  578|  4.04M|    if (nbits > 0) {
  ------------------
  |  Branch (578:9): [True: 1.90M, False: 2.14M]
  ------------------
  579|  1.90M|      WriteBits(bw, nbits, temp2 & ((1 << nbits) - 1));
  580|  1.90M|    }
  581|  4.04M|    ++Ss;
  582|  4.04M|  }
  583|  9.81M|  if (Ss > Se) {
  ------------------
  |  Branch (583:7): [True: 401k, False: 9.41M]
  ------------------
  584|   401k|    return true;
  585|   401k|  }
  586|  9.41M|  int r = 0;
  587|   238M|  for (int k = Ss; k <= Se; ++k) {
  ------------------
  |  Branch (587:20): [True: 228M, False: 9.41M]
  ------------------
  588|   228M|    if ((temp = coeffs[kJPEGNaturalOrder[k]]) == 0) {
  ------------------
  |  Branch (588:9): [True: 228M, False: 53.8k]
  ------------------
  589|   228M|      r++;
  590|   228M|      continue;
  591|   228M|    }
  592|  53.8k|    if (temp < 0) {
  ------------------
  |  Branch (592:9): [True: 38.6k, False: 15.1k]
  ------------------
  593|  38.6k|      temp = -temp;
  594|  38.6k|      temp >>= Al;
  595|  38.6k|      temp2 = ~temp;
  596|  38.6k|    } else {
  597|  15.1k|      temp >>= Al;
  598|  15.1k|      temp2 = temp;
  599|  15.1k|    }
  600|  53.8k|    if (temp == 0) {
  ------------------
  |  Branch (600:9): [True: 2.54k, False: 51.2k]
  ------------------
  601|  2.54k|      r++;
  602|  2.54k|      continue;
  603|  2.54k|    }
  604|  51.2k|    Flush(coding_state, bw);
  605|  86.8k|    while (r > 15) {
  ------------------
  |  Branch (605:12): [True: 35.6k, False: 51.2k]
  ------------------
  606|  35.6k|      WriteBits(bw, ac_huff.depth[0xf0], ac_huff.code[0xf0]);
  607|  35.6k|      r -= 16;
  608|  35.6k|    }
  609|  51.2k|    int nbits = Log2FloorNonZero(temp) + 1;
  610|  51.2k|    int symbol = (r << 4u) + nbits;
  611|  51.2k|    WriteBits(bw, ac_huff.depth[symbol], ac_huff.code[symbol]);
  612|  51.2k|    WriteBits(bw, nbits, temp2 & ((1 << nbits) - 1));
  613|  51.2k|    r = 0;
  614|  51.2k|  }
  615|  9.41M|  if (num_zero_runs > 0) {
  ------------------
  |  Branch (615:7): [True: 5.01k, False: 9.41M]
  ------------------
  616|  5.01k|    Flush(coding_state, bw);
  617|  13.8k|    for (int i = 0; i < num_zero_runs; ++i) {
  ------------------
  |  Branch (617:21): [True: 8.80k, False: 5.01k]
  ------------------
  618|  8.80k|      WriteBits(bw, ac_huff.depth[0xf0], ac_huff.code[0xf0]);
  619|  8.80k|      r -= 16;
  620|  8.80k|    }
  621|  5.01k|  }
  622|  9.41M|  if (r > 0) {
  ------------------
  |  Branch (622:7): [True: 9.41M, False: 2.73k]
  ------------------
  623|       |    // Ignore result: since we do not buffer bits - it can not fail.
  624|  9.41M|    BufferEndOfBand(coding_state, &ac_huff, nullptr, 0, bw);
  625|  9.41M|    if (!eob_run_allowed) {
  ------------------
  |  Branch (625:9): [True: 3.82M, False: 5.58M]
  ------------------
  626|  3.82M|      Flush(coding_state, bw);
  627|  3.82M|    }
  628|  9.41M|  }
  629|  9.41M|  return true;
  630|  9.81M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_115BufferEndOfBandEPNS_8internal3dec14DCTCodingStateEPKNS_16HuffmanCodeTableEPKimPNS2_9BitWriterE:
  224|  35.9M|                                           BitWriter* bw) {
  225|  35.9M|  if (s->eob_run_ == 0) {
  ------------------
  |  Branch (225:7): [True: 8.83M, False: 27.0M]
  ------------------
  226|  8.83M|    s->cur_ac_huff_ = ac_huff;
  227|  8.83M|  }
  228|  35.9M|  ++s->eob_run_;
  229|  35.9M|  if (new_bits_count) {
  ------------------
  |  Branch (229:7): [True: 163k, False: 35.7M]
  ------------------
  230|   163k|    uint64_t new_bits = 0;
  231|   888k|    for (size_t i = 0; i < new_bits_count; ++i) {
  ------------------
  |  Branch (231:24): [True: 725k, False: 163k]
  ------------------
  232|   725k|      new_bits = (new_bits << 1) | new_bits_array[i];
  233|   725k|    }
  234|   163k|    size_t tail = s->refinement_bits_count_ & 0xF;
  235|   163k|    if (tail) {  // First stuff the tail item
  ------------------
  |  Branch (235:9): [True: 111k, False: 52.3k]
  ------------------
  236|   111k|      size_t stuff_bits_count = std::min(16 - tail, new_bits_count);
  237|   111k|      uint16_t stuff_bits = new_bits >> (new_bits_count - stuff_bits_count);
  238|   111k|      stuff_bits &= ((1u << stuff_bits_count) - 1);
  239|   111k|      s->refinement_bits_.back() =
  240|   111k|          (s->refinement_bits_.back() << stuff_bits_count) | stuff_bits;
  241|   111k|      new_bits_count -= stuff_bits_count;
  242|   111k|      s->refinement_bits_count_ += stuff_bits_count;
  243|   111k|    }
  244|   176k|    while (new_bits_count >= 16) {
  ------------------
  |  Branch (244:12): [True: 13.4k, False: 163k]
  ------------------
  245|  13.4k|      s->refinement_bits_.push_back(new_bits >> (new_bits_count - 16));
  246|  13.4k|      new_bits_count -= 16;
  247|  13.4k|      s->refinement_bits_count_ += 16;
  248|  13.4k|    }
  249|   163k|    if (new_bits_count) {
  ------------------
  |  Branch (249:9): [True: 63.0k, False: 100k]
  ------------------
  250|  63.0k|      s->refinement_bits_.push_back(new_bits & ((1u << new_bits_count) - 1));
  251|  63.0k|      s->refinement_bits_count_ += new_bits_count;
  252|  63.0k|    }
  253|   163k|  }
  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.9M|  if (s->refinement_bits_count_ > 0x7FFF * (kDCTBlockSize - 1)) {
  ------------------
  |  Branch (256:7): [True: 0, False: 35.9M]
  ------------------
  257|      0|    return false;
  258|      0|  }
  259|  35.9M|  if (s->eob_run_ == 0x7FFF) {
  ------------------
  |  Branch (259:7): [True: 709, False: 35.9M]
  ------------------
  260|    709|    Flush(s, bw);
  261|    709|  }
  262|  35.9M|  return true;
  263|  35.9M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_112DoEncodeScanILi2EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateE:
  700|  2.56k|                                                  SerializationState* state) {
  701|  2.56k|  const JPEGScanInfo& scan_info = jpg.scan_info[state->scan_index];
  702|  2.56k|  EncodeScanState& ss = state->scan_state;
  703|       |
  704|  2.56k|  const int restart_interval =
  705|  2.56k|      state->seen_dri_marker ? jpg.restart_interval : 0;
  ------------------
  |  Branch (705:7): [True: 961, False: 1.60k]
  ------------------
  706|       |
  707|  2.56k|  const auto get_next_extra_zero_run_index = [&ss, &scan_info]() -> int {
  708|  2.56k|    if (ss.extra_zero_runs_pos < scan_info.extra_zero_runs.size()) {
  709|  2.56k|      return scan_info.extra_zero_runs[ss.extra_zero_runs_pos].block_idx;
  710|  2.56k|    } else {
  711|  2.56k|      return -1;
  712|  2.56k|    }
  713|  2.56k|  };
  714|       |
  715|  2.56k|  const auto get_next_reset_point = [&ss, &scan_info]() -> int {
  716|  2.56k|    if (ss.next_reset_point_pos < scan_info.reset_points.size()) {
  717|  2.56k|      return scan_info.reset_points[ss.next_reset_point_pos++];
  718|  2.56k|    } else {
  719|  2.56k|      return -1;
  720|  2.56k|    }
  721|  2.56k|  };
  722|       |
  723|  2.56k|  if (ss.stage == EncodeScanState::HEAD) {
  ------------------
  |  Branch (723:7): [True: 2.56k, False: 0]
  ------------------
  724|  2.56k|    if (!EncodeSOS(jpg, scan_info, state)) return SerializationStatus::ERROR;
  ------------------
  |  Branch (724:9): [True: 82, False: 2.48k]
  ------------------
  725|  2.48k|    BitWriterInit(&ss.bw, &state->output_queue);
  726|  2.48k|    DCTCodingStateInit(&ss.coding_state);
  727|  2.48k|    ss.restarts_to_go = restart_interval;
  728|  2.48k|    ss.next_restart_marker = 0;
  729|  2.48k|    ss.block_scan_index = 0;
  730|  2.48k|    ss.extra_zero_runs_pos = 0;
  731|  2.48k|    ss.next_extra_zero_run_index = get_next_extra_zero_run_index();
  732|  2.48k|    ss.next_reset_point_pos = 0;
  733|  2.48k|    ss.next_reset_point = get_next_reset_point();
  734|  2.48k|    ss.mcu_y = 0;
  735|  2.48k|    memset(ss.last_dc_coeff, 0, sizeof(ss.last_dc_coeff));
  736|  2.48k|    ss.stage = EncodeScanState::BODY;
  737|  2.48k|  }
  738|  2.48k|  BitWriter* bw = &ss.bw;
  739|  2.48k|  DCTCodingState* coding_state = &ss.coding_state;
  740|       |
  741|  2.48k|  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.48k|  const bool is_interleaved = (scan_info.num_components > 1);
  746|  2.48k|  const JPEGComponent& base_component =
  747|  2.48k|      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.48k|  const int h_group = is_interleaved ? 1 : base_component.h_samp_factor;
  ------------------
  |  Branch (753:23): [True: 1.95k, False: 529]
  ------------------
  754|  2.48k|  const int v_group = is_interleaved ? 1 : base_component.v_samp_factor;
  ------------------
  |  Branch (754:23): [True: 1.95k, False: 529]
  ------------------
  755|  2.48k|  const int MCUs_per_row =
  756|  2.48k|      DivCeil(jpg.width * h_group, 8 * jpg.max_h_samp_factor);
  757|  2.48k|  const int MCU_rows = DivCeil(jpg.height * v_group, 8 * jpg.max_v_samp_factor);
  758|  2.48k|  const bool is_progressive = state->is_progressive;
  759|  2.48k|  const int Al = is_progressive ? scan_info.Al : 0;
  ------------------
  |  Branch (759:18): [True: 2.48k, False: 0]
  ------------------
  760|  2.48k|  const int Ss = is_progressive ? scan_info.Ss : 0;
  ------------------
  |  Branch (760:18): [True: 2.48k, False: 0]
  ------------------
  761|  2.48k|  const int Se = is_progressive ? scan_info.Se : 63;
  ------------------
  |  Branch (761:18): [True: 2.48k, False: 0]
  ------------------
  762|       |
  763|       |  // DC-only is defined by [0..0] spectral range.
  764|  2.48k|  const bool want_ac = ((Ss != 0) || (Se != 0));
  ------------------
  |  Branch (764:25): [True: 1.92k, False: 563]
  |  Branch (764:38): [True: 532, False: 31]
  ------------------
  765|  2.48k|  const bool complete_ac = (parsing_state.stage == Stage::DONE);
  766|  2.48k|  const bool has_ac =
  767|  2.48k|      complete_ac || HasSection(&parsing_state, kBrunsliACDataTag);
  ------------------
  |  Branch (767:7): [True: 2.48k, False: 0]
  |  Branch (767:22): [True: 0, False: 0]
  ------------------
  768|  2.48k|  if (want_ac && !has_ac) return SerializationStatus::NEEDS_MORE_INPUT;
  ------------------
  |  Branch (768:7): [True: 2.45k, False: 31]
  |  Branch (768:18): [True: 0, False: 2.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|  2.48k|  const bool complete_dc = has_ac;
  774|  2.48k|  const bool complete = want_ac ? complete_ac : complete_dc;
  ------------------
  |  Branch (774:25): [True: 2.45k, False: 31]
  ------------------
  775|       |  // When "incomplete" |ac_dc| tracks information about current ("incomplete")
  776|       |  // band parsing progress.
  777|  2.48k|  const int last_mcu_y =
  778|  2.48k|      complete ? MCU_rows : parsing_state.internal->ac_dc.next_mcu_y * v_group;
  ------------------
  |  Branch (778:7): [True: 2.48k, False: 0]
  ------------------
  779|       |
  780|   120k|  for (; ss.mcu_y < last_mcu_y; ++ss.mcu_y) {
  ------------------
  |  Branch (780:10): [True: 118k, False: 2.47k]
  ------------------
  781|  1.37M|    for (int mcu_x = 0; mcu_x < MCUs_per_row; ++mcu_x) {
  ------------------
  |  Branch (781:25): [True: 1.25M, False: 118k]
  ------------------
  782|       |      // Possibly emit a restart marker.
  783|  1.25M|      if (restart_interval > 0 && ss.restarts_to_go == 0) {
  ------------------
  |  Branch (783:11): [True: 996k, False: 258k]
  |  Branch (783:35): [True: 90.5k, False: 906k]
  ------------------
  784|  90.5k|        Flush(coding_state, bw);
  785|  90.5k|        if (!JumpToByteBoundary(bw, &state->pad_bits, state->pad_bits_end)) {
  ------------------
  |  Branch (785:13): [True: 5, False: 90.5k]
  ------------------
  786|      5|          return SerializationStatus::ERROR;
  787|      5|        }
  788|  90.5k|        EmitMarker(bw, 0xD0 + ss.next_restart_marker);
  789|  90.5k|        ss.next_restart_marker += 1;
  790|  90.5k|        ss.next_restart_marker &= 0x7;
  791|  90.5k|        ss.restarts_to_go = restart_interval;
  792|  90.5k|        memset(ss.last_dc_coeff, 0, sizeof(ss.last_dc_coeff));
  793|  90.5k|      }
  794|       |      // Encode one MCU
  795|  3.41M|      for (size_t i = 0; i < scan_info.num_components; ++i) {
  ------------------
  |  Branch (795:26): [True: 2.15M, False: 1.25M]
  ------------------
  796|  2.15M|        const JPEGComponentScanInfo& si = scan_info.components[i];
  797|  2.15M|        const JPEGComponent& c = jpg.components[si.comp_idx];
  798|  2.15M|        const HuffmanCodeTable& dc_huff = state->dc_huff_table[si.dc_tbl_idx];
  799|  2.15M|        const HuffmanCodeTable& ac_huff = state->ac_huff_table[si.ac_tbl_idx];
  800|  2.15M|        int n_blocks_y = is_interleaved ? c.v_samp_factor : 1;
  ------------------
  |  Branch (800:26): [True: 1.21M, False: 943k]
  ------------------
  801|  2.15M|        int n_blocks_x = is_interleaved ? c.h_samp_factor : 1;
  ------------------
  |  Branch (801:26): [True: 1.21M, False: 943k]
  ------------------
  802|  10.1M|        for (int iy = 0; iy < n_blocks_y; ++iy) {
  ------------------
  |  Branch (802:26): [True: 7.96M, False: 2.15M]
  ------------------
  803|  34.9M|          for (int ix = 0; ix < n_blocks_x; ++ix) {
  ------------------
  |  Branch (803:28): [True: 26.9M, False: 7.96M]
  ------------------
  804|  26.9M|            int block_y = ss.mcu_y * n_blocks_y + iy;
  805|  26.9M|            int block_x = mcu_x * n_blocks_x + ix;
  806|  26.9M|            int block_idx = block_y * c.width_in_blocks + block_x;
  807|  26.9M|            if (ss.block_scan_index == ss.next_reset_point) {
  ------------------
  |  Branch (807:17): [True: 10.5k, False: 26.9M]
  ------------------
  808|  10.5k|              Flush(coding_state, bw);
  809|  10.5k|              ss.next_reset_point = get_next_reset_point();
  810|  10.5k|            }
  811|  26.9M|            int num_zero_runs = 0;
  812|  26.9M|            if (ss.block_scan_index == ss.next_extra_zero_run_index) {
  ------------------
  |  Branch (812:17): [True: 1.09k, False: 26.9M]
  ------------------
  813|  1.09k|              num_zero_runs = scan_info.extra_zero_runs[ss.extra_zero_runs_pos]
  814|  1.09k|                                  .num_extra_zero_runs;
  815|  1.09k|              ++ss.extra_zero_runs_pos;
  816|  1.09k|              ss.next_extra_zero_run_index = get_next_extra_zero_run_index();
  817|  1.09k|            }
  818|  26.9M|            const coeff_t* coeffs = &c.coeffs[block_idx << 6];
  819|  26.9M|            bool ok;
  820|  26.9M|            if (kMode == 0) {
  ------------------
  |  Branch (820:17): [Folded, False: 26.9M]
  ------------------
  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.9M|            } else if (kMode == 1) {
  ------------------
  |  Branch (824:24): [Folded, False: 26.9M]
  ------------------
  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.9M|            } else {
  829|  26.9M|              ok = EncodeRefinementBits(coeffs, ac_huff, Ss, Se, Al,
  830|  26.9M|                                        coding_state, bw);
  831|  26.9M|            }
  832|  26.9M|            if (!ok) return SerializationStatus::ERROR;
  ------------------
  |  Branch (832:17): [True: 0, False: 26.9M]
  ------------------
  833|  26.9M|            ++ss.block_scan_index;
  834|  26.9M|          }
  835|  7.96M|        }
  836|  2.15M|      }
  837|  1.25M|      --ss.restarts_to_go;
  838|  1.25M|    }
  839|   118k|  }
  840|  2.47k|  if (ss.mcu_y < MCU_rows) {
  ------------------
  |  Branch (840:7): [True: 0, False: 2.47k]
  ------------------
  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.47k|  Flush(coding_state, bw);
  845|  2.47k|  if (!JumpToByteBoundary(bw, &state->pad_bits, state->pad_bits_end)) {
  ------------------
  |  Branch (845:7): [True: 13, False: 2.46k]
  ------------------
  846|     13|    return SerializationStatus::ERROR;
  847|     13|  }
  848|  2.46k|  BitWriterFinish(bw);
  849|  2.46k|  ss.stage = EncodeScanState::HEAD;
  850|  2.46k|  state->scan_index++;
  851|  2.46k|  if (!bw->healthy) return SerializationStatus::ERROR;
  ------------------
  |  Branch (851:7): [True: 1.88k, False: 580]
  ------------------
  852|       |
  853|    580|  return SerializationStatus::DONE;
  854|  2.46k|}
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_112DoEncodeScanILi2EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateEENKUlvE_clEv:
  707|  3.57k|  const auto get_next_extra_zero_run_index = [&ss, &scan_info]() -> int {
  708|  3.57k|    if (ss.extra_zero_runs_pos < scan_info.extra_zero_runs.size()) {
  ------------------
  |  Branch (708:9): [True: 1.10k, False: 2.47k]
  ------------------
  709|  1.10k|      return scan_info.extra_zero_runs[ss.extra_zero_runs_pos].block_idx;
  710|  2.47k|    } else {
  711|  2.47k|      return -1;
  712|  2.47k|    }
  713|  3.57k|  };
jpeg_data_writer.cc:_ZZN7brunsli12_GLOBAL__N_112DoEncodeScanILi2EEENS_8internal3dec19SerializationStatusERKNS_8JPEGDataERKNS3_5StateEPNS3_18SerializationStateEENKUlvE0_clEv:
  715|  13.0k|  const auto get_next_reset_point = [&ss, &scan_info]() -> int {
  716|  13.0k|    if (ss.next_reset_point_pos < scan_info.reset_points.size()) {
  ------------------
  |  Branch (716:9): [True: 10.6k, False: 2.45k]
  ------------------
  717|  10.6k|      return scan_info.reset_points[ss.next_reset_point_pos++];
  718|  10.6k|    } else {
  719|  2.45k|      return -1;
  720|  2.45k|    }
  721|  13.0k|  };
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_120EncodeRefinementBitsEPKsRKNS_16HuffmanCodeTableEiiiPNS_8internal3dec14DCTCodingStateEPNS7_9BitWriterE:
  634|  26.9M|                          int Al, DCTCodingState* coding_state, BitWriter* bw) {
  635|  26.9M|  bool eob_run_allowed = Ss > 0;
  636|  26.9M|  if (Ss == 0) {
  ------------------
  |  Branch (636:7): [True: 5.03M, False: 21.9M]
  ------------------
  637|       |    // Emit next bit of DC component.
  638|  5.03M|    WriteBits(bw, 1, (coeffs[0] >> Al) & 1);
  639|  5.03M|    ++Ss;
  640|  5.03M|  }
  641|  26.9M|  if (Ss > Se) {
  ------------------
  |  Branch (641:7): [True: 437k, False: 26.5M]
  ------------------
  642|   437k|    return true;
  643|   437k|  }
  644|  26.5M|  int abs_values[kDCTBlockSize];
  645|  26.5M|  int eob = 0;
  646|   731M|  for (int k = Ss; k <= Se; k++) {
  ------------------
  |  Branch (646:20): [True: 705M, False: 26.5M]
  ------------------
  647|   705M|    const coeff_t abs_val = std::abs(coeffs[kJPEGNaturalOrder[k]]);
  648|   705M|    abs_values[k] = abs_val >> Al;
  649|   705M|    if (abs_values[k] == 1) {
  ------------------
  |  Branch (649:9): [True: 99.7k, False: 705M]
  ------------------
  650|  99.7k|      eob = k;
  651|  99.7k|    }
  652|   705M|  }
  653|  26.5M|  int r = 0;
  654|  26.5M|  int refinement_bits[kDCTBlockSize];
  655|  26.5M|  size_t refinement_bits_count = 0;
  656|   731M|  for (int k = Ss; k <= Se; k++) {
  ------------------
  |  Branch (656:20): [True: 705M, False: 26.5M]
  ------------------
  657|   705M|    if (abs_values[k] == 0) {
  ------------------
  |  Branch (657:9): [True: 704M, False: 858k]
  ------------------
  658|   704M|      r++;
  659|   704M|      continue;
  660|   704M|    }
  661|   910k|    while (r > 15 && k <= eob) {
  ------------------
  |  Branch (661:12): [True: 128k, False: 781k]
  |  Branch (661:22): [True: 51.9k, False: 76.8k]
  ------------------
  662|  51.9k|      Flush(coding_state, bw);
  663|  51.9k|      WriteBits(bw, ac_huff.depth[0xf0], ac_huff.code[0xf0]);
  664|  51.9k|      r -= 16;
  665|  60.2k|      for (size_t i = 0; i < refinement_bits_count; ++i) {
  ------------------
  |  Branch (665:26): [True: 8.27k, False: 51.9k]
  ------------------
  666|  8.27k|        WriteBits(bw, 1, refinement_bits[i]);
  667|  8.27k|      }
  668|  51.9k|      refinement_bits_count = 0;
  669|  51.9k|    }
  670|   858k|    if (abs_values[k] > 1) {
  ------------------
  |  Branch (670:9): [True: 758k, False: 99.7k]
  ------------------
  671|   758k|      refinement_bits[refinement_bits_count++] = abs_values[k] & 1u;
  672|   758k|      continue;
  673|   758k|    }
  674|  99.7k|    Flush(coding_state, bw);
  675|  99.7k|    int symbol = (r << 4u) + 1;
  676|  99.7k|    int new_non_zero_bit = (coeffs[kJPEGNaturalOrder[k]] < 0) ? 0 : 1;
  ------------------
  |  Branch (676:28): [True: 69.4k, False: 30.3k]
  ------------------
  677|  99.7k|    WriteBits(bw, ac_huff.depth[symbol], ac_huff.code[symbol]);
  678|  99.7k|    WriteBits(bw, 1, new_non_zero_bit);
  679|   124k|    for (size_t i = 0; i < refinement_bits_count; ++i) {
  ------------------
  |  Branch (679:24): [True: 24.9k, False: 99.7k]
  ------------------
  680|  24.9k|      WriteBits(bw, 1, refinement_bits[i]);
  681|  24.9k|    }
  682|  99.7k|    refinement_bits_count = 0;
  683|  99.7k|    r = 0;
  684|  99.7k|  }
  685|  26.5M|  if (r > 0 || refinement_bits_count) {
  ------------------
  |  Branch (685:7): [True: 26.5M, False: 9.37k]
  |  Branch (685:16): [True: 4.35k, False: 5.02k]
  ------------------
  686|  26.5M|    if (!BufferEndOfBand(coding_state, &ac_huff, refinement_bits,
  ------------------
  |  Branch (686:9): [True: 0, False: 26.5M]
  ------------------
  687|  26.5M|                         refinement_bits_count, bw)) {
  688|      0|      return false;
  689|      0|    }
  690|  26.5M|    if (!eob_run_allowed) {
  ------------------
  |  Branch (690:9): [True: 4.83M, False: 21.6M]
  ------------------
  691|  4.83M|      Flush(coding_state, bw);
  692|  4.83M|    }
  693|  26.5M|  }
  694|  26.5M|  return true;
  695|  26.5M|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeDQTERKNS_8JPEGDataEPNS_8internal3dec18SerializationStateE:
  429|    165|bool EncodeDQT(const JPEGData& jpg, SerializationState* state) {
  430|    165|  int marker_len = 2;
  431|    165|  for (size_t i = state->dqt_index; i < jpg.quant.size(); ++i) {
  ------------------
  |  Branch (431:37): [True: 154, False: 11]
  ------------------
  432|    154|    const JPEGQuantTable& table = jpg.quant[i];
  433|    154|    marker_len += 1 + (table.precision ? 2 : 1) * kDCTBlockSize;
  ------------------
  |  Branch (433:24): [True: 49, False: 105]
  ------------------
  434|    154|    if (table.is_last) break;
  ------------------
  |  Branch (434:9): [True: 154, False: 0]
  ------------------
  435|    154|  }
  436|    165|  state->output_queue.emplace_back(marker_len + 2);
  437|    165|  uint8_t* data = state->output_queue.back().buffer->data();
  438|    165|  size_t pos = 0;
  439|    165|  data[pos++] = 0xFF;
  440|    165|  data[pos++] = 0xDB;
  441|    165|  data[pos++] = marker_len >> 8u;
  442|    165|  data[pos++] = marker_len & 0xFFu;
  443|    165|  while (true) {
  ------------------
  |  Branch (443:10): [True: 165, Folded]
  ------------------
  444|    165|    const size_t idx = state->dqt_index++;
  445|    165|    if (idx >= jpg.quant.size()) {
  ------------------
  |  Branch (445:9): [True: 11, False: 154]
  ------------------
  446|     11|      return false;  // corrupt input
  447|     11|    }
  448|    154|    const JPEGQuantTable& table = jpg.quant[idx];
  449|    154|    data[pos++] = (table.precision << 4u) + table.index;
  450|  10.0k|    for (size_t i = 0; i < kDCTBlockSize; ++i) {
  ------------------
  |  Branch (450:24): [True: 9.85k, False: 154]
  ------------------
  451|  9.85k|      int val_idx = kJPEGNaturalOrder[i];
  452|  9.85k|      int val = table.values[val_idx];
  453|  9.85k|      if (table.precision) {
  ------------------
  |  Branch (453:11): [True: 3.13k, False: 6.72k]
  ------------------
  454|  3.13k|        data[pos++] = val >> 8u;
  455|  3.13k|      }
  456|  9.85k|      data[pos++] = val & 0xFFu;
  457|  9.85k|    }
  458|    154|    if (table.is_last) break;
  ------------------
  |  Branch (458:9): [True: 154, False: 0]
  ------------------
  459|    154|  }
  460|    154|  return true;
  461|    165|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeDRIERKNS_8JPEGDataEPNS_8internal3dec18SerializationStateE:
  463|  1.74k|bool EncodeDRI(const JPEGData& jpg, SerializationState* state) {
  464|  1.74k|  state->seen_dri_marker = true;
  465|  1.74k|  OutputChunk dri_marker = {0xFF,
  466|  1.74k|                            0xDD,
  467|  1.74k|                            0,
  468|  1.74k|                            4,
  469|  1.74k|                            static_cast<uint8_t>(jpg.restart_interval >> 8),
  470|  1.74k|                            static_cast<uint8_t>(jpg.restart_interval & 0xFF)};
  471|  1.74k|  state->output_queue.push_back(std::move(dri_marker));
  472|  1.74k|  return true;
  473|  1.74k|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeAPPERKNS_8JPEGDataEhPNS_8internal3dec18SerializationStateE:
  480|    199|bool EncodeAPP(const JPEGData& jpg, uint8_t marker, SerializationState* state) {
  481|       |  // TODO(eustas): check that marker corresponds to payload?
  482|    199|  (void)marker;
  483|       |
  484|    199|  size_t app_index = state->app_index++;
  485|    199|  if (app_index >= jpg.app_data.size()) return false;
  ------------------
  |  Branch (485:7): [True: 187, False: 12]
  ------------------
  486|     12|  state->output_queue.push_back(OutputChunk({0xFF}));
  487|     12|  state->output_queue.emplace_back(jpg.app_data[app_index]);
  488|     12|  return true;
  489|    199|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_19EncodeCOMERKNS_8JPEGDataEPNS_8internal3dec18SerializationStateE:
  491|      3|bool EncodeCOM(const JPEGData& jpg, SerializationState* state) {
  492|      3|  size_t com_index = state->com_index++;
  493|      3|  if (com_index >= jpg.com_data.size()) return false;
  ------------------
  |  Branch (493:7): [True: 3, 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|      3|}
jpeg_data_writer.cc:_ZN7brunsli12_GLOBAL__N_121EncodeInterMarkerDataERKNS_8JPEGDataEPNS_8internal3dec18SerializationStateE:
  499|     10|bool EncodeInterMarkerData(const JPEGData& jpg, SerializationState* state) {
  500|     10|  size_t index = state->data_index++;
  501|     10|  if (index >= jpg.inter_marker_data.size()) return false;
  ------------------
  |  Branch (501:7): [True: 0, False: 10]
  ------------------
  502|     10|  state->output_queue.emplace_back(jpg.inter_marker_data[index]);
  503|     10|  return true;
  504|     10|}

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

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

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

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

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

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

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

