/* vi: set sw=4 ts=4: */
/*
 * Gzip implementation for busybox
 *
 * Based on GNU gzip Copyright (C) 1992-1993 Jean-loup Gailly.
 *
 * Originally adjusted for busybox by Charles P. Wright <cpw@unix.asb.com>
 * "this is a stripped down version of gzip I put into busybox, it does
 * only standard in to standard out with -9 compression.  It also requires
 * the zcat module for some important functions."
 *
 * Adjusted further by Erik Andersen <andersen@codepoet.org> to support
 * files as well as stdin/stdout, and to generally behave itself wrt
 * command line handling.
 *
 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
 */
/* TODO: full support for -v for DESKTOP
 * "/usr/bin/gzip -v a bogus aa" should say:
a:       85.1% -- replaced with a.gz
gzip: bogus: No such file or directory
aa:      85.1% -- replaced with aa.gz
*/
//config:config GZIP
//config:	bool "gzip (17 kb)"
//config:	default y
//config:	help
//config:	gzip is used to compress files.
//config:	It's probably the most widely used UNIX compression program.
//config:
//config:config FEATURE_GZIP_LONG_OPTIONS
//config:	bool "Enable long options"
//config:	default y
//config:	depends on GZIP && LONG_OPTS
//config:
//config:config GZIP_FAST
//config:	int "Trade memory for speed (0:small,slow - 2:fast,big)"
//config:	default 0
//config:	range 0 2
//config:	depends on GZIP
//config:	help
//config:	Enable big memory options for gzip.
//config:	0: small buffers, small hash-tables
//config:	1: larger buffers, larger hash-tables
//config:	2: larger buffers, largest hash-tables
//config:	Larger models may give slightly better compression
//config:
//config:config FEATURE_GZIP_LEVELS
//config:	bool "Enable compression levels"
//config:	default n
//config:	depends on GZIP
//config:	help
//config:	Enable support for compression levels 4-9. The default level
//config:	is 6. If levels 1-3 are specified, 4 is used.
//config:	If this option is not selected, -N options are ignored and -6
//config:	is used.
//config:
//config:config FEATURE_GZIP_DECOMPRESS
//config:	bool "Enable decompression"
//config:	default y
//config:	depends on GZIP || GUNZIP || ZCAT
//config:	help
//config:	Enable -d (--decompress) and -t (--test) options for gzip.
//config:	This will be automatically selected if gunzip or zcat is
//config:	enabled.

//applet:IF_GZIP(APPLET(gzip, BB_DIR_BIN, BB_SUID_DROP))

//kbuild:lib-$(CONFIG_GZIP) += gzip.o

//usage:#define gzip_trivial_usage
//usage:       "[-cfk" IF_FEATURE_GZIP_DECOMPRESS("dt") IF_FEATURE_GZIP_LEVELS("123456789") "] [FILE]..."
//usage:#define gzip_full_usage "\n\n"
//usage:       "Compress FILEs (or stdin)\n"
//usage:	IF_FEATURE_GZIP_LEVELS(
//usage:     "\n	-1..9	Compression level"
//usage:	)
//usage:	IF_FEATURE_GZIP_DECOMPRESS(
//usage:     "\n	-d	Decompress"
//usage:	)
//usage:     "\n	-c	Write to stdout"
//usage:     "\n	-f	Force"
//usage:     "\n	-k	Keep input files"
//usage:	IF_FEATURE_GZIP_DECOMPRESS(
//usage:     "\n	-t	Test integrity"
//usage:	)
//usage:
//usage:#define gzip_example_usage
//usage:       "$ ls -la /tmp/busybox*\n"
//usage:       "-rw-rw-r--    1 andersen andersen  1761280 Apr 14 17:47 /tmp/busybox.tar\n"
//usage:       "$ gzip /tmp/busybox.tar\n"
//usage:       "$ ls -la /tmp/busybox*\n"
//usage:       "-rw-rw-r--    1 andersen andersen   554058 Apr 14 17:49 /tmp/busybox.tar.gz\n"

#include "libbb.h"
#include "bb_archive.h"

/* ===========================================================================
 */
//#define DEBUG 1
/* Diagnostic functions */
#ifdef DEBUG
static int verbose;
#  define Assert(cond,msg) { if (!(cond)) bb_simple_error_msg(msg); }
#  define Trace(x) fprintf x
#  define Tracev(x) {if (verbose) fprintf x; }
#  define Tracevv(x) {if (verbose > 1) fprintf x; }
#  define Tracec(c,x) {if (verbose && (c)) fprintf x; }
#  define Tracecv(c,x) {if (verbose > 1 && (c)) fprintf x; }
#else
#  define Assert(cond,msg)
#  define Trace(x)
#  define Tracev(x)
#  define Tracevv(x)
#  define Tracec(c,x)
#  define Tracecv(c,x)
#endif

/* ===========================================================================
 */
#if   CONFIG_GZIP_FAST == 0
# define SMALL_MEM
#elif CONFIG_GZIP_FAST == 1
# define MEDIUM_MEM
#elif CONFIG_GZIP_FAST == 2
# define BIG_MEM
#else
# error "Invalid CONFIG_GZIP_FAST value"
#endif

#ifndef INBUFSIZ
#  ifdef SMALL_MEM
#    define INBUFSIZ  0x2000	/* input buffer size */
#  else
#    define INBUFSIZ  0x8000	/* input buffer size */
#  endif
#endif

#ifndef OUTBUFSIZ
#  ifdef SMALL_MEM
#    define OUTBUFSIZ   8192	/* output buffer size */
#  else
#    define OUTBUFSIZ  16384	/* output buffer size */
#  endif
#endif

#ifndef DIST_BUFSIZE
#  ifdef SMALL_MEM
#    define DIST_BUFSIZE 0x2000	/* buffer for distances, see trees.c */
#  else
#    define DIST_BUFSIZE 0x8000	/* buffer for distances, see trees.c */
#  endif
#endif

/* gzip flag byte */
#define ASCII_FLAG   0x01	/* bit 0 set: file probably ascii text */
#define CONTINUATION 0x02	/* bit 1 set: continuation of multi-part gzip file */
#define EXTRA_FIELD  0x04	/* bit 2 set: extra field present */
#define ORIG_NAME    0x08	/* bit 3 set: original file name present */
#define COMMENT      0x10	/* bit 4 set: file comment present */
#define RESERVED     0xC0	/* bit 6,7:   reserved */

/* internal file attribute */
#define UNKNOWN 0xffff
#define BINARY  0
#define ASCII   1

#ifndef WSIZE
#  define WSIZE 0x8000  /* window size--must be a power of two, and */
#endif                  /*  at least 32K for zip's deflate method */

#define MIN_MATCH  3
#define MAX_MATCH  258
/* The minimum and maximum match lengths */

#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
/* Minimum amount of lookahead, except at the end of the input file.
 * See deflate.c for comments about the MIN_MATCH+1.
 */

#define MAX_DIST  (WSIZE-MIN_LOOKAHEAD)
/* In order to simplify the code, particularly on 16 bit machines, match
 * distances are limited to MAX_DIST instead of WSIZE.
 */

#ifndef MAX_PATH_LEN
#  define MAX_PATH_LEN   1024	/* max pathname length */
#endif

#define seekable()    0	/* force sequential output */
#define translate_eol 0	/* no option -a yet */

#ifndef BITS
#  define BITS 16
#endif
#define INIT_BITS 9		/* Initial number of bits per code */

#define BIT_MASK    0x1f	/* Mask for 'number of compression bits' */
/* Mask 0x20 is reserved to mean a fourth header byte, and 0x40 is free.
 * It's a pity that old uncompress does not check bit 0x20. That makes
 * extension of the format actually undesirable because old compress
 * would just crash on the new format instead of giving a meaningful
 * error message. It does check the number of bits, but it's more
 * helpful to say "unsupported format, get a new version" than
 * "can only handle 16 bits".
 */

#ifdef MAX_EXT_CHARS
#  define MAX_SUFFIX  MAX_EXT_CHARS
#else
#  define MAX_SUFFIX  30
#endif

/* ===========================================================================
 * Compile with MEDIUM_MEM to reduce the memory requirements or
 * with SMALL_MEM to use as little memory as possible. Use BIG_MEM if the
 * entire input file can be held in memory (not possible on 16 bit systems).
 * Warning: defining these symbols affects HASH_BITS (see below) and thus
 * affects the compression ratio. The compressed output
 * is still correct, and might even be smaller in some cases.
 */
#ifdef SMALL_MEM
#  define HASH_BITS  13	/* Number of bits used to hash strings */
#endif
#ifdef MEDIUM_MEM
#  define HASH_BITS  14
#endif
#ifndef HASH_BITS
#  define HASH_BITS  15
   /* For portability to 16 bit machines, do not use values above 15. */
#endif

#define HASH_SIZE (unsigned)(1<<HASH_BITS)
#define HASH_MASK (HASH_SIZE-1)
#define WMASK     (WSIZE-1)
/* HASH_SIZE and WSIZE must be powers of two */
#ifndef TOO_FAR
#  define TOO_FAR 4096
#endif
/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */

/* ===========================================================================
 * These types are not really 'char', 'short' and 'long'
 */
typedef uint8_t uch;
typedef uint16_t ush;
typedef uint32_t ulg;
typedef int32_t lng;

typedef ush Pos;
typedef unsigned IPos;
/* A Pos is an index in the character window. We use short instead of int to
 * save space in the various tables. IPos is used only for parameter passing.
 */

enum {
	WINDOW_SIZE = 2 * WSIZE,
/* window size, 2*WSIZE except for MMAP or BIG_MEM, where it is the
 * input file length plus MIN_LOOKAHEAD.
 */

#if !ENABLE_FEATURE_GZIP_LEVELS

	comp_level_minus4 = 6 - 4,
	max_chain_length = 128,
/* To speed up deflation, hash chains are never searched beyond this length.
 * A higher limit improves compression ratio but degrades the speed.
 */

	max_lazy_match = 16,
/* Attempt to find a better match only when the current match is strictly
 * smaller than this value. This mechanism is used only for compression
 * levels >= 4.
 */

