text:
//
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// This is a derivative work based on Zlib, copyright below:
/*
    Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler

    This software is provided 'as-is', without any express or implied
    warranty.  In no event will the authors be held liable for any damages
    arising from the use of this software.

    Permission is granted to anyone to use this software for any purpose,
    including commercial applications, and to alter it and redistribute it
    freely, subject to the following restrictions:

    1. The origin of this software must not be misrepresented; you must not
       claim that you wrote the original software. If you use this software
       in a product, an acknowledgment in the product documentation would be
       appreciated but is not required.
    2. Altered source versions must be plainly marked as such, and must not be
       misrepresented as being the original software.
    3. This notice may not be removed or altered from any source distribution.

    Jean-loup Gailly        Mark Adler
    jloup@gzip.org          madler@alumni.caltech.edu

    The data format used by the zlib library is described by RFCs (Request for
    Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950
    (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format).
*/

#ifndef BEAST_ZLIB_DETAIL_INFLATE_STREAM_HPP
#define BEAST_ZLIB_DETAIL_INFLATE_STREAM_HPP

#include <beast/zlib/error.hpp>
#include <beast/zlib/zlib.hpp>
#include <beast/zlib/detail/bitstream.hpp>
#include <beast/zlib/detail/ranges.hpp>
#include <beast/zlib/detail/window.hpp>
#include <beast/core/detail/type_traits.hpp>
#include <boost/throw_exception.hpp>
#include <algorithm>
#include <array>
#include <cstdint>
#include <cstring>
#include <stdexcept>

namespace beast {
namespace zlib {
namespace detail {

class inflate_stream
{
protected:
    inflate_stream()
    {
        w_.reset(15);
    }

    template<class = void> void doClear();
    template<class = void> void doReset(int windowBits);
    template<class = void> void doWrite(z_params& zs, Flush flush, error_code& ec);

    void
    doReset()
    {
        doReset(w_.bits());
    }

private:
    enum Mode
    {
        HEAD,       // i: waiting for magic header
        FLAGS,      // i: waiting for method and flags (gzip)
        TIME,       // i: waiting for modification time (gzip)
        OS,         // i: waiting for extra flags and operating system (gzip)
        EXLEN,      // i: waiting for extra length (gzip)
        EXTRA,      // i: waiting for extra bytes (gzip)
        NAME,       // i: waiting for end of file name (gzip)
        COMMENT,    // i: waiting for end of comment (gzip)
        HCRC,       // i: waiting for header crc (gzip)
        TYPE,       // i: waiting for type bits, including last-flag bit
        TYPEDO,     // i: same, but skip check to exit inflate on new block
        STORED,     // i: waiting for stored size (length and complement)
        COPY_,      // i/o: same as COPY below, but only first time in
        COPY,       // i/o: waiting for input or output to copy stored block
        TABLE,      // i: waiting for dynamic block table lengths
        LENLENS,    // i: waiting for code length code lengths
        CODELENS,   // i: waiting for length/lit and distance code lengths
            LEN_,   // i: same as LEN below, but only first time in
            LEN,    // i: waiting for length/lit/eob code
            LENEXT, // i: waiting for length extra bits
            DIST,   // i: waiting for distance code
            DISTEXT,// i: waiting for distance extra bits
            MATCH,  // o: waiting for output space to copy string
            LIT,    // o: waiting for output space to write literal
        CHECK,      // i: waiting for 32-bit check value
        LENGTH,     // i: waiting for 32-bit length (gzip)
        DONE,       // finished check, done -- remain here until reset
        BAD,        // got a data error -- remain here until reset
        SYNC        // looking for synchronization bytes to restart inflate()
    };

    /*  Structure for decoding tables.  Each entry provides either the
        information needed to do the operation requested by the code that
        indexed that table entry, or it provides a pointer to another
        table that indexes more bits of the code.  op indicates whether
        the entry is a pointer to another table, a literal, a length or
        distance, an end-of-block, or an invalid code.  For a table
        pointer, the low four bits of op is the number of index bits of
        that table.  For a length or distance, the low four bits of op
        is the number of extra bits to get after the code.  bits is
        the number of bits in this code or part of the code to drop off
        of the bit buffer.  val is the actual byte to output in the case
        of a literal, the base length or distance, or the offset from
        the current table to the next table.  Each entry is four bytes.

        op values as set by inflate_table():

        00000000 - literal
        0000tttt - table link, tttt != 0 is the number of table index bits
        0001eeee - length or distance, eeee is the number of extra bits
        01100000 - end of block
        01000000 - invalid code
    */
    struct code
    {
        std::uint8_t  op;   // operation, extra bits, table bits
        std::uint8_t  bits; // bits in this part of the code
        std::uint16_t val;  // offset in table or code value
    };

    /*  Maximum size of the dynamic table.  The maximum number of code
        structures is 1444, which is the sum of 852 for literal/length codes
        and 592 for distance codes.  These values were found by exhaustive
        searches using the program examples/enough.c found in the zlib
        distribtution.  The arguments to that program are the number of
        symbols, the initial root table size, and the maximum bit length
        of a code.  "enough 286 9 15" for literal/length codes returns
        returns 852, and "enough 30 6 15" for distance codes returns 592.
        The initial root table size (9 or 6) is found in the fifth argument
        of the inflate_table() calls in inflate.c and infback.c.  If the
        root table size is changed, then these maximum sizes would be need
        to be recalculated and updated.
    */
    static std::uint16_t constexpr kEnoughLens = 852;
    static std::uint16_t constexpr kEnoughDists = 592;
    static std::uint16_t constexpr kEnough = kEnoughLens + kEnoughDists;

    struct codes
    {
        code const* lencode;
        code const* distcode;
        unsigned lenbits; // VFALCO use std::uint8_t
        unsigned distbits;
    };

    // Type of code to build for inflate_table()
    enum class build
    {
        codes,
        lens,
        dists
    };

    template<class = void>
    static
    void
    inflate_table(
        build type,
        std::uint16_t* lens,
        std::size_t codes,
        code** table,
        unsigned *bits,
        std::uint16_t* work,
        error_code& ec);

    template<class = void>
    static
    codes const&
    get_fixed_tables();

    template<class = void>
    void
    fixedTables();

    template<class = void>
    void
    inflate_fast(ranges& r, error_code& ec);

    bitstream bi_;

    Mode mode_ = HEAD;              // current inflate mode
    int last_ = 0;                  // true if processing last block
    unsigned dmax_ = 32768U;        // zlib header max distance (INFLATE_STRICT)

    // sliding window
    window w_;

    // for string and stored block copying
    unsigned length_;               // literal or length of data to copy
    unsigned offset_;               // distance back to copy string from

    // for table and code decoding
    unsigned extra_;                // extra bits needed

    // dynamic table building
    unsigned ncode_;                // number of code length code lengths
    unsigned nlen_;                 // number of length code lengths
    unsigned ndist_;                // number of distance code lengths
    unsigned have_;                 // number of code lengths in lens[]
    unsigned short lens_[320];      // temporary storage for code lengths
    unsigned short work_[288];      // work area for code table building
    code codes_[kEnough];           // space for code tables
    code *next_ = codes_;           // next available space in codes[]
    int back_ = -1;                 // bits back of last unprocessed length/lit
    unsigned was_;                  // initial length of match

