LLVMFuzzerTestOneInput:
   36|    412|{
   37|    412|    FuzzHelper f(data, size);
   38|    412|    f.run();
   39|    412|    return 0;
   40|    412|}
_ZN10FuzzHelperC2EPKhm:
   11|    412|        data(data),
   12|    412|        size(size)
   13|    412|    {
   14|    412|    }
_ZN10FuzzHelper3runEv:
   18|    412|    {
   19|    412|        Pl_Discard discard;
   20|    412|        Pl_LZWDecoder p("decode", &discard, false);
   21|    412|        try {
   22|    412|            p.write(data, size);
   23|    412|            p.finish();
   24|    412|        } catch (std::runtime_error const& e) {
   25|     55|            std::cerr << "runtime_error: " << e.what() << '\n';
   26|     55|        }
   27|    412|    }

_ZN8PipelineD2Ev:
   52|    824|    virtual ~Pipeline() = default;
_ZNK8Pipeline4nextEv:
  103|  1.06M|    {
  104|  1.06M|        return next_;
  105|  1.06M|    }

_ZN5QIntC7to_uintImEEjRKT_:
  208|  1.07M|    {
  209|  1.07M|        return IntConverter<T, unsigned int>::convert(i);
  210|  1.07M|    }
_ZN5QIntC12IntConverterImjLb0ELb0EE7convertERKm:
   69|  1.07M|        {
   70|       |            // From and To are both unsigned.
   71|  1.07M|            if (i > std::numeric_limits<To>::max()) {
  ------------------
  |  Branch (71:17): [True: 0, False: 1.07M]
  ------------------
   72|      0|                error(i);
   73|      0|            }
   74|  1.07M|            return static_cast<To>(i);
   75|  1.07M|        }

_ZN3QTC2TCEPKcS1_i:
   36|  1.68k|    {
   37|       |#ifndef QPDF_DISABLE_QTC
   38|       |        TC_real(scope, ccase, n);
   39|       |#endif // QPDF_DISABLE_QTC
   40|  1.68k|    }

_ZN6BufferC2Em:
   38|  1.06M|    m(std::make_unique<Members>(std::string(size, '\0')))
   39|  1.06M|{
   40|  1.06M|}
_ZN6BufferC2EOS_:
   58|  1.31M|    m(std::move(rhs.m))
   59|  1.31M|{
   60|  1.31M|}
_ZN6BufferD2Ev:
   69|  2.37M|Buffer::~Buffer() = default;
_ZNK6Buffer7getSizeEv:
   73|  37.7k|{
   74|  37.7k|    return m->size;
   75|  37.7k|}
_ZN6Buffer9getBufferEv:
   85|  1.11M|{
   86|  1.11M|    return reinterpret_cast<unsigned char*>(m->buf);
   87|  1.11M|}
_ZN6Buffer7MembersD2Ev:
   24|  1.06M|    ~Members() = default;
_ZN6Buffer7MembersC2EONSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE:
   18|  1.06M|        str(std::move(content)),
   19|  1.06M|        size(str.size()),
   20|  1.06M|        buf(str.data())
   21|  1.06M|    {
   22|  1.06M|    }

_ZN8PipelineC2EPKcPS_:
   11|    824|    identifier(identifier),
   12|    824|    next_(next)
   13|    824|{
   14|    824|}

_ZN10Pl_DiscardC2Ev:
    9|    412|    Pipeline("discard", nullptr)
   10|    412|{
   11|    412|}
_ZN10Pl_DiscardD2Ev:
   14|    412|Pl_Discard::~Pl_Discard() = default;
_ZN10Pl_Discard5writeEPKhm:
   18|  1.06M|{
   19|  1.06M|}
_ZN10Pl_Discard6finishEv:
   23|    357|{
   24|    357|}

_ZN13Pl_LZWDecoderC2EPKcP8Pipelineb:
   12|    412|    Pipeline(identifier, next),
   13|    412|    code_change_delta(early_code_change)
   14|    412|{
   15|    412|    util::assertion(next, "Attempt to create Pl_LZWDecoder with nullptr as next");
   16|    412|}