	max_insert_length = max_lazy_match,
/* Insert new strings in the hash table only if the match length
 * is not greater than this length. This saves time but degrades compression.
 * max_insert_length is used only for compression levels <= 3.
 */

	good_match = 8,
/* Use a faster search when the previous match is longer than this */

/* Values for max_lazy_match, good_match and max_chain_length, depending on
 * the desired pack level (0..9). The values given below have been tuned to
 * exclude worst case performance for pathological files. Better values may be
 * found for specific files.
 */

	nice_match = 128,	/* Stop searching when current match exceeds this */
/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4
 * For deflate_fast() (levels <= 3) good is ignored and lazy has a different
 * meaning.
 */
#endif /* ENABLE_FEATURE_GZIP_LEVELS */
};

struct globals {
/* =========================================================================== */
/* global buffers, allocated once */

#define DECLARE(type, array, size) \
	type * array
#define ALLOC(type, array, size) \
	array = xzalloc((size_t)(((size)+1L)/2) * 2*sizeof(type))
#define FREE(array) \
	do { free(array); array = NULL; } while (0)

	/* buffer for literals or lengths */
	/* DECLARE(uch, l_buf, LIT_BUFSIZE); */
	DECLARE(uch, l_buf, INBUFSIZ);

	DECLARE(ush, d_buf, DIST_BUFSIZE);
	DECLARE(uch, outbuf, OUTBUFSIZ);

/* Sliding window. Input bytes are read into the second half of the window,
 * and move to the first half later to keep a dictionary of at least WSIZE
 * bytes. With this organization, matches are limited to a distance of
 * WSIZE-MAX_MATCH bytes, but this ensures that IO is always
 * performed with a length multiple of the block size. Also, it limits
 * the window size to 64K, which is quite useful on MSDOS.
 * To do: limit the window size to WSIZE+BSZ if SMALL_MEM (the code would
 * be less efficient).
 */
	DECLARE(uch, window, 2L * WSIZE);

/* Link to older string with same hash index. To limit the size of this
 * array to 64K, this link is maintained only for the last 32K strings.
 * An index in this array is thus a window index modulo 32K.
 */
	/* DECLARE(Pos, prev, WSIZE); */
	DECLARE(ush, prev, 1L << BITS);

/* Heads of the hash chains or 0. */
	/* DECLARE(Pos, head, 1<<HASH_BITS); */
#define head (G1.prev + WSIZE) /* hash head (see deflate.c) */

#if ENABLE_FEATURE_GZIP_LEVELS
	unsigned comp_level_minus4;	/* can be a byte */
	unsigned max_chain_length;
	unsigned max_lazy_match;
	unsigned good_match;
	unsigned nice_match;
#define comp_level_minus4 (G1.comp_level_minus4)
#define max_chain_length  (G1.max_chain_length)
#define max_lazy_match    (G1.max_lazy_match)
#define good_match        (G1.good_match)
#define nice_match        (G1.nice_match)
#endif

/* =========================================================================== */
/* all members below are zeroed out in pack_gzip() for each next file */

	uint32_t crc;	/* shift register contents */
	/*uint32_t *crc_32_tab;*/

/* window position at the beginning of the current output block. Gets
 * negative when the window is moved backwards.
 */
	lng block_start;

	unsigned ins_h;	/* hash index of string to be inserted */

/* Number of bits by which ins_h and del_h must be shifted at each
 * input step. It must be such that after MIN_MATCH steps, the oldest
 * byte no longer takes part in the hash key, that is:
 * H_SHIFT * MIN_MATCH >= HASH_BITS
 */
#define H_SHIFT  ((HASH_BITS+MIN_MATCH-1) / MIN_MATCH)

/* Length of the best match at previous step. Matches not greater than this
 * are discarded. This is used in the lazy match evaluation.
 */
	unsigned prev_length;

	unsigned strstart;	/* start of string to insert */
	unsigned match_start;	/* start of matching string */
	unsigned lookahead;	/* number of valid bytes ahead in window */

/* number of input bytes */
	ulg isize;		/* only 32 bits stored in .gz file */

/* bbox always use stdin/stdout */
#define ifd STDIN_FILENO	/* input file descriptor */
#define ofd STDOUT_FILENO	/* output file descriptor */

#ifdef DEBUG
	unsigned insize;	/* valid bytes in l_buf */
#endif
	unsigned outcnt;	/* bytes in output buffer */
	smallint eofile;	/* flag set at end of input file */

/* ===========================================================================
 * Local data used by the "bit string" routines.
 */

/* Output buffer. bits are inserted starting at the bottom (least significant
 * bits).
 */
	unsigned bi_buf;	/* was unsigned short */

#undef BUF_SIZE
#define BUF_SIZE (int)(8 * sizeof(G1.bi_buf))

/* Number of bits used within bi_buf. (bi_buf might be implemented on
 * more than 16 bits on some systems.)
 */
	unsigned bi_valid;

#ifdef DEBUG
	ulg bits_sent;	/* bit length of the compressed data */
# define DEBUG_bits_sent(v) (void)(G1.bits_sent v)
#else
# define DEBUG_bits_sent(v) ((void)0)
#endif
};

#define G1 (*(ptr_to_globals - 1))

/* ===========================================================================
 * Write the output buffer outbuf[0..outcnt-1] and update bytes_out.
 * (used for the compressed data only)
 */
static void flush_outbuf(void)
{
	if (G1.outcnt == 0)
		return;

	xwrite(ofd, (char *) G1.outbuf, G1.outcnt);
	G1.outcnt = 0;
}

/* ===========================================================================
 */
/* put_8bit is used for the compressed output */
#define put_8bit(c) \
do { \
	G1.outbuf[G1.outcnt++] = (c); \
	if (G1.outcnt == OUTBUFSIZ) \
		flush_outbuf(); \
} while (0)

/* Output a 16 bit value, lsb first */
static void put_16bit(ush w)
{
	/* GCC 4.2.1 won't optimize out redundant loads of G1.outcnt
	 * (probably because of fear of aliasing with G1.outbuf[]
	 * stores), do it explicitly:
	 */
	unsigned outcnt = G1.outcnt;
	uch *dst = &G1.outbuf[outcnt];

#if BB_UNALIGNED_MEMACCESS_OK && BB_LITTLE_ENDIAN
	if (outcnt < OUTBUFSIZ-2) {
		/* Common case */
		ush *dst16 = (void*) dst;
		*dst16 = w; /* unaligned LSB 16-bit store */
		G1.outcnt = outcnt + 2;
		return;
	}
	*dst = (uch)w;
	w >>= 8;
	G1.outcnt = ++outcnt;
#else
	*dst = (uch)w;
	w >>= 8;
	if (outcnt < OUTBUFSIZ-2) {
		/* Common case */
		dst[1] = w;
		G1.outcnt = outcnt + 2;
		return;
	}
	G1.outcnt = ++outcnt;
#endif

	/* Slowpath: we will need to do flush_outbuf() */
	if (outcnt == OUTBUFSIZ)
		flush_outbuf(); /* here */
	put_8bit(w); /* or here */
}

#define OPTIMIZED_PUT_32BIT (CONFIG_GZIP_FAST > 0 && BB_UNALIGNED_MEMACCESS_OK && BB_LITTLE_ENDIAN)
static void put_32bit(ulg n)
{
	if (OPTIMIZED_PUT_32BIT) {
		unsigned outcnt = G1.outcnt;
		if (outcnt < OUTBUFSIZ-4) {
			/* Common case */
			ulg *dst32 = (void*) &G1.outbuf[outcnt];
			*dst32 = n; /* unaligned LSB 32-bit store */
			//bb_error_msg("%p", dst32); // store alignment debugging
			G1.outcnt = outcnt + 4;
			return;
		}
	}
	put_16bit(n);
	put_16bit(n >> 16);
}
static ALWAYS_INLINE void flush_outbuf_if_32bit_optimized(void)
{
	/* If put_32bit() performs 32bit stores && it is used in send_bits() */
	if (OPTIMIZED_PUT_32BIT && BUF_SIZE > 16)
		flush_outbuf();
}

/* ===========================================================================
 * Run a set of bytes through the crc shift register.  If s is a NULL
 * pointer, then initialize the crc shift register contents instead.
 * Return the current crc in either case.
 */
static void updcrc(uch *s, unsigned n)
{
	G1.crc = crc32_block_endian0(G1.crc, s, n, global_crc32_table /*G1.crc_32_tab*/);
}

/* ===========================================================================
 * Read a new buffer from the current input file, perform end-of-line
 * translation, and update the crc and input file size.
 * IN assertion: size >= 2 (for end-of-line translation)
 */
static unsigned file_read(void *buf, unsigned size)
{
	unsigned len;

	Assert(G1.insize == 0, "l_buf not empty");

	len = safe_read(ifd, buf, size);
	if (len == (unsigned)(-1) || len == 0)
		return len;

	updcrc(buf, len);
	G1.isize += len;
	return len;
}

/* ===========================================================================
 * Send a value on a given number of bits.
 * IN assertion: length <= 16 and value fits in length bits.
 */
static void send_bits(unsigned value, unsigned length)
{
	unsigned new_buf;

#ifdef DEBUG
	Tracev((stderr, " l %2d v %4x ", length, value));
	Assert(length > 0 && length <= 15, "invalid length");
	DEBUG_bits_sent(+= length);
#endif
	BUILD_BUG_ON(BUF_SIZE != 32 && BUF_SIZE != 16);

	new_buf = G1.bi_buf | (value << G1.bi_valid);
	/* NB: the above may sometimes do "<< 32" shift (undefined)
	 * if check below is changed to "length > BUF_SIZE" instead of >= */
	length += G1.bi_valid;

	/* If bi_buf is full */
	if (length >= BUF_SIZE) {
		/* ...use (valid) bits from bi_buf and
		 * (BUF_SIZE - bi_valid) bits from value,
		 *  leaving (width - (BUF_SIZE-bi_valid)) unused bits in value.
		 */
		value >>= (BUF_SIZE - G1.bi_valid);
		if (BUF_SIZE == 32) {
			put_32bit(new_buf);
		} else { /* 16 */
			put_16bit(new_buf);
		}
		new_buf = value;
		length -= BUF_SIZE;
	}
	G1.bi_buf = new_buf;
	G1.bi_valid = length;
}