    // fixed and dynamic code tables
    code const* lencode_ = codes_   ; // starting table for length/literal codes
    code const* distcode_ = codes_; // starting table for distance codes
    unsigned lenbits_;              // index bits for lencode
    unsigned distbits_;             // index bits for distcode
};

//------------------------------------------------------------------------------

template<class>
void
inflate_stream::
doReset(int windowBits)
{
    if(windowBits < 8 || windowBits > 15)
        BOOST_THROW_EXCEPTION(std::domain_error{
            "windowBits out of range"});
    w_.reset(windowBits);

    bi_.flush();
    mode_ = HEAD;
    last_ = 0;
    dmax_ = 32768U;
    lencode_ = codes_;
    distcode_ = codes_;
    next_ = codes_;
    back_ = -1;
}

template<class>
void
inflate_stream::
doClear()
{
}

template<class>
void
inflate_stream::
doWrite(z_params& zs, Flush flush, error_code& ec)
{
    ranges r;
    r.in.first = reinterpret_cast<
        std::uint8_t const*>(zs.next_in);
    r.in.last = r.in.first + zs.avail_in;
    r.in.next = r.in.first;
    r.out.first = reinterpret_cast<
        std::uint8_t*>(zs.next_out);
    r.out.last = r.out.first + zs.avail_out;
    r.out.next = r.out.first;

    auto const done =
        [&]
        {
            /*
               Return from inflate(), updating the total counts and the check value.
               If there was no progress during the inflate() call, return a buffer
               error.  Call updatewindow() to create and/or update the window state.
               Note: a memory error from inflate() is non-recoverable.
             */

            // VFALCO TODO Don't allocate update the window unless necessary
            if(/*wsize_ ||*/ (r.out.used() && mode_ < BAD &&
                    (mode_ < CHECK || flush != Flush::finish)))
                w_.write(r.out.first, r.out.used());

            zs.next_in = r.in.next;
            zs.avail_in = r.in.avail();
            zs.next_out = r.out.next;
            zs.avail_out = r.out.avail();
            zs.total_in += r.in.used();
            zs.total_out += r.out.used();
            zs.data_type = bi_.size() + (last_ ? 64 : 0) +
                (mode_ == TYPE ? 128 : 0) +
                (mode_ == LEN_ || mode_ == COPY_ ? 256 : 0);

            if(((! r.in.used() && ! r.out.used()) ||
                    flush == Flush::finish) && ! ec)
                ec = error::need_buffers;
        };
    auto const err =
        [&](error e)
        {
            ec = e;
            mode_ = BAD;
        };

    if(mode_ == TYPE)
        mode_ = TYPEDO;

    for(;;)
    {
        switch(mode_)
        {
        case HEAD:
            mode_ = TYPEDO;
            break;

        case TYPE:
            if(flush == Flush::block || flush == Flush::trees)
                return done();
            // fall through

        case TYPEDO:
        {
            if(last_)
            {
                bi_.flush_byte();
                mode_ = CHECK;
                break;
            }
            if(! bi_.fill(3, r.in.next, r.in.last))
                return done();
            std::uint8_t v;
            bi_.read(v, 1);
            last_ = v != 0;
            bi_.read(v, 2);
            switch(v)
            {
            case 0:
                // uncompressed block
                mode_ = STORED;
                break;
            case 1:
                // fixed Huffman table
                fixedTables();
                mode_ = LEN_;             /* decode codes */
                if(flush == Flush::trees)
                    return done();
                break;
            case 2:
                // dynamic Huffman table
                mode_ = TABLE;
                break;

            default:
                return err(error::invalid_block_type);
            }
            break;
        }

        case STORED:
        {
            bi_.flush_byte();
            std::uint32_t v;
            if(! bi_.fill(32, r.in.next, r.in.last))
                return done();
            bi_.peek(v, 32);
            length_ = v & 0xffff;
            if(length_ != ((v >> 16) ^ 0xffff))
                return err(error::invalid_stored_length);
            // flush instead of read, otherwise
            // undefined right shift behavior.
            bi_.flush();
            mode_ = COPY_;
            if(flush == Flush::trees)
                return done();
            // fall through
        }

        case COPY_:
            mode_ = COPY;
            // fall through

        case COPY:
        {
            auto copy = length_;
            if(copy == 0)
            {
                mode_ = TYPE;
                break;
            }
            copy = clamp(copy, r.in.avail());
            copy = clamp(copy, r.out.avail());
            if(copy == 0)
                return done();
            std::memcpy(r.out.next, r.in.next, copy);
            r.in.next += copy;
            r.out.next += copy;
            length_ -= copy;
            break;
        }

        case TABLE:
            if(! bi_.fill(5 + 5 + 4, r.in.next, r.in.last))
                return done();
            bi_.read(nlen_, 5);
            nlen_ += 257;
            bi_.read(ndist_, 5);
            ndist_ += 1;
            bi_.read(ncode_, 4);
            ncode_ += 4;
            if(nlen_ > 286 || ndist_ > 30)
                return err(error::too_many_symbols);
            have_ = 0;
            mode_ = LENLENS;
            // fall through

        case LENLENS:
        {
            static std::array<std::uint8_t, 19> constexpr order = {{
                16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}};
            while(have_ < ncode_)
            {
                if(! bi_.fill(3, r.in.next, r.in.last))
                    return done();
                bi_.read(lens_[order[have_]], 3);
                ++have_;
            }
            while(have_ < order.size())
                lens_[order[have_++]] = 0;

            next_ = &codes_[0];
            lencode_ = next_;
            lenbits_ = 7;
            inflate_table(build::codes, &lens_[0],
                order.size(), &next_, &lenbits_, work_, ec);
            if(ec)
            {
                mode_ = BAD;
                break;
            }
            have_ = 0;
            mode_ = CODELENS;
            // fall through
        }

        case CODELENS:
        {
            while(have_ < nlen_ + ndist_)
            {
                std::uint16_t v;
                if(! bi_.fill(lenbits_, r.in.next, r.in.last))
                    return done();
                bi_.peek(v, lenbits_);
                auto cp = &lencode_[v];
                if(cp->val < 16)
                {
                    bi_.drop(cp->bits);
                    lens_[have_++] = cp->val;
                }
                else
                {
                    std::uint16_t len;
                    std::uint16_t copy;
                    if(cp->val == 16)
                    {
                        if(! bi_.fill(cp->bits + 2, r.in.next, r.in.last))
                            return done();
                        bi_.drop(cp->bits);
                        if(have_ == 0)
                            return err(error::invalid_bit_length_repeat);
                        bi_.read(copy, 2);
                        len = lens_[have_ - 1];
                        copy += 3;

                    }
                    else if(cp->val == 17)
                    {
                        if(! bi_.fill(cp->bits + 3, r.in.next, r.in.last))
                            return done();
                        bi_.drop(cp->bits);
                        bi_.read(copy, 3);
                        len = 0;
                        copy += 3;
                    }
                    else
                    {
                        if(! bi_.fill(cp->bits + 7, r.in.next, r.in.last))
                            return done();
                        bi_.drop(cp->bits);
                        bi_.read(copy, 7);
                        len = 0;
                        copy += 11;
                    }
                    if(have_ + copy > nlen_ + ndist_)
                        return err(error::invalid_bit_length_repeat);
                    std::fill(&lens_[have_], &lens_[have_ + copy], len);
                    have_ += copy;
                    copy = 0;
                }
            }
            // handle error breaks in while
            if(mode_ == BAD)
                break;
            // check for end-of-block code (better have one)
            if(lens_[256] == 0)
                return err(error::missing_eob);
            /* build code tables -- note: do not change the lenbits or distbits
               values here (9 and 6) without reading the comments in inftrees.hpp
               concerning the kEnough constants, which depend on those values */
            next_ = &codes_[0];
            lencode_ = next_;
            lenbits_ = 9;
            inflate_table(build::lens, &lens_[0],
                nlen_, &next_, &lenbits_, work_, ec);
            if(ec)
            {
                mode_ = BAD;
                return;
            }
            distcode_ = next_;
            distbits_ = 6;
            inflate_table(build::dists, lens_ + nlen_,
                ndist_, &next_, &distbits_, work_, ec);
            if(ec)
            {
                mode_ = BAD;
                return;
            }
            mode_ = LEN_;
            if(flush == Flush::trees)
                return done();
            // fall through
        }

        case LEN_:
            mode_ = LEN;
            // fall through

        case LEN:
        {
            if(r.in.avail() >= 6 && r.out.avail() >= 258)
            {
                inflate_fast(r, ec);
                if(ec)
                {
                    mode_ = BAD;
                    return;
                }
                if(mode_ == TYPE)
                    back_ = -1;
                break;
            }
            if(! bi_.fill(lenbits_, r.in.next, r.in.last))
                return done();
            std::uint16_t v;
            back_ = 0;
            bi_.peek(v, lenbits_);
            auto cp = &lencode_[v];
            if(cp->op && (cp->op & 0xf0) == 0)
            {
                auto prev = cp;
                if(! bi_.fill(prev->bits + prev->op, r.in.next, r.in.last))
                    return done();
                bi_.peek(v, prev->bits + prev->op);
                cp = &lencode_[prev->val + (v >> prev->bits)];
                bi_.drop(prev->bits + cp->bits);
                back_ += prev->bits + cp->bits;
            }
            else
            {
                bi_.drop(cp->bits);
                back_ += cp->bits;
            }
            length_ = cp->val;
            if(cp->op == 0)
            {
                mode_ = LIT;
                break;
            }
            if(cp->op & 32)
            {
                back_ = -1;
                mode_ = TYPE;
                break;
            }
            if(cp->op & 64)
                return err(error::invalid_literal_length);
            extra_ = cp->op & 15;
            mode_ = LENEXT;
            // fall through
        }

        case LENEXT:
            if(extra_)
            {
                if(! bi_.fill(extra_, r.in.next, r.in.last))
                    return done();
                std::uint16_t v;
                bi_.read(v, extra_);
                length_ += v;
                back_ += extra_;
            }
            was_ = length_;
            mode_ = DIST;
            // fall through

        case DIST:
        {
            if(! bi_.fill(distbits_, r.in.next, r.in.last))
                return done();
            std::uint16_t v;
            bi_.peek(v, distbits_);
            auto cp = &distcode_[v];
            if((cp->op & 0xf0) == 0)
            {
                auto prev = cp;
                if(! bi_.fill(prev->bits + prev->op, r.in.next, r.in.last))
                    return done();
                bi_.peek(v, prev->bits + prev->op);
                cp = &distcode_[prev->val + (v >> prev->bits)];
                bi_.drop(prev->bits + cp->bits);
                back_ += prev->bits + cp->bits;
            }
            else
            {
                bi_.drop(cp->bits);
                back_ += cp->bits;
            }
            if(cp->op & 64)
                return err(error::invalid_distance_code);
            offset_ = cp->val;
            extra_ = cp->op & 15;
            mode_ = DISTEXT;
            // fall through
        }

        case DISTEXT:
            if(extra_)
            {
                std::uint16_t v;
                if(! bi_.fill(extra_, r.in.next, r.in.last))
                    return done();
                bi_.read(v, extra_);
                offset_ += v;
                back_ += extra_;
            }
#ifdef INFLATE_STRICT
            if(offset_ > dmax_)
                return err(error::invalid_distance);
#endif
            mode_ = MATCH;
            // fall through

        case MATCH:
        {
            if(! r.out.avail())
                return done();
            if(offset_ > r.out.used())
            {
                // copy from window
                auto offset = static_cast<std::uint16_t>(
                    offset_ - r.out.used());
                if(offset > w_.size())
                    return err(error::invalid_distance);
                auto const n = clamp(clamp(
                    length_, offset), r.out.avail());
                w_.read(r.out.next, offset, n);
                r.out.next += n;
                length_ -= n;
            }
            else
            {
                // copy from output
                auto in = r.out.next - offset_;
                auto n = clamp(length_, r.out.avail());
                length_ -= n;
                while(n--)
                    *r.out.next++ = *in++;
            }
            if(length_ == 0)
                mode_ = LEN;
            break;
        }

        case LIT:
        {
            if(! r.out.avail())
                return done();
            auto const v = static_cast<std::uint8_t>(length_);
            *r.out.next++ = v;
            mode_ = LEN;
            break;
        }

        case CHECK:
            mode_ = DONE;
            // fall through

        case DONE:
            ec = error::end_of_stream;
            return done();

        case BAD:
            return done();

        case SYNC:
        default:
            BOOST_THROW_EXCEPTION(std::logic_error{
                "stream error"});
        }
    }
}

//------------------------------------------------------------------------------

/*  Build a set of tables to decode the provided canonical Huffman code.
    The code lengths are lens[0..codes-1].  The result starts at *table,
    whose indices are 0..2^bits-1.  work is a writable array of at least
    lens shorts, which is used as a work area.  type is the type of code
    to be generated, build::codes, build::lens, or build::dists.  On
    return, zero is success, -1 is an invalid code, and +1 means that
    kEnough isn't enough.  table on return points to the next available
    entry's address.  bits is the requested root table index bits, and
    on return it is the actual root table index bits.  It will differ if
    the request is greater than the longest code or if it is less than
    the shortest code.
*/
template<class>
void
inflate_stream::
inflate_table(
    build type,
    std::uint16_t* lens,
    std::size_t codes,
    code** table,
    unsigned *bits,
    std::uint16_t* work,
    error_code& ec)
{
    unsigned len;                   // a code's length in bits
    unsigned sym;                   // index of code symbols
    unsigned min, max;              // minimum and maximum code lengths
    unsigned root;                  // number of index bits for root table
    unsigned curr;                  // number of index bits for current table
    unsigned drop;                  // code bits to drop for sub-table
    int left;                       // number of prefix codes available
    unsigned used;                  // code entries in table used
    unsigned huff;                  // Huffman code
    unsigned incr;                  // for incrementing code, index
    unsigned fill;                  // index for replicating entries
    unsigned low;                   // low bits for current root entry
    unsigned mask;                  // mask for low root bits
    code here;                      // table entry for duplication
    code *next;                     // next available space in table
    std::uint16_t const* base;      // base value table to use
    std::uint16_t const* extra;     // extra bits table to use
    int end;                        // use base and extra for symbol > end
    std::uint16_t count[15+1];      // number of codes of each length
    std::uint16_t offs[15+1];       // offsets in table for each length

    // Length codes 257..285 base
    static std::uint16_t constexpr lbase[31] = {
        3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
        35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};

    // Length codes 257..285 extra
    static std::uint16_t constexpr lext[31] = {
        16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
        19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78};

    // Distance codes 0..29 base
    static std::uint16_t constexpr dbase[32] = {
        1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
        257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
        8193, 12289, 16385, 24577, 0, 0};

    // Distance codes 0..29 extra
    static std::uint16_t constexpr dext[32] = {
        16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
        23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
        28, 28, 29, 29, 64, 64};

    /*
       Process a set of code lengths to create a canonical Huffman code.  The
       code lengths are lens[0..codes-1].  Each length corresponds to the
       symbols 0..codes-1.  The Huffman code is generated by first sorting the
       symbols by length from short to long, and retaining the symbol order
       for codes with equal lengths.  Then the code starts with all zero bits
       for the first code of the shortest length, and the codes are integer
       increments for the same length, and zeros are appended as the length
       increases.  For the deflate format, these bits are stored backwards
       from their more natural integer increment ordering, and so when the
       decoding tables are built in the large loop below, the integer codes
       are incremented backwards.

       This routine assumes, but does not check, that all of the entries in
       lens[] are in the range 0..15.  The caller must assure this.
       1..15 is interpreted as that code length.  zero means that that
       symbol does not occur in this code.

       The codes are sorted by computing a count of codes for each length,
       creating from that a table of starting indices for each length in the
       sorted table, and then entering the symbols in order in the sorted
       table.  The sorted table is work[], with that space being provided by
       the caller.

       The length counts are used for other purposes as well, i.e. finding
       the minimum and maximum length codes, determining if there are any
       codes at all, checking for a valid set of lengths, and looking ahead
       at length counts to determine sub-table sizes when building the
       decoding tables.
     */

    /* accumulate lengths for codes (assumes lens[] all in 0..15) */
    for (len = 0; len <= 15; len++)
        count[len] = 0;
    for (sym = 0; sym < codes; sym++)
        count[lens[sym]]++;

    /* bound code lengths, force root to be within code lengths */
    root = *bits;
    for (max = 15; max >= 1; max--)
        if (count[max] != 0)
            break;
    if (root > max)
        root = max;
    if (max == 0)
    {                     /* no symbols to code at all */
        here.op = (std::uint8_t)64;    /* invalid code marker */
        here.bits = (std::uint8_t)1;
        here.val = (std::uint16_t)0;
        *(*table)++ = here;             /* make a table to force an error */
        *(*table)++ = here;
        *bits = 1;
        return;       /* no symbols, but wait for decoding to report error */
    }
    for (min = 1; min < max; min++)
        if (count[min] != 0)
            break;
    if (root < min)
        root = min;

    /* check for an over-subscribed or incomplete set of lengths */
    left = 1;
    for (len = 1; len <= 15; len++)
    {
        left <<= 1;
        left -= count[len];
        if (left < 0)
        {
            ec = error::over_subscribed_length;
            return;
        }
    }
    if (left > 0 && (type == build::codes || max != 1))
    {
        ec = error::incomplete_length_set;
        return;
    }

    /* generate offsets into symbol table for each length for sorting */
    offs[1] = 0;
    for (len = 1; len < 15; len++)
        offs[len + 1] = offs[len] + count[len];

    /* sort symbols by length, by symbol order within each length */
    for (sym = 0; sym < codes; sym++)
        if (lens[sym] != 0)
            work[offs[lens[sym]]++] = (std::uint16_t)sym;

    /*
       Create and fill in decoding tables.  In this loop, the table being
       filled is at next and has curr index bits.  The code being used is huff
       with length len.  That code is converted to an index by dropping drop
       bits off of the bottom.  For codes where len is less than drop + curr,
       those top drop + curr - len bits are incremented through all values to
       fill the table with replicated entries.

       root is the number of index bits for the root table.  When len exceeds
       root, sub-tables are created pointed to by the root entry with an index
       of the low root bits of huff.  This is saved in low to check for when a
       new sub-table should be started.  drop is zero when the root table is
       being filled, and drop is root when sub-tables are being filled.

       When a new sub-table is needed, it is necessary to look ahead in the
       code lengths to determine what size sub-table is needed.  The length
       counts are used for this, and so count[] is decremented as codes are
       entered in the tables.

       used keeps track of how many table entries have been allocated from the
       provided *table space.  It is checked for build::lens and DIST tables against
       the constants kEnoughLens and kEnoughDists to guard against changes in
       the initial root table size constants.  See the comments in inftrees.hpp
       for more information.

       sym increments through all symbols, and the loop terminates when
       all codes of length max, i.e. all codes, have been processed.  This
       routine permits incomplete codes, so another loop after this one fills
       in the rest of the decoding tables with invalid code markers.
     */

    /* set up for code type */
    switch (type)
    {
    case build::codes:
        base = extra = work;    /* dummy value--not used */
        end = 19;
        break;
    case build::lens:
        base = lbase;
        base -= 257;
        extra = lext;
        extra -= 257;
        end = 256;
        break;
    default:            /* build::dists */
        base = dbase;
        extra = dext;
        end = -1;
    }

    /* initialize state for loop */
    huff = 0;                   /* starting code */
    sym = 0;                    /* starting code symbol */
    len = min;                  /* starting code length */
    next = *table;              /* current table to fill in */
    curr = root;                /* current table index bits */
    drop = 0;                   /* current bits to drop from code for index */
    low = (unsigned)(-1);       /* trigger new sub-table when len > root */
    used = 1U << root;          /* use root table entries */
    mask = used - 1;            /* mask for comparing low */

    auto const not_enough = []
    {
        BOOST_THROW_EXCEPTION(std::logic_error{
            "insufficient output size when inflating tables"});
    };

    // check available table space
    if ((type == build::lens && used > kEnoughLens) ||
            (type == build::dists && used > kEnoughDists))
        return not_enough();

    /* process all codes and make table entries */
    for (;;)
    {
        /* create table entry */
        here.bits = (std::uint8_t)(len - drop);
        if ((int)(work[sym]) < end)
        {
            here.op = (std::uint8_t)0;
            here.val = work[sym];
        }
        else if ((int)(work[sym]) > end)
        {
            here.op = (std::uint8_t)(extra[work[sym]]);
            here.val = base[work[sym]];
        }
        else
        {
            here.op = (std::uint8_t)(32 + 64);         /* end of block */
            here.val = 0;
        }

        /* replicate for those indices with low len bits equal to huff */
        incr = 1U << (len - drop);
        fill = 1U << curr;
        min = fill;                 /* save offset to next table */
        do
        {
            fill -= incr;
            next[(huff >> drop) + fill] = here;
        } while (fill != 0);

        /* backwards increment the len-bit code huff */
        incr = 1U << (len - 1);
        while (huff & incr)
            incr >>= 1;
        if (incr != 0)
        {
            huff &= incr - 1;
            huff += incr;
        }
        else
            huff = 0;

        /* go to next symbol, update count, len */
        sym++;
        if (--(count[len]) == 0)
        {
            if (len == max) break;
            len = lens[work[sym]];
        }

        /* create new sub-table if needed */
        if (len > root && (huff & mask) != low)
        {
            /* if first time, transition to sub-tables */
            if (drop == 0)
                drop = root;

            /* increment past last table */
            next += min;            /* here min is 1 << curr */

            /* determine length of next table */
            curr = len - drop;
            left = (int)(1 << curr);
            while (curr + drop < max)
            {
                left -= count[curr + drop];
                if (left <= 0) break;
                curr++;
                left <<= 1;
            }

            /* check for enough space */
            used += 1U << curr;
            if ((type == build::lens && used > kEnoughLens) ||
                    (type == build::dists && used > kEnoughDists))
                return not_enough();

            /* point entry in root table to sub-table */
            low = huff & mask;
            (*table)[low].op = (std::uint8_t)curr;
            (*table)[low].bits = (std::uint8_t)root;
            (*table)[low].val = (std::uint16_t)(next - *table);
        }
    }

    /* fill in remaining table entry if code is incomplete (guaranteed to have
       at most one remaining entry, since if the code is incomplete, the
       maximum code length that was allowed to get this far is one bit) */
    if (huff != 0)
    {
        here.op = 64;   // invalid code marker
        here.bits = (std::uint8_t)(len - drop);
        here.val = 0;
        next[huff] = here;
    }

    *table += used;
    *bits = root;
}

template<class>
auto
inflate_stream::
get_fixed_tables() ->
    codes const&
{
    struct fixed_codes : codes
    {
        code len_[512];
        code dist_[32];

        fixed_codes()
        {
            lencode = len_;
            lenbits = 9;
            distcode = dist_;
            distbits = 5;

            std::uint16_t lens[320];
            std::uint16_t work[288];

            std::fill(&lens[  0], &lens[144], std::uint16_t{8});
            std::fill(&lens[144], &lens[256], std::uint16_t{9});
            std::fill(&lens[256], &lens[280], std::uint16_t{7});
            std::fill(&lens[280], &lens[288], std::uint16_t{8});

            {
                error_code ec;
                auto next = &len_[0];
                inflate_table(build::lens,
                    lens, 288, &next, &lenbits, work, ec);
                if(ec)
                    BOOST_THROW_EXCEPTION(std::logic_error{ec.message()});
            }

            // VFALCO These fixups are from ZLib
            len_[ 99].op = 64;
            len_[227].op = 64;
            len_[355].op = 64;
            len_[483].op = 64;

            {
                error_code ec;
                auto next = &dist_[0];
                std::fill(&lens[0], &lens[32], std::uint16_t{5});
                inflate_table(build::dists,
                    lens, 32, &next, &distbits, work, ec);
                if(ec)
                    BOOST_THROW_EXCEPTION(std::logic_error{ec.message()});
            }
        }
    };

    static fixed_codes const fc;
    return fc;
}

template<class>
void
inflate_stream::
fixedTables()
{
    auto const fc = get_fixed_tables();
    lencode_ = fc.lencode;
    lenbits_ = fc.lenbits;
    distcode_ = fc.distcode;
    distbits_ = fc.distbits;
}

/*
   Decode literal, length, and distance codes and write out the resulting
   literal and match bytes until either not enough input or output is
   available, an end-of-block is encountered, or a data error is encountered.
   When large enough input and output buffers are supplied to inflate(), for
   example, a 16K input buffer and a 64K output buffer, more than 95% of the
   inflate execution time is spent in this routine.

   Entry assumptions:

        state->mode_ == LEN
        zs.avail_in >= 6
        zs.avail_out >= 258
        start >= zs.avail_out
        state->bits_ < 8

   On return, state->mode_ is one of:

        LEN -- ran out of enough output space or enough available input
        TYPE -- reached end of block code, inflate() to interpret next block
        BAD -- error in block data

   Notes:

    - The maximum input bits used by a length/distance pair is 15 bits for the
      length code, 5 bits for the length extra, 15 bits for the distance code,
      and 13 bits for the distance extra.  This totals 48 bits, or six bytes.
      Therefore if zs.avail_in >= 6, then there is enough input to avoid
      checking for available input while decoding.

    - The maximum bytes that a single length/distance pair can output is 258
      bytes, which is the maximum length that can be coded.  inflate_fast()
      requires zs.avail_out >= 258 for each loop to avoid checking for
      output space.

  inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
   - Using bit fields for code structure
   - Different op definition to avoid & for extra bits (do & for table bits)
   - Three separate decoding do-loops for direct, window, and wnext == 0
   - Special case for distance > 1 copies to do overlapped load and store copy
   - Explicit branch predictions (based on measured branch probabilities)
   - Deferring match copy and interspersed it with decoding subsequent codes
   - Swapping literal/length else
   - Swapping window/direct else
   - Larger unrolled copy loops (three is about right)
   - Moving len -= 3 statement into middle of loop
 */
template<class>
void
inflate_stream::
inflate_fast(ranges& r, error_code& ec)
{
    unsigned char const* last;  // have enough input while in < last
    unsigned char *end;         // while out < end, enough space available
    std::size_t op;             // code bits, operation, extra bits, or window position, window bytes to copy
    unsigned len;               // match length, unused bytes
    unsigned dist;              // match distance
    unsigned const lmask =
        (1U << lenbits_) - 1;   // mask for first level of length codes
    unsigned const dmask =
        (1U << distbits_) - 1;  // mask for first level of distance codes

    last = r.in.next + (r.in.avail() - 5);
    end = r.out.next + (r.out.avail() - 257);

    /* decode literals and length/distances until end-of-block or not enough
       input data or output space */
    do
    {
        if(bi_.size() < 15)
            bi_.fill_16(r.in.next);
        auto cp = &lencode_[bi_.peek_fast() & lmask];
    dolen:
        bi_.drop(cp->bits);
        op = (unsigned)(cp->op);
        if(op == 0)
        {
            // literal
            *r.out.next++ = (unsigned char)(cp->val);
        }
        else if(op & 16)
        {
            // length base
            len = (unsigned)(cp->val);
            op &= 15; // number of extra bits
            if(op)
            {
                if(bi_.size() < op)
                    bi_.fill_8(r.in.next);
                len += (unsigned)bi_.peek_fast() & ((1U << op) - 1);
                bi_.drop(op);
            }
            if(bi_.size() < 15)
                bi_.fill_16(r.in.next);
            cp = &distcode_[bi_.peek_fast() & dmask];
        dodist:
            bi_.drop(cp->bits);
            op = (unsigned)(cp->op);
            if(op & 16)
            {
                // distance base
                dist = (unsigned)(cp->val);
                op &= 15; // number of extra bits
                if(bi_.size() < op)
                {
                    bi_.fill_8(r.in.next);
                    if(bi_.size() < op)
                        bi_.fill_8(r.in.next);
                }
                dist += (unsigned)bi_.peek_fast() & ((1U << op) - 1);
#ifdef INFLATE_STRICT
                if(dist > dmax_)
                {
                    ec = error::invalid_distance;
                    mode_ = BAD;
                    break;
                }
#endif
                bi_.drop(op);

                op = r.out.used();
                if(dist > op)
                {
                    // copy from window
                    op = dist - op; // distance back in window
                    if(op > w_.size())
                    {
                        ec = error::invalid_distance;
                        mode_ = BAD;
                        break;
                    }
                    auto const n = clamp(len, op);
                    w_.read(r.out.next, op, n);
                    r.out.next += n;
                    len -= n;
                }
                if(len > 0)
                {
                    // copy from output
                    auto in = r.out.next - dist;
                    auto n = clamp(len, r.out.avail());
                    len -= n;
                    while(n--)
                        *r.out.next++ = *in++;
                }
            }
            else if((op & 64) == 0)
            {
                // 2nd level distance code
                cp = &distcode_[cp->val + (bi_.peek_fast() & ((1U << op) - 1))];
                goto dodist;
            }
            else
            {
                ec = error::invalid_distance_code;
                mode_ = BAD;
                break;
            }
        }
        else if((op & 64) == 0)
        {
            // 2nd level length code
            cp = &lencode_[cp->val + (bi_.peek_fast() & ((1U << op) - 1))];
            goto dolen;
        }
        else if(op & 32)
        {
            // end-of-block
            mode_ = TYPE;
            break;
        }
        else
        {
            ec = error::invalid_literal_length;
            mode_ = BAD;
            break;
        }
    }
    while(r.in.next < last && r.out.next < end);

    // return unused bytes (on entry, bits < 8, so in won't go too far back)
    bi_.rewind(r.in.next);
}

} // detail
} // zlib
} // beast

