static std::vector<char> readFile(const char* filename)
{
std::filebuf filebuf;
if(filebuf.open(filename, std::ios::in) == nullptr)
throw std::runtime_error("Cannot open input file.");
std::streamoff fileSize;
if((fileSize = filebuf.pubseekoff(0, std::ios::end, std::ios::in)) == -1)
throw std::runtime_error("Cannot get the size of the input file.");
const auto bufferSize = fileSize + 1;
if(bufferSize >= std::numeric_limits<std::size_t>::max())
throw std::bad_alloc();
std::vector<char> result(static_cast<std::size_t>(bufferSize), '\0');
if(filebuf.sgetn(&result[0], static_cast<std::streamsize>(fileSize)) != fileSize)
throw std::runtime_error("Cannot read the input file.");
return result;
}
c3RhdGljIHN0ZDo6dmVjdG9yPGNoYXI+IHJlYWRGaWxlKGNvbnN0IGNoYXIqIGZpbGVuYW1lKQp7CiAgc3RkOjpmaWxlYnVmIGZpbGVidWY7CiAgaWYoZmlsZWJ1Zi5vcGVuKGZpbGVuYW1lLCBzdGQ6Omlvczo6aW4pID09IG51bGxwdHIpCiAgICB0aHJvdyBzdGQ6OnJ1bnRpbWVfZXJyb3IoIkNhbm5vdCBvcGVuIGlucHV0IGZpbGUuIik7CgogIHN0ZDo6c3RyZWFtb2ZmIGZpbGVTaXplOwogIGlmKChmaWxlU2l6ZSA9IGZpbGVidWYucHVic2Vla29mZigwLCBzdGQ6Omlvczo6ZW5kLCBzdGQ6Omlvczo6aW4pKSA9PSAtMSkKICAgIHRocm93IHN0ZDo6cnVudGltZV9lcnJvcigiQ2Fubm90IGdldCB0aGUgc2l6ZSBvZiB0aGUgaW5wdXQgZmlsZS4iKTsKCiAgY29uc3QgYXV0byBidWZmZXJTaXplID0gZmlsZVNpemUgKyAxOwogIGlmKGJ1ZmZlclNpemUgPj0gc3RkOjpudW1lcmljX2xpbWl0czxzdGQ6OnNpemVfdD46Om1heCgpKQogICAgdGhyb3cgc3RkOjpiYWRfYWxsb2MoKTsKCiAgc3RkOjp2ZWN0b3I8Y2hhcj4gcmVzdWx0KHN0YXRpY19jYXN0PHN0ZDo6c2l6ZV90PihidWZmZXJTaXplKSwgJ1wwJyk7CiAgaWYoZmlsZWJ1Zi5zZ2V0bigmcmVzdWx0WzBdLCBzdGF0aWNfY2FzdDxzdGQ6OnN0cmVhbXNpemU+KGZpbGVTaXplKSkgIT0gZmlsZVNpemUpCiAgICB0aHJvdyBzdGQ6OnJ1bnRpbWVfZXJyb3IoIkNhbm5vdCByZWFkIHRoZSBpbnB1dCBmaWxlLiIpOwoKICByZXR1cm4gcmVzdWx0Owp9