/* ===========================================================================
 * Reverse the first len bits of a code, using straightforward code (a faster
 * method would use a table)
 * IN assertion: 1 <= len <= 15
 */
static unsigned bi_reverse(unsigned code, int len)
{
	unsigned res = 0;

	while (1) {
		res |= code & 1;
		if (--len <= 0) return res;
		code >>= 1;
		res <<= 1;
	}
}

/* ===========================================================================
 * Write out any remaining bits in an incomplete byte.
 */
static void bi_windup(void)
{
	unsigned bits = G1.bi_buf;
	int cnt = G1.bi_valid;

	while (cnt > 0) {
		put_8bit(bits);
		bits >>= 8;
		cnt -= 8;
	}
	G1.bi_buf = 0;
	G1.bi_valid = 0;
	DEBUG_bits_sent(= (G1.bits_sent + 7) & ~7);
}

/* ===========================================================================
 * Copy a stored block to the zip file, storing first the length and its
 * one's complement if requested.
 */
static void copy_block(const char *buf, unsigned len, int header)
{
	bi_windup();		/* align on byte boundary */

	if (header) {
		unsigned v = ((uint16_t)len) | ((~len) << 16);
		put_32bit(v);
		DEBUG_bits_sent(+= 2 * 16);
	}
	DEBUG_bits_sent(+= (ulg) len << 3);
	while (len--) {
		put_8bit(*buf++);
	}
	/* The above can 32-bit misalign outbuf */
	if (G1.outcnt & 3) /* syscalls are expensive, is it really misaligned? */
		flush_outbuf_if_32bit_optimized();
}

/* ===========================================================================
 * Fill the window when the lookahead becomes insufficient.
 * Updates strstart and lookahead, and sets eofile if end of input file.
 * IN assertion: lookahead < MIN_LOOKAHEAD && strstart + lookahead > 0
 * OUT assertions: at least one byte has been read, or eofile is set;
 *    file reads are performed for at least two bytes (required for the
 *    translate_eol option).
 */
static void fill_window(void)
{
	unsigned n, m;
	unsigned more =	WINDOW_SIZE - G1.lookahead - G1.strstart;
	/* Amount of free space at the end of the window. */

	/* If the window is almost full and there is insufficient lookahead,
	 * move the upper half to the lower one to make room in the upper half.
	 */
	if (more == (unsigned) -1) {
		/* Very unlikely, but possible on 16 bit machine if strstart == 0
		 * and lookahead == 1 (input done one byte at time)
		 */
		more--;
	} else if (G1.strstart >= WSIZE + MAX_DIST) {
		/* By the IN assertion, the window is not empty so we can't confuse
		 * more == 0 with more == 64K on a 16 bit machine.
		 */
		Assert(WINDOW_SIZE == 2 * WSIZE, "no sliding with BIG_MEM");

		memcpy(G1.window, G1.window + WSIZE, WSIZE);
		G1.match_start -= WSIZE;
		G1.strstart -= WSIZE;	/* we now have strstart >= MAX_DIST: */

		G1.block_start -= WSIZE;

		for (n = 0; n < HASH_SIZE; n++) {
			m = head[n];
			head[n] = (Pos) (m >= WSIZE ? m - WSIZE : 0);
		}
		for (n = 0; n < WSIZE; n++) {
			m = G1.prev[n];
			G1.prev[n] = (Pos) (m >= WSIZE ? m - WSIZE : 0);
			/* If n is not on any hash chain, prev[n] is garbage but
			 * its value will never be used.
			 */
		}
		more += WSIZE;
	}
	/* At this point, more >= 2 */
	if (!G1.eofile) {
		n = file_read(G1.window + G1.strstart + G1.lookahead, more);
		if (n == 0 || n == (unsigned) -1) {
			G1.eofile = 1;
		} else {
			G1.lookahead += n;
		}
	}
}
/* Both users fill window with the same loop: */
static void fill_window_if_needed(void)
{
	while (G1.lookahead < MIN_LOOKAHEAD && !G1.eofile)
		fill_window();
}

/* ===========================================================================
 * Set match_start to the longest match starting at the given string and
 * return its length. Matches shorter or equal to prev_length are discarded,
 * in which case the result is equal to prev_length and match_start is
 * garbage.
 * IN assertions: cur_match is the head of the hash chain for the current
 *   string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
 */

/* For MSDOS, OS/2 and 386 Unix, an optimized version is in match.asm or
 * match.s. The code is functionally equivalent, so you can use the C version
 * if desired.
 */
static int longest_match(IPos cur_match)
{
	unsigned chain_length = max_chain_length;	/* max hash chain length */
	uch *scan = G1.window + G1.strstart;	/* current string */
	uch *match;	/* matched string */
	int len;	/* length of current match */
	int best_len = G1.prev_length;	/* best match length so far */
	IPos limit = G1.strstart > (IPos) MAX_DIST ? G1.strstart - (IPos) MAX_DIST : 0;
	/* Stop when cur_match becomes <= limit. To simplify the code,
	 * we prevent matches with the string of window index 0.
	 */

/* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
 * It is easy to get rid of this optimization if necessary.
 */
#if HASH_BITS < 8 || MAX_MATCH != 258
#  error Code too clever
#endif
	uch *strend = G1.window + G1.strstart + MAX_MATCH;
	uch scan_end1 = scan[best_len - 1];
	uch scan_end = scan[best_len];

	/* Do not waste too much time if we already have a good match: */
	if (G1.prev_length >= good_match) {
		chain_length >>= 2;
	}
	Assert(G1.strstart <= WINDOW_SIZE - MIN_LOOKAHEAD, "insufficient lookahead");

	do {
		Assert(cur_match < G1.strstart, "no future");
		match = G1.window + cur_match;

		/* Skip to next match if the match length cannot increase
		 * or if the match length is less than 2:
		 */
		if (match[best_len] != scan_end
		 || match[best_len - 1] != scan_end1
		 || *match != *scan || *++match != scan[1]
		) {
			continue;
		}

		/* The check at best_len-1 can be removed because it will be made
		 * again later. (This heuristic is not always a win.)
		 * It is not necessary to compare scan[2] and match[2] since they
		 * are always equal when the other bytes match, given that
		 * the hash keys are equal and that HASH_BITS >= 8.
		 */
		scan += 2, match++;

		/* We check for insufficient lookahead only every 8th comparison;
		 * the 256th check will be made at strstart+258.
		 */
		do {
		} while (*++scan == *++match && *++scan == *++match &&
				 *++scan == *++match && *++scan == *++match &&
				 *++scan == *++match && *++scan == *++match &&
				 *++scan == *++match && *++scan == *++match && scan < strend);

		len = MAX_MATCH - (int) (strend - scan);
		scan = strend - MAX_MATCH;

		if (len > best_len) {
			G1.match_start = cur_match;
			best_len = len;
			if (len >= nice_match)
				break;
			scan_end1 = scan[best_len - 1];
			scan_end = scan[best_len];
		}
	} while ((cur_match = G1.prev[cur_match & WMASK]) > limit
			 && --chain_length != 0);

	return best_len;
}

#ifdef DEBUG
/* ===========================================================================
 * Check that the match at match_start is indeed a match.
 */
static void check_match(IPos start, IPos match, int length)
{
	/* check that the match is indeed a match */
	if (memcmp(G1.window + match, G1.window + start, length) != 0) {
		bb_error_msg(" start %d, match %d, length %d", start, match, length);
		bb_simple_error_msg("invalid match");
	}
	if (verbose > 1) {
		bb_error_msg("\\[%d,%d]", start - match, length);
		do {
			bb_putchar_stderr(G1.window[start++]);
		} while (--length != 0);
	}
}
#else
#  define check_match(start, match, length) ((void)0)
#endif


/* trees.c -- output deflated data using Huffman coding
 * Copyright (C) 1992-1993 Jean-loup Gailly
 * This is free software; you can redistribute it and/or modify it under the
 * terms of the GNU General Public License, see the file COPYING.
 */

/*  PURPOSE
 *      Encode various sets of source values using variable-length
 *      binary code trees.
 *
 *  DISCUSSION
 *      The PKZIP "deflation" process uses several Huffman trees. The more
 *      common source values are represented by shorter bit sequences.
 *
 *      Each code tree is stored in the ZIP file in a compressed form
 *      which is itself a Huffman encoding of the lengths of
 *      all the code strings (in ascending order by source values).
 *      The actual code strings are reconstructed from the lengths in
 *      the UNZIP process, as described in the "application note"
 *      (APPNOTE.TXT) distributed as part of PKWARE's PKZIP program.
 *
 *  REFERENCES
 *      Lynch, Thomas J.
 *          Data Compression:  Techniques and Applications, pp. 53-55.
 *          Lifetime Learning Publications, 1985.  ISBN 0-534-03418-7.
 *
 *      Storer, James A.
 *          Data Compression:  Methods and Theory, pp. 49-50.
 *          Computer Science Press, 1988.  ISBN 0-7167-8156-5.
 *
 *      Sedgewick, R.
 *          Algorithms, p290.
 *          Addison-Wesley, 1983. ISBN 0-201-06672-6.
 *
 *  INTERFACE
 *      void ct_init()
 *          Allocate the match buffer, initialize the various tables [and save
 *          the location of the internal file attribute (ascii/binary) and
 *          method (DEFLATE/STORE) -- deleted in bbox]
 *
 *      void ct_tally(int dist, int lc);
 *          Save the match info and tally the frequency counts.
 *
 *      ulg flush_block(char *buf, ulg stored_len, int eof)
 *          Determine the best encoding for the current block: dynamic trees,
 *          static trees or store, and output the encoded block to the zip
 *          file. Returns the total compressed length for the file so far.
 */

#define MAX_BITS 15
/* All codes must not exceed MAX_BITS bits */

#define MAX_BL_BITS 7
/* Bit length codes must not exceed MAX_BL_BITS bits */

#define LENGTH_CODES 29
/* number of length codes, not counting the special END_BLOCK code */

#define LITERALS  256
/* number of literal bytes 0..255 */