#endif


text:
// Copyright (c) 2020, Viktor Larsson
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//
//     * Neither the name of the copyright holder nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "univariate.h"

#include <Eigen/Eigen>
#include <complex>

namespace poselib {
namespace univariate {
/* Solves the quadratic equation a*x^2 + b*x + c = 0 */
void solve_quadratic(double a, double b, double c, std::complex<double> roots[2]) {

    std::complex<double> b2m4ac = b * b - 4 * a * c;
    std::complex<double> sq = std::sqrt(b2m4ac);

    // Choose sign to avoid cancellations
    roots[0] = (b > 0) ? (2 * c) / (-b - sq) : (2 * c) / (-b + sq);
    roots[1] = c / (a * roots[0]);
}

/* Solves the quadratic equation a*x^2 + b*x + c = 0 */
int solve_quadratic_real(double a, double b, double c, double roots[2]) {

    double b2m4ac = b * b - 4 * a * c;
    if (b2m4ac < 0)
        return 0;

    double sq = std::sqrt(b2m4ac);

    // Choose sign to avoid cancellations
    roots[0] = (b > 0) ? (2 * c) / (-b - sq) : (2 * c) / (-b + sq);
    roots[1] = c / (a * roots[0]);

    return 2;
}

/* Sign of component with largest magnitude */
inline double sign2(const std::complex<double> z) {
    if (std::abs(z.real()) > std::abs(z.imag()))
        return z.real() < 0 ? -1.0 : 1.0;
    else
        return z.imag() < 0 ? -1.0 : 1.0;
}

/* Sign of component with largest magnitude */
inline double sign(const double z) { return z < 0 ? -1.0 : 1.0; }

void solve_cubic_single_real(double c2, double c1, double c0, double &root) {
    double a = c1 - c2 * c2 / 3.0;
    double b = (2.0 * c2 * c2 * c2 - 9.0 * c2 * c1) / 27.0 + c0;
    double c = b * b / 4.0 + a * a * a / 27.0;
    if (c > 0) {
        c = std::sqrt(c);
        b *= -0.5;
        root = std::cbrt(b + c) + std::cbrt(b - c) - c2 / 3.0;
    } else {
        c = 3.0 * b / (2.0 * a) * std::sqrt(-3.0 / a);
        root = 2.0 * std::sqrt(-a / 3.0) * std::cos(std::acos(c) / 3.0) - c2 / 3.0;
    }
}

int solve_cubic_real(double c2, double c1, double c0, double roots[3]) {
    double a = c1 - c2 * c2 / 3.0;
    double b = (2.0 * c2 * c2 * c2 - 9.0 * c2 * c1) / 27.0 + c0;
    double c = b * b / 4.0 + a * a * a / 27.0;
    int n_roots;
    if (c > 0) {
        c = std::sqrt(c);
        b *= -0.5;
        roots[0] = std::cbrt(b + c) + std::cbrt(b - c) - c2 / 3.0;
        n_roots = 1;
    } else {
        c = 3.0 * b / (2.0 * a) * std::sqrt(-3.0 / a);
        double d = 2.0 * std::sqrt(-a / 3.0);
        roots[0] = d * std::cos(std::acos(c) / 3.0) - c2 / 3.0;
        roots[1] = d * std::cos(std::acos(c) / 3.0 - 2.09439510239319526263557236234192) - c2 / 3.0; // 2*pi/3
        roots[2] = d * std::cos(std::acos(c) / 3.0 - 4.18879020478639052527114472468384) - c2 / 3.0; // 4*pi/3
        n_roots = 3;
    }

    // single newton iteration
    for (int i = 0; i < n_roots; ++i) {
        double x = roots[i];
        double x2 = x * x;
        double x3 = x * x2;
        double dx = -(x3 + c2 * x2 + c1 * x + c0) / (3 * x2 + 2 * c2 * x + c1);
        roots[i] += dx;
    }
    return n_roots;
}

/* Solves the quartic equation x^4 + b*x^3 + c*x^2 + d*x + e = 0 */
void solve_quartic(double b, double c, double d, double e, std::complex<double> roots[4]) {

    // Find depressed quartic
    std::complex<double> p = c - 3.0 * b * b / 8.0;
    std::complex<double> q = b * b * b / 8.0 - 0.5 * b * c + d;
    std::complex<double> r = (-3.0 * b * b * b * b + 256.0 * e - 64.0 * b * d + 16.0 * b * b * c) / 256.0;

    // Resolvent cubic is now
    // U^3 + 2*p U^2 + (p^2 - 4*r) * U - q^2
    std::complex<double> bb = 2.0 * p;
    std::complex<double> cc = p * p - 4.0 * r;
    std::complex<double> dd = -q * q;

    // Solve resolvent cubic
    std::complex<double> d0 = bb * bb - 3.0 * cc;
    std::complex<double> d1 = 2.0 * bb * bb * bb - 9.0 * bb * cc + 27.0 * dd;

    std::complex<double> C3 = (d1.real() < 0) ? (d1 - sqrt(d1 * d1 - 4.0 * d0 * d0 * d0)) / 2.0
                                              : (d1 + sqrt(d1 * d1 - 4.0 * d0 * d0 * d0)) / 2.0;

    std::complex<double> C;
    if (C3.real() < 0)
        C = -std::pow(-C3, 1.0 / 3);
    else
        C = std::pow(C3, 1.0 / 3);

    std::complex<double> u2 = (bb + C + d0 / C) / -3.0;

    // std::complex<double> db = u2 * u2 * u2 + bb * u2 * u2 + cc * u2 + dd;

    std::complex<double> u = sqrt(u2);

    std::complex<double> s = -u;
    std::complex<double> t = (p + u * u + q / u) / 2.0;
    std::complex<double> v = (p + u * u - q / u) / 2.0;

    roots[0] = (-u - sign2(u) * sqrt(u * u - 4.0 * v)) / 2.0;
    roots[1] = v / roots[0];
    roots[2] = (-s - sign2(s) * sqrt(s * s - 4.0 * t)) / 2.0;
    roots[3] = t / roots[2];

    for (int i = 0; i < 4; i++) {
        roots[i] = roots[i] - b / 4.0;

        // do one step of newton refinement
        std::complex<double> x = roots[i];
        std::complex<double> x2 = x * x;
        std::complex<double> x3 = x * x2;
        std::complex<double> dx =
            -(x2 * x2 + b * x3 + c * x2 + d * x + e) / (4.0 * x3 + 3.0 * b * x2 + 2.0 * c * x + d);
        roots[i] = x + dx;
    }
}

/* Solves the quartic equation x^4 + b*x^3 + c*x^2 + d*x + e = 0 */
int solve_quartic_real(double b, double c, double d, double e, double roots[4]) {

    // Find depressed quartic
    double p = c - 3.0 * b * b / 8.0;
    double q = b * b * b / 8.0 - 0.5 * b * c + d;
    double r = (-3.0 * b * b * b * b + 256.0 * e - 64.0 * b * d + 16.0 * b * b * c) / 256.0;

    // Resolvent cubic is now
    // U^3 + 2*p U^2 + (p^2 - 4*r) * U - q^2
    double bb = 2.0 * p;
    double cc = p * p - 4.0 * r;
    double dd = -q * q;

    // Solve resolvent cubic
    double u2;
    solve_cubic_single_real(bb, cc, dd, u2);

    if (u2 < 0)
        return 0;

    double u = sqrt(u2);

    double s = -u;
    double t = (p + u * u + q / u) / 2.0;
    double v = (p + u * u - q / u) / 2.0;

    int sols = 0;
    double disc = u * u - 4.0 * v;
    if (disc > 0) {
        roots[0] = (-u - sign(u) * std::sqrt(disc)) / 2.0;
        roots[1] = v / roots[0];
        sols += 2;
    }
    disc = s * s - 4.0 * t;
    if (disc > 0) {
        roots[sols] = (-s - sign(s) * std::sqrt(disc)) / 2.0;
        roots[sols + 1] = t / roots[sols];
        sols += 2;
    }

    for (int i = 0; i < sols; i++) {
        roots[i] = roots[i] - b / 4.0;

        // do one step of newton refinement
        double x = roots[i];
        double x2 = x * x;
        double x3 = x * x2;
        double dx = -(x2 * x2 + b * x3 + c * x2 + d * x + e) / (4.0 * x3 + 3.0 * b * x2 + 2.0 * c * x + d);
        roots[i] = x + dx;
    }
    return sols;
}

}; // namespace univariate
}; // namespace poselib

