/* Generated by fuzzing - test hash_head == 0 handling. */

#include "zbuild.h"
#ifdef ZLIB_COMPAT
#  include "zlib.h"
#else
#  include "zlib-ng.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    PREFIX3(stream) strm;
    memset(&strm, 0, sizeof(strm));

    int ret = PREFIX(deflateInit2)(&strm, 1, Z_DEFLATED, -15, 4, Z_HUFFMAN_ONLY);
    if (ret != Z_OK) {
        fprintf(stderr, "deflateInit2() failed with code %d\n", ret);
        return EXIT_FAILURE;
    }

    unsigned char next_in[9698];
    memset(next_in, 0x30, sizeof(next_in));
    next_in[8193] = 0x00;
    next_in[8194] = 0x00;
    next_in[8195] = 0x00;
    next_in[8199] = 0x8a;
    strm.next_in = next_in;
    unsigned char next_out[21572];
    strm.next_out = next_out;

    strm.avail_in = 0;
    strm.avail_out = 1348;
    ret = PREFIX(deflateParams(&strm, 3, Z_FILTERED));
    if (ret != Z_OK) {
        fprintf(stderr, "deflateParams() failed with code %d\n", ret);
        return EXIT_FAILURE;
    }

    strm.avail_in = 6728;
    strm.avail_out = 2696;
    ret = PREFIX(deflate(&strm, Z_SYNC_FLUSH));
    if (ret != Z_OK) {
        fprintf(stderr, "deflate() failed with code %d\n", ret);
        return EXIT_FAILURE;
    }

    strm.avail_in = 15;
    strm.avail_out = 1348;
    ret = PREFIX(deflateParams(&strm, 9, Z_FILTERED));
    if (ret != Z_OK) {
        fprintf(stderr, "deflateParams() failed with code %d\n", ret);
        return EXIT_FAILURE;
    }

    strm.avail_in = 1453;
    strm.avail_out = 1348;
    ret = PREFIX(deflate(&strm, Z_FULL_FLUSH));
    if (ret != Z_OK) {
        fprintf(stderr, "deflate() failed with code %d\n", ret);
        return EXIT_FAILURE;
    }

    strm.avail_in = (uint32_t)(next_in + sizeof(next_in) - strm.next_in);
    strm.avail_out = (uint32_t)(next_out + sizeof(next_out) - strm.next_out);
    ret = PREFIX(deflate)(&strm, Z_FINISH);
    if (ret != Z_STREAM_END) {
        fprintf(stderr, "deflate() failed with code %d\n", ret);
        return EXIT_FAILURE;
    }
    uint32_t compressed_size = (uint32_t)(strm.next_out - next_out);

    ret = PREFIX(deflateEnd)(&strm);
    if (ret != Z_OK) {
        fprintf(stderr, "deflateEnd() failed with code %d\n", ret);
        return EXIT_FAILURE;
    }

    memset(&strm, 0, sizeof(strm));
    ret = PREFIX(inflateInit2)(&strm, -15);
    if (ret != Z_OK) {
        fprintf(stderr, "inflateInit2() failed with code %d\n", ret);
        return EXIT_FAILURE;
    }

    strm.next_in = next_out;
    strm.avail_in = compressed_size;
    unsigned char uncompressed[sizeof(next_in)];
    strm.next_out = uncompressed;
    strm.avail_out = sizeof(uncompressed);

    ret = PREFIX(inflate)(&strm, Z_NO_FLUSH);
    if (ret != Z_STREAM_END) {
        fprintf(stderr, "inflate() failed with code %d\n", ret);
        return EXIT_FAILURE;
    }

    ret = PREFIX(inflateEnd)(&strm);
    if (ret != Z_OK) {
        fprintf(stderr, "inflateEnd() failed with code %d\n", ret);
        return EXIT_FAILURE;
    }

    if (memcmp(uncompressed, next_in, sizeof(uncompressed)) != 0) {
        fprintf(stderr, "Uncompressed data differs from the original\n");
        return EXIT_FAILURE;
    }
}