#define END_BLOCK 256
/* end of block literal code */

#define L_CODES (LITERALS+1+LENGTH_CODES)
/* number of Literal or Length codes, including the END_BLOCK code */

#define D_CODES   30
/* number of distance codes */

#define BL_CODES  19
/* number of codes used to transfer the bit lengths */

/* extra bits for each length code */
static const uint8_t extra_lbits[LENGTH_CODES] ALIGN1 = {
	0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4,
	4, 4, 5, 5, 5, 5, 0
};

/* extra bits for each distance code */
static const uint8_t extra_dbits[D_CODES] ALIGN1 = {
	0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,
	10, 10, 11, 11, 12, 12, 13, 13
};

/* extra bits for each bit length code */
static const uint8_t extra_blbits[BL_CODES] ALIGN1 = {
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7 };

/* number of codes at each bit length for an optimal tree */
static const uint8_t bl_order[BL_CODES] ALIGN1 = {
	16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };

#define STORED_BLOCK 0
#define STATIC_TREES 1
#define DYN_TREES    2
/* The three kinds of block type */

#ifndef LIT_BUFSIZE
#  ifdef SMALL_MEM
#    define LIT_BUFSIZE  0x2000
#  else
#  ifdef MEDIUM_MEM
#    define LIT_BUFSIZE  0x4000
#  else
#    define LIT_BUFSIZE  0x8000
#  endif
#  endif
#endif
#ifndef DIST_BUFSIZE
#  define DIST_BUFSIZE  LIT_BUFSIZE
#endif
/* Sizes of match buffers for literals/lengths and distances.  There are
 * 4 reasons for limiting LIT_BUFSIZE to 64K:
 *   - frequencies can be kept in 16 bit counters
 *   - if compression is not successful for the first block, all input data is
 *     still in the window so we can still emit a stored block even when input
 *     comes from standard input.  (This can also be done for all blocks if
 *     LIT_BUFSIZE is not greater than 32K.)
 *   - if compression is not successful for a file smaller than 64K, we can
 *     even emit a stored file instead of a stored block (saving 5 bytes).
 *   - creating new Huffman trees less frequently may not provide fast
 *     adaptation to changes in the input data statistics. (Take for
 *     example a binary file with poorly compressible code followed by
 *     a highly compressible string table.) Smaller buffer sizes give
 *     fast adaptation but have of course the overhead of transmitting trees
 *     more frequently.
 *   - I can't count above 4
 * The current code is general and allows DIST_BUFSIZE < LIT_BUFSIZE (to save
 * memory at the expense of compression). Some optimizations would be possible
 * if we rely on DIST_BUFSIZE == LIT_BUFSIZE.
 */
#define REP_3_6      16
/* repeat previous bit length 3-6 times (2 bits of repeat count) */
#define REPZ_3_10    17
/* repeat a zero length 3-10 times  (3 bits of repeat count) */
#define REPZ_11_138  18
/* repeat a zero length 11-138 times  (7 bits of repeat count) */

/* ===========================================================================
*/
/* Data structure describing a single value and its code string. */
typedef struct ct_data {
	union {
		ush freq;		/* frequency count */
		ush code;		/* bit string */
	} fc;
	union {
		ush dad;		/* father node in Huffman tree */
		ush len;		/* length of bit string */
	} dl;
} ct_data;

#define Freq fc.freq
#define Code fc.code
#define Dad  dl.dad
#define Len  dl.len

#define HEAP_SIZE (2*L_CODES + 1)
/* maximum heap size */

typedef struct tree_desc {
	ct_data *dyn_tree;	/* the dynamic tree */
	ct_data *static_tree;	/* corresponding static tree or NULL */
	const uint8_t *extra_bits;	/* extra bits for each code or NULL */
	int extra_base;		/* base index for extra_bits */
	int elems;			/* max number of elements in the tree */
	int max_length;		/* max bit length for the codes */
	int max_code;		/* largest code with non zero frequency */
} tree_desc;

struct globals2 {

	ush heap[HEAP_SIZE];     /* heap used to build the Huffman trees */
	int heap_len;            /* number of elements in the heap */
	int heap_max;            /* element of largest frequency */

/* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
 * The same heap array is used to build all trees.
 */

	ct_data dyn_ltree[HEAP_SIZE];	/* literal and length tree */
	ct_data dyn_dtree[2 * D_CODES + 1];	/* distance tree */

	ct_data static_ltree[L_CODES + 2];

/* The static literal tree. Since the bit lengths are imposed, there is no
 * need for the L_CODES extra codes used during heap construction. However
 * The codes 286 and 287 are needed to build a canonical tree (see ct_init
 * below).
 */

	ct_data static_dtree[D_CODES];

/* The static distance tree. (Actually a trivial tree since all codes use
 * 5 bits.)
 */

	ct_data bl_tree[2 * BL_CODES + 1];

/* Huffman tree for the bit lengths */

	tree_desc l_desc;
	tree_desc d_desc;
	tree_desc bl_desc;

	/* was "ush", but "unsigned" results in smaller code */
	unsigned bl_count[MAX_BITS + 1];

/* The lengths of the bit length codes are sent in order of decreasing
 * probability, to avoid transmitting the lengths for unused bit length codes.
 */

	uch depth[2 * L_CODES + 1];

/* Depth of each subtree used as tie breaker for trees of equal frequency */

	uch length_code[MAX_MATCH - MIN_MATCH + 1];

/* length code for each normalized match length (0 == MIN_MATCH) */

	uch dist_code[512];

/* distance codes. The first 256 values correspond to the distances
 * 3 .. 258, the last 256 values correspond to the top 8 bits of
 * the 15 bit distances.
 */

	int base_length[LENGTH_CODES];

/* First normalized length for each code (0 = MIN_MATCH) */

	int base_dist[D_CODES];

/* First normalized distance for each code (0 = distance of 1) */

	uch flag_buf[LIT_BUFSIZE / 8];

/* flag_buf is a bit array distinguishing literals from lengths in
 * l_buf, thus indicating the presence or absence of a distance.
 */

	unsigned last_lit;       /* running index in l_buf */
	unsigned last_dist;      /* running index in d_buf */
	unsigned last_flags;     /* running index in flag_buf */
	uch flags;               /* current flags not yet saved in flag_buf */
	uch flag_bit;            /* current bit used in flags */

/* bits are filled in flags starting at bit 0 (least significant).
 * Note: these flags are overkill in the current code since we don't
 * take advantage of DIST_BUFSIZE == LIT_BUFSIZE.
 */

	ulg opt_len;             /* bit length of current block with optimal trees */
	ulg static_len;          /* bit length of current block with static trees */

//	ulg compressed_len;      /* total bit length of compressed file */
};

#define G2ptr ((struct globals2*)(ptr_to_globals))
#define G2 (*G2ptr)

/* ===========================================================================
 */
#ifndef DEBUG
/* Send a code of the given tree. c and tree must not have side effects */
#  define SEND_CODE(c, tree) send_bits(tree[c].Code, tree[c].Len)
#else
#  define SEND_CODE(c, tree) \
{ \
	if (verbose > 1) bb_error_msg("\ncd %3d ", (c)); \
	send_bits(tree[c].Code, tree[c].Len); \
}
#endif

#define D_CODE(dist) \
	((dist) < 256 ? G2.dist_code[dist] : G2.dist_code[256 + ((dist)>>7)])
/* Mapping from a distance to a distance code. dist is the distance - 1 and
 * must not have side effects. dist_code[256] and dist_code[257] are never
 * used.
 * The arguments must not have side effects.
 */

/* ===========================================================================
 * Initialize a new block.
 */
static void init_block(void)
{
	int n; /* iterates over tree elements */

	/* Initialize the trees. */
	for (n = 0; n < L_CODES; n++)
		G2.dyn_ltree[n].Freq = 0;
	for (n = 0; n < D_CODES; n++)
		G2.dyn_dtree[n].Freq = 0;
	for (n = 0; n < BL_CODES; n++)
		G2.bl_tree[n].Freq = 0;

	G2.dyn_ltree[END_BLOCK].Freq = 1;
	G2.opt_len = G2.static_len = 0;
	G2.last_lit = G2.last_dist = G2.last_flags = 0;
	G2.flags = 0;
	G2.flag_bit = 1;
}

/* ===========================================================================
 * Restore the heap property by moving down the tree starting at node k,
 * exchanging a node with the smallest of its two sons if necessary, stopping
 * when the heap property is re-established (each father smaller than its
 * two sons).
 */

/* Compares to subtrees, using the tree depth as tie breaker when
 * the subtrees have equal frequency. This minimizes the worst case length. */
#define SMALLER(tree, n, m) \
	(tree[n].Freq < tree[m].Freq \
	|| (tree[n].Freq == tree[m].Freq && G2.depth[n] <= G2.depth[m]))

static void pqdownheap(const ct_data *tree, int k)
{
	int v = G2.heap[k];
	int j = k << 1;		/* left son of k */

	while (j <= G2.heap_len) {
		/* Set j to the smallest of the two sons: */
		if (j < G2.heap_len && SMALLER(tree, G2.heap[j + 1], G2.heap[j]))
			j++;

		/* Exit if v is smaller than both sons */
		if (SMALLER(tree, v, G2.heap[j]))
			break;

		/* Exchange v with the smallest son */
		G2.heap[k] = G2.heap[j];
		k = j;

		/* And continue down the tree, setting j to the left son of k */
		j <<= 1;
	}
	G2.heap[k] = v;
}

/* ===========================================================================
 * Compute the optimal bit lengths for a tree and update the total bit length
 * for the current block.
 * IN assertion: the fields freq and dad are set, heap[heap_max] and
 *    above are the tree nodes sorted by increasing frequency.
 * OUT assertions: the field len is set to the optimal bit length, the
 *     array bl_count contains the frequencies for each bit length.
 *     The length opt_len is updated; static_len is also updated if stree is
 *     not null.
 */