ext: cc

max_stars_repo_name: MikhailTerekhov/PoseLib

max_issues_repo_name: wuyuanmm/PoseLib

max_forks_repo_name: wuyuanmm/PoseLib


text:
//==============================================================================
//         Copyright 2003 - 2011 LASMEA UMR 6602 CNRS/Univ. Clermont II
//         Copyright 2009 - 2011 LRI    UMR 8623 CNRS/Univ Paris Sud XI
//
//          Distributed under the Boost Software License, Version 1.0.
//                 See accompanying file LICENSE.txt or copy at
//                     http://www.boost.org/LICENSE_1_0.txt
//==============================================================================
#ifndef BOOST_SIMD_SWAR_FUNCTIONS_SIMD_SSE_SSE2_LOOKUP_HPP_INCLUDED
#define BOOST_SIMD_SWAR_FUNCTIONS_SIMD_SSE_SSE2_LOOKUP_HPP_INCLUDED
#ifdef BOOST_SIMD_HAS_SSE2_SUPPORT
#include <boost/simd/swar/functions/lookup.hpp>
#include <boost/dispatch/meta/as_floating.hpp>
#include <boost/simd/sdk/meta/size.hpp>
#include <boost/dispatch/meta/strip.hpp>
#include <boost/simd/sdk/memory/aligned_type.hpp>