_ZN13Pl_LZWDecoder5writeEPKhm:
   20|    412|{
   21|  1.36M|    for (size_t i = 0; i < len; ++i) {
  ------------------
  |  Branch (21:24): [True: 1.36M, False: 412]
  ------------------
   22|  1.36M|        buf[next_char_++] = bytes[i];
   23|  1.36M|        if (next_char_ == 3) {
  ------------------
  |  Branch (23:13): [True: 456k, False: 913k]
  ------------------
   24|   456k|            next_char_ = 0;
   25|   456k|        }
   26|  1.36M|        bits_available += 8;
   27|  1.36M|        if (bits_available >= code_size) {
  ------------------
  |  Branch (27:13): [True: 1.06M, False: 303k]
  ------------------
   28|  1.06M|            sendNextCode();
   29|  1.06M|        }
   30|  1.36M|    }
   31|    412|}
_ZN13Pl_LZWDecoder6finishEv:
   35|    357|{
   36|    357|    next()->finish();
   37|    357|}
_ZN13Pl_LZWDecoder12sendNextCodeEv:
   41|  1.06M|{
   42|  1.06M|    unsigned int high = byte_pos;
   43|  1.06M|    unsigned int med = (byte_pos + 1) % 3;
   44|  1.06M|    unsigned int low = (byte_pos + 2) % 3;
   45|       |
   46|  1.06M|    unsigned int bits_from_high = 8 - bit_pos;
   47|  1.06M|    unsigned int bits_from_med = code_size - bits_from_high;
   48|  1.06M|    unsigned int bits_from_low = 0;
   49|  1.06M|    if (bits_from_med > 8) {
  ------------------
  |  Branch (49:9): [True: 216k, False: 850k]
  ------------------
   50|   216k|        bits_from_low = bits_from_med - 8;
   51|   216k|        bits_from_med = 8;
   52|   216k|    }
   53|  1.06M|    unsigned int high_mask = (1U << bits_from_high) - 1U;
   54|  1.06M|    unsigned int med_mask = 0xff - ((1U << (8 - bits_from_med)) - 1U);
   55|  1.06M|    unsigned int low_mask = 0xff - ((1U << (8 - bits_from_low)) - 1U);
   56|  1.06M|    unsigned int code = 0;
   57|  1.06M|    code += (buf[high] & high_mask) << bits_from_med;
   58|  1.06M|    code += ((buf[med] & med_mask) >> (8 - bits_from_med));
   59|  1.06M|    if (bits_from_low) {
  ------------------
  |  Branch (59:9): [True: 216k, False: 850k]
  ------------------
   60|   216k|        code <<= bits_from_low;
   61|   216k|        code += ((buf[low] & low_mask) >> (8 - bits_from_low));
   62|   216k|        byte_pos = low;
   63|   216k|        bit_pos = bits_from_low;
   64|   850k|    } else {
   65|   850k|        byte_pos = med;
   66|   850k|        bit_pos = bits_from_med;
   67|   850k|    }
   68|  1.06M|    if (bit_pos == 8) {
  ------------------
  |  Branch (68:9): [True: 86.8k, False: 979k]
  ------------------
   69|  86.8k|        bit_pos = 0;
   70|  86.8k|        ++byte_pos;
   71|  86.8k|        byte_pos %= 3;
   72|  86.8k|    }
   73|  1.06M|    bits_available -= code_size;
   74|       |
   75|  1.06M|    handleCode(code);
   76|  1.06M|}
_ZN13Pl_LZWDecoder12getFirstCharEj:
   80|  18.9k|{
   81|  18.9k|    if (code < 256) {
  ------------------
  |  Branch (81:9): [True: 590, False: 18.3k]
  ------------------
   82|    590|        return static_cast<unsigned char>(code);
   83|    590|    }
   84|  18.3k|    util::no_ci_rt_error_if(
   85|  18.3k|        code <= 257,
   86|  18.3k|        "Pl_LZWDecoder::getFirstChar called with invalid code (" + std::to_string(code) + ")");
   87|       |
   88|  18.3k|    unsigned int idx = code - 258;
   89|  18.3k|    util::no_ci_rt_error_if(idx >= table.size(), "Pl_LZWDecoder::getFirstChar: table overflow");
   90|  18.3k|    Buffer& b = table.at(idx);
   91|  18.3k|    return b.getBuffer()[0];
   92|  18.9k|}
