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