/////////////////////////////////////////////////////////////////////////////
// Implementation when type A0 is arithmetic_
/////////////////////////////////////////////////////////////////////////////
namespace boost { namespace simd { namespace ext
{
  BOOST_SIMD_FUNCTOR_IMPLEMENTATION( boost::simd::tag::lookup_, boost::simd::tag::sse2_
                            , (A0)(A1)
                            , ((simd_<arithmetic_<A0>,boost::simd::tag::sse_>))((simd_<integer_<A1>,boost::simd::tag::sse_>))
                            )
  {

    typedef A0 result_type;

    BOOST_SIMD_FUNCTOR_CALL(2)
    {
      typedef typename meta::scalar_of<A0>::type sA0;
      BOOST_SIMD_ALIGNED_TYPE(sA0) tmp[meta::cardinal_of<A0>::value];
      BOOST_SIMD_ALIGNED_TYPE(sA0) tmp1[meta::cardinal_of<A0>::value];
      boost::simd::store<A0>(a0, &tmp[0], 0);

      for(unsigned int i=0; i < meta::cardinal_of<A0>::value; i++) { tmp1[i] = tmp[a1[i]]; }// TODO unroll
      return boost::simd::load<A0>(&tmp1[0], 0);
    }
  };
} } }

#endif
#endif

