1 /* minilzo.c -- mini subset of the LZO real-time data compression library
2 
3    This file is part of the LZO real-time data compression library.
4 
5    Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
6    Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
7    Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
8    Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
9    Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
10    Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
11    Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
12    Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
13    Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
14    Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
15    All Rights Reserved.
16 
17    The LZO library is free software; you can redistribute it and/or
18    modify it under the terms of the GNU General Public License,
19    version 2, as published by the Free Software Foundation.
20 
21    The LZO library is distributed in the hope that it will be useful,
22    but WITHOUT ANY WARRANTY; without even the implied warranty of
23    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24    GNU General Public License for more details.
25 
26    You should have received a copy of the GNU General Public License
27    along with the LZO library; see the file COPYING.
28    If not, write to the Free Software Foundation, Inc.,
29    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 
31    Markus F.X.J. Oberhumer
32    <markus@oberhumer.com>
33    http://www.oberhumer.com/opensource/lzo/
34  */
35 
36 /*
37  * NOTE:
38  *   the full LZO package can be found at
39  *   http://www.oberhumer.com/opensource/lzo/
40  */
41 
42 #define __LZO_IN_MINILZO
43 #define LZO_BUILD
44 
45 #if defined(LZO_CFG_FREESTANDING)
46 #  undef MINILZO_HAVE_CONFIG_H
47 #  define LZO_LIBC_FREESTANDING 1
48 #  define LZO_OS_FREESTANDING 1
49 #endif
50 
51 #ifdef MINILZO_HAVE_CONFIG_H
52 #  include <config.h>
53 #endif
54 #include <limits.h>
55 #include <stddef.h>
56 #if defined(MINILZO_CFG_USE_INTERNAL_LZODEFS)
57 
58 #ifndef __LZODEFS_H_INCLUDED
59 #define __LZODEFS_H_INCLUDED 1
60 
61 #if defined(__CYGWIN32__) && !defined(__CYGWIN__)
62 #  define __CYGWIN__ __CYGWIN32__
63 #endif
64 #if defined(__IBMCPP__) && !defined(__IBMC__)
65 #  define __IBMC__ __IBMCPP__
66 #endif
67 #if defined(__ICL) && defined(_WIN32) && !defined(__INTEL_COMPILER)
68 #  define __INTEL_COMPILER __ICL
69 #endif
70 #if 1 && defined(__INTERIX) && defined(__GNUC__) && !defined(_ALL_SOURCE)
71 #  define _ALL_SOURCE 1
72 #endif
73 #if defined(__mips__) && defined(__R5900__)
74 #  if !defined(__LONG_MAX__)
75 #    define __LONG_MAX__ 9223372036854775807L
76 #  endif
77 #endif
78 #if defined(__INTEL_COMPILER) && defined(__linux__)
79 #  pragma warning(disable: 193)
80 #endif
81 #if defined(__KEIL__) && defined(__C166__)
82 #  pragma warning disable = 322
83 #elif 0 && defined(__C251__)
84 #  pragma warning disable = 322
85 #endif
86 #if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__)
87 #  if (_MSC_VER >= 1300)
88 #    pragma warning(disable: 4668)
89 #  endif
90 #endif
91 #if 0 && defined(__WATCOMC__)
92 #  if (__WATCOMC__ >= 1050) && (__WATCOMC__ < 1060)
93 #    pragma warning 203 9
94 #  endif
95 #endif
96 #if defined(__BORLANDC__) && defined(__MSDOS__) && !defined(__FLAT__)
97 #  pragma option -h
98 #endif
99 #if 0
100 #define LZO_0xffffL             0xfffful
101 #define LZO_0xffffffffL         0xfffffffful
102 #else
103 #define LZO_0xffffL             65535ul
104 #define LZO_0xffffffffL         4294967295ul
105 #endif
106 #if (LZO_0xffffL == LZO_0xffffffffL)
107 #  error "your preprocessor is broken 1"
108 #endif
109 #if (16ul * 16384ul != 262144ul)
110 #  error "your preprocessor is broken 2"
111 #endif
112 #if 0
113 #if (32767 >= 4294967295ul)
114 #  error "your preprocessor is broken 3"
115 #endif
116 #if (65535u >= 4294967295ul)
117 #  error "your preprocessor is broken 4"
118 #endif
119 #endif
120 #if (UINT_MAX == LZO_0xffffL)
121 #if defined(__ZTC__) && defined(__I86__) && !defined(__OS2__)
122 #  if !defined(MSDOS)
123 #    define MSDOS 1
124 #  endif
125 #  if !defined(_MSDOS)
126 #    define _MSDOS 1
127 #  endif
128 #elif 0 && defined(__VERSION) && defined(MB_LEN_MAX)
129 #  if (__VERSION == 520) && (MB_LEN_MAX == 1)
130 #    if !defined(__AZTEC_C__)
131 #      define __AZTEC_C__ __VERSION
132 #    endif
133 #    if !defined(__DOS__)
134 #      define __DOS__ 1
135 #    endif
136 #  endif
137 #endif
138 #endif
139 #if defined(_MSC_VER) && defined(M_I86HM) && (UINT_MAX == LZO_0xffffL)
140 #  define ptrdiff_t long
141 #  define _PTRDIFF_T_DEFINED
142 #endif
143 #if (UINT_MAX == LZO_0xffffL)
144 #  undef __LZO_RENAME_A
145 #  undef __LZO_RENAME_B
146 #  if defined(__AZTEC_C__) && defined(__DOS__)
147 #    define __LZO_RENAME_A 1
148 #  elif defined(_MSC_VER) && defined(MSDOS)
149 #    if (_MSC_VER < 600)
150 #      define __LZO_RENAME_A 1
151 #    elif (_MSC_VER < 700)
152 #      define __LZO_RENAME_B 1
153 #    endif
154 #  elif defined(__TSC__) && defined(__OS2__)
155 #    define __LZO_RENAME_A 1
156 #  elif defined(__MSDOS__) && defined(__TURBOC__) && (__TURBOC__ < 0x0410)
157 #    define __LZO_RENAME_A 1
158 #  elif defined(__PACIFIC__) && defined(DOS)
159 #    if !defined(__far)
160 #      define __far far
161 #    endif
162 #    if !defined(__near)
163 #      define __near near
164 #    endif
165 #  endif
166 #  if defined(__LZO_RENAME_A)
167 #    if !defined(__cdecl)
168 #      define __cdecl cdecl
169 #    endif
170 #    if !defined(__far)
171 #      define __far far
172 #    endif
173 #    if !defined(__huge)
174 #      define __huge huge
175 #    endif
176 #    if !defined(__near)
177 #      define __near near
178 #    endif
179 #    if !defined(__pascal)
180 #      define __pascal pascal
181 #    endif
182 #    if !defined(__huge)
183 #      define __huge huge
184 #    endif
185 #  elif defined(__LZO_RENAME_B)
186 #    if !defined(__cdecl)
187 #      define __cdecl _cdecl
188 #    endif
189 #    if !defined(__far)
190 #      define __far _far
191 #    endif
192 #    if !defined(__huge)
193 #      define __huge _huge
194 #    endif
195 #    if !defined(__near)
196 #      define __near _near
197 #    endif
198 #    if !defined(__pascal)
199 #      define __pascal _pascal
200 #    endif
201 #  elif (defined(__PUREC__) || defined(__TURBOC__)) && defined(__TOS__)
202 #    if !defined(__cdecl)
203 #      define __cdecl cdecl
204 #    endif
205 #    if !defined(__pascal)
206 #      define __pascal pascal
207 #    endif
208 #  endif
209 #  undef __LZO_RENAME_A
210 #  undef __LZO_RENAME_B
211 #endif
212 #if (UINT_MAX == LZO_0xffffL)
213 #if defined(__AZTEC_C__) && defined(__DOS__)
214 #  define LZO_BROKEN_CDECL_ALT_SYNTAX 1
215 #elif defined(_MSC_VER) && defined(MSDOS)
216 #  if (_MSC_VER < 600)
217 #    define LZO_BROKEN_INTEGRAL_CONSTANTS 1
218 #  endif
219 #  if (_MSC_VER < 700)
220 #    define LZO_BROKEN_INTEGRAL_PROMOTION 1
221 #    define LZO_BROKEN_SIZEOF 1
222 #  endif
223 #elif defined(__PACIFIC__) && defined(DOS)
224 #  define LZO_BROKEN_INTEGRAL_CONSTANTS 1
225 #elif defined(__TURBOC__) && defined(__MSDOS__)
226 #  if (__TURBOC__ < 0x0150)
227 #    define LZO_BROKEN_CDECL_ALT_SYNTAX 1
228 #    define LZO_BROKEN_INTEGRAL_CONSTANTS 1
229 #    define LZO_BROKEN_INTEGRAL_PROMOTION 1
230 #  endif
231 #  if (__TURBOC__ < 0x0200)
232 #    define LZO_BROKEN_SIZEOF 1
233 #  endif
234 #  if (__TURBOC__ < 0x0400) && defined(__cplusplus)
235 #    define LZO_BROKEN_CDECL_ALT_SYNTAX 1
236 #  endif
237 #elif (defined(__PUREC__) || defined(__TURBOC__)) && defined(__TOS__)
238 #  define LZO_BROKEN_CDECL_ALT_SYNTAX 1
239 #  define LZO_BROKEN_SIZEOF 1
240 #endif
241 #endif
242 #if defined(__WATCOMC__) && (__WATCOMC__ < 900)
243 #  define LZO_BROKEN_INTEGRAL_CONSTANTS 1
244 #endif
245 #define LZO_CPP_STRINGIZE(x)            #x
246 #define LZO_CPP_MACRO_EXPAND(x)         LZO_CPP_STRINGIZE(x)
247 #define LZO_CPP_CONCAT2(a,b)            a ## b
248 #define LZO_CPP_CONCAT3(a,b,c)          a ## b ## c
249 #define LZO_CPP_CONCAT4(a,b,c,d)        a ## b ## c ## d
250 #define LZO_CPP_CONCAT5(a,b,c,d,e)      a ## b ## c ## d ## e
251 #define LZO_CPP_ECONCAT2(a,b)           LZO_CPP_CONCAT2(a,b)
252 #define LZO_CPP_ECONCAT3(a,b,c)         LZO_CPP_CONCAT3(a,b,c)
253 #define LZO_CPP_ECONCAT4(a,b,c,d)       LZO_CPP_CONCAT4(a,b,c,d)
254 #define LZO_CPP_ECONCAT5(a,b,c,d,e)     LZO_CPP_CONCAT5(a,b,c,d,e)
255 #define __LZO_MASK_GEN(o,b)     (((((o) << ((b)-1)) - (o)) << 1) + (o))
256 #if 1 && defined(__cplusplus)
257 #  if !defined(__STDC_CONSTANT_MACROS)
258 #    define __STDC_CONSTANT_MACROS 1
259 #  endif
260 #  if !defined(__STDC_LIMIT_MACROS)
261 #    define __STDC_LIMIT_MACROS 1
262 #  endif
263 #endif
264 #if defined(__cplusplus)
265 #  define LZO_EXTERN_C extern "C"
266 #else
267 #  define LZO_EXTERN_C extern
268 #endif
269 #if !defined(__LZO_OS_OVERRIDE)
270 #if defined(LZO_OS_FREESTANDING)
271 #  define LZO_INFO_OS           "freestanding"
272 #elif defined(LZO_OS_EMBEDDED)
273 #  define LZO_INFO_OS           "embedded"
274 #elif defined(__CYGWIN__) && defined(__GNUC__)
275 #  define LZO_OS_CYGWIN         1
276 #  define LZO_INFO_OS           "cygwin"
277 #elif defined(__EMX__) && defined(__GNUC__)
278 #  define LZO_OS_EMX            1
279 #  define LZO_INFO_OS           "emx"
280 #elif defined(__BEOS__)
281 #  define LZO_OS_BEOS           1
282 #  define LZO_INFO_OS           "beos"
283 #elif defined(__Lynx__)
284 #  define LZO_OS_LYNXOS         1
285 #  define LZO_INFO_OS           "lynxos"
286 #elif defined(__OS400__)
287 #  define LZO_OS_OS400          1
288 #  define LZO_INFO_OS           "os400"
289 #elif defined(__QNX__)
290 #  define LZO_OS_QNX            1
291 #  define LZO_INFO_OS           "qnx"
292 #elif defined(__BORLANDC__) && defined(__DPMI32__) && (__BORLANDC__ >= 0x0460)
293 #  define LZO_OS_DOS32          1
294 #  define LZO_INFO_OS           "dos32"
295 #elif defined(__BORLANDC__) && defined(__DPMI16__)
296 #  define LZO_OS_DOS16          1
297 #  define LZO_INFO_OS           "dos16"
298 #elif defined(__ZTC__) && defined(DOS386)
299 #  define LZO_OS_DOS32          1
300 #  define LZO_INFO_OS           "dos32"
301 #elif defined(__OS2__) || defined(__OS2V2__)
302 #  if (UINT_MAX == LZO_0xffffL)
303 #    define LZO_OS_OS216        1
304 #    define LZO_INFO_OS         "os216"
305 #  elif (UINT_MAX == LZO_0xffffffffL)
306 #    define LZO_OS_OS2          1
307 #    define LZO_INFO_OS         "os2"
308 #  else
309 #    error "check your limits.h header"
310 #  endif
311 #elif defined(__WIN64__) || defined(_WIN64) || defined(WIN64)
312 #  define LZO_OS_WIN64          1
313 #  define LZO_INFO_OS           "win64"
314 #elif defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(__WINDOWS_386__)
315 #  define LZO_OS_WIN32          1
316 #  define LZO_INFO_OS           "win32"
317 #elif defined(__MWERKS__) && defined(__INTEL__)
318 #  define LZO_OS_WIN32          1
319 #  define LZO_INFO_OS           "win32"
320 #elif defined(__WINDOWS__) || defined(_WINDOWS) || defined(_Windows)
321 #  if (UINT_MAX == LZO_0xffffL)
322 #    define LZO_OS_WIN16        1
323 #    define LZO_INFO_OS         "win16"
324 #  elif (UINT_MAX == LZO_0xffffffffL)
325 #    define LZO_OS_WIN32        1
326 #    define LZO_INFO_OS         "win32"
327 #  else
328 #    error "check your limits.h header"
329 #  endif
330 #elif defined(__DOS__) || defined(__MSDOS__) || defined(_MSDOS) || defined(MSDOS) || (defined(__PACIFIC__) && defined(DOS))
331 #  if (UINT_MAX == LZO_0xffffL)
332 #    define LZO_OS_DOS16        1
333 #    define LZO_INFO_OS         "dos16"
334 #  elif (UINT_MAX == LZO_0xffffffffL)
335 #    define LZO_OS_DOS32        1
336 #    define LZO_INFO_OS         "dos32"
337 #  else
338 #    error "check your limits.h header"
339 #  endif
340 #elif defined(__WATCOMC__)
341 #  if defined(__NT__) && (UINT_MAX == LZO_0xffffL)
342 #    define LZO_OS_DOS16        1
343 #    define LZO_INFO_OS         "dos16"
344 #  elif defined(__NT__) && (__WATCOMC__ < 1100)
345 #    define LZO_OS_WIN32        1
346 #    define LZO_INFO_OS         "win32"
347 #  else
348 #    error "please specify a target using the -bt compiler option"
349 #  endif
350 #elif defined(__palmos__)
351 #  define LZO_OS_PALMOS         1
352 #  define LZO_INFO_OS           "palmos"
353 #elif defined(__TOS__) || defined(__atarist__)
354 #  define LZO_OS_TOS            1
355 #  define LZO_INFO_OS           "tos"
356 #elif defined(macintosh) && !defined(__ppc__)
357 #  define LZO_OS_MACCLASSIC     1
358 #  define LZO_INFO_OS           "macclassic"
359 #elif defined(__VMS)
360 #  define LZO_OS_VMS            1
361 #  define LZO_INFO_OS           "vms"
362 #elif ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__))
363 #  define LZO_OS_CONSOLE        1
364 #  define LZO_OS_CONSOLE_PS2    1
365 #  define LZO_INFO_OS           "console"
366 #  define LZO_INFO_OS_CONSOLE   "ps2"
367 #elif (defined(__mips__) && defined(__psp__))
368 #  define LZO_OS_CONSOLE        1
369 #  define LZO_OS_CONSOLE_PSP    1
370 #  define LZO_INFO_OS           "console"
371 #  define LZO_INFO_OS_CONSOLE   "psp"
372 #else
373 #  define LZO_OS_POSIX          1
374 #  define LZO_INFO_OS           "posix"
375 #endif
376 #if (LZO_OS_POSIX)
377 #  if defined(_AIX) || defined(__AIX__) || defined(__aix__)
378 #    define LZO_OS_POSIX_AIX        1
379 #    define LZO_INFO_OS_POSIX       "aix"
380 #  elif defined(__FreeBSD__)
381 #    define LZO_OS_POSIX_FREEBSD    1
382 #    define LZO_INFO_OS_POSIX       "freebsd"
383 #  elif defined(__hpux__) || defined(__hpux)
384 #    define LZO_OS_POSIX_HPUX       1
385 #    define LZO_INFO_OS_POSIX       "hpux"
386 #  elif defined(__INTERIX)
387 #    define LZO_OS_POSIX_INTERIX    1
388 #    define LZO_INFO_OS_POSIX       "interix"
389 #  elif defined(__IRIX__) || defined(__irix__)
390 #    define LZO_OS_POSIX_IRIX       1
391 #    define LZO_INFO_OS_POSIX       "irix"
392 #  elif defined(__linux__) || defined(__linux)
393 #    define LZO_OS_POSIX_LINUX      1
394 #    define LZO_INFO_OS_POSIX       "linux"
395 #  elif defined(__APPLE__) || defined(__MACOS__)
396 #    define LZO_OS_POSIX_MACOSX     1
397 #    define LZO_INFO_OS_POSIX       "macosx"
398 #  elif defined(__NetBSD__)
399 #    define LZO_OS_POSIX_NETBSD     1
400 #    define LZO_INFO_OS_POSIX       "netbsd"
401 #  elif defined(__OpenBSD__)
402 #    define LZO_OS_POSIX_OPENBSD    1
403 #    define LZO_INFO_OS_POSIX       "openbsd"
404 #  elif defined(__osf__)
405 #    define LZO_OS_POSIX_OSF        1
406 #    define LZO_INFO_OS_POSIX       "osf"
407 #  elif defined(__solaris__) || defined(__sun)
408 #    if defined(__SVR4) || defined(__svr4__)
409 #      define LZO_OS_POSIX_SOLARIS  1
410 #      define LZO_INFO_OS_POSIX     "solaris"
411 #    else
412 #      define LZO_OS_POSIX_SUNOS    1
413 #      define LZO_INFO_OS_POSIX     "sunos"
414 #    endif
415 #  elif defined(__ultrix__) || defined(__ultrix)
416 #    define LZO_OS_POSIX_ULTRIX     1
417 #    define LZO_INFO_OS_POSIX       "ultrix"
418 #  else
419 #    define LZO_OS_POSIX_UNKNOWN    1
420 #    define LZO_INFO_OS_POSIX       "unknown"
421 #  endif
422 #endif
423 #endif
424 #if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16)
425 #  if (UINT_MAX != LZO_0xffffL)
426 #    error "this should not happen"
427 #  endif
428 #  if (ULONG_MAX != LZO_0xffffffffL)
429 #    error "this should not happen"
430 #  endif
431 #endif
432 #if (LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_WIN32 || LZO_OS_WIN64)
433 #  if (UINT_MAX != LZO_0xffffffffL)
434 #    error "this should not happen"
435 #  endif
436 #  if (ULONG_MAX != LZO_0xffffffffL)
437 #    error "this should not happen"
438 #  endif
439 #endif
440 #if defined(CIL) && defined(_GNUCC) && defined(__GNUC__)
441 #  define LZO_CC_CILLY          1
442 #  define LZO_INFO_CC           "Cilly"
443 #  if defined(__CILLY__)
444 #    define LZO_INFO_CCVER      LZO_CPP_MACRO_EXPAND(__CILLY__)
445 #  else
446 #    define LZO_INFO_CCVER      "unknown"
447 #  endif
448 #elif 0 && defined(SDCC) && defined(__VERSION__) && !defined(__GNUC__)
449 #  define LZO_CC_SDCC           1
450 #  define LZO_INFO_CC           "sdcc"
451 #  define LZO_INFO_CCVER        LZO_CPP_MACRO_EXPAND(SDCC)
452 #elif defined(__PATHSCALE__) && defined(__PATHCC_PATCHLEVEL__)
453 #  define LZO_CC_PATHSCALE      (__PATHCC__ * 0x10000L + __PATHCC_MINOR__ * 0x100 + __PATHCC_PATCHLEVEL__)
454 #  define LZO_INFO_CC           "Pathscale C"
455 #  define LZO_INFO_CCVER        __PATHSCALE__
456 #elif defined(__INTEL_COMPILER)
457 #  define LZO_CC_INTELC         1
458 #  define LZO_INFO_CC           "Intel C"
459 #  define LZO_INFO_CCVER        LZO_CPP_MACRO_EXPAND(__INTEL_COMPILER)
460 #elif defined(__POCC__) && defined(_WIN32)
461 #  define LZO_CC_PELLESC        1
462 #  define LZO_INFO_CC           "Pelles C"
463 #  define LZO_INFO_CCVER        LZO_CPP_MACRO_EXPAND(__POCC__)
464 #elif defined(__llvm__) && defined(__GNUC__) && defined(__VERSION__)
465 #  define LZO_CC_LLVM           1
466 #  define LZO_INFO_CC           "llvm-gcc"
467 #  define LZO_INFO_CCVER        __VERSION__
468 #elif defined(__GNUC__) && defined(__VERSION__)
469 #  if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
470 #    define LZO_CC_GNUC         (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__)
471 #  elif defined(__GNUC_MINOR__)
472 #    define LZO_CC_GNUC         (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100)
473 #  else
474 #    define LZO_CC_GNUC         (__GNUC__ * 0x10000L)
475 #  endif
476 #  define LZO_INFO_CC           "gcc"
477 #  define LZO_INFO_CCVER        __VERSION__
478 #elif defined(__AZTEC_C__)
479 #  define LZO_CC_AZTECC         1
480 #  define LZO_INFO_CC           "Aztec C"
481 #  define LZO_INFO_CCVER        LZO_CPP_MACRO_EXPAND(__AZTEC_C__)
482 #elif defined(__BORLANDC__)
483 #  define LZO_CC_BORLANDC       1
484 #  define LZO_INFO_CC           "Borland C"
485 #  define LZO_INFO_CCVER        LZO_CPP_MACRO_EXPAND(__BORLANDC__)
486 #elif defined(__DMC__) && defined(__SC__)
487 #  define LZO_CC_DMC            1
488 #  define LZO_INFO_CC           "Digital Mars C"
489 #  define LZO_INFO_CCVER        LZO_CPP_MACRO_EXPAND(__DMC__)
490 #elif defined(__DECC)
491 #  define LZO_CC_DECC           1
492 #  define LZO_INFO_CC           "DEC C"
493 #  define LZO_INFO_CCVER        LZO_CPP_MACRO_EXPAND(__DECC)
494 #elif defined(__HIGHC__)
495 #  define LZO_CC_HIGHC          1
496 #  define LZO_INFO_CC           "MetaWare High C"
497 #  define LZO_INFO_CCVER        "unknown"
498 #elif defined(__IBMC__)
499 #  define LZO_CC_IBMC           1
500 #  define LZO_INFO_CC           "IBM C"
501 #  define LZO_INFO_CCVER        LZO_CPP_MACRO_EXPAND(__IBMC__)
502 #elif defined(__KEIL__) && defined(__C166__)
503 #  define LZO_CC_KEILC          1
504 #  define LZO_INFO_CC           "Keil C"
505 #  define LZO_INFO_CCVER        LZO_CPP_MACRO_EXPAND(__C166__)
506 #elif defined(__LCC__) && defined(_WIN32) && defined(__LCCOPTIMLEVEL)
507 #  define LZO_CC_LCCWIN32       1
508 #  define LZO_INFO_CC           "lcc-win32"
509 #  define LZO_INFO_CCVER        "unknown"
510 #elif defined(__LCC__)
511 #  define LZO_CC_LCC            1
512 #  define LZO_INFO_CC           "lcc"
513 #  if defined(__LCC_VERSION__)
514 #    define LZO_INFO_CCVER      LZO_CPP_MACRO_EXPAND(__LCC_VERSION__)
515 #  else
516 #    define LZO_INFO_CCVER      "unknown"
517 #  endif
518 #elif defined(_MSC_VER)
519 #  define LZO_CC_MSC            1
520 #  define LZO_INFO_CC           "Microsoft C"
521 #  if defined(_MSC_FULL_VER)
522 #    define LZO_INFO_CCVER      LZO_CPP_MACRO_EXPAND(_MSC_VER) "." LZO_CPP_MACRO_EXPAND(_MSC_FULL_VER)
523 #  else
524 #    define LZO_INFO_CCVER      LZO_CPP_MACRO_EXPAND(_MSC_VER)
525 #  endif
526 #elif defined(__MWERKS__)
527 #  define LZO_CC_MWERKS         1
528 #  define LZO_INFO_CC           "Metrowerks C"
529 #  define LZO_INFO_CCVER        LZO_CPP_MACRO_EXPAND(__MWERKS__)
530 #elif (defined(__NDPC__) || defined(__NDPX__)) && defined(__i386)
531 #  define LZO_CC_NDPC           1
532 #  define LZO_INFO_CC           "Microway NDP C"
533 #  define LZO_INFO_CCVER        "unknown"
534 #elif defined(__PACIFIC__)
535 #  define LZO_CC_PACIFICC       1
536 #  define LZO_INFO_CC           "Pacific C"
537 #  define LZO_INFO_CCVER        LZO_CPP_MACRO_EXPAND(__PACIFIC__)
538 #elif defined(__PGI) && (defined(__linux__) || defined(__WIN32__))
539 #  define LZO_CC_PGI            1
540 #  define LZO_INFO_CC           "Portland Group PGI C"
541 #  define LZO_INFO_CCVER        "unknown"
542 #elif defined(__PUREC__) && defined(__TOS__)
543 #  define LZO_CC_PUREC          1
544 #  define LZO_INFO_CC           "Pure C"
545 #  define LZO_INFO_CCVER        LZO_CPP_MACRO_EXPAND(__PUREC__)
546 #elif defined(__SC__) && defined(__ZTC__)
547 #  define LZO_CC_SYMANTECC      1
548 #  define LZO_INFO_CC           "Symantec C"
549 #  define LZO_INFO_CCVER        LZO_CPP_MACRO_EXPAND(__SC__)
550 #elif defined(__SUNPRO_C)
551 #  define LZO_CC_SUNPROC        1
552 #  define LZO_INFO_CC           "Sun C"
553 #  define LZO_INFO_CCVER        "unknown"
554 #elif defined(__TINYC__)
555 #  define LZO_CC_TINYC          1
556 #  define LZO_INFO_CC           "Tiny C"
557 #  define LZO_INFO_CCVER        LZO_CPP_MACRO_EXPAND(__TINYC__)
558 #elif defined(__TSC__)
559 #  define LZO_CC_TOPSPEEDC      1
560 #  define LZO_INFO_CC           "TopSpeed C"
561 #  define LZO_INFO_CCVER        LZO_CPP_MACRO_EXPAND(__TSC__)
562 #elif defined(__WATCOMC__)
563 #  define LZO_CC_WATCOMC        1
564 #  define LZO_INFO_CC           "Watcom C"
565 #  define LZO_INFO_CCVER        LZO_CPP_MACRO_EXPAND(__WATCOMC__)
566 #elif defined(__TURBOC__)
567 #  define LZO_CC_TURBOC         1
568 #  define LZO_INFO_CC           "Turbo C"
569 #  define LZO_INFO_CCVER        LZO_CPP_MACRO_EXPAND(__TURBOC__)
570 #elif defined(__ZTC__)
571 #  define LZO_CC_ZORTECHC       1
572 #  define LZO_INFO_CC           "Zortech C"
573 #  if (__ZTC__ == 0x310)
574 #    define LZO_INFO_CCVER      "0x310"
575 #  else
576 #    define LZO_INFO_CCVER      LZO_CPP_MACRO_EXPAND(__ZTC__)
577 #  endif
578 #else
579 #  define LZO_CC_UNKNOWN        1
580 #  define LZO_INFO_CC           "unknown"
581 #  define LZO_INFO_CCVER        "unknown"
582 #endif
583 #if 0 && (LZO_CC_MSC && (_MSC_VER >= 1200)) && !defined(_MSC_FULL_VER)
584 #  error "LZO_CC_MSC: _MSC_FULL_VER is not defined"
585 #endif
586 #if !defined(__LZO_ARCH_OVERRIDE)
587 #if defined(LZO_ARCH_GENERIC)
588 #  define LZO_INFO_ARCH             "generic"
589 #elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16)
590 #  define LZO_ARCH_I086             1
591 #  define LZO_ARCH_IA16             1
592 #  define LZO_INFO_ARCH             "i086"
593 #elif defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA)
594 #  define LZO_ARCH_ALPHA            1
595 #  define LZO_INFO_ARCH             "alpha"
596 #elif defined(__amd64__) || defined(__x86_64__) || defined(_M_AMD64)
597 #  define LZO_ARCH_AMD64            1
598 #  define LZO_INFO_ARCH             "amd64"
599 #elif defined(__thumb__) || (defined(_M_ARM) && defined(_M_THUMB))
600 #  define LZO_ARCH_ARM              1
601 #  define LZO_ARCH_ARM_THUMB        1
602 #  define LZO_INFO_ARCH             "arm_thumb"
603 #elif defined(__arm__) || defined(_M_ARM)
604 #  define LZO_ARCH_ARM              1
605 #  define LZO_INFO_ARCH             "arm"
606 #elif (UINT_MAX <= LZO_0xffffL) && defined(__AVR__)
607 #  define LZO_ARCH_AVR              1
608 #  define LZO_INFO_ARCH             "avr"
609 #elif defined(__bfin__)
610 #  define LZO_ARCH_BLACKFIN         1
611 #  define LZO_INFO_ARCH             "blackfin"
612 #elif (UINT_MAX == LZO_0xffffL) && defined(__C166__)
613 #  define LZO_ARCH_C166             1
614 #  define LZO_INFO_ARCH             "c166"
615 #elif defined(__cris__)
616 #  define LZO_ARCH_CRIS             1
617 #  define LZO_INFO_ARCH             "cris"
618 #elif defined(__H8300__) || defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__)
619 #  define LZO_ARCH_H8300            1
620 #  define LZO_INFO_ARCH             "h8300"
621 #elif defined(__hppa__) || defined(__hppa)
622 #  define LZO_ARCH_HPPA             1
623 #  define LZO_INFO_ARCH             "hppa"
624 #elif defined(__386__) || defined(__i386__) || defined(__i386) || defined(_M_IX86) || defined(_M_I386)
625 #  define LZO_ARCH_I386             1
626 #  define LZO_ARCH_IA32             1
627 #  define LZO_INFO_ARCH             "i386"
628 #elif (LZO_CC_ZORTECHC && defined(__I86__))
629 #  define LZO_ARCH_I386             1
630 #  define LZO_ARCH_IA32             1
631 #  define LZO_INFO_ARCH             "i386"
632 #elif (LZO_OS_DOS32 && LZO_CC_HIGHC) && defined(_I386)
633 #  define LZO_ARCH_I386             1
634 #  define LZO_ARCH_IA32             1
635 #  define LZO_INFO_ARCH             "i386"
636 #elif defined(__ia64__) || defined(__ia64) || defined(_M_IA64)
637 #  define LZO_ARCH_IA64             1
638 #  define LZO_INFO_ARCH             "ia64"
639 #elif (UINT_MAX == LZO_0xffffL) && defined(__m32c__)
640 #  define LZO_ARCH_M16C             1
641 #  define LZO_INFO_ARCH             "m16c"
642 #elif defined(__m32r__)
643 #  define LZO_ARCH_M32R             1
644 #  define LZO_INFO_ARCH             "m32r"
645 #elif (LZO_OS_TOS) || defined(__m68k__) || defined(__m68000__) || defined(__mc68000__) || defined(_M_M68K)
646 #  define LZO_ARCH_M68K             1
647 #  define LZO_INFO_ARCH             "m68k"
648 #elif (UINT_MAX == LZO_0xffffL) && defined(__C251__)
649 #  define LZO_ARCH_MCS251           1
650 #  define LZO_INFO_ARCH             "mcs251"
651 #elif (UINT_MAX == LZO_0xffffL) && defined(__C51__)
652 #  define LZO_ARCH_MCS51            1
653 #  define LZO_INFO_ARCH             "mcs51"
654 #elif defined(__mips__) || defined(__mips) || defined(_MIPS_ARCH) || defined(_M_MRX000)
655 #  define LZO_ARCH_MIPS             1
656 #  define LZO_INFO_ARCH             "mips"
657 #elif (UINT_MAX == LZO_0xffffL) && defined(__MSP430__)
658 #  define LZO_ARCH_MSP430           1
659 #  define LZO_INFO_ARCH             "msp430"
660 #elif defined(__powerpc__) || defined(__powerpc) || defined(__ppc__) || defined(__PPC__) || defined(_M_PPC)
661 #  define LZO_ARCH_POWERPC          1
662 #  define LZO_INFO_ARCH             "powerpc"
663 #elif defined(__s390__) || defined(__s390) || defined(__s390x__) || defined(__s390x)
664 #  define LZO_ARCH_S390             1
665 #  define LZO_INFO_ARCH             "s390"
666 #elif defined(__sh__) || defined(_M_SH)
667 #  define LZO_ARCH_SH               1
668 #  define LZO_INFO_ARCH             "sh"
669 #elif defined(__sparc__) || defined(__sparc) || defined(__sparcv8)
670 #  define LZO_ARCH_SPARC            1
671 #  define LZO_INFO_ARCH             "sparc"
672 #elif (UINT_MAX == LZO_0xffffL) && defined(__z80)
673 #  define LZO_ARCH_Z80              1
674 #  define LZO_INFO_ARCH             "z80"
675 #else
676 #  define LZO_ARCH_UNKNOWN          1
677 #  define LZO_INFO_ARCH             "unknown"
678 #endif
679 #endif
680 #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_DOS32 || LZO_OS_OS2)
681 #  error "FIXME - missing define for CPU architecture"
682 #endif
683 #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN32)
684 #  error "FIXME - missing WIN32 define for CPU architecture"
685 #endif
686 #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN64)
687 #  error "FIXME - missing WIN64 define for CPU architecture"
688 #endif
689 #if (LZO_OS_OS216 || LZO_OS_WIN16)
690 #  define LZO_ARCH_I086PM           1
691 #  define LZO_ARCH_IA16PM           1
692 #elif 1 && (LZO_OS_DOS16 && defined(BLX286))
693 #  define LZO_ARCH_I086PM           1
694 #  define LZO_ARCH_IA16PM           1
695 #elif 1 && (LZO_OS_DOS16 && defined(DOSX286))
696 #  define LZO_ARCH_I086PM           1
697 #  define LZO_ARCH_IA16PM           1
698 #elif 1 && (LZO_OS_DOS16 && LZO_CC_BORLANDC && defined(__DPMI16__))
699 #  define LZO_ARCH_I086PM           1
700 #  define LZO_ARCH_IA16PM           1
701 #endif
702 #if defined(LZO_ARCH_ARM_THUMB) && !defined(LZO_ARCH_ARM)
703 #  error "this should not happen"
704 #endif
705 #if defined(LZO_ARCH_I086PM) && !defined(LZO_ARCH_I086)
706 #  error "this should not happen"
707 #endif
708 #if (LZO_ARCH_I086)
709 #  if (UINT_MAX != LZO_0xffffL)
710 #    error "this should not happen"
711 #  endif
712 #  if (ULONG_MAX != LZO_0xffffffffL)
713 #    error "this should not happen"
714 #  endif
715 #endif
716 #if (LZO_ARCH_I386)
717 #  if (UINT_MAX != LZO_0xffffL) && defined(__i386_int16__)
718 #    error "this should not happen"
719 #  endif
720 #  if (UINT_MAX != LZO_0xffffffffL) && !defined(__i386_int16__)
721 #    error "this should not happen"
722 #  endif
723 #  if (ULONG_MAX != LZO_0xffffffffL)
724 #    error "this should not happen"
725 #  endif
726 #endif
727 #if !defined(__LZO_MM_OVERRIDE)
728 #if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16)
729 #if (UINT_MAX != LZO_0xffffL)
730 #  error "this should not happen"
731 #endif
732 #if defined(__TINY__) || defined(M_I86TM) || defined(_M_I86TM)
733 #  define LZO_MM_TINY           1
734 #elif defined(__HUGE__) || defined(_HUGE_) || defined(M_I86HM) || defined(_M_I86HM)
735 #  define LZO_MM_HUGE           1
736 #elif defined(__SMALL__) || defined(M_I86SM) || defined(_M_I86SM) || defined(SMALL_MODEL)
737 #  define LZO_MM_SMALL          1
738 #elif defined(__MEDIUM__) || defined(M_I86MM) || defined(_M_I86MM)
739 #  define LZO_MM_MEDIUM         1
740 #elif defined(__COMPACT__) || defined(M_I86CM) || defined(_M_I86CM)
741 #  define LZO_MM_COMPACT        1
742 #elif defined(__LARGE__) || defined(M_I86LM) || defined(_M_I86LM) || defined(LARGE_MODEL)
743 #  define LZO_MM_LARGE          1
744 #elif (LZO_CC_AZTECC)
745 #  if defined(_LARGE_CODE) && defined(_LARGE_DATA)
746 #    define LZO_MM_LARGE        1
747 #  elif defined(_LARGE_CODE)
748 #    define LZO_MM_MEDIUM       1
749 #  elif defined(_LARGE_DATA)
750 #    define LZO_MM_COMPACT      1
751 #  else
752 #    define LZO_MM_SMALL        1
753 #  endif
754 #elif (LZO_CC_ZORTECHC && defined(__VCM__))
755 #  define LZO_MM_LARGE          1
756 #else
757 #  error "unknown memory model"
758 #endif
759 #define LZO_HAVE_MM_HUGE_PTR        1
760 #define LZO_HAVE_MM_HUGE_ARRAY      1
761 #if (LZO_MM_TINY)
762 #  undef LZO_HAVE_MM_HUGE_ARRAY
763 #endif
764 #if (LZO_CC_AZTECC || LZO_CC_PACIFICC || LZO_CC_ZORTECHC)
765 #  undef LZO_HAVE_MM_HUGE_PTR
766 #  undef LZO_HAVE_MM_HUGE_ARRAY
767 #elif (LZO_CC_DMC || LZO_CC_SYMANTECC)
768 #  undef LZO_HAVE_MM_HUGE_ARRAY
769 #elif (LZO_CC_MSC && defined(_QC))
770 #  undef LZO_HAVE_MM_HUGE_ARRAY
771 #  if (_MSC_VER < 600)
772 #    undef LZO_HAVE_MM_HUGE_PTR
773 #  endif
774 #elif (LZO_CC_TURBOC && (__TURBOC__ < 0x0295))
775 #  undef LZO_HAVE_MM_HUGE_ARRAY
776 #endif
777 #if (LZO_ARCH_I086PM) && !defined(LZO_HAVE_MM_HUGE_PTR)
778 #  if (LZO_OS_DOS16)
779 #    error "this should not happen"
780 #  elif (LZO_CC_ZORTECHC)
781 #  else
782 #    error "this should not happen"
783 #  endif
784 #endif
785 #ifdef __cplusplus
786 extern "C" {
787 #endif
788 #if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0200))
789    extern void __near __cdecl _AHSHIFT(void);
790 #  define LZO_MM_AHSHIFT      ((unsigned) _AHSHIFT)
791 #elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC)
792    extern void __near __cdecl _AHSHIFT(void);
793 #  define LZO_MM_AHSHIFT      ((unsigned) _AHSHIFT)
794 #elif (LZO_CC_MSC || LZO_CC_TOPSPEEDC)
795    extern void __near __cdecl _AHSHIFT(void);
796 #  define LZO_MM_AHSHIFT      ((unsigned) _AHSHIFT)
797 #elif (LZO_CC_TURBOC && (__TURBOC__ >= 0x0295))
798    extern void __near __cdecl _AHSHIFT(void);
799 #  define LZO_MM_AHSHIFT      ((unsigned) _AHSHIFT)
800 #elif ((LZO_CC_AZTECC || LZO_CC_PACIFICC || LZO_CC_TURBOC) && LZO_OS_DOS16)
801 #  define LZO_MM_AHSHIFT      12
802 #elif (LZO_CC_WATCOMC)
803    extern unsigned char _HShift;
804 #  define LZO_MM_AHSHIFT      ((unsigned) _HShift)
805 #else
806 #  error "FIXME - implement LZO_MM_AHSHIFT"
807 #endif
808 #ifdef __cplusplus
809 }
810 #endif
811 #elif (LZO_ARCH_C166)
812 #if !defined(__MODEL__)
813 #  error "FIXME - C166 __MODEL__"
814 #elif ((__MODEL__) == 0)
815 #  define LZO_MM_SMALL          1
816 #elif ((__MODEL__) == 1)
817 #  define LZO_MM_SMALL          1
818 #elif ((__MODEL__) == 2)
819 #  define LZO_MM_LARGE          1
820 #elif ((__MODEL__) == 3)
821 #  define LZO_MM_TINY           1
822 #elif ((__MODEL__) == 4)
823 #  define LZO_MM_XTINY          1
824 #elif ((__MODEL__) == 5)
825 #  define LZO_MM_XSMALL         1
826 #else
827 #  error "FIXME - C166 __MODEL__"
828 #endif
829 #elif (LZO_ARCH_MCS251)
830 #if !defined(__MODEL__)
831 #  error "FIXME - MCS251 __MODEL__"
832 #elif ((__MODEL__) == 0)
833 #  define LZO_MM_SMALL          1
834 #elif ((__MODEL__) == 2)
835 #  define LZO_MM_LARGE          1
836 #elif ((__MODEL__) == 3)
837 #  define LZO_MM_TINY           1
838 #elif ((__MODEL__) == 4)
839 #  define LZO_MM_XTINY          1
840 #elif ((__MODEL__) == 5)
841 #  define LZO_MM_XSMALL         1
842 #else
843 #  error "FIXME - MCS251 __MODEL__"
844 #endif
845 #elif (LZO_ARCH_MCS51)
846 #if !defined(__MODEL__)
847 #  error "FIXME - MCS51 __MODEL__"
848 #elif ((__MODEL__) == 1)
849 #  define LZO_MM_SMALL          1
850 #elif ((__MODEL__) == 2)
851 #  define LZO_MM_LARGE          1
852 #elif ((__MODEL__) == 3)
853 #  define LZO_MM_TINY           1
854 #elif ((__MODEL__) == 4)
855 #  define LZO_MM_XTINY          1
856 #elif ((__MODEL__) == 5)
857 #  define LZO_MM_XSMALL         1
858 #else
859 #  error "FIXME - MCS51 __MODEL__"
860 #endif
861 #else
862 #  define LZO_MM_FLAT           1
863 #endif
864 #if (LZO_MM_FLAT)
865 #  define LZO_INFO_MM           "flat"
866 #elif (LZO_MM_TINY)
867 #  define LZO_INFO_MM           "tiny"
868 #elif (LZO_MM_SMALL)
869 #  define LZO_INFO_MM           "small"
870 #elif (LZO_MM_MEDIUM)
871 #  define LZO_INFO_MM           "medium"
872 #elif (LZO_MM_COMPACT)
873 #  define LZO_INFO_MM           "compact"
874 #elif (LZO_MM_LARGE)
875 #  define LZO_INFO_MM           "large"
876 #elif (LZO_MM_HUGE)
877 #  define LZO_INFO_MM           "huge"
878 #else
879 #  error "unknown memory model"
880 #endif
881 #endif
882 #if defined(SIZEOF_SHORT)
883 #  define LZO_SIZEOF_SHORT          (SIZEOF_SHORT)
884 #endif
885 #if defined(SIZEOF_INT)
886 #  define LZO_SIZEOF_INT            (SIZEOF_INT)
887 #endif
888 #if defined(SIZEOF_LONG)
889 #  define LZO_SIZEOF_LONG           (SIZEOF_LONG)
890 #endif
891 #if defined(SIZEOF_LONG_LONG)
892 #  define LZO_SIZEOF_LONG_LONG      (SIZEOF_LONG_LONG)
893 #endif
894 #if defined(SIZEOF___INT16)
895 #  define LZO_SIZEOF___INT16        (SIZEOF___INT16)
896 #endif
897 #if defined(SIZEOF___INT32)
898 #  define LZO_SIZEOF___INT32        (SIZEOF___INT32)
899 #endif
900 #if defined(SIZEOF___INT64)
901 #  define LZO_SIZEOF___INT64        (SIZEOF___INT64)
902 #endif
903 #if defined(SIZEOF_VOID_P)
904 #  define LZO_SIZEOF_VOID_P         (SIZEOF_VOID_P)
905 #endif
906 #if defined(SIZEOF_SIZE_T)
907 #  define LZO_SIZEOF_SIZE_T         (SIZEOF_SIZE_T)
908 #endif
909 #if defined(SIZEOF_PTRDIFF_T)
910 #  define LZO_SIZEOF_PTRDIFF_T      (SIZEOF_PTRDIFF_T)
911 #endif
912 #define __LZO_LSR(x,b)    (((x)+0ul) >> (b))
913 #if !defined(LZO_SIZEOF_SHORT)
914 #  if (USHRT_MAX == LZO_0xffffL)
915 #    define LZO_SIZEOF_SHORT        2
916 #  elif (__LZO_LSR(USHRT_MAX,7) == 1)
917 #    define LZO_SIZEOF_SHORT        1
918 #  elif (__LZO_LSR(USHRT_MAX,15) == 1)
919 #    define LZO_SIZEOF_SHORT        2
920 #  elif (__LZO_LSR(USHRT_MAX,31) == 1)
921 #    define LZO_SIZEOF_SHORT        4
922 #  elif (__LZO_LSR(USHRT_MAX,63) == 1)
923 #    define LZO_SIZEOF_SHORT        8
924 #  elif (__LZO_LSR(USHRT_MAX,127) == 1)
925 #    define LZO_SIZEOF_SHORT        16
926 #  else
927 #    error "LZO_SIZEOF_SHORT"
928 #  endif
929 #endif
930 #if !defined(LZO_SIZEOF_INT)
931 #  if (UINT_MAX == LZO_0xffffL)
932 #    define LZO_SIZEOF_INT          2
933 #  elif (UINT_MAX == LZO_0xffffffffL)
934 #    define LZO_SIZEOF_INT          4
935 #  elif (__LZO_LSR(UINT_MAX,7) == 1)
936 #    define LZO_SIZEOF_INT          1
937 #  elif (__LZO_LSR(UINT_MAX,15) == 1)
938 #    define LZO_SIZEOF_INT          2
939 #  elif (__LZO_LSR(UINT_MAX,31) == 1)
940 #    define LZO_SIZEOF_INT          4
941 #  elif (__LZO_LSR(UINT_MAX,63) == 1)
942 #    define LZO_SIZEOF_INT          8
943 #  elif (__LZO_LSR(UINT_MAX,127) == 1)
944 #    define LZO_SIZEOF_INT          16
945 #  else
946 #    error "LZO_SIZEOF_INT"
947 #  endif
948 #endif
949 #if !defined(LZO_SIZEOF_LONG)
950 #  if (ULONG_MAX == LZO_0xffffffffL)
951 #    define LZO_SIZEOF_LONG         4
952 #  elif (__LZO_LSR(ULONG_MAX,7) == 1)
953 #    define LZO_SIZEOF_LONG         1
954 #  elif (__LZO_LSR(ULONG_MAX,15) == 1)
955 #    define LZO_SIZEOF_LONG         2
956 #  elif (__LZO_LSR(ULONG_MAX,31) == 1)
957 #    define LZO_SIZEOF_LONG         4
958 #  elif (__LZO_LSR(ULONG_MAX,63) == 1)
959 #    define LZO_SIZEOF_LONG         8
960 #  elif (__LZO_LSR(ULONG_MAX,127) == 1)
961 #    define LZO_SIZEOF_LONG         16
962 #  else
963 #    error "LZO_SIZEOF_LONG"
964 #  endif
965 #endif
966 #if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64)
967 #if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8)
968 #  if defined(__LONG_MAX__) && defined(__LONG_LONG_MAX__)
969 #    if (LZO_CC_GNUC >= 0x030300ul)
970 #      if ((__LONG_MAX__)+0 == (__LONG_LONG_MAX__)+0)
971 #        define LZO_SIZEOF_LONG_LONG      LZO_SIZEOF_LONG
972 #      endif
973 #    endif
974 #  endif
975 #endif
976 #endif
977 #if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64)
978 #if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8)
979 #if (LZO_ARCH_I086 && LZO_CC_DMC)
980 #elif (LZO_CC_CILLY) && defined(__GNUC__)
981 #  define LZO_SIZEOF_LONG_LONG      8
982 #elif (LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE)
983 #  define LZO_SIZEOF_LONG_LONG      8
984 #elif ((LZO_OS_WIN32 || LZO_OS_WIN64) && LZO_CC_MSC && (_MSC_VER >= 1400))
985 #  define LZO_SIZEOF_LONG_LONG      8
986 #elif (LZO_OS_WIN64)
987 #  define LZO_SIZEOF___INT64        8
988 #elif (LZO_ARCH_I386 && (LZO_CC_DMC))
989 #  define LZO_SIZEOF_LONG_LONG      8
990 #elif (LZO_ARCH_I386 && (LZO_CC_SYMANTECC && (__SC__ >= 0x700)))
991 #  define LZO_SIZEOF_LONG_LONG      8
992 #elif (LZO_ARCH_I386 && (LZO_CC_INTELC && defined(__linux__)))
993 #  define LZO_SIZEOF_LONG_LONG      8
994 #elif (LZO_ARCH_I386 && (LZO_CC_MWERKS || LZO_CC_PELLESC || LZO_CC_PGI))
995 #  define LZO_SIZEOF_LONG_LONG      8
996 #elif (LZO_ARCH_I386 && (LZO_CC_INTELC || LZO_CC_MSC))
997 #  define LZO_SIZEOF___INT64        8
998 #elif (LZO_OS_WIN32 && (LZO_CC_MSC))
999 #  define LZO_SIZEOF___INT64        8
1000 #elif (LZO_ARCH_I386 && (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0520)))
1001 #  define LZO_SIZEOF___INT64        8
1002 #elif (LZO_ARCH_I386 && (LZO_CC_WATCOMC && (__WATCOMC__ >= 1100)))
1003 #  define LZO_SIZEOF___INT64        8
1004 #elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && (_INTEGRAL_MAX_BITS == 64))
1005 #  define LZO_SIZEOF___INT64        8
1006 #elif (LZO_OS_OS400) && defined(__LLP64_IFC__)
1007 #  define LZO_SIZEOF_LONG_LONG      8
1008 #elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64)
1009 #  define LZO_SIZEOF_LONG_LONG      8
1010 #elif (LZO_CC_SDCC) && (LZO_SIZEOF_INT == 2)
1011 #elif 1 && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
1012 #  define LZO_SIZEOF_LONG_LONG      8
1013 #endif
1014 #endif
1015 #endif
1016 #if defined(__cplusplus) && defined(LZO_CC_GNUC)
1017 #  if (LZO_CC_GNUC < 0x020800ul)
1018 #    undef LZO_SIZEOF_LONG_LONG
1019 #  endif
1020 #endif
1021 #if defined(LZO_CFG_NO_LONG_LONG) || defined(__NO_LONG_LONG)
1022 #  undef LZO_SIZEOF_LONG_LONG
1023 #endif
1024 #if !defined(LZO_SIZEOF_VOID_P)
1025 #if (LZO_ARCH_I086)
1026 #  define __LZO_WORDSIZE            2
1027 #  if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM)
1028 #    define LZO_SIZEOF_VOID_P       2
1029 #  elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE)
1030 #    define LZO_SIZEOF_VOID_P       4
1031 #  else
1032 #    error "LZO_MM"
1033 #  endif
1034 #elif (LZO_ARCH_AVR || LZO_ARCH_Z80)
1035 #  define __LZO_WORDSIZE            1
1036 #  define LZO_SIZEOF_VOID_P         2
1037 #elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430)
1038 #  define LZO_SIZEOF_VOID_P         2
1039 #elif (LZO_ARCH_H8300)
1040 #  if defined(__NORMAL_MODE__)
1041 #    define __LZO_WORDSIZE          4
1042 #    define LZO_SIZEOF_VOID_P       2
1043 #  elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__)
1044 #    define __LZO_WORDSIZE          4
1045 #    define LZO_SIZEOF_VOID_P       4
1046 #  else
1047 #    define __LZO_WORDSIZE          2
1048 #    define LZO_SIZEOF_VOID_P       2
1049 #  endif
1050 #  if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4)
1051 #    define LZO_SIZEOF_SIZE_T       LZO_SIZEOF_INT
1052 #    define LZO_SIZEOF_PTRDIFF_T    LZO_SIZEOF_INT
1053 #  endif
1054 #elif (LZO_ARCH_M16C)
1055 #  define __LZO_WORDSIZE            2
1056 #  if defined(__m32c_cpu__) || defined(__m32cm_cpu__)
1057 #    define LZO_SIZEOF_VOID_P       4
1058 #  else
1059 #    define LZO_SIZEOF_VOID_P       2
1060 #  endif
1061 #elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__))
1062 #  define __LZO_WORDSIZE            8
1063 #  define LZO_SIZEOF_VOID_P         4
1064 #elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64)
1065 #  define __LZO_WORDSIZE            8
1066 #  define LZO_SIZEOF_VOID_P         8
1067 #elif (LZO_OS_OS400) && defined(__LLP64_IFC__)
1068 #  define LZO_SIZEOF_VOID_P         LZO_SIZEOF_LONG
1069 #  define LZO_SIZEOF_SIZE_T         LZO_SIZEOF_LONG
1070 #  define LZO_SIZEOF_PTRDIFF_T      LZO_SIZEOF_LONG
1071 #elif (LZO_OS_OS400)
1072 #  define __LZO_WORDSIZE            LZO_SIZEOF_LONG
1073 #  define LZO_SIZEOF_VOID_P         16
1074 #  define LZO_SIZEOF_SIZE_T         LZO_SIZEOF_LONG
1075 #  define LZO_SIZEOF_PTRDIFF_T      LZO_SIZEOF_LONG
1076 #elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64)
1077 #  define LZO_SIZEOF_VOID_P         8
1078 #  define LZO_SIZEOF_SIZE_T         LZO_SIZEOF_LONG
1079 #  define LZO_SIZEOF_PTRDIFF_T      LZO_SIZEOF_LONG
1080 #else
1081 #  define LZO_SIZEOF_VOID_P         LZO_SIZEOF_LONG
1082 #endif
1083 #endif
1084 #if !defined(LZO_WORDSIZE)
1085 #  if defined(__LZO_WORDSIZE)
1086 #    define LZO_WORDSIZE            __LZO_WORDSIZE
1087 #  else
1088 #    define LZO_WORDSIZE            LZO_SIZEOF_VOID_P
1089 #  endif
1090 #endif
1091 #if !defined(LZO_SIZEOF_SIZE_T)
1092 #if (LZO_ARCH_I086 || LZO_ARCH_M16C)
1093 #  define LZO_SIZEOF_SIZE_T         2
1094 #else
1095 #  define LZO_SIZEOF_SIZE_T         LZO_SIZEOF_VOID_P
1096 #endif
1097 #endif
1098 #if !defined(LZO_SIZEOF_PTRDIFF_T)
1099 #if (LZO_ARCH_I086)
1100 #  if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM || LZO_MM_HUGE)
1101 #    define LZO_SIZEOF_PTRDIFF_T    LZO_SIZEOF_VOID_P
1102 #  elif (LZO_MM_COMPACT || LZO_MM_LARGE)
1103 #    if (LZO_CC_BORLANDC || LZO_CC_TURBOC)
1104 #      define LZO_SIZEOF_PTRDIFF_T  4
1105 #    else
1106 #      define LZO_SIZEOF_PTRDIFF_T  2
1107 #    endif
1108 #  else
1109 #    error "LZO_MM"
1110 #  endif
1111 #else
1112 #  define LZO_SIZEOF_PTRDIFF_T      LZO_SIZEOF_SIZE_T
1113 #endif
1114 #endif
1115 #if !defined(LZO_ABI_BIG_ENDIAN) && !defined(LZO_ABI_LITTLE_ENDIAN) && !defined(LZO_ABI_NEUTRAL_ENDIAN)
1116 #if (LZO_ARCH_AMD64 || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430)
1117 #  define LZO_ABI_LITTLE_ENDIAN     1
1118 #elif (LZO_ARCH_M68K || LZO_ARCH_S390)
1119 #  define LZO_ABI_BIG_ENDIAN        1
1120 #elif 1 && defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
1121 #  define LZO_ABI_BIG_ENDIAN        1
1122 #elif 1 && defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
1123 #  define LZO_ABI_LITTLE_ENDIAN     1
1124 #elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__)
1125 #  define LZO_ABI_BIG_ENDIAN        1
1126 #elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__)
1127 #  define LZO_ABI_LITTLE_ENDIAN     1
1128 #endif
1129 #endif
1130 #if defined(LZO_ABI_BIG_ENDIAN) && defined(LZO_ABI_LITTLE_ENDIAN)
1131 #  error "this should not happen"
1132 #endif
1133 #if defined(LZO_ABI_BIG_ENDIAN)
1134 #  define LZO_INFO_ABI_ENDIAN       "be"
1135 #elif defined(LZO_ABI_LITTLE_ENDIAN)
1136 #  define LZO_INFO_ABI_ENDIAN       "le"
1137 #elif defined(LZO_ABI_NEUTRAL_ENDIAN)
1138 #  define LZO_INFO_ABI_ENDIAN       "neutral"
1139 #endif
1140 #if (LZO_SIZEOF_INT == 1 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2)
1141 #  define LZO_ABI_I8LP16         1
1142 #  define LZO_INFO_ABI_PM       "i8lp16"
1143 #elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2)
1144 #  define LZO_ABI_ILP16         1
1145 #  define LZO_INFO_ABI_PM       "ilp16"
1146 #elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4)
1147 #  define LZO_ABI_ILP32         1
1148 #  define LZO_INFO_ABI_PM       "ilp32"
1149 #elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 8 && LZO_SIZEOF_SIZE_T == 8)
1150 #  define LZO_ABI_LLP64         1
1151 #  define LZO_INFO_ABI_PM       "llp64"
1152 #elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8)
1153 #  define LZO_ABI_LP64          1
1154 #  define LZO_INFO_ABI_PM       "lp64"
1155 #elif (LZO_SIZEOF_INT == 8 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8)
1156 #  define LZO_ABI_ILP64         1
1157 #  define LZO_INFO_ABI_PM       "ilp64"
1158 #elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 4)
1159 #  define LZO_ABI_IP32L64       1
1160 #  define LZO_INFO_ABI_PM       "ip32l64"
1161 #endif
1162 #if !defined(__LZO_LIBC_OVERRIDE)
1163 #if defined(LZO_LIBC_NAKED)
1164 #  define LZO_INFO_LIBC         "naked"
1165 #elif defined(LZO_LIBC_FREESTANDING)
1166 #  define LZO_INFO_LIBC         "freestanding"
1167 #elif defined(LZO_LIBC_MOSTLY_FREESTANDING)
1168 #  define LZO_INFO_LIBC         "mfreestanding"
1169 #elif defined(LZO_LIBC_ISOC90)
1170 #  define LZO_INFO_LIBC         "isoc90"
1171 #elif defined(LZO_LIBC_ISOC99)
1172 #  define LZO_INFO_LIBC         "isoc99"
1173 #elif defined(__dietlibc__)
1174 #  define LZO_LIBC_DIETLIBC     1
1175 #  define LZO_INFO_LIBC         "dietlibc"
1176 #elif defined(_NEWLIB_VERSION)
1177 #  define LZO_LIBC_NEWLIB       1
1178 #  define LZO_INFO_LIBC         "newlib"
1179 #elif defined(__UCLIBC__) && defined(__UCLIBC_MAJOR__) && defined(__UCLIBC_MINOR__)
1180 #  if defined(__UCLIBC_SUBLEVEL__)
1181 #    define LZO_LIBC_UCLIBC     (__UCLIBC_MAJOR__ * 0x10000L + __UCLIBC_MINOR__ * 0x100 + __UCLIBC_SUBLEVEL__)
1182 #  else
1183 #    define LZO_LIBC_UCLIBC     0x00090bL
1184 #  endif
1185 #  define LZO_INFO_LIBC         "uclibc"
1186 #elif defined(__GLIBC__) && defined(__GLIBC_MINOR__)
1187 #  define LZO_LIBC_GLIBC        (__GLIBC__ * 0x10000L + __GLIBC_MINOR__ * 0x100)
1188 #  define LZO_INFO_LIBC         "glibc"
1189 #elif (LZO_CC_MWERKS) && defined(__MSL__)
1190 #  define LZO_LIBC_MSL          __MSL__
1191 #  define LZO_INFO_LIBC         "msl"
1192 #else
1193 #  define LZO_LIBC_DEFAULT      1
1194 #  define LZO_INFO_LIBC         "default"
1195 #endif
1196 #endif
1197 #if (LZO_CC_GNUC >= 0x020800ul)
1198 #  define __lzo_gnuc_extension__ __extension__
1199 #elif (LZO_CC_LLVM || LZO_CC_PATHSCALE)
1200 #  define __lzo_gnuc_extension__ __extension__
1201 #else
1202 #  define __lzo_gnuc_extension__
1203 #endif
1204 #if (LZO_CC_CILLY || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI)
1205 #  define lzo_alignof(e)        __alignof__(e)
1206 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700))
1207 #  define lzo_alignof(e)        __alignof__(e)
1208 #elif (LZO_CC_MSC && (_MSC_VER >= 1300))
1209 #  define lzo_alignof(e)        __alignof(e)
1210 #endif
1211 #if (LZO_CC_TURBOC && (__TURBOC__ <= 0x0295))
1212 #elif defined(__cplusplus)
1213 #  define __lzo_inline          inline
1214 #elif (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0550))
1215 #  define __lzo_inline          __inline
1216 #elif (LZO_CC_CILLY || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI)
1217 #  define __lzo_inline          __inline__
1218 #elif (LZO_CC_DMC)
1219 #  define __lzo_inline          __inline
1220 #elif (LZO_CC_INTELC)
1221 #  define __lzo_inline          __inline
1222 #elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x2405))
1223 #  define __lzo_inline          __inline
1224 #elif (LZO_CC_MSC && (_MSC_VER >= 900))
1225 #  define __lzo_inline          __inline
1226 #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
1227 #  define __lzo_inline          inline
1228 #endif
1229 #if (LZO_CC_GNUC >= 0x030200ul)
1230 #  define __lzo_forceinline     __inline__ __attribute__((__always_inline__))
1231 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && (LZO_OS_WIN32 || LZO_OS_WIN64))
1232 #  define __lzo_forceinline     __forceinline
1233 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800))
1234 #  define __lzo_forceinline     __inline__ __attribute__((__always_inline__))
1235 #elif (LZO_CC_LLVM || LZO_CC_PATHSCALE)
1236 #  define __lzo_forceinline     __inline__ __attribute__((__always_inline__))
1237 #elif (LZO_CC_MSC && (_MSC_VER >= 1200))
1238 #  define __lzo_forceinline     __forceinline
1239 #endif
1240 #if (LZO_CC_GNUC >= 0x030200ul)
1241 #  define __lzo_noinline        __attribute__((__noinline__))
1242 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && (LZO_OS_WIN32 || LZO_OS_WIN64))
1243 #  define __lzo_noinline        __declspec(noinline)
1244 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800))
1245 #  define __lzo_noinline        __attribute__((__noinline__))
1246 #elif (LZO_CC_LLVM || LZO_CC_PATHSCALE)
1247 #  define __lzo_noinline        __attribute__((__noinline__))
1248 #elif (LZO_CC_MSC && (_MSC_VER >= 1300))
1249 #  define __lzo_noinline        __declspec(noinline)
1250 #elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x3200) && (LZO_OS_WIN32 || LZO_OS_WIN64))
1251 #  if defined(__cplusplus)
1252 #  else
1253 #    define __lzo_noinline      __declspec(noinline)
1254 #  endif
1255 #endif
1256 #if (defined(__lzo_forceinline) || defined(__lzo_noinline)) && !defined(__lzo_inline)
1257 #  error "this should not happen"
1258 #endif
1259 #if (LZO_CC_GNUC >= 0x020700ul)
1260 #  define __lzo_noreturn        __attribute__((__noreturn__))
1261 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && (LZO_OS_WIN32 || LZO_OS_WIN64))
1262 #  define __lzo_noreturn        __declspec(noreturn)
1263 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && (LZO_OS_POSIX))
1264 #  define __lzo_noreturn        __attribute__((__noreturn__))
1265 #elif (LZO_CC_LLVM || LZO_CC_PATHSCALE)
1266 #  define __lzo_noreturn        __attribute__((__noreturn__))
1267 #elif (LZO_CC_MSC && (_MSC_VER >= 1200))
1268 #  define __lzo_noreturn        __declspec(noreturn)
1269 #endif
1270 #if (LZO_CC_GNUC >= 0x030400ul)
1271 #  define __lzo_constructor     __attribute__((__constructor__,__used__))
1272 #elif (LZO_CC_GNUC >= 0x020700ul)
1273 #  define __lzo_constructor     __attribute__((__constructor__))
1274 #elif (LZO_CC_LLVM || LZO_CC_PATHSCALE)
1275 #  define __lzo_constructor     __attribute__((__constructor__))
1276 #endif
1277 #if (LZO_CC_GNUC >= 0x030400ul)
1278 #  define __lzo_destructor      __attribute__((__destructor__,__used__))
1279 #elif (LZO_CC_GNUC >= 0x020700ul)
1280 #  define __lzo_destructor      __attribute__((__destructor__))
1281 #elif (LZO_CC_LLVM || LZO_CC_PATHSCALE)
1282 #  define __lzo_destructor      __attribute__((__destructor__))
1283 #endif
1284 #if defined(__lzo_destructor) && !defined(__lzo_constructor)
1285 #  error "this should not happen"
1286 #endif
1287 #if (LZO_CC_GNUC >= 0x030200ul)
1288 #  define __lzo_likely(e)       (__builtin_expect(!!(e),1))
1289 #  define __lzo_unlikely(e)     (__builtin_expect(!!(e),0))
1290 #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800))
1291 #  define __lzo_likely(e)       (__builtin_expect(!!(e),1))
1292 #  define __lzo_unlikely(e)     (__builtin_expect(!!(e),0))
1293 #elif (LZO_CC_LLVM || LZO_CC_PATHSCALE)
1294 #  define __lzo_likely(e)       (__builtin_expect(!!(e),1))
1295 #  define __lzo_unlikely(e)     (__builtin_expect(!!(e),0))
1296 #else
1297 #  define __lzo_likely(e)       (e)
1298 #  define __lzo_unlikely(e)     (e)
1299 #endif
1300 #if !defined(LZO_UNUSED)
1301 #  if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600))
1302 #    define LZO_UNUSED(var)         ((void) &var)
1303 #  elif (LZO_CC_BORLANDC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PELLESC || LZO_CC_TURBOC)
1304 #    define LZO_UNUSED(var)         if (&var) ; else
1305 #  elif (LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE)
1306 #    define LZO_UNUSED(var)         ((void) var)
1307 #  elif (LZO_CC_MSC && (_MSC_VER < 900))
1308 #    define LZO_UNUSED(var)         if (&var) ; else
1309 #  elif (LZO_CC_KEILC)
1310 #    define LZO_UNUSED(var)         {extern int __lzo_unused[1-2*!(sizeof(var)>0)];}
1311 #  elif (LZO_CC_PACIFICC)
1312 #    define LZO_UNUSED(var)         ((void) sizeof(var))
1313 #  elif (LZO_CC_WATCOMC) && defined(__cplusplus)
1314 #    define LZO_UNUSED(var)         ((void) var)
1315 #  else
1316 #    define LZO_UNUSED(var)         ((void) &var)
1317 #  endif
1318 #endif
1319 #if !defined(LZO_UNUSED_FUNC)
1320 #  if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600))
1321 #    define LZO_UNUSED_FUNC(func)   ((void) func)
1322 #  elif (LZO_CC_BORLANDC || LZO_CC_NDPC || LZO_CC_TURBOC)
1323 #    define LZO_UNUSED_FUNC(func)   if (func) ; else
1324 #  elif (LZO_CC_LLVM)
1325 #    define LZO_UNUSED_FUNC(func)   ((void) &func)
1326 #  elif (LZO_CC_MSC && (_MSC_VER < 900))
1327 #    define LZO_UNUSED_FUNC(func)   if (func) ; else
1328 #  elif (LZO_CC_MSC)
1329 #    define LZO_UNUSED_FUNC(func)   ((void) &func)
1330 #  elif (LZO_CC_KEILC || LZO_CC_PELLESC)
1331 #    define LZO_UNUSED_FUNC(func)   {extern int __lzo_unused[1-2*!(sizeof((int)func)>0)];}
1332 #  else
1333 #    define LZO_UNUSED_FUNC(func)   ((void) func)
1334 #  endif
1335 #endif
1336 #if !defined(LZO_UNUSED_LABEL)
1337 #  if (LZO_CC_WATCOMC) && defined(__cplusplus)
1338 #    define LZO_UNUSED_LABEL(l)     switch(0) case 1:goto l
1339 #  elif (LZO_CC_INTELC || LZO_CC_WATCOMC)
1340 #    define LZO_UNUSED_LABEL(l)     if (0) goto l
1341 #  else
1342 #    define LZO_UNUSED_LABEL(l)     switch(0) case 1:goto l
1343 #  endif
1344 #endif
1345 #if !defined(LZO_COMPILE_TIME_ASSERT_HEADER)
1346 #  if (LZO_CC_AZTECC || LZO_CC_ZORTECHC)
1347 #    define LZO_COMPILE_TIME_ASSERT_HEADER(e)  extern int __lzo_cta[1-!(e)];
1348 #  elif (LZO_CC_DMC || LZO_CC_SYMANTECC)
1349 #    define LZO_COMPILE_TIME_ASSERT_HEADER(e)  extern int __lzo_cta[1u-2*!(e)];
1350 #  elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295))
1351 #    define LZO_COMPILE_TIME_ASSERT_HEADER(e)  extern int __lzo_cta[1-!(e)];
1352 #  else
1353 #    define LZO_COMPILE_TIME_ASSERT_HEADER(e)  extern int __lzo_cta[1-2*!(e)];
1354 #  endif
1355 #endif
1356 #if !defined(LZO_COMPILE_TIME_ASSERT)
1357 #  if (LZO_CC_AZTECC)
1358 #    define LZO_COMPILE_TIME_ASSERT(e)  {typedef int __lzo_cta_t[1-!(e)];}
1359 #  elif (LZO_CC_DMC || LZO_CC_PACIFICC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC)
1360 #    define LZO_COMPILE_TIME_ASSERT(e)  switch(0) case 1:case !(e):break;
1361 #  elif (LZO_CC_MSC && (_MSC_VER < 900))
1362 #    define LZO_COMPILE_TIME_ASSERT(e)  switch(0) case 1:case !(e):break;
1363 #  elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295))
1364 #    define LZO_COMPILE_TIME_ASSERT(e)  switch(0) case 1:case !(e):break;
1365 #  else
1366 #    define LZO_COMPILE_TIME_ASSERT(e)  {typedef int __lzo_cta_t[1-2*!(e)];}
1367 #  endif
1368 #endif
1369 #if (LZO_ARCH_I086 || LZO_ARCH_I386) && (LZO_OS_DOS16 || LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_OS216 || LZO_OS_WIN16 || LZO_OS_WIN32 || LZO_OS_WIN64)
1370 #  if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC)
1371 #  elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC)
1372 #    define __lzo_cdecl                 __cdecl
1373 #    define __lzo_cdecl_atexit
1374 #    define __lzo_cdecl_main            __cdecl
1375 #    if (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC))
1376 #      define __lzo_cdecl_qsort         __pascal
1377 #    elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC))
1378 #      define __lzo_cdecl_qsort         _stdcall
1379 #    else
1380 #      define __lzo_cdecl_qsort         __cdecl
1381 #    endif
1382 #  elif (LZO_CC_WATCOMC)
1383 #    define __lzo_cdecl                 __cdecl
1384 #  else
1385 #    define __lzo_cdecl                 __cdecl
1386 #    define __lzo_cdecl_atexit          __cdecl
1387 #    define __lzo_cdecl_main            __cdecl
1388 #    define __lzo_cdecl_qsort           __cdecl
1389 #  endif
1390 #  if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC || LZO_CC_WATCOMC)
1391 #  elif (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC))
1392 #    define __lzo_cdecl_sighandler      __pascal
1393 #  elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC))
1394 #    define __lzo_cdecl_sighandler      _stdcall
1395 #  elif (LZO_CC_MSC && (_MSC_VER >= 1400)) && defined(_M_CEE_PURE)
1396 #    define __lzo_cdecl_sighandler      __clrcall
1397 #  elif (LZO_CC_MSC && (_MSC_VER >= 600 && _MSC_VER < 700))
1398 #    if defined(_DLL)
1399 #      define __lzo_cdecl_sighandler    _far _cdecl _loadds
1400 #    elif defined(_MT)
1401 #      define __lzo_cdecl_sighandler    _far _cdecl
1402 #    else
1403 #      define __lzo_cdecl_sighandler    _cdecl
1404 #    endif
1405 #  else
1406 #    define __lzo_cdecl_sighandler      __cdecl
1407 #  endif
1408 #elif (LZO_ARCH_M68K && LZO_OS_TOS && (LZO_CC_PUREC || LZO_CC_TURBOC))
1409 #  define __lzo_cdecl                   cdecl
1410 #endif
1411 #if !defined(__lzo_cdecl)
1412 #  define __lzo_cdecl
1413 #endif
1414 #if !defined(__lzo_cdecl_atexit)
1415 #  define __lzo_cdecl_atexit
1416 #endif
1417 #if !defined(__lzo_cdecl_main)
1418 #  define __lzo_cdecl_main
1419 #endif
1420 #if !defined(__lzo_cdecl_qsort)
1421 #  define __lzo_cdecl_qsort
1422 #endif
1423 #if !defined(__lzo_cdecl_sighandler)
1424 #  define __lzo_cdecl_sighandler
1425 #endif
1426 #if !defined(__lzo_cdecl_va)
1427 #  define __lzo_cdecl_va                __lzo_cdecl
1428 #endif
1429 #if (LZO_OS_CYGWIN || (LZO_OS_EMX && defined(__RSXNT__)) || LZO_OS_WIN32 || LZO_OS_WIN64)
1430 #  if (LZO_CC_WATCOMC && (__WATCOMC__ < 1000))
1431 #  elif (LZO_OS_WIN32 && LZO_CC_GNUC) && defined(__PW32__)
1432 #  elif ((LZO_OS_CYGWIN || defined(__MINGW32__)) && (LZO_CC_GNUC && (LZO_CC_GNUC < 0x025f00ul)))
1433 #  else
1434 #    define LZO_HAVE_WINDOWS_H 1
1435 #  endif
1436 #endif
1437 #if (LZO_ARCH_ALPHA)
1438 #  define LZO_OPT_AVOID_UINT_INDEX  1
1439 #  define LZO_OPT_AVOID_SHORT       1
1440 #  define LZO_OPT_AVOID_USHORT      1
1441 #elif (LZO_ARCH_AMD64)
1442 #  define LZO_OPT_AVOID_INT_INDEX   1
1443 #  define LZO_OPT_AVOID_UINT_INDEX  1
1444 #  define LZO_OPT_UNALIGNED16       1
1445 #  define LZO_OPT_UNALIGNED32       1
1446 #  define LZO_OPT_UNALIGNED64       1
1447 #elif (LZO_ARCH_ARM && LZO_ARCH_ARM_THUMB)
1448 #elif (LZO_ARCH_ARM)
1449 #  define LZO_OPT_AVOID_SHORT       1
1450 #  define LZO_OPT_AVOID_USHORT      1
1451 #elif (LZO_ARCH_CRIS)
1452 #  define LZO_OPT_UNALIGNED16       1
1453 #  define LZO_OPT_UNALIGNED32       1
1454 #elif (LZO_ARCH_I386)
1455 #  define LZO_OPT_UNALIGNED16       1
1456 #  define LZO_OPT_UNALIGNED32       1
1457 #elif (LZO_ARCH_IA64)
1458 #  define LZO_OPT_AVOID_INT_INDEX   1
1459 #  define LZO_OPT_AVOID_UINT_INDEX  1
1460 #  define LZO_OPT_PREFER_POSTINC    1
1461 #elif (LZO_ARCH_M68K)
1462 #  define LZO_OPT_PREFER_POSTINC    1
1463 #  define LZO_OPT_PREFER_PREDEC     1
1464 #  if defined(__mc68020__) && !defined(__mcoldfire__)
1465 #    define LZO_OPT_UNALIGNED16     1
1466 #    define LZO_OPT_UNALIGNED32     1
1467 #  endif
1468 #elif (LZO_ARCH_MIPS)
1469 #  define LZO_OPT_AVOID_UINT_INDEX  1
1470 #elif (LZO_ARCH_POWERPC)
1471 #  define LZO_OPT_PREFER_PREINC     1
1472 #  define LZO_OPT_PREFER_PREDEC     1
1473 #  if defined(LZO_ABI_BIG_ENDIAN)
1474 #    define LZO_OPT_UNALIGNED16     1
1475 #    define LZO_OPT_UNALIGNED32     1
1476 #  endif
1477 #elif (LZO_ARCH_S390)
1478 #  define LZO_OPT_UNALIGNED16       1
1479 #  define LZO_OPT_UNALIGNED32       1
1480 #  if (LZO_SIZEOF_SIZE_T == 8)
1481 #    define LZO_OPT_UNALIGNED64     1
1482 #  endif
1483 #elif (LZO_ARCH_SH)
1484 #  define LZO_OPT_PREFER_POSTINC    1
1485 #  define LZO_OPT_PREFER_PREDEC     1
1486 #endif
1487 #if !defined(LZO_CFG_NO_INLINE_ASM)
1488 #if defined(LZO_CC_LLVM)
1489 #  define LZO_CFG_NO_INLINE_ASM 1
1490 #endif
1491 #endif
1492 #if !defined(LZO_CFG_NO_UNALIGNED)
1493 #if defined(LZO_ABI_NEUTRAL_ENDIAN) || defined(LZO_ARCH_GENERIC)
1494 #  define LZO_CFG_NO_UNALIGNED 1
1495 #endif
1496 #endif
1497 #if defined(LZO_CFG_NO_UNALIGNED)
1498 #  undef LZO_OPT_UNALIGNED16
1499 #  undef LZO_OPT_UNALIGNED32
1500 #  undef LZO_OPT_UNALIGNED64
1501 #endif
1502 #if defined(LZO_CFG_NO_INLINE_ASM)
1503 #elif (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC))
1504 #  define LZO_ASM_SYNTAX_MSC 1
1505 #elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC))
1506 #elif (LZO_ARCH_I386 && (LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE))
1507 #  define LZO_ASM_SYNTAX_GNUC 1
1508 #elif (LZO_ARCH_AMD64 && (LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE))
1509 #  define LZO_ASM_SYNTAX_GNUC 1
1510 #endif
1511 #if (LZO_ASM_SYNTAX_GNUC)
1512 #if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul))
1513 #  define __LZO_ASM_CLOBBER         "ax"
1514 #elif (LZO_CC_INTELC)
1515 #  define __LZO_ASM_CLOBBER         "memory"
1516 #else
1517 #  define __LZO_ASM_CLOBBER         "cc", "memory"
1518 #endif
1519 #endif
1520 #if defined(__LZO_INFOSTR_MM)
1521 #elif (LZO_MM_FLAT) && (defined(__LZO_INFOSTR_PM) || defined(LZO_INFO_ABI_PM))
1522 #  define __LZO_INFOSTR_MM          ""
1523 #elif defined(LZO_INFO_MM)
1524 #  define __LZO_INFOSTR_MM          "." LZO_INFO_MM
1525 #else
1526 #  define __LZO_INFOSTR_MM          ""
1527 #endif
1528 #if defined(__LZO_INFOSTR_PM)
1529 #elif defined(LZO_INFO_ABI_PM)
1530 #  define __LZO_INFOSTR_PM          "." LZO_INFO_ABI_PM
1531 #else
1532 #  define __LZO_INFOSTR_PM          ""
1533 #endif
1534 #if defined(__LZO_INFOSTR_ENDIAN)
1535 #elif defined(LZO_INFO_ABI_ENDIAN)
1536 #  define __LZO_INFOSTR_ENDIAN      "." LZO_INFO_ABI_ENDIAN
1537 #else
1538 #  define __LZO_INFOSTR_ENDIAN      ""
1539 #endif
1540 #if defined(__LZO_INFOSTR_OSNAME)
1541 #elif defined(LZO_INFO_OS_CONSOLE)
1542 #  define __LZO_INFOSTR_OSNAME      LZO_INFO_OS "." LZO_INFO_OS_CONSOLE
1543 #elif defined(LZO_INFO_OS_POSIX)
1544 #  define __LZO_INFOSTR_OSNAME      LZO_INFO_OS "." LZO_INFO_OS_POSIX
1545 #else
1546 #  define __LZO_INFOSTR_OSNAME      LZO_INFO_OS
1547 #endif
1548 #if defined(__LZO_INFOSTR_LIBC)
1549 #elif defined(LZO_INFO_LIBC)
1550 #  define __LZO_INFOSTR_LIBC        "." LZO_INFO_LIBC
1551 #else
1552 #  define __LZO_INFOSTR_LIBC        ""
1553 #endif
1554 #if defined(__LZO_INFOSTR_CCVER)
1555 #elif defined(LZO_INFO_CCVER)
1556 #  define __LZO_INFOSTR_CCVER       " " LZO_INFO_CCVER
1557 #else
1558 #  define __LZO_INFOSTR_CCVER       ""
1559 #endif
1560 #define LZO_INFO_STRING \
1561     LZO_INFO_ARCH __LZO_INFOSTR_MM __LZO_INFOSTR_PM __LZO_INFOSTR_ENDIAN \
1562     " " __LZO_INFOSTR_OSNAME __LZO_INFOSTR_LIBC " " LZO_INFO_CC __LZO_INFOSTR_CCVER
1563 
1564 #endif
1565 
1566 #endif
1567 
1568 #undef LZO_HAVE_CONFIG_H
1569 #include "minilzo.h"
1570 
1571 #if !defined(MINILZO_VERSION) || (MINILZO_VERSION != 0x2020)
1572 #  error "version mismatch in miniLZO source files"
1573 #endif
1574 
1575 #ifdef MINILZO_HAVE_CONFIG_H
1576 #  define LZO_HAVE_CONFIG_H
1577 #endif
1578 
1579 #ifndef __LZO_CONF_H
1580 #define __LZO_CONF_H
1581 
1582 #if !defined(__LZO_IN_MINILZO)
1583 #if defined(LZO_CFG_FREESTANDING)
1584 #  define LZO_LIBC_FREESTANDING 1
1585 #  define LZO_OS_FREESTANDING 1
1586 #  define ACC_LIBC_FREESTANDING 1
1587 #  define ACC_OS_FREESTANDING 1
1588 #endif
1589 #if defined(LZO_CFG_NO_UNALIGNED)
1590 #  define ACC_CFG_NO_UNALIGNED 1
1591 #endif
1592 #if defined(LZO_HAVE_CONFIG_H)
1593 #  define ACC_CONFIG_NO_HEADER 1
1594 #endif
1595 #if defined(__LZOCONF_H) || defined(__LZOCONF_H_INCLUDED)
1596 #  error "include this file first"
1597 #endif
1598 #include "lzo/lzoconf.h"
1599 #endif
1600 
1601 #if (LZO_VERSION < 0x02000) || !defined(__LZOCONF_H_INCLUDED)
1602 #  error "version mismatch"
1603 #endif
1604 
1605 #if (LZO_CC_BORLANDC && LZO_ARCH_I086)
1606 #  pragma option -h
1607 #endif
1608 
1609 #if (LZO_CC_MSC && (_MSC_VER >= 1000))
1610 #  pragma warning(disable: 4127 4701)
1611 #endif
1612 #if (LZO_CC_MSC && (_MSC_VER >= 1300))
1613 #  pragma warning(disable: 4820)
1614 #  pragma warning(disable: 4514 4710 4711)
1615 #endif
1616 
1617 #if defined(__LZO_MMODEL_HUGE) && (!LZO_HAVE_MM_HUGE_PTR)
1618 #  error "this should not happen - check defines for __huge"
1619 #endif
1620 
1621 #if defined(__LZO_IN_MINILZO) || defined(LZO_CFG_FREESTANDING)
1622 #elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16)
1623 #  define ACC_WANT_ACC_INCD_H 1
1624 #  define ACC_WANT_ACC_INCE_H 1
1625 #  define ACC_WANT_ACC_INCI_H 1
1626 #elif 1
1627 #  include <string.h>
1628 #else
1629 #  define ACC_WANT_ACC_INCD_H 1
1630 #endif
1631 
1632 #if (LZO_ARCH_I086)
1633 #  define ACC_MM_AHSHIFT        LZO_MM_AHSHIFT
1634 #  define ACC_PTR_FP_OFF(x)     (((const unsigned __far*)&(x))[0])
1635 #  define ACC_PTR_FP_SEG(x)     (((const unsigned __far*)&(x))[1])
1636 #  define ACC_PTR_MK_FP(s,o)    ((void __far*)(((unsigned long)(s)<<16)+(unsigned)(o)))
1637 #endif
1638 
1639 #if !defined(lzo_uintptr_t)
1640 #  if defined(__LZO_MMODEL_HUGE)
1641 #    define lzo_uintptr_t       unsigned long
1642 #  elif 1 && defined(LZO_OS_OS400) && (LZO_SIZEOF_VOID_P == 16)
1643 #    define __LZO_UINTPTR_T_IS_POINTER 1
1644      typedef char*              lzo_uintptr_t;
1645 #    define lzo_uintptr_t       lzo_uintptr_t
1646 #  elif (LZO_SIZEOF_SIZE_T == LZO_SIZEOF_VOID_P)
1647 #    define lzo_uintptr_t       size_t
1648 #  elif (LZO_SIZEOF_LONG == LZO_SIZEOF_VOID_P)
1649 #    define lzo_uintptr_t       unsigned long
1650 #  elif (LZO_SIZEOF_INT == LZO_SIZEOF_VOID_P)
1651 #    define lzo_uintptr_t       unsigned int
1652 #  elif (LZO_SIZEOF_LONG_LONG == LZO_SIZEOF_VOID_P)
1653 #    define lzo_uintptr_t       unsigned long long
1654 #  else
1655 #    define lzo_uintptr_t       size_t
1656 #  endif
1657 #endif
1658 LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp))
1659 
1660 #if 1 && !defined(LZO_CFG_FREESTANDING)
1661 #if 1 && !defined(HAVE_STRING_H)
1662 #define HAVE_STRING_H 1
1663 #endif
1664 #if 1 && !defined(HAVE_MEMCMP)
1665 #define HAVE_MEMCMP 1
1666 #endif
1667 #if 1 && !defined(HAVE_MEMCPY)
1668 #define HAVE_MEMCPY 1
1669 #endif
1670 #if 1 && !defined(HAVE_MEMMOVE)
1671 #define HAVE_MEMMOVE 1
1672 #endif
1673 #if 1 && !defined(HAVE_MEMSET)
1674 #define HAVE_MEMSET 1
1675 #endif
1676 #endif
1677 
1678 #if 1 && defined(HAVE_STRING_H)
1679 #include <string.h>
1680 #endif
1681 
1682 #if defined(LZO_CFG_FREESTANDING)
1683 #  undef HAVE_MEMCMP
1684 #  undef HAVE_MEMCPY
1685 #  undef HAVE_MEMMOVE
1686 #  undef HAVE_MEMSET
1687 #endif
1688 
1689 #if !defined(HAVE_MEMCMP)
1690 #  undef memcmp
1691 #  define memcmp(a,b,c)         lzo_memcmp(a,b,c)
1692 #elif !defined(__LZO_MMODEL_HUGE)
1693 #  define lzo_memcmp(a,b,c)     memcmp(a,b,c)
1694 #endif
1695 #if !defined(HAVE_MEMCPY)
1696 #  undef memcpy
1697 #  define memcpy(a,b,c)         lzo_memcpy(a,b,c)
1698 #elif !defined(__LZO_MMODEL_HUGE)
1699 #  define lzo_memcpy(a,b,c)     memcpy(a,b,c)
1700 #endif
1701 #if !defined(HAVE_MEMMOVE)
1702 #  undef memmove
1703 #  define memmove(a,b,c)        lzo_memmove(a,b,c)
1704 #elif !defined(__LZO_MMODEL_HUGE)
1705 #  define lzo_memmove(a,b,c)    memmove(a,b,c)
1706 #endif
1707 #if !defined(HAVE_MEMSET)
1708 #  undef memset
1709 #  define memset(a,b,c)         lzo_memset(a,b,c)
1710 #elif !defined(__LZO_MMODEL_HUGE)
1711 #  define lzo_memset(a,b,c)     memset(a,b,c)
1712 #endif
1713 
1714 #undef NDEBUG
1715 #if defined(LZO_CFG_FREESTANDING)
1716 #  undef LZO_DEBUG
1717 #  define NDEBUG 1
1718 #  undef assert
1719 #  define assert(e) ((void)0)
1720 #else
1721 #  if !defined(LZO_DEBUG)
1722 #    define NDEBUG 1
1723 #  endif
1724 #  include <assert.h>
1725 #endif
1726 
1727 #if 0 && defined(__BOUNDS_CHECKING_ON)
1728 #  include <unchecked.h>
1729 #else
1730 #  define BOUNDS_CHECKING_OFF_DURING(stmt)      stmt
1731 #  define BOUNDS_CHECKING_OFF_IN_EXPR(expr)     (expr)
1732 #endif
1733 
1734 #if !defined(__lzo_inline)
1735 #  define __lzo_inline
1736 #endif
1737 #if !defined(__lzo_forceinline)
1738 #  define __lzo_forceinline
1739 #endif
1740 #if !defined(__lzo_noinline)
1741 #  define __lzo_noinline
1742 #endif
1743 
1744 #if 1
1745 #  define LZO_BYTE(x)       ((unsigned char) (x))
1746 #else
1747 #  define LZO_BYTE(x)       ((unsigned char) ((x) & 0xff))
1748 #endif
1749 
1750 #define LZO_MAX(a,b)        ((a) >= (b) ? (a) : (b))
1751 #define LZO_MIN(a,b)        ((a) <= (b) ? (a) : (b))
1752 #define LZO_MAX3(a,b,c)     ((a) >= (b) ? LZO_MAX(a,c) : LZO_MAX(b,c))
1753 #define LZO_MIN3(a,b,c)     ((a) <= (b) ? LZO_MIN(a,c) : LZO_MIN(b,c))
1754 
1755 #define lzo_sizeof(type)    ((lzo_uint) (sizeof(type)))
1756 
1757 #define LZO_HIGH(array)     ((lzo_uint) (sizeof(array)/sizeof(*(array))))
1758 
1759 #define LZO_SIZE(bits)      (1u << (bits))
1760 #define LZO_MASK(bits)      (LZO_SIZE(bits) - 1)
1761 
1762 #define LZO_LSIZE(bits)     (1ul << (bits))
1763 #define LZO_LMASK(bits)     (LZO_LSIZE(bits) - 1)
1764 
1765 #define LZO_USIZE(bits)     ((lzo_uint) 1 << (bits))
1766 #define LZO_UMASK(bits)     (LZO_USIZE(bits) - 1)
1767 
1768 #if !defined(DMUL)
1769 #if 0
1770 
1771 #  define DMUL(a,b) ((lzo_xint) ((lzo_uint32)(a) * (lzo_uint32)(b)))
1772 #else
1773 #  define DMUL(a,b) ((lzo_xint) ((a) * (b)))
1774 #endif
1775 #endif
1776 
1777 #if 1 && !defined(LZO_CFG_NO_UNALIGNED)
1778 #if 1 && (LZO_ARCH_AMD64 || LZO_ARCH_I386)
1779 #  if (LZO_SIZEOF_SHORT == 2)
1780 #    define LZO_UNALIGNED_OK_2
1781 #  endif
1782 #  if (LZO_SIZEOF_INT == 4)
1783 #    define LZO_UNALIGNED_OK_4
1784 #  endif
1785 #endif
1786 #endif
1787 
1788 #if defined(LZO_UNALIGNED_OK_2)
1789   LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(short) == 2)
1790 #endif
1791 #if defined(LZO_UNALIGNED_OK_4)
1792   LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint32) == 4)
1793 #elif defined(LZO_ALIGNED_OK_4)
1794   LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint32) == 4)
1795 #endif
1796 
1797 #define MEMCPY8_DS(dest,src,len) \
1798     lzo_memcpy(dest,src,len); dest += len; src += len
1799 
1800 #define BZERO8_PTR(s,l,n) \
1801     lzo_memset((lzo_voidp)(s),0,(lzo_uint)(l)*(n))
1802 
1803 #define MEMCPY_DS(dest,src,len) \
1804     do *dest++ = *src++; while (--len > 0)
1805 
1806 __LZO_EXTERN_C int __lzo_init_done;
1807 __LZO_EXTERN_C const char __lzo_copyright[];
1808 LZO_EXTERN(const lzo_bytep) lzo_copyright(void);
1809 
1810 #ifndef __LZO_PTR_H
1811 #define __LZO_PTR_H
1812 
1813 #ifdef __cplusplus
1814 extern "C" {
1815 #endif
1816 
1817 #if !defined(lzo_uintptr_t)
1818 #  if defined(__LZO_MMODEL_HUGE)
1819 #    define lzo_uintptr_t   unsigned long
1820 #  else
1821 #    define lzo_uintptr_t   acc_uintptr_t
1822 #    ifdef __ACC_INTPTR_T_IS_POINTER
1823 #      define __LZO_UINTPTR_T_IS_POINTER 1
1824 #    endif
1825 #  endif
1826 #endif
1827 
1828 #if (LZO_ARCH_I086)
1829 #define PTR(a)              ((lzo_bytep) (a))
1830 #define PTR_ALIGNED_4(a)    ((ACC_PTR_FP_OFF(a) & 3) == 0)
1831 #define PTR_ALIGNED2_4(a,b) (((ACC_PTR_FP_OFF(a) | ACC_PTR_FP_OFF(b)) & 3) == 0)
1832 #else
1833 #define PTR(a)              ((lzo_uintptr_t) (a))
1834 #define PTR_LINEAR(a)       PTR(a)
1835 #define PTR_ALIGNED_4(a)    ((PTR_LINEAR(a) & 3) == 0)
1836 #define PTR_ALIGNED_8(a)    ((PTR_LINEAR(a) & 7) == 0)
1837 #define PTR_ALIGNED2_4(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 3) == 0)
1838 #define PTR_ALIGNED2_8(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 7) == 0)
1839 #endif
1840 
1841 #define PTR_LT(a,b)         (PTR(a) < PTR(b))
1842 #define PTR_GE(a,b)         (PTR(a) >= PTR(b))
1843 #define PTR_DIFF(a,b)       (PTR(a) - PTR(b))
1844 #define pd(a,b)             ((lzo_uint) ((a)-(b)))
1845 
1846 LZO_EXTERN(lzo_uintptr_t)
1847 __lzo_ptr_linear(const lzo_voidp ptr);
1848 
1849 typedef union
1850 {
1851     char            a_char;
1852     unsigned char   a_uchar;
1853     short           a_short;
1854     unsigned short  a_ushort;
1855     int             a_int;
1856     unsigned int    a_uint;
1857     long            a_long;
1858     unsigned long   a_ulong;
1859     lzo_int         a_lzo_int;
1860     lzo_uint        a_lzo_uint;
1861     lzo_int32       a_lzo_int32;
1862     lzo_uint32      a_lzo_uint32;
1863     ptrdiff_t       a_ptrdiff_t;
1864     lzo_uintptr_t   a_lzo_uintptr_t;
1865     lzo_voidp       a_lzo_voidp;
1866     void *          a_void_p;
1867     lzo_bytep       a_lzo_bytep;
1868     lzo_bytepp      a_lzo_bytepp;
1869     lzo_uintp       a_lzo_uintp;
1870     lzo_uint *      a_lzo_uint_p;
1871     lzo_uint32p     a_lzo_uint32p;
1872     lzo_uint32 *    a_lzo_uint32_p;
1873     unsigned char * a_uchar_p;
1874     char *          a_char_p;
1875 }
1876 lzo_full_align_t;
1877 
1878 #ifdef __cplusplus
1879 }
1880 #endif
1881 
1882 #endif
1883 
1884 #define LZO_DETERMINISTIC
1885 
1886 #define LZO_DICT_USE_PTR
1887 #if 0 && (LZO_ARCH_I086)
1888 #  undef LZO_DICT_USE_PTR
1889 #endif
1890 
1891 #if defined(LZO_DICT_USE_PTR)
1892 #  define lzo_dict_t    const lzo_bytep
1893 #  define lzo_dict_p    lzo_dict_t __LZO_MMODEL *
1894 #else
1895 #  define lzo_dict_t    lzo_uint
1896 #  define lzo_dict_p    lzo_dict_t __LZO_MMODEL *
1897 #endif
1898 
1899 #endif
1900 
1901 #if !defined(MINILZO_CFG_SKIP_LZO_PTR)
1902 
1903 LZO_PUBLIC(lzo_uintptr_t)
__lzo_ptr_linear(const lzo_voidp ptr)1904 __lzo_ptr_linear(const lzo_voidp ptr)
1905 {
1906     lzo_uintptr_t p;
1907 
1908 #if (LZO_ARCH_I086)
1909     p = (((lzo_uintptr_t)(ACC_PTR_FP_SEG(ptr))) << (16 - ACC_MM_AHSHIFT)) + (ACC_PTR_FP_OFF(ptr));
1910 #else
1911     p = (lzo_uintptr_t) PTR_LINEAR(ptr);
1912 #endif
1913 
1914     return p;
1915 }
1916 
1917 LZO_PUBLIC(unsigned)
__lzo_align_gap(const lzo_voidp ptr,lzo_uint size)1918 __lzo_align_gap(const lzo_voidp ptr, lzo_uint size)
1919 {
1920 #if defined(__LZO_UINTPTR_T_IS_POINTER)
1921     size_t n = (size_t) ptr;
1922     n = (((n + size - 1) / size) * size) - n;
1923 #else
1924     lzo_uintptr_t p, n;
1925     p = __lzo_ptr_linear(ptr);
1926     n = (((p + size - 1) / size) * size) - p;
1927 #endif
1928 
1929     assert(size > 0);
1930     assert((long)n >= 0);
1931     assert(n <= s);
1932     return (unsigned)n;
1933 }
1934 
1935 #endif
1936 
1937 /* If you use the LZO library in a product, you *must* keep this
1938  * copyright string in the executable of your product.
1939  */
1940 
1941 const char __lzo_copyright[] =
1942 #if !defined(__LZO_IN_MINLZO)
1943     LZO_VERSION_STRING;
1944 #else
1945     "\r\n\n"
1946     "LZO data compression library.\n"
1947     "$Copyright: LZO (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Markus Franz Xaver Johannes Oberhumer\n"
1948     "<markus@oberhumer.com>\n"
1949     "http://www.oberhumer.com $\n\n"
1950     "$Id: LZO version: v" LZO_VERSION_STRING ", " LZO_VERSION_DATE " $\n"
1951     "$Built: " __DATE__ " " __TIME__ " $\n"
1952     "$Info: " LZO_INFO_STRING " $\n";
1953 #endif
1954 
1955 LZO_PUBLIC(const lzo_bytep)
lzo_copyright(void)1956 lzo_copyright(void)
1957 {
1958 #if (LZO_OS_DOS16 && LZO_CC_TURBOC)
1959     return (lzo_voidp) __lzo_copyright;
1960 #else
1961     return (const lzo_bytep) __lzo_copyright;
1962 #endif
1963 }
1964 
1965 LZO_PUBLIC(unsigned)
lzo_version(void)1966 lzo_version(void)
1967 {
1968     return LZO_VERSION;
1969 }
1970 
1971 LZO_PUBLIC(const char *)
lzo_version_string(void)1972 lzo_version_string(void)
1973 {
1974     return LZO_VERSION_STRING;
1975 }
1976 
1977 LZO_PUBLIC(const char *)
lzo_version_date(void)1978 lzo_version_date(void)
1979 {
1980     return LZO_VERSION_DATE;
1981 }
1982 
1983 LZO_PUBLIC(const lzo_charp)
_lzo_version_string(void)1984 _lzo_version_string(void)
1985 {
1986     return LZO_VERSION_STRING;
1987 }
1988 
1989 LZO_PUBLIC(const lzo_charp)
_lzo_version_date(void)1990 _lzo_version_date(void)
1991 {
1992     return LZO_VERSION_DATE;
1993 }
1994 
1995 #define LZO_BASE 65521u
1996 #define LZO_NMAX 5552
1997 
1998 #define LZO_DO1(buf,i)  s1 += buf[i]; s2 += s1
1999 #define LZO_DO2(buf,i)  LZO_DO1(buf,i); LZO_DO1(buf,i+1);
2000 #define LZO_DO4(buf,i)  LZO_DO2(buf,i); LZO_DO2(buf,i+2);
2001 #define LZO_DO8(buf,i)  LZO_DO4(buf,i); LZO_DO4(buf,i+4);
2002 #define LZO_DO16(buf,i) LZO_DO8(buf,i); LZO_DO8(buf,i+8);
2003 
2004 LZO_PUBLIC(lzo_uint32)
lzo_adler32(lzo_uint32 adler,const lzo_bytep buf,lzo_uint len)2005 lzo_adler32(lzo_uint32 adler, const lzo_bytep buf, lzo_uint len)
2006 {
2007     lzo_uint32 s1 = adler & 0xffff;
2008     lzo_uint32 s2 = (adler >> 16) & 0xffff;
2009     unsigned k;
2010 
2011     if (buf == NULL)
2012         return 1;
2013 
2014     while (len > 0)
2015     {
2016         k = len < LZO_NMAX ? (unsigned) len : LZO_NMAX;
2017         len -= k;
2018         if (k >= 16) do
2019         {
2020             LZO_DO16(buf,0);
2021             buf += 16;
2022             k -= 16;
2023         } while (k >= 16);
2024         if (k != 0) do
2025         {
2026             s1 += *buf++;
2027             s2 += s1;
2028         } while (--k > 0);
2029         s1 %= LZO_BASE;
2030         s2 %= LZO_BASE;
2031     }
2032     return (s2 << 16) | s1;
2033 }
2034 
2035 #undef LZO_DO1
2036 #undef LZO_DO2
2037 #undef LZO_DO4
2038 #undef LZO_DO8
2039 #undef LZO_DO16
2040 
2041 #if !defined(MINILZO_CFG_SKIP_LZO_STRING)
2042 #undef lzo_memcmp
2043 #undef lzo_memcpy
2044 #undef lzo_memmove
2045 #undef lzo_memset
2046 #if !defined(__LZO_MMODEL_HUGE)
2047 #  undef LZO_HAVE_MM_HUGE_PTR
2048 #endif
2049 #define lzo_hsize_t             lzo_uint
2050 #define lzo_hvoid_p             lzo_voidp
2051 #define lzo_hbyte_p             lzo_bytep
2052 #define LZOLIB_PUBLIC(r,f)      LZO_PUBLIC(r) f
2053 #define lzo_hmemcmp             lzo_memcmp
2054 #define lzo_hmemcpy             lzo_memcpy
2055 #define lzo_hmemmove            lzo_memmove
2056 #define lzo_hmemset             lzo_memset
2057 #define __LZOLIB_HMEMCPY_CH_INCLUDED 1
2058 #if !defined(LZOLIB_PUBLIC)
2059 #  define LZOLIB_PUBLIC(r,f)    r __LZOLIB_FUNCNAME(f)
2060 #endif
LZOLIB_PUBLIC(int,lzo_hmemcmp)2061 LZOLIB_PUBLIC(int, lzo_hmemcmp) (const lzo_hvoid_p s1, const lzo_hvoid_p s2, lzo_hsize_t len)
2062 {
2063 #if (LZO_HAVE_MM_HUGE_PTR) || !defined(HAVE_MEMCMP)
2064     const lzo_hbyte_p p1 = (const lzo_hbyte_p) s1;
2065     const lzo_hbyte_p p2 = (const lzo_hbyte_p) s2;
2066     if __lzo_likely(len > 0) do
2067     {
2068         int d = *p1 - *p2;
2069         if (d != 0)
2070             return d;
2071         p1++; p2++;
2072     } while __lzo_likely(--len > 0);
2073     return 0;
2074 #else
2075     return memcmp(s1, s2, len);
2076 #endif
2077 }
LZOLIB_PUBLIC(lzo_hvoid_p,lzo_hmemcpy)2078 LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemcpy) (lzo_hvoid_p dest, const lzo_hvoid_p src, lzo_hsize_t len)
2079 {
2080 #if (LZO_HAVE_MM_HUGE_PTR) || !defined(HAVE_MEMCPY)
2081     lzo_hbyte_p p1 = (lzo_hbyte_p) dest;
2082     const lzo_hbyte_p p2 = (const lzo_hbyte_p) src;
2083     if (len <= 0 || p1 == p2)
2084         return dest;
2085     do
2086         *p1++ = *p2++;
2087     while __lzo_likely(--len > 0);
2088     return dest;
2089 #else
2090     return memcpy(dest, src, len);
2091 #endif
2092 }
LZOLIB_PUBLIC(lzo_hvoid_p,lzo_hmemmove)2093 LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemmove) (lzo_hvoid_p dest, const lzo_hvoid_p src, lzo_hsize_t len)
2094 {
2095 #if (LZO_HAVE_MM_HUGE_PTR) || !defined(HAVE_MEMMOVE)
2096     lzo_hbyte_p p1 = (lzo_hbyte_p) dest;
2097     const lzo_hbyte_p p2 = (const lzo_hbyte_p) src;
2098     if (len <= 0 || p1 == p2)
2099         return dest;
2100     if (p1 < p2)
2101     {
2102         do
2103             *p1++ = *p2++;
2104         while __lzo_likely(--len > 0);
2105     }
2106     else
2107     {
2108         p1 += len;
2109         p2 += len;
2110         do
2111             *--p1 = *--p2;
2112         while __lzo_likely(--len > 0);
2113     }
2114     return dest;
2115 #else
2116     return memmove(dest, src, len);
2117 #endif
2118 }
LZOLIB_PUBLIC(lzo_hvoid_p,lzo_hmemset)2119 LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemset) (lzo_hvoid_p s, int c, lzo_hsize_t len)
2120 {
2121 #if (LZO_HAVE_MM_HUGE_PTR) || !defined(HAVE_MEMSET)
2122     lzo_hbyte_p p = (lzo_hbyte_p) s;
2123     if __lzo_likely(len > 0) do
2124         *p++ = (unsigned char) c;
2125     while __lzo_likely(--len > 0);
2126     return s;
2127 #else
2128     return memset(s, c, len);
2129 #endif
2130 }
2131 #undef LZOLIB_PUBLIC
2132 #endif
2133 
2134 #if !defined(__LZO_IN_MINILZO)
2135 
2136 #define ACC_WANT_ACC_CHK_CH 1
2137 #undef ACCCHK_ASSERT
2138 
2139     ACCCHK_ASSERT_IS_SIGNED_T(lzo_int)
ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint)2140     ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint)
2141 
2142     ACCCHK_ASSERT_IS_SIGNED_T(lzo_int32)
2143     ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint32)
2144     ACCCHK_ASSERT((LZO_UINT32_C(1) << (int)(8*sizeof(LZO_UINT32_C(1))-1)) > 0)
2145     ACCCHK_ASSERT(sizeof(lzo_uint32) >= 4)
2146 
2147 #if !defined(__LZO_UINTPTR_T_IS_POINTER)
2148     ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uintptr_t)
2149 #endif
2150     ACCCHK_ASSERT(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp))
2151 
2152     ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_xint)
2153     ACCCHK_ASSERT(sizeof(lzo_xint) >= sizeof(lzo_uint32))
2154     ACCCHK_ASSERT(sizeof(lzo_xint) >= sizeof(lzo_uint))
2155     ACCCHK_ASSERT(sizeof(lzo_xint) == sizeof(lzo_uint32) || sizeof(lzo_xint) == sizeof(lzo_uint))
2156 
2157 #endif
2158 #undef ACCCHK_ASSERT
2159 
2160 LZO_PUBLIC(int)
2161 _lzo_config_check(void)
2162 {
2163     lzo_bool r = 1;
2164     union { unsigned char c[2*sizeof(lzo_xint)]; lzo_xint l[2]; } u;
2165 
2166 #if !defined(LZO_CFG_NO_CONFIG_CHECK)
2167 #if defined(LZO_ABI_BIG_ENDIAN)
2168     u.l[0] = u.l[1] = 0; u.c[sizeof(lzo_xint) - 1] = 128;
2169     r &= (u.l[0] == 128);
2170 #endif
2171 #if defined(LZO_ABI_LITTLE_ENDIAN)
2172     u.l[0] = u.l[1] = 0; u.c[0] = 128;
2173     r &= (u.l[0] == 128);
2174 #endif
2175 #if defined(LZO_UNALIGNED_OK_2)
2176     u.l[0] = u.l[1] = 0;
2177     r &= ((* (const lzo_ushortp) (const lzo_voidp) &u.c[1]) == 0);
2178 #endif
2179 #if defined(LZO_UNALIGNED_OK_4)
2180     u.l[0] = u.l[1] = 0;
2181     r &= ((* (const lzo_uint32p) (const lzo_voidp) &u.c[1]) == 0);
2182 #endif
2183 #endif
2184 
2185     LZO_UNUSED(u);
2186     return r == 1 ? LZO_E_OK : LZO_E_ERROR;
2187 }
2188 
2189 int __lzo_init_done = 0;
2190 
2191 LZO_PUBLIC(int)
__lzo_init_v2(unsigned v,int s1,int s2,int s3,int s4,int s5,int s6,int s7,int s8,int s9)2192 __lzo_init_v2(unsigned v, int s1, int s2, int s3, int s4, int s5,
2193                           int s6, int s7, int s8, int s9)
2194 {
2195     int r;
2196 
2197 #if defined(__LZO_IN_MINILZO)
2198 #elif (LZO_CC_MSC && ((_MSC_VER) < 700))
2199 #else
2200 #define ACC_WANT_ACC_CHK_CH 1
2201 #undef ACCCHK_ASSERT
2202 #define ACCCHK_ASSERT(expr)  LZO_COMPILE_TIME_ASSERT(expr)
2203 #endif
2204 #undef ACCCHK_ASSERT
2205 
2206     __lzo_init_done = 1;
2207 
2208     if (v == 0)
2209         return LZO_E_ERROR;
2210 
2211     r = (s1 == -1 || s1 == (int) sizeof(short)) &&
2212         (s2 == -1 || s2 == (int) sizeof(int)) &&
2213         (s3 == -1 || s3 == (int) sizeof(long)) &&
2214         (s4 == -1 || s4 == (int) sizeof(lzo_uint32)) &&
2215         (s5 == -1 || s5 == (int) sizeof(lzo_uint)) &&
2216         (s6 == -1 || s6 == (int) lzo_sizeof_dict_t) &&
2217         (s7 == -1 || s7 == (int) sizeof(char *)) &&
2218         (s8 == -1 || s8 == (int) sizeof(lzo_voidp)) &&
2219         (s9 == -1 || s9 == (int) sizeof(lzo_callback_t));
2220     if (!r)
2221         return LZO_E_ERROR;
2222 
2223     r = _lzo_config_check();
2224     if (r != LZO_E_OK)
2225         return r;
2226 
2227     return r;
2228 }
2229 
2230 #if !defined(__LZO_IN_MINILZO)
2231 
2232 #if (LZO_OS_WIN16 && LZO_CC_WATCOMC) && defined(__SW_BD)
2233 
2234 #if 0
2235 BOOL FAR PASCAL LibMain ( HANDLE hInstance, WORD wDataSegment,
2236                           WORD wHeapSize, LPSTR lpszCmdLine )
2237 #else
LibMain(int a,short b,short c,long d)2238 int __far __pascal LibMain ( int a, short b, short c, long d )
2239 #endif
2240 {
2241     LZO_UNUSED(a); LZO_UNUSED(b); LZO_UNUSED(c); LZO_UNUSED(d);
2242     return 1;
2243 }
2244 
2245 #endif
2246 
2247 #endif
2248 
2249 #define do_compress         _lzo1x_1_do_compress
2250 
2251 #if !defined(MINILZO_CFG_SKIP_LZO1X_1_COMPRESS)
2252 
2253 #define LZO_NEED_DICT_H
2254 #define D_BITS          14
2255 #define D_INDEX1(d,p)       d = DM(DMUL(0x21,DX3(p,5,5,6)) >> 5)
2256 #define D_INDEX2(d,p)       d = (d & (D_MASK & 0x7ff)) ^ (D_HIGH | 0x1f)
2257 
2258 #ifndef __LZO_CONFIG1X_H
2259 #define __LZO_CONFIG1X_H
2260 
2261 #if !defined(LZO1X) && !defined(LZO1Y) && !defined(LZO1Z)
2262 #  define LZO1X
2263 #endif
2264 
2265 #if !defined(__LZO_IN_MINILZO)
2266 #include "lzo/lzo1x.h"
2267 #endif
2268 
2269 #define LZO_EOF_CODE
2270 #undef LZO_DETERMINISTIC
2271 
2272 #define M1_MAX_OFFSET   0x0400
2273 #ifndef M2_MAX_OFFSET
2274 #define M2_MAX_OFFSET   0x0800
2275 #endif
2276 #define M3_MAX_OFFSET   0x4000
2277 #define M4_MAX_OFFSET   0xbfff
2278 
2279 #define MX_MAX_OFFSET   (M1_MAX_OFFSET + M2_MAX_OFFSET)
2280 
2281 #define M1_MIN_LEN      2
2282 #define M1_MAX_LEN      2
2283 #define M2_MIN_LEN      3
2284 #ifndef M2_MAX_LEN
2285 #define M2_MAX_LEN      8
2286 #endif
2287 #define M3_MIN_LEN      3
2288 #define M3_MAX_LEN      33
2289 #define M4_MIN_LEN      3
2290 #define M4_MAX_LEN      9
2291 
2292 #define M1_MARKER       0
2293 #define M2_MARKER       64
2294 #define M3_MARKER       32
2295 #define M4_MARKER       16
2296 
2297 #ifndef MIN_LOOKAHEAD
2298 #define MIN_LOOKAHEAD       (M2_MAX_LEN + 1)
2299 #endif
2300 
2301 #if defined(LZO_NEED_DICT_H)
2302 
2303 #ifndef LZO_HASH
2304 #define LZO_HASH            LZO_HASH_LZO_INCREMENTAL_B
2305 #endif
2306 #define DL_MIN_LEN          M2_MIN_LEN
2307 
2308 #ifndef __LZO_DICT_H
2309 #define __LZO_DICT_H
2310 
2311 #ifdef __cplusplus
2312 extern "C" {
2313 #endif
2314 
2315 #if !defined(D_BITS) && defined(DBITS)
2316 #  define D_BITS        DBITS
2317 #endif
2318 #if !defined(D_BITS)
2319 #  error "D_BITS is not defined"
2320 #endif
2321 #if (D_BITS < 16)
2322 #  define D_SIZE        LZO_SIZE(D_BITS)
2323 #  define D_MASK        LZO_MASK(D_BITS)
2324 #else
2325 #  define D_SIZE        LZO_USIZE(D_BITS)
2326 #  define D_MASK        LZO_UMASK(D_BITS)
2327 #endif
2328 #define D_HIGH          ((D_MASK >> 1) + 1)
2329 
2330 #if !defined(DD_BITS)
2331 #  define DD_BITS       0
2332 #endif
2333 #define DD_SIZE         LZO_SIZE(DD_BITS)
2334 #define DD_MASK         LZO_MASK(DD_BITS)
2335 
2336 #if !defined(DL_BITS)
2337 #  define DL_BITS       (D_BITS - DD_BITS)
2338 #endif
2339 #if (DL_BITS < 16)
2340 #  define DL_SIZE       LZO_SIZE(DL_BITS)
2341 #  define DL_MASK       LZO_MASK(DL_BITS)
2342 #else
2343 #  define DL_SIZE       LZO_USIZE(DL_BITS)
2344 #  define DL_MASK       LZO_UMASK(DL_BITS)
2345 #endif
2346 
2347 #if (D_BITS != DL_BITS + DD_BITS)
2348 #  error "D_BITS does not match"
2349 #endif
2350 #if (D_BITS < 8 || D_BITS > 18)
2351 #  error "invalid D_BITS"
2352 #endif
2353 #if (DL_BITS < 8 || DL_BITS > 20)
2354 #  error "invalid DL_BITS"
2355 #endif
2356 #if (DD_BITS < 0 || DD_BITS > 6)
2357 #  error "invalid DD_BITS"
2358 #endif
2359 
2360 #if !defined(DL_MIN_LEN)
2361 #  define DL_MIN_LEN    3
2362 #endif
2363 #if !defined(DL_SHIFT)
2364 #  define DL_SHIFT      ((DL_BITS + (DL_MIN_LEN - 1)) / DL_MIN_LEN)
2365 #endif
2366 
2367 #define LZO_HASH_GZIP                   1
2368 #define LZO_HASH_GZIP_INCREMENTAL       2
2369 #define LZO_HASH_LZO_INCREMENTAL_A      3
2370 #define LZO_HASH_LZO_INCREMENTAL_B      4
2371 
2372 #if !defined(LZO_HASH)
2373 #  error "choose a hashing strategy"
2374 #endif
2375 
2376 #undef DM
2377 #undef DX
2378 
2379 #if (DL_MIN_LEN == 3)
2380 #  define _DV2_A(p,shift1,shift2) \
2381         (((( (lzo_xint)((p)[0]) << shift1) ^ (p)[1]) << shift2) ^ (p)[2])
2382 #  define _DV2_B(p,shift1,shift2) \
2383         (((( (lzo_xint)((p)[2]) << shift1) ^ (p)[1]) << shift2) ^ (p)[0])
2384 #  define _DV3_B(p,shift1,shift2,shift3) \
2385         ((_DV2_B((p)+1,shift1,shift2) << (shift3)) ^ (p)[0])
2386 #elif (DL_MIN_LEN == 2)
2387 #  define _DV2_A(p,shift1,shift2) \
2388         (( (lzo_xint)(p[0]) << shift1) ^ p[1])
2389 #  define _DV2_B(p,shift1,shift2) \
2390         (( (lzo_xint)(p[1]) << shift1) ^ p[2])
2391 #else
2392 #  error "invalid DL_MIN_LEN"
2393 #endif
2394 #define _DV_A(p,shift)      _DV2_A(p,shift,shift)
2395 #define _DV_B(p,shift)      _DV2_B(p,shift,shift)
2396 #define DA2(p,s1,s2) \
2397         (((((lzo_xint)((p)[2]) << (s2)) + (p)[1]) << (s1)) + (p)[0])
2398 #define DS2(p,s1,s2) \
2399         (((((lzo_xint)((p)[2]) << (s2)) - (p)[1]) << (s1)) - (p)[0])
2400 #define DX2(p,s1,s2) \
2401         (((((lzo_xint)((p)[2]) << (s2)) ^ (p)[1]) << (s1)) ^ (p)[0])
2402 #define DA3(p,s1,s2,s3) ((DA2((p)+1,s2,s3) << (s1)) + (p)[0])
2403 #define DS3(p,s1,s2,s3) ((DS2((p)+1,s2,s3) << (s1)) - (p)[0])
2404 #define DX3(p,s1,s2,s3) ((DX2((p)+1,s2,s3) << (s1)) ^ (p)[0])
2405 #define DMS(v,s)        ((lzo_uint) (((v) & (D_MASK >> (s))) << (s)))
2406 #define DM(v)           DMS(v,0)
2407 
2408 #if (LZO_HASH == LZO_HASH_GZIP)
2409 #  define _DINDEX(dv,p)     (_DV_A((p),DL_SHIFT))
2410 
2411 #elif (LZO_HASH == LZO_HASH_GZIP_INCREMENTAL)
2412 #  define __LZO_HASH_INCREMENTAL
2413 #  define DVAL_FIRST(dv,p)  dv = _DV_A((p),DL_SHIFT)
2414 #  define DVAL_NEXT(dv,p)   dv = (((dv) << DL_SHIFT) ^ p[2])
2415 #  define _DINDEX(dv,p)     (dv)
2416 #  define DVAL_LOOKAHEAD    DL_MIN_LEN
2417 
2418 #elif (LZO_HASH == LZO_HASH_LZO_INCREMENTAL_A)
2419 #  define __LZO_HASH_INCREMENTAL
2420 #  define DVAL_FIRST(dv,p)  dv = _DV_A((p),5)
2421 #  define DVAL_NEXT(dv,p) \
2422                 dv ^= (lzo_xint)(p[-1]) << (2*5); dv = (((dv) << 5) ^ p[2])
2423 #  define _DINDEX(dv,p)     ((DMUL(0x9f5f,dv)) >> 5)
2424 #  define DVAL_LOOKAHEAD    DL_MIN_LEN
2425 
2426 #elif (LZO_HASH == LZO_HASH_LZO_INCREMENTAL_B)
2427 #  define __LZO_HASH_INCREMENTAL
2428 #  define DVAL_FIRST(dv,p)  dv = _DV_B((p),5)
2429 #  define DVAL_NEXT(dv,p) \
2430                 dv ^= p[-1]; dv = (((dv) >> 5) ^ ((lzo_xint)(p[2]) << (2*5)))
2431 #  define _DINDEX(dv,p)     ((DMUL(0x9f5f,dv)) >> 5)
2432 #  define DVAL_LOOKAHEAD    DL_MIN_LEN
2433 
2434 #else
2435 #  error "choose a hashing strategy"
2436 #endif
2437 
2438 #ifndef DINDEX
2439 #define DINDEX(dv,p)        ((lzo_uint)((_DINDEX(dv,p)) & DL_MASK) << DD_BITS)
2440 #endif
2441 #if !defined(DINDEX1) && defined(D_INDEX1)
2442 #define DINDEX1             D_INDEX1
2443 #endif
2444 #if !defined(DINDEX2) && defined(D_INDEX2)
2445 #define DINDEX2             D_INDEX2
2446 #endif
2447 
2448 #if !defined(__LZO_HASH_INCREMENTAL)
2449 #  define DVAL_FIRST(dv,p)  ((void) 0)
2450 #  define DVAL_NEXT(dv,p)   ((void) 0)
2451 #  define DVAL_LOOKAHEAD    0
2452 #endif
2453 
2454 #if !defined(DVAL_ASSERT)
2455 #if defined(__LZO_HASH_INCREMENTAL) && !defined(NDEBUG)
DVAL_ASSERT(lzo_xint dv,const lzo_bytep p)2456 static void DVAL_ASSERT(lzo_xint dv, const lzo_bytep p)
2457 {
2458     lzo_xint df;
2459     DVAL_FIRST(df,(p));
2460     assert(DINDEX(dv,p) == DINDEX(df,p));
2461 }
2462 #else
2463 #  define DVAL_ASSERT(dv,p) ((void) 0)
2464 #endif
2465 #endif
2466 
2467 #if defined(LZO_DICT_USE_PTR)
2468 #  define DENTRY(p,in)                          (p)
2469 #  define GINDEX(m_pos,m_off,dict,dindex,in)    m_pos = dict[dindex]
2470 #else
2471 #  define DENTRY(p,in)                          ((lzo_uint) ((p)-(in)))
2472 #  define GINDEX(m_pos,m_off,dict,dindex,in)    m_off = dict[dindex]
2473 #endif
2474 
2475 #if (DD_BITS == 0)
2476 
2477 #  define UPDATE_D(dict,drun,dv,p,in)       dict[ DINDEX(dv,p) ] = DENTRY(p,in)
2478 #  define UPDATE_I(dict,drun,index,p,in)    dict[index] = DENTRY(p,in)
2479 #  define UPDATE_P(ptr,drun,p,in)           (ptr)[0] = DENTRY(p,in)
2480 
2481 #else
2482 
2483 #  define UPDATE_D(dict,drun,dv,p,in)   \
2484         dict[ DINDEX(dv,p) + drun++ ] = DENTRY(p,in); drun &= DD_MASK
2485 #  define UPDATE_I(dict,drun,index,p,in)    \
2486         dict[ (index) + drun++ ] = DENTRY(p,in); drun &= DD_MASK
2487 #  define UPDATE_P(ptr,drun,p,in)   \
2488         (ptr) [ drun++ ] = DENTRY(p,in); drun &= DD_MASK
2489 
2490 #endif
2491 
2492 #if defined(LZO_DICT_USE_PTR)
2493 
2494 #define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \
2495         (m_pos == NULL || (m_off = pd(ip, m_pos)) > max_offset)
2496 
2497 #define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \
2498     (BOUNDS_CHECKING_OFF_IN_EXPR(( \
2499         m_pos = ip - (lzo_uint) PTR_DIFF(ip,m_pos), \
2500         PTR_LT(m_pos,in) || \
2501         (m_off = (lzo_uint) PTR_DIFF(ip,m_pos)) <= 0 || \
2502          m_off > max_offset )))
2503 
2504 #else
2505 
2506 #define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \
2507         (m_off == 0 || \
2508          ((m_off = pd(ip, in) - m_off) > max_offset) || \
2509          (m_pos = (ip) - (m_off), 0) )
2510 
2511 #define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \
2512         (pd(ip, in) <= m_off || \
2513          ((m_off = pd(ip, in) - m_off) > max_offset) || \
2514          (m_pos = (ip) - (m_off), 0) )
2515 
2516 #endif
2517 
2518 #if defined(LZO_DETERMINISTIC)
2519 #  define LZO_CHECK_MPOS    LZO_CHECK_MPOS_DET
2520 #else
2521 #  define LZO_CHECK_MPOS    LZO_CHECK_MPOS_NON_DET
2522 #endif
2523 
2524 #ifdef __cplusplus
2525 }
2526 #endif
2527 
2528 #endif
2529 
2530 #endif
2531 
2532 #endif
2533 
2534 #define DO_COMPRESS     lzo1x_1_compress
2535 
2536 static __lzo_noinline lzo_uint
do_compress(const lzo_bytep in,lzo_uint in_len,lzo_bytep out,lzo_uintp out_len,lzo_voidp wrkmem)2537 do_compress ( const lzo_bytep in , lzo_uint  in_len,
2538                     lzo_bytep out, lzo_uintp out_len,
2539                     lzo_voidp wrkmem )
2540 {
2541     register const lzo_bytep ip;
2542     lzo_bytep op;
2543     const lzo_bytep const in_end = in + in_len;
2544     const lzo_bytep const ip_end = in + in_len - M2_MAX_LEN - 5;
2545     const lzo_bytep ii;
2546     lzo_dict_p const dict = (lzo_dict_p) wrkmem;
2547 
2548     op = out;
2549     ip = in;
2550     ii = ip;
2551 
2552     ip += 4;
2553     for (;;)
2554     {
2555         register const lzo_bytep m_pos;
2556         lzo_uint m_off;
2557         lzo_uint m_len;
2558         lzo_uint dindex;
2559 
2560         DINDEX1(dindex,ip);
2561         GINDEX(m_pos,m_off,dict,dindex,in);
2562         if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
2563             goto literal;
2564 #if 1
2565         if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
2566             goto try_match;
2567         DINDEX2(dindex,ip);
2568 #endif
2569         GINDEX(m_pos,m_off,dict,dindex,in);
2570         if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
2571             goto literal;
2572         if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
2573             goto try_match;
2574         goto literal;
2575 
2576 try_match:
2577 #if 1 && defined(LZO_UNALIGNED_OK_2)
2578         if (* (const lzo_ushortp) m_pos != * (const lzo_ushortp) ip)
2579 #else
2580         if (m_pos[0] != ip[0] || m_pos[1] != ip[1])
2581 #endif
2582         {
2583         }
2584         else
2585         {
2586             if __lzo_likely(m_pos[2] == ip[2])
2587             {
2588 #if 0
2589                 if (m_off <= M2_MAX_OFFSET)
2590                     goto match;
2591                 if (lit <= 3)
2592                     goto match;
2593                 if (lit == 3)
2594                 {
2595                     assert(op - 2 > out); op[-2] |= LZO_BYTE(3);
2596                     *op++ = *ii++; *op++ = *ii++; *op++ = *ii++;
2597                     goto code_match;
2598                 }
2599                 if (m_pos[3] == ip[3])
2600 #endif
2601                     goto match;
2602             }
2603             else
2604             {
2605 #if 0
2606 #if 0
2607                 if (m_off <= M1_MAX_OFFSET && lit > 0 && lit <= 3)
2608 #else
2609                 if (m_off <= M1_MAX_OFFSET && lit == 3)
2610 #endif
2611                 {
2612                     register lzo_uint t;
2613 
2614                     t = lit;
2615                     assert(op - 2 > out); op[-2] |= LZO_BYTE(t);
2616                     do *op++ = *ii++; while (--t > 0);
2617                     assert(ii == ip);
2618                     m_off -= 1;
2619                     *op++ = LZO_BYTE(M1_MARKER | ((m_off & 3) << 2));
2620                     *op++ = LZO_BYTE(m_off >> 2);
2621                     ip += 2;
2622                     goto match_done;
2623                 }
2624 #endif
2625             }
2626         }
2627 
2628 literal:
2629         UPDATE_I(dict,0,dindex,ip,in);
2630         ++ip;
2631         if __lzo_unlikely(ip >= ip_end)
2632             break;
2633         continue;
2634 
2635 match:
2636         UPDATE_I(dict,0,dindex,ip,in);
2637         if (pd(ip,ii) > 0)
2638         {
2639             register lzo_uint t = pd(ip,ii);
2640 
2641             if (t <= 3)
2642             {
2643                 assert(op - 2 > out);
2644                 op[-2] |= LZO_BYTE(t);
2645             }
2646             else if (t <= 18)
2647                 *op++ = LZO_BYTE(t - 3);
2648             else
2649             {
2650                 register lzo_uint tt = t - 18;
2651 
2652                 *op++ = 0;
2653                 while (tt > 255)
2654                 {
2655                     tt -= 255;
2656                     *op++ = 0;
2657                 }
2658                 assert(tt > 0);
2659                 *op++ = LZO_BYTE(tt);
2660             }
2661             do *op++ = *ii++; while (--t > 0);
2662         }
2663 
2664         assert(ii == ip);
2665         ip += 3;
2666         if (m_pos[3] != *ip++ || m_pos[4] != *ip++ || m_pos[5] != *ip++ ||
2667             m_pos[6] != *ip++ || m_pos[7] != *ip++ || m_pos[8] != *ip++
2668 #ifdef LZO1Y
2669             || m_pos[ 9] != *ip++ || m_pos[10] != *ip++ || m_pos[11] != *ip++
2670             || m_pos[12] != *ip++ || m_pos[13] != *ip++ || m_pos[14] != *ip++
2671 #endif
2672            )
2673         {
2674             --ip;
2675             m_len = pd(ip, ii);
2676             assert(m_len >= 3); assert(m_len <= M2_MAX_LEN);
2677 
2678             if (m_off <= M2_MAX_OFFSET)
2679             {
2680                 m_off -= 1;
2681 #if defined(LZO1X)
2682                 *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2));
2683                 *op++ = LZO_BYTE(m_off >> 3);
2684 #elif defined(LZO1Y)
2685                 *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2));
2686                 *op++ = LZO_BYTE(m_off >> 2);
2687 #endif
2688             }
2689             else if (m_off <= M3_MAX_OFFSET)
2690             {
2691                 m_off -= 1;
2692                 *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
2693                 goto m3_m4_offset;
2694             }
2695             else
2696 #if defined(LZO1X)
2697             {
2698                 m_off -= 0x4000;
2699                 assert(m_off > 0); assert(m_off <= 0x7fff);
2700                 *op++ = LZO_BYTE(M4_MARKER |
2701                                  ((m_off & 0x4000) >> 11) | (m_len - 2));
2702                 goto m3_m4_offset;
2703             }
2704 #elif defined(LZO1Y)
2705                 goto m4_match;
2706 #endif
2707         }
2708         else
2709         {
2710             {
2711                 const lzo_bytep end = in_end;
2712                 const lzo_bytep m = m_pos + M2_MAX_LEN + 1;
2713                 while (ip < end && *m == *ip)
2714                     m++, ip++;
2715                 m_len = pd(ip, ii);
2716             }
2717             assert(m_len > M2_MAX_LEN);
2718 
2719             if (m_off <= M3_MAX_OFFSET)
2720             {
2721                 m_off -= 1;
2722                 if (m_len <= 33)
2723                     *op++ = LZO_BYTE(M3_MARKER | (m_len - 2));
2724                 else
2725                 {
2726                     m_len -= 33;
2727                     *op++ = M3_MARKER | 0;
2728                     goto m3_m4_len;
2729                 }
2730             }
2731             else
2732             {
2733 #if defined(LZO1Y)
2734 m4_match:
2735 #endif
2736                 m_off -= 0x4000;
2737                 assert(m_off > 0); assert(m_off <= 0x7fff);
2738                 if (m_len <= M4_MAX_LEN)
2739                     *op++ = LZO_BYTE(M4_MARKER |
2740                                      ((m_off & 0x4000) >> 11) | (m_len - 2));
2741                 else
2742                 {
2743                     m_len -= M4_MAX_LEN;
2744                     *op++ = LZO_BYTE(M4_MARKER | ((m_off & 0x4000) >> 11));
2745 m3_m4_len:
2746                     while (m_len > 255)
2747                     {
2748                         m_len -= 255;
2749                         *op++ = 0;
2750                     }
2751                     assert(m_len > 0);
2752                     *op++ = LZO_BYTE(m_len);
2753                 }
2754             }
2755 
2756 m3_m4_offset:
2757             *op++ = LZO_BYTE((m_off & 63) << 2);
2758             *op++ = LZO_BYTE(m_off >> 6);
2759         }
2760 
2761 #if 0
2762 match_done:
2763 #endif
2764         ii = ip;
2765         if __lzo_unlikely(ip >= ip_end)
2766             break;
2767     }
2768 
2769     *out_len = pd(op, out);
2770     return pd(in_end,ii);
2771 }
2772 
2773 LZO_PUBLIC(int)
DO_COMPRESS(const lzo_bytep in,lzo_uint in_len,lzo_bytep out,lzo_uintp out_len,lzo_voidp wrkmem)2774 DO_COMPRESS      ( const lzo_bytep in , lzo_uint  in_len,
2775                          lzo_bytep out, lzo_uintp out_len,
2776                          lzo_voidp wrkmem )
2777 {
2778     lzo_bytep op = out;
2779     lzo_uint t;
2780 
2781     if __lzo_unlikely(in_len <= M2_MAX_LEN + 5)
2782         t = in_len;
2783     else
2784     {
2785         t = do_compress(in,in_len,op,out_len,wrkmem);
2786         op += *out_len;
2787     }
2788 
2789     if (t > 0)
2790     {
2791         const lzo_bytep ii = in + in_len - t;
2792 
2793         if (op == out && t <= 238)
2794             *op++ = LZO_BYTE(17 + t);
2795         else if (t <= 3)
2796             op[-2] |= LZO_BYTE(t);
2797         else if (t <= 18)
2798             *op++ = LZO_BYTE(t - 3);
2799         else
2800         {
2801             lzo_uint tt = t - 18;
2802 
2803             *op++ = 0;
2804             while (tt > 255)
2805             {
2806                 tt -= 255;
2807                 *op++ = 0;
2808             }
2809             assert(tt > 0);
2810             *op++ = LZO_BYTE(tt);
2811         }
2812         do *op++ = *ii++; while (--t > 0);
2813     }
2814 
2815     *op++ = M4_MARKER | 1;
2816     *op++ = 0;
2817     *op++ = 0;
2818 
2819     *out_len = pd(op, out);
2820     return LZO_E_OK;
2821 }
2822 
2823 #endif
2824 
2825 #undef do_compress
2826 #undef DO_COMPRESS
2827 #undef LZO_HASH
2828 
2829 #undef LZO_TEST_OVERRUN
2830 #undef DO_DECOMPRESS
2831 #define DO_DECOMPRESS       lzo1x_decompress
2832 
2833 #if !defined(MINILZO_CFG_SKIP_LZO1X_DECOMPRESS)
2834 
2835 #if defined(LZO_TEST_OVERRUN)
2836 #  if !defined(LZO_TEST_OVERRUN_INPUT)
2837 #    define LZO_TEST_OVERRUN_INPUT       2
2838 #  endif
2839 #  if !defined(LZO_TEST_OVERRUN_OUTPUT)
2840 #    define LZO_TEST_OVERRUN_OUTPUT      2
2841 #  endif
2842 #  if !defined(LZO_TEST_OVERRUN_LOOKBEHIND)
2843 #    define LZO_TEST_OVERRUN_LOOKBEHIND
2844 #  endif
2845 #endif
2846 
2847 #undef TEST_IP
2848 #undef TEST_OP
2849 #undef TEST_LB
2850 #undef TEST_LBO
2851 #undef NEED_IP
2852 #undef NEED_OP
2853 #undef HAVE_TEST_IP
2854 #undef HAVE_TEST_OP
2855 #undef HAVE_NEED_IP
2856 #undef HAVE_NEED_OP
2857 #undef HAVE_ANY_IP
2858 #undef HAVE_ANY_OP
2859 
2860 #if defined(LZO_TEST_OVERRUN_INPUT)
2861 #  if (LZO_TEST_OVERRUN_INPUT >= 1)
2862 #    define TEST_IP             (ip < ip_end)
2863 #  endif
2864 #  if (LZO_TEST_OVERRUN_INPUT >= 2)
2865 #    define NEED_IP(x) \
2866             if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x))  goto input_overrun
2867 #  endif
2868 #endif
2869 
2870 #if defined(LZO_TEST_OVERRUN_OUTPUT)
2871 #  if (LZO_TEST_OVERRUN_OUTPUT >= 1)
2872 #    define TEST_OP             (op <= op_end)
2873 #  endif
2874 #  if (LZO_TEST_OVERRUN_OUTPUT >= 2)
2875 #    undef TEST_OP
2876 #    define NEED_OP(x) \
2877             if ((lzo_uint)(op_end - op) < (lzo_uint)(x))  goto output_overrun
2878 #  endif
2879 #endif
2880 
2881 #if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
2882 #  define TEST_LB(m_pos)        if (m_pos < out || m_pos >= op) goto lookbehind_overrun
2883 #  define TEST_LBO(m_pos,o)     if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun
2884 #else
2885 #  define TEST_LB(m_pos)        ((void) 0)
2886 #  define TEST_LBO(m_pos,o)     ((void) 0)
2887 #endif
2888 
2889 #if !defined(LZO_EOF_CODE) && !defined(TEST_IP)
2890 #  define TEST_IP               (ip < ip_end)
2891 #endif
2892 
2893 #if defined(TEST_IP)
2894 #  define HAVE_TEST_IP
2895 #else
2896 #  define TEST_IP               1
2897 #endif
2898 #if defined(TEST_OP)
2899 #  define HAVE_TEST_OP
2900 #else
2901 #  define TEST_OP               1
2902 #endif
2903 
2904 #if defined(NEED_IP)
2905 #  define HAVE_NEED_IP
2906 #else
2907 #  define NEED_IP(x)            ((void) 0)
2908 #endif
2909 #if defined(NEED_OP)
2910 #  define HAVE_NEED_OP
2911 #else
2912 #  define NEED_OP(x)            ((void) 0)
2913 #endif
2914 
2915 #if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP)
2916 #  define HAVE_ANY_IP
2917 #endif
2918 #if defined(HAVE_TEST_OP) || defined(HAVE_NEED_OP)
2919 #  define HAVE_ANY_OP
2920 #endif
2921 
2922 #undef __COPY4
2923 #define __COPY4(dst,src)    * (lzo_uint32p)(dst) = * (const lzo_uint32p)(src)
2924 
2925 #undef COPY4
2926 #if defined(LZO_UNALIGNED_OK_4)
2927 #  define COPY4(dst,src)    __COPY4(dst,src)
2928 #elif defined(LZO_ALIGNED_OK_4)
2929 #  define COPY4(dst,src)    __COPY4((lzo_uintptr_t)(dst),(lzo_uintptr_t)(src))
2930 #endif
2931 
2932 #if defined(DO_DECOMPRESS)
2933 LZO_PUBLIC(int)
DO_DECOMPRESS(const lzo_bytep in,lzo_uint in_len,lzo_bytep out,lzo_uintp out_len,lzo_voidp wrkmem)2934 DO_DECOMPRESS  ( const lzo_bytep in , lzo_uint  in_len,
2935                        lzo_bytep out, lzo_uintp out_len,
2936                        lzo_voidp wrkmem )
2937 #endif
2938 {
2939     register lzo_bytep op;
2940     register const lzo_bytep ip;
2941     register lzo_uint t;
2942 #if defined(COPY_DICT)
2943     lzo_uint m_off;
2944     const lzo_bytep dict_end;
2945 #else
2946     register const lzo_bytep m_pos;
2947 #endif
2948 
2949     const lzo_bytep const ip_end = in + in_len;
2950 #if defined(HAVE_ANY_OP)
2951     lzo_bytep const op_end = out + *out_len;
2952 #endif
2953 #if defined(LZO1Z)
2954     lzo_uint last_m_off = 0;
2955 #endif
2956 
2957     LZO_UNUSED(wrkmem);
2958 
2959 #if defined(COPY_DICT)
2960     if (dict)
2961     {
2962         if (dict_len > M4_MAX_OFFSET)
2963         {
2964             dict += dict_len - M4_MAX_OFFSET;
2965             dict_len = M4_MAX_OFFSET;
2966         }
2967         dict_end = dict + dict_len;
2968     }
2969     else
2970     {
2971         dict_len = 0;
2972         dict_end = NULL;
2973     }
2974 #endif
2975 
2976     *out_len = 0;
2977 
2978     op = out;
2979     ip = in;
2980 
2981     if (*ip > 17)
2982     {
2983         t = *ip++ - 17;
2984         if (t < 4)
2985             goto match_next;
2986         assert(t > 0); NEED_OP(t); NEED_IP(t+1);
2987         do *op++ = *ip++; while (--t > 0);
2988         goto first_literal_run;
2989     }
2990 
2991     while (TEST_IP && TEST_OP)
2992     {
2993         t = *ip++;
2994         if (t >= 16)
2995             goto match;
2996         if (t == 0)
2997         {
2998             NEED_IP(1);
2999             while (*ip == 0)
3000             {
3001                 t += 255;
3002                 ip++;
3003                 NEED_IP(1);
3004             }
3005             t += 15 + *ip++;
3006         }
3007         assert(t > 0); NEED_OP(t+3); NEED_IP(t+4);
3008 #if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
3009 #if !defined(LZO_UNALIGNED_OK_4)
3010         if (PTR_ALIGNED2_4(op,ip))
3011         {
3012 #endif
3013         COPY4(op,ip);
3014         op += 4; ip += 4;
3015         if (--t > 0)
3016         {
3017             if (t >= 4)
3018             {
3019                 do {
3020                     COPY4(op,ip);
3021                     op += 4; ip += 4; t -= 4;
3022                 } while (t >= 4);
3023                 if (t > 0) do *op++ = *ip++; while (--t > 0);
3024             }
3025             else
3026                 do *op++ = *ip++; while (--t > 0);
3027         }
3028 #if !defined(LZO_UNALIGNED_OK_4)
3029         }
3030         else
3031 #endif
3032 #endif
3033 #if !defined(LZO_UNALIGNED_OK_4)
3034         {
3035             *op++ = *ip++; *op++ = *ip++; *op++ = *ip++;
3036             do *op++ = *ip++; while (--t > 0);
3037         }
3038 #endif
3039 
3040 first_literal_run:
3041 
3042         t = *ip++;
3043         if (t >= 16)
3044             goto match;
3045 #if defined(COPY_DICT)
3046 #if defined(LZO1Z)
3047         m_off = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
3048         last_m_off = m_off;
3049 #else
3050         m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2);
3051 #endif
3052         NEED_OP(3);
3053         t = 3; COPY_DICT(t,m_off)
3054 #else
3055 #if defined(LZO1Z)
3056         t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
3057         m_pos = op - t;
3058         last_m_off = t;
3059 #else
3060         m_pos = op - (1 + M2_MAX_OFFSET);
3061         m_pos -= t >> 2;
3062         m_pos -= *ip++ << 2;
3063 #endif
3064         TEST_LB(m_pos); NEED_OP(3);
3065         *op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos;
3066 #endif
3067         goto match_done;
3068 
3069         do {
3070 match:
3071             if (t >= 64)
3072             {
3073 #if defined(COPY_DICT)
3074 #if defined(LZO1X)
3075                 m_off = 1 + ((t >> 2) & 7) + (*ip++ << 3);
3076                 t = (t >> 5) - 1;
3077 #elif defined(LZO1Y)
3078                 m_off = 1 + ((t >> 2) & 3) + (*ip++ << 2);
3079                 t = (t >> 4) - 3;
3080 #elif defined(LZO1Z)
3081                 m_off = t & 0x1f;
3082                 if (m_off >= 0x1c)
3083                     m_off = last_m_off;
3084                 else
3085                 {
3086                     m_off = 1 + (m_off << 6) + (*ip++ >> 2);
3087                     last_m_off = m_off;
3088                 }
3089                 t = (t >> 5) - 1;
3090 #endif
3091 #else
3092 #if defined(LZO1X)
3093                 m_pos = op - 1;
3094                 m_pos -= (t >> 2) & 7;
3095                 m_pos -= *ip++ << 3;
3096                 t = (t >> 5) - 1;
3097 #elif defined(LZO1Y)
3098                 m_pos = op - 1;
3099                 m_pos -= (t >> 2) & 3;
3100                 m_pos -= *ip++ << 2;
3101                 t = (t >> 4) - 3;
3102 #elif defined(LZO1Z)
3103                 {
3104                     lzo_uint off = t & 0x1f;
3105                     m_pos = op;
3106                     if (off >= 0x1c)
3107                     {
3108                         assert(last_m_off > 0);
3109                         m_pos -= last_m_off;
3110                     }
3111                     else
3112                     {
3113                         off = 1 + (off << 6) + (*ip++ >> 2);
3114                         m_pos -= off;
3115                         last_m_off = off;
3116                     }
3117                 }
3118                 t = (t >> 5) - 1;
3119 #endif
3120                 TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1);
3121                 goto copy_match;
3122 #endif
3123             }
3124             else if (t >= 32)
3125             {
3126                 t &= 31;
3127                 if (t == 0)
3128                 {
3129                     NEED_IP(1);
3130                     while (*ip == 0)
3131                     {
3132                         t += 255;
3133                         ip++;
3134                         NEED_IP(1);
3135                     }
3136                     t += 31 + *ip++;
3137                 }
3138 #if defined(COPY_DICT)
3139 #if defined(LZO1Z)
3140                 m_off = 1 + (ip[0] << 6) + (ip[1] >> 2);
3141                 last_m_off = m_off;
3142 #else
3143                 m_off = 1 + (ip[0] >> 2) + (ip[1] << 6);
3144 #endif
3145 #else
3146 #if defined(LZO1Z)
3147                 {
3148                     lzo_uint off = 1 + (ip[0] << 6) + (ip[1] >> 2);
3149                     m_pos = op - off;
3150                     last_m_off = off;
3151                 }
3152 #elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN)
3153                 m_pos = op - 1;
3154                 m_pos -= (* (const lzo_ushortp) ip) >> 2;
3155 #else
3156                 m_pos = op - 1;
3157                 m_pos -= (ip[0] >> 2) + (ip[1] << 6);
3158 #endif
3159 #endif
3160                 ip += 2;
3161             }
3162             else if (t >= 16)
3163             {
3164 #if defined(COPY_DICT)
3165                 m_off = (t & 8) << 11;
3166 #else
3167                 m_pos = op;
3168                 m_pos -= (t & 8) << 11;
3169 #endif
3170                 t &= 7;
3171                 if (t == 0)
3172                 {
3173                     NEED_IP(1);
3174                     while (*ip == 0)
3175                     {
3176                         t += 255;
3177                         ip++;
3178                         NEED_IP(1);
3179                     }
3180                     t += 7 + *ip++;
3181                 }
3182 #if defined(COPY_DICT)
3183 #if defined(LZO1Z)
3184                 m_off += (ip[0] << 6) + (ip[1] >> 2);
3185 #else
3186                 m_off += (ip[0] >> 2) + (ip[1] << 6);
3187 #endif
3188                 ip += 2;
3189                 if (m_off == 0)
3190                     goto eof_found;
3191                 m_off += 0x4000;
3192 #if defined(LZO1Z)
3193                 last_m_off = m_off;
3194 #endif
3195 #else
3196 #if defined(LZO1Z)
3197                 m_pos -= (ip[0] << 6) + (ip[1] >> 2);
3198 #elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN)
3199                 m_pos -= (* (const lzo_ushortp) ip) >> 2;
3200 #else
3201                 m_pos -= (ip[0] >> 2) + (ip[1] << 6);
3202 #endif
3203                 ip += 2;
3204                 if (m_pos == op)
3205                     goto eof_found;
3206                 m_pos -= 0x4000;
3207 #if defined(LZO1Z)
3208                 last_m_off = pd((const lzo_bytep)op, m_pos);
3209 #endif
3210 #endif
3211             }
3212             else
3213             {
3214 #if defined(COPY_DICT)
3215 #if defined(LZO1Z)
3216                 m_off = 1 + (t << 6) + (*ip++ >> 2);
3217                 last_m_off = m_off;
3218 #else
3219                 m_off = 1 + (t >> 2) + (*ip++ << 2);
3220 #endif
3221                 NEED_OP(2);
3222                 t = 2; COPY_DICT(t,m_off)
3223 #else
3224 #if defined(LZO1Z)
3225                 t = 1 + (t << 6) + (*ip++ >> 2);
3226                 m_pos = op - t;
3227                 last_m_off = t;
3228 #else
3229                 m_pos = op - 1;
3230                 m_pos -= t >> 2;
3231                 m_pos -= *ip++ << 2;
3232 #endif
3233                 TEST_LB(m_pos); NEED_OP(2);
3234                 *op++ = *m_pos++; *op++ = *m_pos;
3235 #endif
3236                 goto match_done;
3237             }
3238 
3239 #if defined(COPY_DICT)
3240 
3241             NEED_OP(t+3-1);
3242             t += 3-1; COPY_DICT(t,m_off)
3243 
3244 #else
3245 
3246             TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1);
3247 #if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
3248 #if !defined(LZO_UNALIGNED_OK_4)
3249             if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos))
3250             {
3251                 assert((op - m_pos) >= 4);
3252 #else
3253             if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4)
3254             {
3255 #endif
3256                 COPY4(op,m_pos);
3257                 op += 4; m_pos += 4; t -= 4 - (3 - 1);
3258                 do {
3259                     COPY4(op,m_pos);
3260                     op += 4; m_pos += 4; t -= 4;
3261                 } while (t >= 4);
3262                 if (t > 0) do *op++ = *m_pos++; while (--t > 0);
3263             }
3264             else
3265 #endif
3266             {
3267 copy_match:
3268                 *op++ = *m_pos++; *op++ = *m_pos++;
3269                 do *op++ = *m_pos++; while (--t > 0);
3270             }
3271 
3272 #endif
3273 
3274 match_done:
3275 #if defined(LZO1Z)
3276             t = ip[-1] & 3;
3277 #else
3278             t = ip[-2] & 3;
3279 #endif
3280             if (t == 0)
3281                 break;
3282 
3283 match_next:
3284             assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+1);
3285 #if 0
3286             do *op++ = *ip++; while (--t > 0);
3287 #else
3288             *op++ = *ip++;
3289             if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } }
3290 #endif
3291             t = *ip++;
3292         } while (TEST_IP && TEST_OP);
3293     }
3294 
3295 #if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP)
3296     *out_len = pd(op, out);
3297     return LZO_E_EOF_NOT_FOUND;
3298 #endif
3299 
3300 eof_found:
3301     assert(t == 1);
3302     *out_len = pd(op, out);
3303     return (ip == ip_end ? LZO_E_OK :
3304            (ip < ip_end  ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
3305 
3306 #if defined(HAVE_NEED_IP)
3307 input_overrun:
3308     *out_len = pd(op, out);
3309     return LZO_E_INPUT_OVERRUN;
3310 #endif
3311 
3312 #if defined(HAVE_NEED_OP)
3313 output_overrun:
3314     *out_len = pd(op, out);
3315     return LZO_E_OUTPUT_OVERRUN;
3316 #endif
3317 
3318 #if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
3319 lookbehind_overrun:
3320     *out_len = pd(op, out);
3321     return LZO_E_LOOKBEHIND_OVERRUN;
3322 #endif
3323 }
3324 
3325 #endif
3326 
3327 #define LZO_TEST_OVERRUN
3328 #undef DO_DECOMPRESS
3329 #define DO_DECOMPRESS       lzo1x_decompress_safe
3330 
3331 #if !defined(MINILZO_CFG_SKIP_LZO1X_DECOMPRESS_SAFE)
3332 
3333 #if defined(LZO_TEST_OVERRUN)
3334 #  if !defined(LZO_TEST_OVERRUN_INPUT)
3335 #    define LZO_TEST_OVERRUN_INPUT       2
3336 #  endif
3337 #  if !defined(LZO_TEST_OVERRUN_OUTPUT)
3338 #    define LZO_TEST_OVERRUN_OUTPUT      2
3339 #  endif
3340 #  if !defined(LZO_TEST_OVERRUN_LOOKBEHIND)
3341 #    define LZO_TEST_OVERRUN_LOOKBEHIND
3342 #  endif
3343 #endif
3344 
3345 #undef TEST_IP
3346 #undef TEST_OP
3347 #undef TEST_LB
3348 #undef TEST_LBO
3349 #undef NEED_IP
3350 #undef NEED_OP
3351 #undef HAVE_TEST_IP
3352 #undef HAVE_TEST_OP
3353 #undef HAVE_NEED_IP
3354 #undef HAVE_NEED_OP
3355 #undef HAVE_ANY_IP
3356 #undef HAVE_ANY_OP
3357 
3358 #if defined(LZO_TEST_OVERRUN_INPUT)
3359 #  if (LZO_TEST_OVERRUN_INPUT >= 1)
3360 #    define TEST_IP             (ip < ip_end)
3361 #  endif
3362 #  if (LZO_TEST_OVERRUN_INPUT >= 2)
3363 #    define NEED_IP(x) \
3364             if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x))  goto input_overrun
3365 #  endif
3366 #endif
3367 
3368 #if defined(LZO_TEST_OVERRUN_OUTPUT)
3369 #  if (LZO_TEST_OVERRUN_OUTPUT >= 1)
3370 #    define TEST_OP             (op <= op_end)
3371 #  endif
3372 #  if (LZO_TEST_OVERRUN_OUTPUT >= 2)
3373 #    undef TEST_OP
3374 #    define NEED_OP(x) \
3375             if ((lzo_uint)(op_end - op) < (lzo_uint)(x))  goto output_overrun
3376 #  endif
3377 #endif
3378 
3379 #if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
3380 #  define TEST_LB(m_pos)        if (m_pos < out || m_pos >= op) goto lookbehind_overrun
3381 #  define TEST_LBO(m_pos,o)     if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun
3382 #else
3383 #  define TEST_LB(m_pos)        ((void) 0)
3384 #  define TEST_LBO(m_pos,o)     ((void) 0)
3385 #endif
3386 
3387 #if !defined(LZO_EOF_CODE) && !defined(TEST_IP)
3388 #  define TEST_IP               (ip < ip_end)
3389 #endif
3390 
3391 #if defined(TEST_IP)
3392 #  define HAVE_TEST_IP
3393 #else
3394 #  define TEST_IP               1
3395 #endif
3396 #if defined(TEST_OP)
3397 #  define HAVE_TEST_OP
3398 #else
3399 #  define TEST_OP               1
3400 #endif
3401 
3402 #if defined(NEED_IP)
3403 #  define HAVE_NEED_IP
3404 #else
3405 #  define NEED_IP(x)            ((void) 0)
3406 #endif
3407 #if defined(NEED_OP)
3408 #  define HAVE_NEED_OP
3409 #else
3410 #  define NEED_OP(x)            ((void) 0)
3411 #endif
3412 
3413 #if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP)
3414 #  define HAVE_ANY_IP
3415 #endif
3416 #if defined(HAVE_TEST_OP) || defined(HAVE_NEED_OP)
3417 #  define HAVE_ANY_OP
3418 #endif
3419 
3420 #undef __COPY4
3421 #define __COPY4(dst,src)    * (lzo_uint32p)(dst) = * (const lzo_uint32p)(src)
3422 
3423 #undef COPY4
3424 #if defined(LZO_UNALIGNED_OK_4)
3425 #  define COPY4(dst,src)    __COPY4(dst,src)
3426 #elif defined(LZO_ALIGNED_OK_4)
3427 #  define COPY4(dst,src)    __COPY4((lzo_uintptr_t)(dst),(lzo_uintptr_t)(src))
3428 #endif
3429 
3430 #if defined(DO_DECOMPRESS)
3431 LZO_PUBLIC(int)
3432 DO_DECOMPRESS  ( const lzo_bytep in , lzo_uint  in_len,
3433                        lzo_bytep out, lzo_uintp out_len,
3434                        lzo_voidp wrkmem )
3435 #endif
3436 {
3437     register lzo_bytep op;
3438     register const lzo_bytep ip;
3439     register lzo_uint t;
3440 #if defined(COPY_DICT)
3441     lzo_uint m_off;
3442     const lzo_bytep dict_end;
3443 #else
3444     register const lzo_bytep m_pos;
3445 #endif
3446 
3447     const lzo_bytep const ip_end = in + in_len;
3448 #if defined(HAVE_ANY_OP)
3449     lzo_bytep const op_end = out + *out_len;
3450 #endif
3451 #if defined(LZO1Z)
3452     lzo_uint last_m_off = 0;
3453 #endif
3454 
3455     LZO_UNUSED(wrkmem);
3456 
3457 #if defined(COPY_DICT)
3458     if (dict)
3459     {
3460         if (dict_len > M4_MAX_OFFSET)
3461         {
3462             dict += dict_len - M4_MAX_OFFSET;
3463             dict_len = M4_MAX_OFFSET;
3464         }
3465         dict_end = dict + dict_len;
3466     }
3467     else
3468     {
3469         dict_len = 0;
3470         dict_end = NULL;
3471     }
3472 #endif
3473 
3474     *out_len = 0;
3475 
3476     op = out;
3477     ip = in;
3478 
3479     if (*ip > 17)
3480     {
3481         t = *ip++ - 17;
3482         if (t < 4)
3483             goto match_next;
3484         assert(t > 0); NEED_OP(t); NEED_IP(t+1);
3485         do *op++ = *ip++; while (--t > 0);
3486         goto first_literal_run;
3487     }
3488 
3489     while (TEST_IP && TEST_OP)
3490     {
3491         t = *ip++;
3492         if (t >= 16)
3493             goto match;
3494         if (t == 0)
3495         {
3496             NEED_IP(1);
3497             while (*ip == 0)
3498             {
3499                 t += 255;
3500                 ip++;
3501                 NEED_IP(1);
3502             }
3503             t += 15 + *ip++;
3504         }
3505         assert(t > 0); NEED_OP(t+3); NEED_IP(t+4);
3506 #if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
3507 #if !defined(LZO_UNALIGNED_OK_4)
3508         if (PTR_ALIGNED2_4(op,ip))
3509         {
3510 #endif
3511         COPY4(op,ip);
3512         op += 4; ip += 4;
3513         if (--t > 0)
3514         {
3515             if (t >= 4)
3516             {
3517                 do {
3518                     COPY4(op,ip);
3519                     op += 4; ip += 4; t -= 4;
3520                 } while (t >= 4);
3521                 if (t > 0) do *op++ = *ip++; while (--t > 0);
3522             }
3523             else
3524                 do *op++ = *ip++; while (--t > 0);
3525         }
3526 #if !defined(LZO_UNALIGNED_OK_4)
3527         }
3528         else
3529 #endif
3530 #endif
3531 #if !defined(LZO_UNALIGNED_OK_4)
3532         {
3533             *op++ = *ip++; *op++ = *ip++; *op++ = *ip++;
3534             do *op++ = *ip++; while (--t > 0);
3535         }
3536 #endif
3537 
3538 first_literal_run:
3539 
3540         t = *ip++;
3541         if (t >= 16)
3542             goto match;
3543 #if defined(COPY_DICT)
3544 #if defined(LZO1Z)
3545         m_off = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
3546         last_m_off = m_off;
3547 #else
3548         m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2);
3549 #endif
3550         NEED_OP(3);
3551         t = 3; COPY_DICT(t,m_off)
3552 #else
3553 #if defined(LZO1Z)
3554         t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
3555         m_pos = op - t;
3556         last_m_off = t;
3557 #else
3558         m_pos = op - (1 + M2_MAX_OFFSET);
3559         m_pos -= t >> 2;
3560         m_pos -= *ip++ << 2;
3561 #endif
3562         TEST_LB(m_pos); NEED_OP(3);
3563         *op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos;
3564 #endif
3565         goto match_done;
3566 
3567         do {
3568 match:
3569             if (t >= 64)
3570             {
3571 #if defined(COPY_DICT)
3572 #if defined(LZO1X)
3573                 m_off = 1 + ((t >> 2) & 7) + (*ip++ << 3);
3574                 t = (t >> 5) - 1;
3575 #elif defined(LZO1Y)
3576                 m_off = 1 + ((t >> 2) & 3) + (*ip++ << 2);
3577                 t = (t >> 4) - 3;
3578 #elif defined(LZO1Z)
3579                 m_off = t & 0x1f;
3580                 if (m_off >= 0x1c)
3581                     m_off = last_m_off;
3582                 else
3583                 {
3584                     m_off = 1 + (m_off << 6) + (*ip++ >> 2);
3585                     last_m_off = m_off;
3586                 }
3587                 t = (t >> 5) - 1;
3588 #endif
3589 #else
3590 #if defined(LZO1X)
3591                 m_pos = op - 1;
3592                 m_pos -= (t >> 2) & 7;
3593                 m_pos -= *ip++ << 3;
3594                 t = (t >> 5) - 1;
3595 #elif defined(LZO1Y)
3596                 m_pos = op - 1;
3597                 m_pos -= (t >> 2) & 3;
3598                 m_pos -= *ip++ << 2;
3599                 t = (t >> 4) - 3;
3600 #elif defined(LZO1Z)
3601                 {
3602                     lzo_uint off = t & 0x1f;
3603                     m_pos = op;
3604                     if (off >= 0x1c)
3605                     {
3606                         assert(last_m_off > 0);
3607                         m_pos -= last_m_off;
3608                     }
3609                     else
3610                     {
3611                         off = 1 + (off << 6) + (*ip++ >> 2);
3612                         m_pos -= off;
3613                         last_m_off = off;
3614                     }
3615                 }
3616                 t = (t >> 5) - 1;
3617 #endif
3618                 TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1);
3619                 goto copy_match;
3620 #endif
3621             }
3622             else if (t >= 32)
3623             {
3624                 t &= 31;
3625                 if (t == 0)
3626                 {
3627                     NEED_IP(1);
3628                     while (*ip == 0)
3629                     {
3630                         t += 255;
3631                         ip++;
3632                         NEED_IP(1);
3633                     }
3634                     t += 31 + *ip++;
3635                 }
3636 #if defined(COPY_DICT)
3637 #if defined(LZO1Z)
3638                 m_off = 1 + (ip[0] << 6) + (ip[1] >> 2);
3639                 last_m_off = m_off;
3640 #else
3641                 m_off = 1 + (ip[0] >> 2) + (ip[1] << 6);
3642 #endif
3643 #else
3644 #if defined(LZO1Z)
3645                 {
3646                     lzo_uint off = 1 + (ip[0] << 6) + (ip[1] >> 2);
3647                     m_pos = op - off;
3648                     last_m_off = off;
3649                 }
3650 #elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN)
3651                 m_pos = op - 1;
3652                 m_pos -= (* (const lzo_ushortp) ip) >> 2;
3653 #else
3654                 m_pos = op - 1;
3655                 m_pos -= (ip[0] >> 2) + (ip[1] << 6);
3656 #endif
3657 #endif
3658                 ip += 2;
3659             }
3660             else if (t >= 16)
3661             {
3662 #if defined(COPY_DICT)
3663                 m_off = (t & 8) << 11;
3664 #else
3665                 m_pos = op;
3666                 m_pos -= (t & 8) << 11;
3667 #endif
3668                 t &= 7;
3669                 if (t == 0)
3670                 {
3671                     NEED_IP(1);
3672                     while (*ip == 0)
3673                     {
3674                         t += 255;
3675                         ip++;
3676                         NEED_IP(1);
3677                     }
3678                     t += 7 + *ip++;
3679                 }
3680 #if defined(COPY_DICT)
3681 #if defined(LZO1Z)
3682                 m_off += (ip[0] << 6) + (ip[1] >> 2);
3683 #else
3684                 m_off += (ip[0] >> 2) + (ip[1] << 6);
3685 #endif
3686                 ip += 2;
3687                 if (m_off == 0)
3688                     goto eof_found;
3689                 m_off += 0x4000;
3690 #if defined(LZO1Z)
3691                 last_m_off = m_off;
3692 #endif
3693 #else
3694 #if defined(LZO1Z)
3695                 m_pos -= (ip[0] << 6) + (ip[1] >> 2);
3696 #elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN)
3697                 m_pos -= (* (const lzo_ushortp) ip) >> 2;
3698 #else
3699                 m_pos -= (ip[0] >> 2) + (ip[1] << 6);
3700 #endif
3701                 ip += 2;
3702                 if (m_pos == op)
3703                     goto eof_found;
3704                 m_pos -= 0x4000;
3705 #if defined(LZO1Z)
3706                 last_m_off = pd((const lzo_bytep)op, m_pos);
3707 #endif
3708 #endif
3709             }
3710             else
3711             {
3712 #if defined(COPY_DICT)
3713 #if defined(LZO1Z)
3714                 m_off = 1 + (t << 6) + (*ip++ >> 2);
3715                 last_m_off = m_off;
3716 #else
3717                 m_off = 1 + (t >> 2) + (*ip++ << 2);
3718 #endif
3719                 NEED_OP(2);
3720                 t = 2; COPY_DICT(t,m_off)
3721 #else
3722 #if defined(LZO1Z)
3723                 t = 1 + (t << 6) + (*ip++ >> 2);
3724                 m_pos = op - t;
3725                 last_m_off = t;
3726 #else
3727                 m_pos = op - 1;
3728                 m_pos -= t >> 2;
3729                 m_pos -= *ip++ << 2;
3730 #endif
3731                 TEST_LB(m_pos); NEED_OP(2);
3732                 *op++ = *m_pos++; *op++ = *m_pos;
3733 #endif
3734                 goto match_done;
3735             }
3736 
3737 #if defined(COPY_DICT)
3738 
3739             NEED_OP(t+3-1);
3740             t += 3-1; COPY_DICT(t,m_off)
3741 
3742 #else
3743 
3744             TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1);
3745 #if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
3746 #if !defined(LZO_UNALIGNED_OK_4)
3747             if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos))
3748             {
3749                 assert((op - m_pos) >= 4);
3750 #else
3751             if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4)
3752             {
3753 #endif
3754                 COPY4(op,m_pos);
3755                 op += 4; m_pos += 4; t -= 4 - (3 - 1);
3756                 do {
3757                     COPY4(op,m_pos);
3758                     op += 4; m_pos += 4; t -= 4;
3759                 } while (t >= 4);
3760                 if (t > 0) do *op++ = *m_pos++; while (--t > 0);
3761             }
3762             else
3763 #endif
3764             {
3765 copy_match:
3766                 *op++ = *m_pos++; *op++ = *m_pos++;
3767                 do *op++ = *m_pos++; while (--t > 0);
3768             }
3769 
3770 #endif
3771 
3772 match_done:
3773 #if defined(LZO1Z)
3774             t = ip[-1] & 3;
3775 #else
3776             t = ip[-2] & 3;
3777 #endif
3778             if (t == 0)
3779                 break;
3780 
3781 match_next:
3782             assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+1);
3783 #if 0
3784             do *op++ = *ip++; while (--t > 0);
3785 #else
3786             *op++ = *ip++;
3787             if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } }
3788 #endif
3789             t = *ip++;
3790         } while (TEST_IP && TEST_OP);
3791     }
3792 
3793 #if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP)
3794     *out_len = pd(op, out);
3795     return LZO_E_EOF_NOT_FOUND;
3796 #endif
3797 
3798 eof_found:
3799     assert(t == 1);
3800     *out_len = pd(op, out);
3801     return (ip == ip_end ? LZO_E_OK :
3802            (ip < ip_end  ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
3803 
3804 #if defined(HAVE_NEED_IP)
3805 input_overrun:
3806     *out_len = pd(op, out);
3807     return LZO_E_INPUT_OVERRUN;
3808 #endif
3809 
3810 #if defined(HAVE_NEED_OP)
3811 output_overrun:
3812     *out_len = pd(op, out);
3813     return LZO_E_OUTPUT_OVERRUN;
3814 #endif
3815 
3816 #if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
3817 lookbehind_overrun:
3818     *out_len = pd(op, out);
3819     return LZO_E_LOOKBEHIND_OVERRUN;
3820 #endif
3821 }
3822 
3823 #endif
3824 
3825 /***** End of minilzo.c *****/
3826 
3827