static void gen_bitlen(const tree_desc *desc)
{
#define tree desc->dyn_tree
	int h;          /* heap index */
	int n, m;       /* iterate over the tree elements */
	int bits;       /* bit length */
	int overflow;   /* number of elements with bit length too large */

	for (bits = 0; bits < ARRAY_SIZE(G2.bl_count); bits++)
		G2.bl_count[bits] = 0;

	/* In a first pass, compute the optimal bit lengths (which may
	 * overflow in the case of the bit length tree).
	 */
	tree[G2.heap[G2.heap_max]].Len = 0;	/* root of the heap */

	overflow = 0;
	for (h = G2.heap_max + 1; h < HEAP_SIZE; h++) {
		ulg f;          /* frequency */
		int xbits;      /* extra bits */

		n = G2.heap[h];
		bits = tree[tree[n].Dad].Len + 1;
		if (bits > desc->max_length) {
			bits = desc->max_length;
			overflow++;
		}
		tree[n].Len = (ush) bits;
		/* We overwrite tree[n].Dad which is no longer needed */

		if (n > desc->max_code)
			continue;	/* not a leaf node */

		G2.bl_count[bits]++;
		xbits = 0;
		if (n >= desc->extra_base)
			xbits = desc->extra_bits[n - desc->extra_base];
		f = tree[n].Freq;
		G2.opt_len += f * (bits + xbits);

		if (desc->static_tree)
			G2.static_len += f * (desc->static_tree[n].Len + xbits);
	}
	if (overflow == 0)
		return;

	Trace((stderr, "\nbit length overflow\n"));
	/* This happens for example on obj2 and pic of the Calgary corpus */

	/* Find the first bit length which could increase: */
	do {
		bits = desc->max_length - 1;
		while (G2.bl_count[bits] == 0)
			bits--;
		G2.bl_count[bits]--;	/* move one leaf down the tree */
		G2.bl_count[bits + 1] += 2;	/* move one overflow item as its brother */
		G2.bl_count[desc->max_length]--;
		/* The brother of the overflow item also moves one step up,
		 * but this does not affect bl_count[desc->max_length]
		 */
		overflow -= 2;
	} while (overflow > 0);

	/* Now recompute all bit lengths, scanning in increasing frequency.
	 * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
	 * lengths instead of fixing only the wrong ones. This idea is taken
	 * from 'ar' written by Haruhiko Okumura.)
	 */
	for (bits = desc->max_length; bits != 0; bits--) {
		n = G2.bl_count[bits];
		while (n != 0) {
			m = G2.heap[--h];
			if (m > desc->max_code)
				continue;
			if (tree[m].Len != (unsigned) bits) {
				Trace((stderr, "code %d bits %d->%d\n", m, tree[m].Len, bits));
				G2.opt_len += ((int32_t) bits - tree[m].Len) * tree[m].Freq;
				tree[m].Len = bits;
			}
			n--;
		}
	}
#undef tree
}

/* ===========================================================================
 * Generate the codes for a given tree and bit counts (which need not be
 * optimal).
 * IN assertion: the array bl_count contains the bit length statistics for
 * the given tree and the field len is set for all tree elements.
 * OUT assertion: the field code is set for all tree elements of non
 *     zero code length.
 */
static void gen_codes(ct_data *tree, int max_code)
{
	/* next_code[] and code used to be "ush", but "unsigned" results in smaller code */
	unsigned next_code[MAX_BITS + 1]; /* next code value for each bit length */
	unsigned code = 0;      /* running code value */
	int bits;               /* bit index */
	int n;                  /* code index */

	/* The distribution counts are first used to generate the code values
	 * without bit reversal.
	 */
	for (bits = 1; bits <= MAX_BITS; bits++) {
		next_code[bits] = code = (code + G2.bl_count[bits - 1]) << 1;
	}
	/* Check that the bit counts in bl_count are consistent. The last code
	 * must be all ones.
	 */
	Assert(code + G2.bl_count[MAX_BITS] - 1 == (1 << MAX_BITS) - 1,
			"inconsistent bit counts");
	Tracev((stderr, "\ngen_codes: max_code %d ", max_code));

	for (n = 0; n <= max_code; n++) {
		int len = tree[n].Len;

		if (len == 0)
			continue;
		/* Now reverse the bits */
		tree[n].Code = bi_reverse(next_code[len]++, len);

		Tracec(tree != G2.static_ltree,
			   (stderr, "\nn %3d %c l %2d c %4x (%x) ", n,
				(n > ' ' ? n : ' '), len, tree[n].Code,
				next_code[len] - 1));
	}
}

/* ===========================================================================
 * Construct one Huffman tree and assigns the code bit strings and lengths.
 * Update the total bit length for the current block.
 * IN assertion: the field freq is set for all tree elements.
 * OUT assertions: the fields len and code are set to the optimal bit length
 *     and corresponding code. The length opt_len is updated; static_len is
 *     also updated if stree is not null. The field max_code is set.
 */

/* Remove the smallest element from the heap and recreate the heap with
 * one less element. Updates heap and heap_len. */

#define SMALLEST 1
/* Index within the heap array of least frequent node in the Huffman tree */

#define PQREMOVE(tree, top) \
do { \
	top = G2.heap[SMALLEST]; \
	G2.heap[SMALLEST] = G2.heap[G2.heap_len--]; \
	pqdownheap(tree, SMALLEST); \
} while (0)