ext: hpp


text:
#include "echo_session.h"
#include <boost/bind.hpp>
#include <memory>
#include <time.h>

#include "read_awaiter.h"
#include "std_future.hpp"
#include "write_awaiter.h"

#define BUF_LEN 1024

std::future<void> EchoSession::run(tcp::socket sock) {
  char buf[BUF_LEN];

  while (true) {
    size_t bytes_read = co_await AsyncRead(sock, boost::asio::buffer(buf));
    std::cout << "Server get message: " << buf << std::endl;
    co_await AsyncWrite(sock, {buf, bytes_read});
    std::cout << "Server has sent message" << std::endl;
  }
}

ext: cpp

max_stars_repo_name: maxerMU/db-course

max_issues_repo_name: maxerMU/db-course

max_forks_repo_name: maxerMU/db-course


text:
#ifndef FBi_SERVER_IF_HPP
#define FBi_SERVER_IF_HPP

#include <http_server/libhttp_server_config.h>
#include <boost/asio/io_service.hpp>
#include <boost/function.hpp>

namespace FBi
{

typedef boost::function< void() > MeetMaxConnectionNumCallback;

/// Abstract interfaces for server.
class LIBHTTPSERVER_DECL IServer
{
public:
	/// For the destrcutor of child can be called correctly.
	virtual ~IServer() {}

	/// Interface to start server
	virtual void StartServer() = 0;

	/// Interface to stop server
	virtual void StopServer() = 0;

	/**
	 * @brief Interface to register the callback function for the max connection number fit the limitation.
	 *
	 * @param[in] callback The callback function to be registered.
	 */
	virtual void RegisterMeetMaxConnectionCallback(const MeetMaxConnectionNumCallback& callback) = 0;
};

}

#endif


text:
#ifndef __FILESYSTEM_HPP__
#define __FILESYSTEM_HPP__

#if defined(SIRIUS_BOOST_FILESYSTEM)

#include <boost/filesystem.hpp>

namespace fs = boost::filesystem;

#elif defined(SIRIUS_STD_FILESYSTEM_EXPERIMENTAL)

#include <experimental/filesystem>

namespace fs = std::experimental::filesystem;

#else

#include <filesystem>

namespace fs = std::filesystem;

#endif // BOOST_FILESYSTEM__

#endif // __FILESYSTEM_HPP__

max_stars_repo_name: mtaillefumier/SIRIUS

max_issues_repo_name: simonpintarelli/SIRIUS

max_forks_repo_name: simonpintarelli/SIRIUS


text:
#include <boost/python.hpp>

#include <ast.hpp>
#include <type.hpp>
#include <util.hpp>
#include <exception.hpp>
#include <abstraction.hpp>
#include <logging.hpp>
#include <EqvChecker.hpp>
#include <uclid5.hpp>

using namespace boost::python;
using namespace ila;