_ZN13Pl_LZWDecoder10addToTableEh:
   96|  1.06M|{
   97|  1.06M|    unsigned int last_size = 0;
   98|  1.06M|    unsigned char const* last_data = nullptr;
   99|  1.06M|    unsigned char tmp[1];
  100|       |
  101|  1.06M|    if (last_code < 256) {
  ------------------
  |  Branch (101:9): [True: 1.04M, False: 18.7k]
  ------------------
  102|  1.04M|        tmp[0] = static_cast<unsigned char>(last_code);
  103|  1.04M|        last_data = tmp;
  104|  1.04M|        last_size = 1;
  105|  1.04M|    } else {
  106|  18.7k|        util::no_ci_rt_error_if(
  107|  18.7k|            last_code <= 257,
  108|  18.7k|            "Pl_LZWDecoder::addToTable called with invalid code (" + std::to_string(last_code) +
  109|  18.7k|                ")");
  110|  18.7k|        unsigned int idx = last_code - 258;
  111|  18.7k|        util::no_ci_rt_error_if(idx >= table.size(), "Pl_LZWDecoder::addToTable: table overflow");
  112|  18.7k|        Buffer& b = table.at(idx);
  113|  18.7k|        last_data = b.getBuffer();
  114|  18.7k|        last_size = QIntC::to_uint(b.getSize());
  115|  18.7k|    }
  116|       |
  117|  1.06M|    Buffer entry(1 + last_size);
  118|  1.06M|    unsigned char* new_data = entry.getBuffer();
  119|  1.06M|    memcpy(new_data, last_data, last_size);
  120|  1.06M|    new_data[last_size] = c;
  121|  1.06M|    table.push_back(std::move(entry));
  122|  1.06M|}
_ZN13Pl_LZWDecoder10handleCodeEj:
  126|  1.06M|{
  127|  1.06M|    if (eod) {
  ------------------
  |  Branch (127:9): [True: 1.41k, False: 1.06M]
  ------------------
  128|  1.41k|        return;
  129|  1.41k|    }
  130|       |
  131|  1.06M|    if (code == 256) {
  ------------------
  |  Branch (131:9): [True: 2.42k, False: 1.06M]
  ------------------
  132|  2.42k|        if (!table.empty()) {
  ------------------
  |  Branch (132:13): [True: 1.68k, False: 740]
  ------------------
  133|  1.68k|            QTC::TC("libtests", "Pl_LZWDecoder intermediate reset");
  134|  1.68k|        }
  135|  2.42k|        table.clear();
  136|  2.42k|        code_size = 9;
  137|  1.06M|    } else if (code == 257) {
  ------------------
  |  Branch (137:16): [True: 23, False: 1.06M]
  ------------------
  138|     23|        eod = true;
  139|  1.06M|    } else {
  140|  1.06M|        if (last_code != 256) {
  ------------------
  |  Branch (140:13): [True: 1.06M, False: 2.24k]
  ------------------
  141|       |            // Add to the table from last time.  New table entry would be what we read last plus the
  142|       |            // first character of what we're reading now.
  143|  1.06M|            unsigned char next_c = '\0';
  144|  1.06M|            unsigned int table_size = QIntC::to_uint(table.size());
  145|  1.06M|            if (code < 256) {
  ------------------
  |  Branch (145:17): [True: 1.04M, False: 18.9k]
  ------------------
  146|       |                // just read < 256; last time's next_c was code
  147|  1.04M|                next_c = static_cast<unsigned char>(code);
  148|  1.04M|            } else if (code > 257) {
  ------------------
  |  Branch (148:24): [True: 18.9k, False: 0]
  ------------------
  149|  18.9k|                size_t idx = code - 258;
  150|  18.9k|                if (idx > table_size) {
  ------------------
  |  Branch (150:21): [True: 38, False: 18.9k]
  ------------------
  151|     38|                    throw std::runtime_error("LZWDecoder: bad code received");
  152|  18.9k|                } else if (idx == table_size) {
  ------------------
  |  Branch (152:28): [True: 2.85k, False: 16.1k]
  ------------------
  153|       |                    // The encoder would have just created this entry, so the first character of
  154|       |                    // this entry would have been the same as the first character of the last entry.
  155|  2.85k|                    next_c = getFirstChar(last_code);
  156|  16.1k|                } else {
  157|  16.1k|                    next_c = getFirstChar(code);
  158|  16.1k|                }
  159|  18.9k|            }
  160|  1.06M|            unsigned int new_idx = 258 + table_size;
  161|  1.06M|            util::no_ci_rt_error_if(new_idx == 4096, "LZWDecoder: table full");
  162|  1.06M|            addToTable(next_c);
  163|  1.06M|            unsigned int change_idx = new_idx + code_change_delta;
  164|  1.06M|            if (change_idx == 511 || change_idx == 1023 || change_idx == 2047) {
  ------------------
  |  Branch (164:17): [True: 881, False: 1.05M]
  |  Branch (164:38): [True: 633, False: 1.05M]
  |  Branch (164:60): [True: 399, False: 1.05M]
  ------------------
  165|  1.91k|                ++code_size;
  166|  1.91k|            }
  167|  1.06M|        }
  168|       |
  169|  1.06M|        if (code < 256) {
  ------------------
  |  Branch (169:13): [True: 1.04M, False: 18.9k]
  ------------------
  170|  1.04M|            auto ch = static_cast<unsigned char>(code);
  171|  1.04M|            next()->write(&ch, 1);
  172|  1.04M|        } else {
  173|  18.9k|            unsigned int idx = code - 258;
  174|  18.9k|            if (idx >= table.size()) {
  ------------------
  |  Branch (174:17): [True: 14, False: 18.9k]
  ------------------
  175|     14|                throw std::runtime_error("Pl_LZWDecoder::handleCode: table overflow");
  176|     14|            }
  177|  18.9k|            Buffer& b = table.at(idx);
  178|  18.9k|            next()->write(b.getBuffer(), b.getSize());
  179|  18.9k|        }
  180|  1.06M|    }
  181|       |
  182|  1.06M|    last_code = code;
  183|  1.06M|}