static void build_tree(tree_desc *desc)
{
	ct_data *tree = desc->dyn_tree;
	ct_data *stree = desc->static_tree;
	int elems = desc->elems;
	int n, m;			/* iterate over heap elements */
	int max_code = -1;	/* largest code with non zero frequency */
	int node = elems;	/* next internal node of the tree */

	/* Construct the initial heap, with least frequent element in
	 * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
	 * heap[0] is not used.
	 */
	G2.heap_len = 0;
	G2.heap_max = HEAP_SIZE;

	for (n = 0; n < elems; n++) {
		if (tree[n].Freq != 0) {
			G2.heap[++G2.heap_len] = max_code = n;
			G2.depth[n] = 0;
		} else {
			tree[n].Len = 0;
		}
	}

	/* The pkzip format requires that at least one distance code exists,
	 * and that at least one bit should be sent even if there is only one
	 * possible code. So to avoid special checks later on we force at least
	 * two codes of non zero frequency.
	 */
	while (G2.heap_len < 2) {
		int new = G2.heap[++G2.heap_len] = (max_code < 2 ? ++max_code : 0);

		tree[new].Freq = 1;
		G2.depth[new] = 0;
		G2.opt_len--;
		if (stree)
			G2.static_len -= stree[new].Len;
		/* new is 0 or 1 so it does not have extra bits */
	}
	desc->max_code = max_code;

	/* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
	 * establish sub-heaps of increasing lengths:
	 */
	for (n = G2.heap_len / 2; n >= 1; n--)
		pqdownheap(tree, n);

	/* Construct the Huffman tree by repeatedly combining the least two
	 * frequent nodes.
	 */
	do {
		PQREMOVE(tree, n);	/* n = node of least frequency */
		m = G2.heap[SMALLEST];	/* m = node of next least frequency */

		G2.heap[--G2.heap_max] = n;	/* keep the nodes sorted by frequency */
		G2.heap[--G2.heap_max] = m;

		/* Create a new node father of n and m */
		tree[node].Freq = tree[n].Freq + tree[m].Freq;
		G2.depth[node] = MAX(G2.depth[n], G2.depth[m]) + 1;
		tree[n].Dad = tree[m].Dad = (ush) node;
#ifdef DUMP_BL_TREE
		if (tree == G2.bl_tree) {
			bb_error_msg("\nnode %d(%d), sons %d(%d) %d(%d)",
					node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
		}
#endif
		/* and insert the new node in the heap */
		G2.heap[SMALLEST] = node++;
		pqdownheap(tree, SMALLEST);
	} while (G2.heap_len >= 2);

	G2.heap[--G2.heap_max] = G2.heap[SMALLEST];

	/* At this point, the fields freq and dad are set. We can now
	 * generate the bit lengths.
	 */
	gen_bitlen(desc);

	/* The field len is now set, we can generate the bit codes */
	gen_codes(tree, max_code);
}

/* ===========================================================================
 * Scan a literal or distance tree to determine the frequencies of the codes
 * in the bit length tree. Updates opt_len to take into account the repeat
 * counts. (The contribution of the bit length codes will be added later
 * during the construction of bl_tree.)
 */
static void scan_tree(ct_data *tree, int max_code)
{
	int n;				/* iterates over all tree elements */
	int prevlen = -1;	/* last emitted length */
	int curlen;			/* length of current code */
	int nextlen = tree[0].Len;	/* length of next code */
	int count = 0;		/* repeat count of the current code */
	int max_count = 7;	/* max repeat count */
	int min_count = 4;	/* min repeat count */

	if (nextlen == 0) {
		max_count = 138;
		min_count = 3;
	}
	tree[max_code + 1].Len = 0xffff; /* guard */

	for (n = 0; n <= max_code; n++) {
		curlen = nextlen;
		nextlen = tree[n + 1].Len;
		if (++count < max_count && curlen == nextlen)
			continue;

		if (count < min_count) {
			G2.bl_tree[curlen].Freq += count;
		} else if (curlen != 0) {
			if (curlen != prevlen)
				G2.bl_tree[curlen].Freq++;
			G2.bl_tree[REP_3_6].Freq++;
		} else if (count <= 10) {
			G2.bl_tree[REPZ_3_10].Freq++;
		} else {
			G2.bl_tree[REPZ_11_138].Freq++;
		}
		count = 0;
		prevlen = curlen;

		max_count = 7;
		min_count = 4;
		if (nextlen == 0) {
			max_count = 138;
			min_count = 3;
		} else if (curlen == nextlen) {
			max_count = 6;
			min_count = 3;
		}
	}
}

/* ===========================================================================
 * Send a literal or distance tree in compressed form, using the codes in
 * bl_tree.
 */
static void send_tree(const ct_data *tree, int max_code)
{
	int n;				/* iterates over all tree elements */
	int prevlen = -1;	/* last emitted length */
	int curlen;			/* length of current code */
	int nextlen = tree[0].Len;	/* length of next code */
	int count = 0;		/* repeat count of the current code */
	int max_count = 7;	/* max repeat count */
	int min_count = 4;	/* min repeat count */

/* tree[max_code+1].Len = -1; *//* guard already set */
	if (nextlen == 0)
		max_count = 138, min_count = 3;

	for (n = 0; n <= max_code; n++) {
		curlen = nextlen;
		nextlen = tree[n + 1].Len;
		if (++count < max_count && curlen == nextlen) {
			continue;
		} else if (count < min_count) {
			do {
				SEND_CODE(curlen, G2.bl_tree);
			} while (--count);
		} else if (curlen != 0) {
			if (curlen != prevlen) {
				SEND_CODE(curlen, G2.bl_tree);
				count--;
			}
			Assert(count >= 3 && count <= 6, " 3_6?");
			SEND_CODE(REP_3_6, G2.bl_tree);
			send_bits(count - 3, 2);
		} else if (count <= 10) {
			SEND_CODE(REPZ_3_10, G2.bl_tree);
			send_bits(count - 3, 3);
		} else {
			SEND_CODE(REPZ_11_138, G2.bl_tree);
			send_bits(count - 11, 7);
		}
		count = 0;
		prevlen = curlen;
		if (nextlen == 0) {
			max_count = 138;
			min_count = 3;
		} else if (curlen == nextlen) {
			max_count = 6;
			min_count = 3;
		} else {
			max_count = 7;
			min_count = 4;
		}
	}
}

/* ===========================================================================
 * Construct the Huffman tree for the bit lengths and return the index in
 * bl_order of the last bit length code to send.
 */
static int build_bl_tree(void)
{
	int max_blindex;	/* index of last bit length code of non zero freq */

	/* Determine the bit length frequencies for literal and distance trees */
	scan_tree(G2.dyn_ltree, G2.l_desc.max_code);
	scan_tree(G2.dyn_dtree, G2.d_desc.max_code);

	/* Build the bit length tree: */
	build_tree(&G2.bl_desc);
	/* opt_len now includes the length of the tree representations, except
	 * the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
	 */

	/* Determine the number of bit length codes to send. The pkzip format
	 * requires that at least 4 bit length codes be sent. (appnote.txt says
	 * 3 but the actual value used is 4.)
	 */
	for (max_blindex = BL_CODES - 1; max_blindex >= 3; max_blindex--) {
		if (G2.bl_tree[bl_order[max_blindex]].Len != 0)
			break;
	}
	/* Update opt_len to include the bit length tree and counts */
	G2.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4;
	Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", (long)G2.opt_len, (long)G2.static_len));

	return max_blindex;
}

/* ===========================================================================
 * Send the header for a block using dynamic Huffman trees: the counts, the
 * lengths of the bit length codes, the literal tree and the distance tree.
 * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
 */
static void send_all_trees(int lcodes, int dcodes, int blcodes)
{
	int rank;			/* index in bl_order */

	Assert(lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
	Assert(lcodes <= L_CODES && dcodes <= D_CODES
		   && blcodes <= BL_CODES, "too many codes");
	Tracev((stderr, "\nbl counts: "));
	send_bits(lcodes - 257, 5);	/* not +255 as stated in appnote.txt */
	send_bits(dcodes - 1, 5);
	send_bits(blcodes - 4, 4);	/* not -3 as stated in appnote.txt */
	for (rank = 0; rank < blcodes; rank++) {
		Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
		send_bits(G2.bl_tree[bl_order[rank]].Len, 3);
	}
	Tracev((stderr, "\nbl tree: sent %ld", (long)G1.bits_sent));

	send_tree((ct_data *) G2.dyn_ltree, lcodes - 1);	/* send the literal tree */
	Tracev((stderr, "\nlit tree: sent %ld", (long)G1.bits_sent));

	send_tree((ct_data *) G2.dyn_dtree, dcodes - 1);	/* send the distance tree */
	Tracev((stderr, "\ndist tree: sent %ld", (long)G1.bits_sent));
}

/* ===========================================================================
 * Save the match info and tally the frequency counts. Return true if
 * the current block must be flushed.
 */
static int ct_tally(int dist, int lc)
{
	G1.l_buf[G2.last_lit++] = lc;
	if (dist == 0) {
		/* lc is the unmatched char */
		G2.dyn_ltree[lc].Freq++;
	} else {
		/* Here, lc is the match length - MIN_MATCH */
		dist--;			/* dist = match distance - 1 */
		Assert((ush) dist < (ush) MAX_DIST
		 && (ush) lc <= (ush) (MAX_MATCH - MIN_MATCH)
		 && (ush) D_CODE(dist) < (ush) D_CODES, "ct_tally: bad match"
		);

		G2.dyn_ltree[G2.length_code[lc] + LITERALS + 1].Freq++;
		G2.dyn_dtree[D_CODE(dist)].Freq++;

		G1.d_buf[G2.last_dist++] = dist;
		G2.flags |= G2.flag_bit;
	}
	G2.flag_bit <<= 1;

	/* Output the flags if they fill a byte: */
	if ((G2.last_lit & 7) == 0) {
		G2.flag_buf[G2.last_flags++] = G2.flags;
		G2.flags = 0;
		G2.flag_bit = 1;
	}
	/* Try to guess if it is profitable to stop the current block here */
	if ((G2.last_lit & 0xfff) == 0) {
		/* Compute an upper bound for the compressed length */
		ulg out_length = G2.last_lit * 8L;
		ulg in_length = (ulg) G1.strstart - G1.block_start;
		int dcode;

		for (dcode = 0; dcode < D_CODES; dcode++) {
			out_length += G2.dyn_dtree[dcode].Freq * (5L + extra_dbits[dcode]);
		}
		out_length >>= 3;
		Trace((stderr,
				"\nlast_lit %u, last_dist %u, in %ld, out ~%ld(%ld%%) ",
				G2.last_lit, G2.last_dist,
				(long)in_length, (long)out_length,
				100L - out_length * 100L / in_length));
		if (G2.last_dist < G2.last_lit / 2 && out_length < in_length / 2)
			return 1;
	}
	return (G2.last_lit == LIT_BUFSIZE - 1 || G2.last_dist == DIST_BUFSIZE);
	/* We avoid equality with LIT_BUFSIZE because of wraparound at 64K
	 * on 16 bit machines and because stored blocks are restricted to
	 * 64K-1 bytes.
	 */
}

/* ===========================================================================
 * Send the block data compressed using the given Huffman trees
 */
static void compress_block(const ct_data *ltree, const ct_data *dtree)
{
	unsigned dist;          /* distance of matched string */
	int lc;                 /* match length or unmatched char (if dist == 0) */
	unsigned lx = 0;        /* running index in l_buf */
	unsigned dx = 0;        /* running index in d_buf */
	unsigned fx = 0;        /* running index in flag_buf */
	uch flag = 0;           /* current flags */
	unsigned code;          /* the code to send */
	int extra;              /* number of extra bits to send */

	if (G2.last_lit != 0) do {
		if ((lx & 7) == 0)
			flag = G2.flag_buf[fx++];
		lc = G1.l_buf[lx++];
		if ((flag & 1) == 0) {
			SEND_CODE(lc, ltree);	/* send a literal byte */
			Tracecv(lc > ' ', (stderr, " '%c' ", lc));
		} else {
			/* Here, lc is the match length - MIN_MATCH */
			code = G2.length_code[lc];
			SEND_CODE(code + LITERALS + 1, ltree);	/* send the length code */
			extra = extra_lbits[code];
			if (extra != 0) {
				lc -= G2.base_length[code];
				send_bits(lc, extra);	/* send the extra length bits */
			}
			dist = G1.d_buf[dx++];
			/* Here, dist is the match distance - 1 */
			code = D_CODE(dist);
			Assert(code < D_CODES, "bad d_code");

			SEND_CODE(code, dtree);	/* send the distance code */
			extra = extra_dbits[code];
			if (extra != 0) {
				dist -= G2.base_dist[code];
				send_bits(dist, extra);	/* send the extra distance bits */
			}
		}			/* literal or match pair ? */
		flag >>= 1;
	} while (lx < G2.last_lit);

	SEND_CODE(END_BLOCK, ltree);
}

/* ===========================================================================
 * Determine the best encoding for the current block: dynamic trees, static
 * trees or store, and output the encoded block to the zip file. This function
 * returns the total compressed length for the file so far.
 */
static void flush_block(const char *buf, ulg stored_len, int eof)
{
	ulg opt_lenb, static_lenb;      /* opt_len and static_len in bytes */
	int max_blindex;                /* index of last bit length code of non zero freq */

	G2.flag_buf[G2.last_flags] = G2.flags;   /* Save the flags for the last 8 items */

	/* Construct the literal and distance trees */
	build_tree(&G2.l_desc);
	Tracev((stderr, "\nlit data: dyn %ld, stat %ld", (long)G2.opt_len, (long)G2.static_len));

	build_tree(&G2.d_desc);
	Tracev((stderr, "\ndist data: dyn %ld, stat %ld", (long)G2.opt_len, (long)G2.static_len));
	/* At this point, opt_len and static_len are the total bit lengths of
	 * the compressed block data, excluding the tree representations.
	 */

	/* Build the bit length tree for the above two trees, and get the index
	 * in bl_order of the last bit length code to send.
	 */
	max_blindex = build_bl_tree();

	/* Determine the best encoding. Compute first the block length in bytes */
	opt_lenb = (G2.opt_len + 3 + 7) >> 3;
	static_lenb = (G2.static_len + 3 + 7) >> 3;

	Trace((stderr,
			"\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u dist %u ",
			(unsigned long)opt_lenb, (unsigned long)G2.opt_len,
			(unsigned long)static_lenb, (unsigned long)G2.static_len,
			(unsigned long)stored_len,
			G2.last_lit, G2.last_dist));

	if (static_lenb <= opt_lenb)
		opt_lenb = static_lenb;

	/* If compression failed and this is the first and last block,
	 * and if the zip file can be seeked (to rewrite the local header),
	 * the whole file is transformed into a stored file:
	 */
// seekable() is constant FALSE in busybox, and G2.compressed_len is disabled
// (this was the only user)
//	if (stored_len <= opt_lenb && eof && G2.compressed_len == 0L && seekable()) {
//		/* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */
//		if (buf == NULL)
//			bb_error_msg("block vanished");
//
//		G2.compressed_len = stored_len << 3;
//		copy_block(buf, (unsigned) stored_len, 0);	/* without header */
//	} else
	if (stored_len + 4 <= opt_lenb && buf != NULL) {
		/* 4: two words for the lengths */
		/* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
		 * Otherwise we can't have processed more than WSIZE input bytes since
		 * the last block flush, because compression would have been
		 * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
		 * transform a block into a stored block.
		 */
		send_bits((STORED_BLOCK << 1) + eof, 3);	/* send block type */
//		G2.compressed_len = ((G2.compressed_len + 3 + 7) & ~7L)
//				+ ((stored_len + 4) << 3);
		copy_block(buf, (unsigned) stored_len, 1);	/* with header */
	} else
	if (static_lenb == opt_lenb) {
		send_bits((STATIC_TREES << 1) + eof, 3);
		compress_block((ct_data *) G2.static_ltree, (ct_data *) G2.static_dtree);
//		G2.compressed_len += 3 + G2.static_len;
	} else {
		send_bits((DYN_TREES << 1) + eof, 3);
		send_all_trees(G2.l_desc.max_code + 1, G2.d_desc.max_code + 1,
					max_blindex + 1);
		compress_block((ct_data *) G2.dyn_ltree, (ct_data *) G2.dyn_dtree);
//		G2.compressed_len += 3 + G2.opt_len;
	}
//	Assert(G2.compressed_len == G1.bits_sent, "bad compressed size");
	init_block();

	if (eof) {
		bi_windup();
//		G2.compressed_len += 7;	/* align on byte boundary */
	}
//	Tracev((stderr, "\ncomprlen %lu(%lu) ",
//			(unsigned long)G2.compressed_len >> 3,
//			(unsigned long)G2.compressed_len - 7 * eof));

	return; /* was "return G2.compressed_len >> 3;" */
}

/* ===========================================================================
 * Update a hash value with the given input byte
 * IN  assertion: all calls to UPDATE_HASH are made with consecutive
 *    input characters, so that a running hash key can be computed from the
 *    previous key instead of complete recalculation each time.
 */
#define UPDATE_HASH(h, c) (h = (((h)<<H_SHIFT) ^ (c)) & HASH_MASK)

/* ===========================================================================
 * Same as above, but achieves better compression. We use a lazy
 * evaluation for matches: a match is finally adopted only if there is
 * no better match at the next window position.
 *
 * Processes a new input file and return its compressed length. Sets
 * the compressed length, crc, deflate flags and internal file
 * attributes.
 */

/* Flush the current block, with given end-of-file flag.
 * IN assertion: strstart is set to the end of the current match. */
#define FLUSH_BLOCK(eof) \
	flush_block( \
		G1.block_start >= 0L \
			? (char*)&G1.window[(unsigned)G1.block_start] \
			: (char*)NULL, \
		(ulg)G1.strstart - G1.block_start, \
		(eof) \
	)

/* Insert string s in the dictionary and set match_head to the previous head
 * of the hash chain (the most recent string with same hash key). Return
 * the previous length of the hash chain.
 * IN  assertion: all calls to INSERT_STRING are made with consecutive
 *    input characters and the first MIN_MATCH bytes of s are valid
 *    (except for the last MIN_MATCH-1 bytes of the input file). */
#define INSERT_STRING(s, match_head) \
do { \
	UPDATE_HASH(G1.ins_h, G1.window[(s) + MIN_MATCH-1]); \
	G1.prev[(s) & WMASK] = match_head = head[G1.ins_h]; \
	head[G1.ins_h] = (s); \
} while (0)

static NOINLINE void deflate(void)
{
	IPos hash_head;		/* head of hash chain */
	IPos prev_match;	/* previous match */
	int flush;			/* set if current block must be flushed */
	int match_available = 0;	/* set if previous match exists */
	unsigned match_length = MIN_MATCH - 1;	/* length of best match */

	/* Process the input block. */
	while (G1.lookahead != 0) {
		/* Insert the string window[strstart .. strstart+2] in the
		 * dictionary, and set hash_head to the head of the hash chain:
		 */
		INSERT_STRING(G1.strstart, hash_head);

		/* Find the longest match, discarding those <= prev_length.
		 */
		G1.prev_length = match_length;
		prev_match = G1.match_start;
		match_length = MIN_MATCH - 1;

		if (hash_head != 0 && G1.prev_length < max_lazy_match
		 && G1.strstart - hash_head <= MAX_DIST
		) {
			/* To simplify the code, we prevent matches with the string
			 * of window index 0 (in particular we have to avoid a match
			 * of the string with itself at the start of the input file).
			 */
			match_length = longest_match(hash_head);
			/* longest_match() sets match_start */
			if (match_length > G1.lookahead)
				match_length = G1.lookahead;

			/* Ignore a length 3 match if it is too distant: */
			if (match_length == MIN_MATCH && G1.strstart - G1.match_start > TOO_FAR) {
				/* If prev_match is also MIN_MATCH, G1.match_start is garbage
				 * but we will ignore the current match anyway.
				 */
				match_length--;
			}
		}
		/* If there was a match at the previous step and the current
		 * match is not better, output the previous match:
		 */
		if (G1.prev_length >= MIN_MATCH && match_length <= G1.prev_length) {
			check_match(G1.strstart - 1, prev_match, G1.prev_length);
			flush = ct_tally(G1.strstart - 1 - prev_match, G1.prev_length - MIN_MATCH);

			/* Insert in hash table all strings up to the end of the match.
			 * strstart-1 and strstart are already inserted.
			 */
			G1.lookahead -= G1.prev_length - 1;
			G1.prev_length -= 2;
			do {
				G1.strstart++;
				INSERT_STRING(G1.strstart, hash_head);
				/* strstart never exceeds WSIZE-MAX_MATCH, so there are
				 * always MIN_MATCH bytes ahead. If lookahead < MIN_MATCH
				 * these bytes are garbage, but it does not matter since the
				 * next lookahead bytes will always be emitted as literals.
				 */
			} while (--G1.prev_length != 0);
			match_available = 0;
			match_length = MIN_MATCH - 1;
			G1.strstart++;
			if (flush) {
				FLUSH_BLOCK(0);
				G1.block_start = G1.strstart;
			}
		} else if (match_available) {
			/* If there was no match at the previous position, output a
			 * single literal. If there was a match but the current match
			 * is longer, truncate the previous match to a single literal.
			 */
			Tracevv((stderr, "%c", G1.window[G1.strstart - 1]));
			if (ct_tally(0, G1.window[G1.strstart - 1])) {
				FLUSH_BLOCK(0);
				G1.block_start = G1.strstart;
			}
			G1.strstart++;
			G1.lookahead--;
		} else {
			/* There is no previous match to compare with, wait for
			 * the next step to decide.
			 */
			match_available = 1;
			G1.strstart++;
			G1.lookahead--;
		}
		Assert(G1.strstart <= G1.isize && G1.lookahead <= G1.isize, "a bit too far");

		/* Make sure that we always have enough lookahead, except
		 * at the end of the input file. We need MAX_MATCH bytes
		 * for the next match, plus MIN_MATCH bytes to insert the
		 * string following the next match.
		 */
		fill_window_if_needed();
	}
	if (match_available)
		ct_tally(0, G1.window[G1.strstart - 1]);

	FLUSH_BLOCK(1);	/* eof */
}

/* ===========================================================================
 * Initialize the bit string routines.
 */
static void bi_init(void)
{
	//G1.bi_buf = 0; // globals are zeroed in pack_gzip()
	//G1.bi_valid = 0; // globals are zeroed in pack_gzip()
	//DEBUG_bits_sent(= 0L); // globals are zeroed in pack_gzip()
}

/* ===========================================================================
 * Initialize the "longest match" routines for a new file
 */
static void lm_init(void)
{
	unsigned j;

	/* Initialize the hash table. */
	memset(head, 0, HASH_SIZE * sizeof(*head));
	/* prev will be initialized on the fly */

	/* ??? reduce max_chain_length for binary files */

	//G1.strstart = 0; // globals are zeroed in pack_gzip()
	//G1.block_start = 0L; // globals are zeroed in pack_gzip()

	G1.lookahead = file_read(G1.window,
			sizeof(int) <= 2 ? (unsigned) WSIZE : 2 * WSIZE);

	if (G1.lookahead == 0 || G1.lookahead == (unsigned) -1) {
		G1.eofile = 1;
		G1.lookahead = 0;
		return;
	}
	//G1.eofile = 0; // globals are zeroed in pack_gzip()

	/* Make sure that we always have enough lookahead. This is important
	 * if input comes from a device such as a tty.
	 */
	fill_window_if_needed();

	//G1.ins_h = 0; // globals are zeroed in pack_gzip()
	for (j = 0; j < MIN_MATCH - 1; j++)
		UPDATE_HASH(G1.ins_h, G1.window[j]);
	/* If lookahead < MIN_MATCH, ins_h is garbage, but this is
	 * not important since only literal bytes will be emitted.
	 */
}

/* ===========================================================================
 * Allocate the match buffer, initialize the various tables and save the
 * location of the internal file attribute (ascii/binary) and method
 * (DEFLATE/STORE).
 * One callsite in zip()
 */
static void ct_init(void)
{
	int n;				/* iterates over tree elements */
	int length;			/* length value */
	int code;			/* code value */
	int dist;			/* distance index */

//	//G2.compressed_len = 0L; // globals are zeroed in pack_gzip()

#ifdef NOT_NEEDED
	if (G2.static_dtree[0].Len != 0)
		return;			/* ct_init already called */
#endif

	/* Initialize the mapping length (0..255) -> length code (0..28) */
	length = 0;
	for (code = 0; code < LENGTH_CODES - 1; code++) {
		G2.base_length[code] = length;
		for (n = 0; n < (1 << extra_lbits[code]); n++) {
			G2.length_code[length++] = code;
		}
	}
	Assert(length == 256, "ct_init: length != 256");
	/* Note that the length 255 (match length 258) can be represented
	 * in two different ways: code 284 + 5 bits or code 285, so we
	 * overwrite length_code[255] to use the best encoding:
	 */
	G2.length_code[length - 1] = code;

	/* Initialize the mapping dist (0..32K) -> dist code (0..29) */
	dist = 0;
	for (code = 0; code < 16; code++) {
		G2.base_dist[code] = dist;
		for (n = 0; n < (1 << extra_dbits[code]); n++) {
			G2.dist_code[dist++] = code;
		}
	}
	Assert(dist == 256, "ct_init: dist != 256");
	dist >>= 7;			/* from now on, all distances are divided by 128 */
	for (; code < D_CODES; code++) {
		G2.base_dist[code] = dist << 7;
		for (n = 0; n < (1 << (extra_dbits[code] - 7)); n++) {
			G2.dist_code[256 + dist++] = code;
		}
	}
	Assert(dist == 256, "ct_init: 256+dist != 512");

	/* Construct the codes of the static literal tree */
	//for (n = 0; n <= MAX_BITS; n++) // globals are zeroed in pack_gzip()
	//	G2.bl_count[n] = 0;

	n = 0;
	while (n <= 143) {
		G2.static_ltree[n++].Len = 8;
		//G2.bl_count[8]++;
	}
	//G2.bl_count[8] = 143 + 1;
	while (n <= 255) {
		G2.static_ltree[n++].Len = 9;
		//G2.bl_count[9]++;
	}
	//G2.bl_count[9] = 255 - 143;
	while (n <= 279) {
		G2.static_ltree[n++].Len = 7;
		//G2.bl_count[7]++;
	}
	//G2.bl_count[7] = 279 - 255;
	while (n <= 287) {
		G2.static_ltree[n++].Len = 8;
		//G2.bl_count[8]++;
	}
	//G2.bl_count[8] += 287 - 279;
	G2.bl_count[7] = 279 - 255;
	G2.bl_count[8] = (143 + 1) + (287 - 279);
	G2.bl_count[9] = 255 - 143;
	/* Codes 286 and 287 do not exist, but we must include them in the
	 * tree construction to get a canonical Huffman tree (longest code
	 * all ones)
	 */
	gen_codes((ct_data *) G2.static_ltree, L_CODES + 1);

	/* The static distance tree is trivial: */
	for (n = 0; n < D_CODES; n++) {
		G2.static_dtree[n].Len = 5;
		G2.static_dtree[n].Code = bi_reverse(n, 5);
	}

	/* Initialize the first block of the first file: */
	init_block();
}

/* ===========================================================================
 * Deflate in to out.
 * IN assertions: the input and output buffers are cleared.
 */
static void zip(void)
{
	unsigned deflate_flags;

	//G1.outcnt = 0; // globals are zeroed in pack_gzip()

	/* Write the header to the gzip file. See algorithm.doc for the format */
	/* magic header for gzip files: 1F 8B */
	/* compression method: 8 (DEFLATED) */
	/* general flags: 0 */
	put_32bit(0x00088b1f);
	put_32bit(0);		/* Unix timestamp */

	/* Write deflated file to zip file */
	G1.crc = ~0;

	bi_init();
	ct_init();
	lm_init();

	deflate_flags = 0x300; /* extra flags. OS id = 3 (Unix) */
#if ENABLE_FEATURE_GZIP_LEVELS
	/* Note that comp_level < 4 do not exist in this version of gzip */
	if (comp_level_minus4 == 9 - 4) {
		deflate_flags |= 0x02; /* SLOW flag */
	}
#endif
	put_16bit(deflate_flags);

	/* The above 32-bit misaligns outbuf (10 bytes are stored), flush it */
	flush_outbuf_if_32bit_optimized();

	deflate();

	/* Write the crc and uncompressed size */
	put_32bit(~G1.crc);
	put_32bit(G1.isize);

	flush_outbuf();
}

/* ======================================================================== */
static
IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_state_t *xstate UNUSED_PARAM)
{
	/* Reinit G1.xxx except pointers to allocated buffers, and entire G2 */
	memset(&G1.crc, 0, (sizeof(G1) - offsetof(struct globals, crc)) + sizeof(G2));

	/* Clear input and output buffers */
	//G1.outcnt = 0;
#ifdef DEBUG
	//G1.insize = 0;
#endif
	//G1.isize = 0;

	/* Reinit G2.xxx */
	G2.l_desc.dyn_tree     = G2.dyn_ltree;
	G2.l_desc.static_tree  = G2.static_ltree;
	G2.l_desc.extra_bits   = extra_lbits;
	G2.l_desc.extra_base   = LITERALS + 1;
	G2.l_desc.elems        = L_CODES;
	G2.l_desc.max_length   = MAX_BITS;
	//G2.l_desc.max_code     = 0;
	G2.d_desc.dyn_tree     = G2.dyn_dtree;
	G2.d_desc.static_tree  = G2.static_dtree;
	G2.d_desc.extra_bits   = extra_dbits;
	//G2.d_desc.extra_base   = 0;
	G2.d_desc.elems        = D_CODES;
	G2.d_desc.max_length   = MAX_BITS;
	//G2.d_desc.max_code     = 0;
	G2.bl_desc.dyn_tree    = G2.bl_tree;
	//G2.bl_desc.static_tree = NULL;
	G2.bl_desc.extra_bits  = extra_blbits,
	//G2.bl_desc.extra_base  = 0;
	G2.bl_desc.elems       = BL_CODES;
	G2.bl_desc.max_length  = MAX_BL_BITS;
	//G2.bl_desc.max_code    = 0;

#if 0
	/* Saving of timestamp is disabled. Why?
	 * - it is not Y2038-safe.
	 * - some people want deterministic results
	 *   (normally they'd use -n, but our -n is a nop).
	 * - it's bloat.
	 * Per RFC 1952, gzfile.time=0 is "no timestamp".
	 * If users will demand this to be reinstated,
	 * implement -n "don't save timestamp".
	 */
	struct stat s;
	s.st_ctime = 0;
	fstat(STDIN_FILENO, &s);
	zip(s.st_ctime);
#else
	zip();
#endif
	return 0;
}

#if ENABLE_FEATURE_GZIP_LONG_OPTIONS
static const char gzip_longopts[] ALIGN1 =
	"stdout\0"              No_argument       "c"
	"to-stdout\0"           No_argument       "c"
	"force\0"               No_argument       "f"
	"verbose\0"             No_argument       "v"
#if ENABLE_FEATURE_GZIP_DECOMPRESS
	"decompress\0"          No_argument       "d"
	"uncompress\0"          No_argument       "d"
	"test\0"                No_argument       "t"
#endif
	"quiet\0"               No_argument       "q"
	"fast\0"                No_argument       "1"
	"best\0"                No_argument       "9"
	"no-name\0"             No_argument       "n"
	;
#endif

/*
 * Linux kernel build uses gzip -d -n. We accept and ignore -n.
 * Man page says:
 * -n --no-name
 * gzip: do not save the original file name and time stamp.
 * (The original name is always saved if the name had to be truncated.)
 * gunzip: do not restore the original file name/time even if present
 * (remove only the gzip suffix from the compressed file name).
 * This option is the default when decompressing.
 * -N --name
 * gzip: always save the original file name and time stamp (this is the default)
 * gunzip: restore the original file name and time stamp if present.
 */

int gzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
#if ENABLE_FEATURE_GZIP_DECOMPRESS
int gzip_main(int argc, char **argv)
#else
int gzip_main(int argc UNUSED_PARAM, char **argv)
#endif
{
	unsigned opt;
#if ENABLE_FEATURE_GZIP_LEVELS
	static const struct {
		uint8_t good;
		uint8_t chain_shift;
		uint8_t lazy2;
		uint8_t nice2;
	} gzip_level_config[6] = {
		{4,   4,   4/2,  16/2}, /* Level 4 */
		{8,   5,  16/2,  32/2}, /* Level 5 */
		{8,   7,  16/2, 128/2}, /* Level 6 */
		{8,   8,  32/2, 128/2}, /* Level 7 */
		{32, 10, 128/2, 258/2}, /* Level 8 */
		{32, 12, 258/2, 258/2}, /* Level 9 */
	};
#endif

	SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2))
			+ sizeof(struct globals));

	/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