BOOST_PYTHON_MODULE(ila)
{
    initLogging();

    // setup the exception translator.
    register_exception_translator
        <PyILAException>(translateILAException);

    // Enum for the types we recognize.
    enum_<NodeType::Type>("Types")
        .value("INVALID", NodeType::INVALID)
        .value("BOOL", NodeType::BOOL)
        .value("BITVECTOR", NodeType::BITVECTOR)
        .value("MEM", NodeType::MEM)
    ;

    // This is the typename + size (so the "real" type).
    class_<NodeType>("Type", init<>())
        .def_readonly("bitwidth", &NodeType::bitWidth)
        .def_readonly("addrwidth", &NodeType::addrWidth)
        .def_readonly("datawidth", &NodeType::dataWidth)
        .def(init<NodeType::Type>())
        .def(init<NodeType::Type, int>())
        .def(init<NodeType::Type, int, int>())
        .def(self_ns::str(self))
        .def(!self)
    ;

    // This is the real node type.
    class_<NodeRef>("Node")
        .add_property("name", &NodeRef::getName)
        .add_property("type", &NodeRef::getType)
        .def("equal", &NodeRef::equal)
        .def_readonly("value", &NodeRef::value)
        // unary operators.
        .def("__invert__",
                &NodeRef::complement,
                return_value_policy<manage_new_object>())
        .def("__neg__",
                &NodeRef::negate,
                return_value_policy<manage_new_object>())

        // logical operators.
        .def("__and__",
                &NodeRef::logicalAnd,
                return_value_policy<manage_new_object>())
        .def("__and__",
                &NodeRef::logicalAndInt,
                return_value_policy<manage_new_object>())
        .def("__rand__",
                &NodeRef::logicalAndRInt,
                return_value_policy<manage_new_object>())

        .def("__or__",
                &NodeRef::logicalOr,
                return_value_policy<manage_new_object>())
        .def("__or__",
                &NodeRef::logicalOrInt,
                return_value_policy<manage_new_object>())
        .def("__ror__",
                &NodeRef::logicalOrRInt,
                return_value_policy<manage_new_object>())

        .def("__xor__",
                &NodeRef::logicalXor,
                return_value_policy<manage_new_object>())
        .def("__xor__",
                &NodeRef::logicalXorInt,
                return_value_policy<manage_new_object>())
        .def("__rxor__",
                &NodeRef::logicalXorRInt,
                return_value_policy<manage_new_object>())

        // arithmetic operators.
        .def("__add__",
                &NodeRef::add,
                return_value_policy<manage_new_object>())
        .def("__add__",
                &NodeRef::addInt,
                return_value_policy<manage_new_object>())
        .def("__radd__",
                &NodeRef::raddInt,
                return_value_policy<manage_new_object>())
        .def("__sub__",
                &NodeRef::sub,
                return_value_policy<manage_new_object>())
        .def("__sub__",
                &NodeRef::subInt,
                return_value_policy<manage_new_object>())
        .def("__rsub__",
                &NodeRef::rsubInt,
                return_value_policy<manage_new_object>())
        .def("__mul__",
                &NodeRef::mul,
                return_value_policy<manage_new_object>())
        .def("__mul__",
                &NodeRef::mulInt,
                return_value_policy<manage_new_object>())
        .def("__rmul__",
                &NodeRef::rmulInt,
                return_value_policy<manage_new_object>())
        .def("__div__",
                &NodeRef::udiv,
                return_value_policy<manage_new_object>())
        .def("__div__",
                &NodeRef::udivInt,
                return_value_policy<manage_new_object>())
        .def("__rdiv__",
                &NodeRef::rudivInt,
                return_value_policy<manage_new_object>())
        .def("__mod__",
                &NodeRef::urem,
                return_value_policy<manage_new_object>())
        .def("__mod__",
                &NodeRef::uremInt,
                return_value_policy<manage_new_object>())
        .def("__rmod__",
                &NodeRef::ruremInt,
                return_value_policy<manage_new_object>())
        .def("__lshift__",
                &NodeRef::shl,
                return_value_policy<manage_new_object>())
        .def("__lshift__",
                &NodeRef::shlInt,
                return_value_policy<manage_new_object>())
        .def("__rlshift__",
                &NodeRef::rshlInt,
                return_value_policy<manage_new_object>())
        .def("__rshift__",
                &NodeRef::lshr,
                return_value_policy<manage_new_object>())
        .def("__rshift__",
                &NodeRef::lshrInt,
                return_value_policy<manage_new_object>())
        .def("__rrshift__",
                &NodeRef::rlshrInt,
                return_value_policy<manage_new_object>())

        // comparison operators.
        .def("__eq__",
                &NodeRef::eq,
                return_value_policy<manage_new_object>())
        .def("__eq__",
                &NodeRef::eqInt,
                return_value_policy<manage_new_object>())
        .def("__ne__",
                &NodeRef::neq,
                return_value_policy<manage_new_object>())
        .def("__ne__",
                &NodeRef::neqInt,
                return_value_policy<manage_new_object>())
        .def("__lt__",
                &NodeRef::ult,
                return_value_policy<manage_new_object>())
        .def("__lt__",
                &NodeRef::ultInt,
                return_value_policy<manage_new_object>())
        .def("__le__",
                &NodeRef::ule,
                return_value_policy<manage_new_object>())
        .def("__le__",
                &NodeRef::uleInt,
                return_value_policy<manage_new_object>())
        .def("__gt__",
                &NodeRef::ugt,
                return_value_policy<manage_new_object>())
        .def("__gt__",
                &NodeRef::ugtInt,
                return_value_policy<manage_new_object>())
        .def("__ge__",
                &NodeRef::uge,
                return_value_policy<manage_new_object>())
        .def("__ge__",
                &NodeRef::ugeInt,
                return_value_policy<manage_new_object>())

        // slice operator
        .def("__getslice__",
                &NodeRef::slice,
                return_value_policy<manage_new_object>())
        // get bit operator
        .def("__getitem__",
                &NodeRef::getItem,
                return_value_policy<manage_new_object>())
        .def("__getitem__",
                &NodeRef::getItemInt,
                return_value_policy<manage_new_object>())

        // set reference name
        .def("setRefName",
                &NodeRef::setRefName)

        .def(self_ns::str(self))

        .def("__hash__", &NodeRef::hash)
    ;

    // functions which expose operators on nodes.

    // memory load.
    def("load", &NodeRef::load,
            return_value_policy<manage_new_object>());
    def("loadblk", &NodeRef::loadblock,
            return_value_policy<manage_new_object>());
    def("loadblk_big", &NodeRef::loadblockB,
            return_value_policy<manage_new_object>());
    // memory write.
    def("store", &NodeRef::store,
            return_value_policy<manage_new_object>());
    def("storeblk", &NodeRef::storeblock,
            return_value_policy<manage_new_object>());
    def("storeblk_big", &NodeRef::storeblockB,
            return_value_policy<manage_new_object>());

    // logical operators.
    def("nand", &NodeRef::logicalNand,
            return_value_policy<manage_new_object>());
    def("nor", &NodeRef::logicalNor,
            return_value_policy<manage_new_object>());
    def("xnor", &NodeRef::logicalXnor,
            return_value_policy<manage_new_object>());

    // arithmetic operators.
    def("sdiv", &NodeRef::sdiv,
            return_value_policy<manage_new_object>());
    def("sdiv", &NodeRef::sdivInt,
            return_value_policy<manage_new_object>());
    def("sdiv", &NodeRef::rsdivInt,
            return_value_policy<manage_new_object>());
    def("smod", &NodeRef::smod,
            return_value_policy<manage_new_object>());
    def("smod", &NodeRef::smodInt,
            return_value_policy<manage_new_object>());
    def("smod", &NodeRef::rsmodInt,
            return_value_policy<manage_new_object>());
    def("srem", &NodeRef::srem,
            return_value_policy<manage_new_object>());
    def("srem", &NodeRef::sremInt,
            return_value_policy<manage_new_object>());
    def("srem", &NodeRef::rsremInt,
            return_value_policy<manage_new_object>());
    def("ashr", &NodeRef::ashr,
            return_value_policy<manage_new_object>());
    def("ashr", &NodeRef::ashrInt,
            return_value_policy<manage_new_object>());
    def("ashr", &NodeRef::rashrInt,
            return_value_policy<manage_new_object>());

    // manipulate operators.
    def("concat", &NodeRef::concat,
            return_value_policy<manage_new_object>());
    def("concat", &NodeRef::concatList,
            return_value_policy<manage_new_object>());
    def("lrotate", &NodeRef::lrotate,
            return_value_policy<manage_new_object>());
    def("rrotate", &NodeRef::rrotate,
            return_value_policy<manage_new_object>());
    def("zero_extend", &NodeRef::zero_extend,
            return_value_policy<manage_new_object>());
    def("sign_extend", &NodeRef::sign_extend,
            return_value_policy<manage_new_object>());

    // comparison operators.
    def("slt", &NodeRef::slt,
            return_value_policy<manage_new_object>());
    def("slt", &NodeRef::sltInt,
            return_value_policy<manage_new_object>());
    def("sle", &NodeRef::sle,
            return_value_policy<manage_new_object>());
    def("sle", &NodeRef::sleInt,
            return_value_policy<manage_new_object>());
    def("sgt", &NodeRef::sgt,
            return_value_policy<manage_new_object>());
    def("sgt", &NodeRef::sgtInt,
            return_value_policy<manage_new_object>());
    def("sge", &NodeRef::sge,
            return_value_policy<manage_new_object>());
    def("sge", &NodeRef::sgeInt,
            return_value_policy<manage_new_object>());

    // nonzero.
    def("nonzero", &NodeRef::nonzero,
            return_value_policy<manage_new_object>());
    // imply.
    def("implies", &NodeRef::imply,
            return_value_policy<manage_new_object>());
    // ite.
    def("ite", &NodeRef::ite,
            return_value_policy<manage_new_object>());

    // constant may not rely on instances
    def("const", &AbstractionWrapper::bvConstLongStatic, return_value_policy<manage_new_object>());
    def("const", &AbstractionWrapper::bvConstIntStatic, return_value_policy<manage_new_object>());
    def("const", &AbstractionWrapper::memConstStatic, return_value_policy<manage_new_object>());
    def("bool", &AbstractionWrapper::boolConstBStatic, return_value_policy<manage_new_object>());
    def("bool", &AbstractionWrapper::boolConstIStatic, return_value_policy<manage_new_object>());
    def("bool", &AbstractionWrapper::boolConstLStatic, return_value_policy<manage_new_object>());

    // apply function.
    def("appfun", &NodeRef::appfunc0,
            return_value_policy<manage_new_object>());
    def("appfun", &NodeRef::appfunc1,
            return_value_policy<manage_new_object>());
    def("appfun", &NodeRef::appfunc2,
            return_value_policy<manage_new_object>());
    def("appfun", &NodeRef::appfuncL,
            return_value_policy<manage_new_object>());

    // choice
    def("choice", &NodeRef::choice2,
            return_value_policy<manage_new_object>());
    def("choice", &NodeRef::choice3,
            return_value_policy<manage_new_object>());
    def("choice", &NodeRef::choice4,
            return_value_policy<manage_new_object>());
    def("choice", &NodeRef::choice5,
            return_value_policy<manage_new_object>());
    def("choice", &NodeRef::choice6,
            return_value_policy<manage_new_object>());
    def("choice", &NodeRef::choiceL,
            return_value_policy<manage_new_object>());

    // inrange
    def("inrange", &NodeRef::inRange,
            return_value_policy<manage_new_object>());

    // readslice.
    def("readslice", &NodeRef::readSlice,
            return_value_policy<manage_new_object>());

    // readchunk.
    def("readchunk", &NodeRef::readChunk,
            return_value_policy<manage_new_object>());

    // writeslice
    def("writeslice", &NodeRef::writeSlice,
            return_value_policy<manage_new_object>());

    // writechunk
    def("writechunk", &NodeRef::writeChunk,
            return_value_policy<manage_new_object>());

    // simplify.
    def("simplify", &NodeRef::simplify,
            return_value_policy<manage_new_object>());
    // logging.
    def("setloglevel", &ila::setLogLevel);
    def("enablelog", &ila::enableLog);
    def("disablelog", &ila::disableLog);
    def("clearlogs", &ila::clearLogs);

    // bmc
    def("bmc", &AbstractionWrapper::bmc);
    // EQcheckSimple
    def("eqcheckSimple",&AbstractionWrapper::EQcheckSimple);
    def("eqcheck",&AbstractionWrapper::EQcheck);
    def("eqcheck",&AbstractionWrapper::EQcheckWithAssump,
        (arg("u1"),arg("u2"),
         arg("s1"),arg("s2"),arg("assumption")) );
    def("eqcheckExport",&AbstractionWrapper::EQcheckExport);
    def("eqcheckExport",&AbstractionWrapper::EQcheckWithAssumpExport,
        (arg("filename"), arg("u1"),arg("u2"),
         arg("s1"),arg("s2"),arg("assumption")) );

    // This is the top-level class.
    class_<AbstractionWrapper>("Abstraction", init<const std::string&>())
        // the name of this abstraction
        .def_readonly("name", &AbstractionWrapper::getName)

        // inputs
        .def("inp", &AbstractionWrapper::addInp, return_value_policy<manage_new_object>())
        .def("getinp", &AbstractionWrapper::getInp, return_value_policy<manage_new_object>())
        // bits.
        .def("bit", &AbstractionWrapper::addBit, return_value_policy<manage_new_object>())
        .def("getbit", &AbstractionWrapper::getBit, return_value_policy<manage_new_object>())
        // registers.
        .def("reg", &AbstractionWrapper::addReg, return_value_policy<manage_new_object>())
        .def("getreg", &AbstractionWrapper::getReg, return_value_policy<manage_new_object>())
        // memories.
        .def("mem", &AbstractionWrapper::addMem, return_value_policy<manage_new_object>())
        .def("getmem", &AbstractionWrapper::getMem, return_value_policy<manage_new_object>())
        // functions.
        .def("fun", &AbstractionWrapper::addFun, return_value_policy<manage_new_object>())
        .def("getfun", &AbstractionWrapper::getFun, return_value_policy<manage_new_object>())

        // init function
        .def("set_init", &AbstractionWrapper::setInit)
        .def("get_init", &AbstractionWrapper::getInit, return_value_policy<manage_new_object>())
        // ipred
        .def("set_ipred", &AbstractionWrapper::setIpred)
        .def("get_ipred", &AbstractionWrapper::getIpred, return_value_policy<manage_new_object>())
        // next function
        .def("set_next", &AbstractionWrapper::setNext)
        .def("get_next", &AbstractionWrapper::getNext, return_value_policy<manage_new_object>())
        .def("get_next", &AbstractionWrapper::getNextI, return_value_policy<manage_new_object>())
        // uabs
        .def("add_microabstraction", &AbstractionWrapper::addUAbs,
                                     return_value_policy<manage_new_object>())
        .def("get_microabstraction", &AbstractionWrapper::getUAbs,
                                     return_value_policy<manage_new_object>())
        .def("connect_microabstraction", &AbstractionWrapper::connectUInst)
        // constants.
        .def("const", &AbstractionWrapper::bvConstLong, return_value_policy<manage_new_object>())
        .def("const", &AbstractionWrapper::bvConstInt, return_value_policy<manage_new_object>())
        .def("const", &AbstractionWrapper::memConst, return_value_policy<manage_new_object>())
        .def("bool", &AbstractionWrapper::boolConstB, return_value_policy<manage_new_object>())
        .def("bool", &AbstractionWrapper::boolConstI, return_value_policy<manage_new_object>())
        .def("bool", &AbstractionWrapper::boolConstL, return_value_policy<manage_new_object>())

        // synthesis.
        .def("synthesize", &AbstractionWrapper::synthesizeAll)
        .def("synthesize", &AbstractionWrapper::synthesizeReg)
        .def("syn_elem", &AbstractionWrapper::synthesizeElement, return_value_policy<manage_new_object>())

        // smt solver.
        .def("areEqual", &AbstractionWrapper::areEqual)
        .def("areEqual", &AbstractionWrapper::areEqualAssump)
        .def("areEqualUnrolled", &AbstractionWrapper::areEqualUnrolled)
        // boogie
        .def("toBoogie", &AbstractionWrapper::toBoogie)
        // uclid5
        .def("toUclid5", &AbstractionWrapper::toUclid5)

        // hornify all abstraction
        .def("hornifyAll", &AbstractionWrapper::hornifyAll)
        // hornify one ast node
        .def("hornifyNode", &AbstractionWrapper::hornifyNode)
        // generate horn clause mapping
        .def("generateHornMapping", &AbstractionWrapper::generateHornMapping)
        // create an instruction for horn clause generation
        .def("addHornInstr", &AbstractionWrapper::addHornInstr)
        // create a child-instruction for horn clause generation
        .def("addHornChild", &AbstractionWrapper::addHornChild)
        // add next state function for an instruction
        .def("addHornNext", &AbstractionWrapper::addHornNext)
        // set flag to hornify ite as node (default true)
        .def("hornifyIteAsNode", &AbstractionWrapper::hornifyIteAsNode)
        // set flag to hornify bitvector as Int (default true)
        .def("hornifyBvAsInt", &AbstractionWrapper::hornifyBvAsInt)
        // export horn to file
        .def("exportHornToFile", &AbstractionWrapper::exportHornToFile)

        // assumptions.
        .def("add_assumption", &AbstractionWrapper::addAssumption)
        .def("get_all_assumptions", &AbstractionWrapper::getAllAssumptions)

        // import/export.
        .def("exportOne", &AbstractionWrapper::exportOneToFile)
        .def("exportList", &AbstractionWrapper::exportListToFile)
        .def("exportAll", &AbstractionWrapper::exportAllToFile)
        .def("importOne", &AbstractionWrapper::importOneFromFile, return_value_policy<manage_new_object>())
        .def("importList", &AbstractionWrapper::importListFromFile)
        .def("importAll", &AbstractionWrapper::importAllFromFile)
        .def("generateVerilog", &AbstractionWrapper::generateVerilogToFile)
        .def("generateVerilog", &AbstractionWrapper::generateVerilogModule)

        // simulator.
        .def("generateSim", &AbstractionWrapper::generateSimToFile)
        .def("generateSimToDir", &AbstractionWrapper::generateSimToDir)

        // CBMC verification
        .def("generateCbmcC", &AbstractionWrapper::generateCbmcCtoFile)
        .def("generateCbmcCtoDir", &AbstractionWrapper::generateCbmcCtoDir)

        // generate unroller
        .def("newUnroller", &AbstractionWrapper::newUnroller,
        (arg("uILA"), arg("setInitCondition")) ,return_value_policy<manage_new_object>())

        // individual Abstraction bmc
        .def("bmcInit", &AbstractionWrapper::bmcInit, (arg("assertion"),arg("bound"),arg("init")))
        .def("bmcCond", &AbstractionWrapper::bmcCond, (arg("assertion"), arg("bound"), arg("assumpt")))

        // configure Verilg export
        .def("verilogExpConfig",&AbstractionWrapper::setVlgExpConfig, (arg("externalMemory"), arg("funcAsModule")))

        .add_property("fetch_expr",
            make_function(&AbstractionWrapper::getFetchExpr, return_value_policy<manage_new_object>()),
            &AbstractionWrapper::setFetchExpr)
        .add_property("fetch_valid",
            make_function(&AbstractionWrapper::getFetchValid, return_value_policy<manage_new_object>()),
            &AbstractionWrapper::setFetchValid)

        .add_property("decode_exprs",
            &AbstractionWrapper::getDecodeExpressions,
            &AbstractionWrapper::setDecodeExpressions)

        .add_property("enable_parameterized_synthesis",
            &AbstractionWrapper::getEnParamSyn,
            &AbstractionWrapper::setEnParamSyn)

        .add_property("enable_reduce_when_import",
            &AbstractionWrapper::getReduceWhenImport,
            &AbstractionWrapper::setReduceWhenImport)

    ;

    class_<Uclid5Translator>("Uclid5Translator", no_init)
        .def("initVar", &Uclid5Translator::initVar)
        .def("setVar", &Uclid5Translator::setVar)
        .def("getExprValues", &Uclid5Translator::getExprValues)
	.def("getTranslation", &Uclid5Translator::getTranslation)
        .def("simplify", &Uclid5Translator::simplify,
                return_value_policy<manage_new_object>());
    ;

    class_<MicroUnroller>("MicroUnroller", no_init)
        .def("addAssumption", &MicroUnroller::addAssumption)
        .def("checkAssertion", &MicroUnroller::checkAssertion)
        .def("dumpAssertion", &MicroUnroller::dumpAssertion)
        .def("unrollTo", &MicroUnroller::unrollToStep)
    ;

    class_<MemValues>("MemValues", init<int, int, const object&>())
        .add_property("default", &MemValues::getDefault, &MemValues::setDefault)
        .def_readonly("values", &MemValues::getValues)
        .def("__getitem__", &MemValues::getItem)
        .def("__setitem__", &MemValues::setItem)
        .def("__repr__", &MemValues::str)
        .def(self_ns::str(self))
    ;
}

max_stars_repo_name: pramodsu/ILA-Tools

max_issues_repo_name: pramodsu/ILA-Tools

max_forks_repo_name: pramodsu/ILA-Tools