_ZN13Pl_LZWDecoderD2Ev:
   13|    412|    ~Pl_LZWDecoder() final = default;

_ZN4qpdf4util9assertionIRA53_KcEEvbOT_:
   27|    412|    {
   28|    412|        if (!cond) {
  ------------------
  |  Branch (28:13): [True: 0, False: 412]
  ------------------
   29|      0|            throw std::logic_error(std::forward<T>(msg));
   30|      0|        }
   31|    412|    }
_ZN4qpdf4util17no_ci_rt_error_ifINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEEEvbOT_:
   48|  37.1k|    {
   49|  37.1k|        if (cond) {
  ------------------
  |  Branch (49:13): [True: 0, False: 37.1k]
  ------------------
   50|      0|            throw std::runtime_error(std::forward<T>(msg));
   51|      0|        }
   52|  37.1k|    }
_ZN4qpdf4util17no_ci_rt_error_ifIRA44_KcEEvbOT_:
   48|  18.3k|    {
   49|  18.3k|        if (cond) {
  ------------------
  |  Branch (49:13): [True: 0, False: 18.3k]
  ------------------
   50|      0|            throw std::runtime_error(std::forward<T>(msg));
   51|      0|        }
   52|  18.3k|    }
_ZN4qpdf4util17no_ci_rt_error_ifIRA42_KcEEvbOT_:
   48|  18.7k|    {
   49|  18.7k|        if (cond) {
  ------------------
  |  Branch (49:13): [True: 0, False: 18.7k]
  ------------------
   50|      0|            throw std::runtime_error(std::forward<T>(msg));
   51|      0|        }
   52|  18.7k|    }
_ZN4qpdf4util17no_ci_rt_error_ifIRA23_KcEEvbOT_:
   48|  1.06M|    {
   49|  1.06M|        if (cond) {
  ------------------
  |  Branch (49:13): [True: 3, False: 1.06M]
  ------------------
   50|      3|            throw std::runtime_error(std::forward<T>(msg));
   51|      3|        }
   52|  1.06M|    }