#if ENABLE_FEATURE_GZIP_LONG_OPTIONS
	opt = getopt32long(argv, BBUNPK_OPTSTR IF_FEATURE_GZIP_DECOMPRESS("dt") "n123456789", gzip_longopts);
#else
	opt = getopt32(argv, BBUNPK_OPTSTR IF_FEATURE_GZIP_DECOMPRESS("dt") "n123456789");
#endif
#if ENABLE_FEATURE_GZIP_DECOMPRESS /* gunzip_main may not be visible... */
	if (opt & (BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST)) /* -d and/or -t */
		return gunzip_main(argc, argv);
#endif
#if ENABLE_FEATURE_GZIP_LEVELS
	opt >>= (BBUNPK_OPTSTRLEN IF_FEATURE_GZIP_DECOMPRESS(+ 2) + 1); /* drop cfkvq[dt]n bits */
	if (opt == 0)
		opt = 1 << 5; /* default: 6 */
	opt = ffs(opt >> 4); /* Maps -1..-4 to [0], -5 to [1] ... -9 to [5] */

	comp_level_minus4 = opt;

	max_chain_length = 1 << gzip_level_config[opt].chain_shift;
	good_match	 = gzip_level_config[opt].good;
	max_lazy_match	 = gzip_level_config[opt].lazy2 * 2;
	nice_match	 = gzip_level_config[opt].nice2 * 2;
#endif
	option_mask32 &= BBUNPK_OPTSTRMASK; /* retain only -cfkvq */

	/* Allocate all global buffers (for DYN_ALLOC option) */
	ALLOC(uch, G1.l_buf, INBUFSIZ);
	ALLOC(uch, G1.outbuf, OUTBUFSIZ);
	ALLOC(ush, G1.d_buf, DIST_BUFSIZE);
	ALLOC(uch, G1.window, 2L * WSIZE);
	ALLOC(ush, G1.prev, 1L << BITS);

	/* Initialize the CRC32 table */
	global_crc32_new_table_le();

	argv += optind;
	return bbunpack(argv, pack_gzip, append_ext, "gz");
}
