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